Mastodon Filter Editor: Move Add Keywords Button

Modifies the keyword insertion behavior in Mastodon's filter edit page - moves the "Add Keyword" form above the list and changes insertion to prepend new keywords at the top

  1. // ==UserScript==
  2. // @name Mastodon Filter Editor: Move Add Keywords Button
  3. // @description Modifies the keyword insertion behavior in Mastodon's filter edit page - moves the "Add Keyword" form above the list and changes insertion to prepend new keywords at the top
  4. // @match https://mastodon.social/filters/*/edit
  5. // @version 0.0.1.20250521181415
  6. // @namespace https://gf.qytechs.cn/users/1435046
  7. // ==/UserScript==
  8.  
  9. if (/^\/filters\/\d+\/edit$/.test(location.pathname)) {
  10. const anchor = document.querySelector('a.add_fields');
  11. if (anchor) {
  12.  
  13. // Change insertion method to 'prepend'
  14. anchor.setAttribute('data-association-insertion-method', 'prepend');
  15.  
  16. // Change insertion target to second tbody
  17. anchor.setAttribute('data-association-insertion-node', '.keywords-table tbody:nth-of-type(2)');
  18.  
  19. const originalTfoot = anchor.closest('tfoot');
  20. if (originalTfoot) {
  21. // Grab the inner rows HTML
  22. const rowsHtml = originalTfoot.innerHTML;
  23. const table = originalTfoot.closest('table');
  24. const thead = table && table.querySelector('thead');
  25. if (table && thead) {
  26. // Remove the old tfoot
  27. originalTfoot.remove();
  28. // Create a new tbody, inject the rows
  29. const newTbody = document.createElement('tbody');
  30. newTbody.innerHTML = rowsHtml;
  31. // Insert right after the thead
  32. thead.insertAdjacentElement('afterend', newTbody);
  33. }
  34. }
  35.  
  36. // Scope to the form
  37. const form = document.querySelector('form.edit_custom_filter');
  38. if (form) {
  39. const actionsDiv = form.querySelector('div.actions');
  40. const tableWrapper = form.querySelector('div.table-wrapper');
  41. if (actionsDiv && tableWrapper && tableWrapper.parentNode) {
  42. tableWrapper.parentNode.insertBefore(actionsDiv, tableWrapper);
  43. }
  44. }
  45. }
  46. }

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址