Settings Tab Manager (STM)

Provides an API for other userscripts to add tabs to a site's settings menu.

目前為 2025-04-22 提交的版本,檢視 最新版本

此腳本不應該直接安裝,它是一個供其他腳本使用的函式庫。欲使用本函式庫,請在腳本 metadata 寫上: // @require https://update.cn-greasyfork.org/scripts/533630/1575656/Settings%20Tab%20Manager%20%28STM%29.js

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Settings Tab Manager (STM)
// @namespace    shared-settings-manager
// @version      1.1.2 // Incremented version
// @description  Provides an API for other userscripts to add tabs to a site's settings menu.
// @author       Your Name (or AI Collaborator)
// @license      MIT
// @match        https://8chan.moe/*
// @match        https://8chan.se/*
// @grant        GM_addStyle
// @run-at       document-idle
// ==/UserScript==

(function() {
    'use strict';

    // ... (Constants, State, Readiness Promise, Public API Definition, Styling remain the same) ...
    const log = (...args) => console.log(`[${MANAGER_ID}]`, ...args);
    const warn = (...args) => console.warn(`[${MANAGER_ID}]`, ...args);
    const error = (...args) => console.error(`[${MANAGER_ID}]`, ...args);
    const MANAGER_ID = 'SettingsTabManager';
    const SELECTORS = {/* ... */};
    const ACTIVE_CLASSES = {/* ... */};
    const ATTRS = {/* ... */};


    // ... (findSettingsElements, deactivateCurrentTab, activateTab remain the same) ...
    function activateTab(scriptId) { /* ... same code ... */ }
    function deactivateCurrentTab() { /* ... same code ... */ }

    /** Handles clicks within the tab container. */
    function handleTabClick(event) {
        // Find the closest ancestor tab element that was created by STM
        const clickedTab = event.target.closest(`span[${ATTRS.MANAGED}][${ATTRS.SCRIPT_ID}]`);

        if (clickedTab) {
            // REMOVED: event.stopPropagation(); - Let the event bubble up for the site's handlers
            const scriptId = clickedTab.getAttribute(ATTRS.SCRIPT_ID);
            if (scriptId) {
                activateTab(scriptId); // Call the internal activate function
            }
        } else {
             // If a non-STM tab was clicked, make sure our active tab is deactivated
             // Check if the actual clicked target or its ancestor is a site tab NOT managed by STM
             if (event.target.closest(`${SELECTORS.SITE_TAB}:not([${ATTRS.MANAGED}])`)) {
                 deactivateCurrentTab();
             }
        }
    }

    // ... (attachTabClickListener, createSeparator, createTabAndPanel, processPendingRegistrations remain the same) ...
    function createTabAndPanel(config) { /* ... same code ... */ }
    function attachTabClickListener() { /* ... same code ... */ }


    // ... (Initialization, Observer, API Implementation, Global Exposure remain the same) ...
    function initializeManager() { /* ... same code ... */ }
    const observer = new MutationObserver(/* ... */);
    // ... start observer ...
    // ... initializeManager() call ...
    // ... API Implementation functions (registerTabImpl etc.) ...
    // ... Global Exposure logic ...

})();