Provides an API for other userscripts to add tabs to a site's settings menu.
当前为
此脚本不应直接安装。它是供其他脚本使用的外部库,要使用该库请加入元指令 // @require https://update.cn-greasyfork.org/scripts/533630/1575656/Settings%20Tab%20Manager%20%28STM%29.js
// ==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 ...
})();