Greasy Fork

Greasy Fork is available in English.

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

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         Mastodon Filter Editor: Move Add Keywords Button
// @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
// @match        https://mastodon.social/filters/*/edit
// @version 0.0.1.20250521181415
// @namespace http://greasyfork.icu/users/1435046
// ==/UserScript==

if (/^\/filters\/\d+\/edit$/.test(location.pathname)) {
  const anchor = document.querySelector('a.add_fields');
  if (anchor) {

    // Change insertion method to 'prepend'
    anchor.setAttribute('data-association-insertion-method', 'prepend');

    // Change insertion target to second tbody
    anchor.setAttribute('data-association-insertion-node', '.keywords-table tbody:nth-of-type(2)');

    const originalTfoot = anchor.closest('tfoot');
    if (originalTfoot) {
      // Grab the inner rows HTML
      const rowsHtml = originalTfoot.innerHTML;
      const table = originalTfoot.closest('table');
      const thead = table && table.querySelector('thead');
      if (table && thead) {
        // Remove the old tfoot
        originalTfoot.remove();
        // Create a new tbody, inject the rows
        const newTbody = document.createElement('tbody');
        newTbody.innerHTML = rowsHtml;
        // Insert right after the thead
        thead.insertAdjacentElement('afterend', newTbody);
      }
    }

    // Scope to the form
    const form = document.querySelector('form.edit_custom_filter');
    if (form) {
      const actionsDiv = form.querySelector('div.actions');
      const tableWrapper = form.querySelector('div.table-wrapper');
      if (actionsDiv && tableWrapper && tableWrapper.parentNode) {
        tableWrapper.parentNode.insertBefore(actionsDiv, tableWrapper);
      }
    }
  }
}