智能展开折叠内容;防冲突、防误杀、高性能、用户友好
// ==UserScript==
// @name 网页自动展开(优化版·防冲突)
// @version 1.1.2
// @description 智能展开折叠内容;防冲突、防误杀、高性能、用户友好
// @namespace Kiwifruit13
// @match *://*/*
// @run-at document-start
// @grant GM_setValue
// @grant GM_getValue
// @grant GM_registerMenuCommand
// @grant GM_notification
// @license MIT
// ==/UserScript==
(() => {
'use strict';
// 命名空间隔离
const AE_PREFIX = 'ae_';
const AE_DATA_PREFIX = 'data-ae-';
// 配置管理
const Config = {
get: (key, defaultValue) => GM_getValue(`${AE_PREFIX}${key}`, defaultValue),
set: (key, value) => GM_setValue(`${AE_PREFIX}${key}`, value),
init() {
this.enabled = this.get('enabled', true);
this.scanInterval = this.get('scan_interval', 300);
this.excludeHosts = this.get('exclude_hosts', []);
}
};
// 状态管理
const State = {
expandedSet: new WeakSet(),
clickedSet: new WeakSet(),
scannedSet: new WeakSet(),
observers: new Set()
};
// 工具函数
const Utils = {
debounce(func, wait) {
let timeout;
return function executedFunction(...args) {
const later = () => {
clearTimeout(timeout);
func(...args);
};
clearTimeout(timeout);
timeout = setTimeout(later, wait);
};
},
throttle(func, limit) {
let inThrottle;
return function () {
const args = arguments;
const context = this;
if (!inThrottle) {
func.apply(context, args);
inThrottle = true;
setTimeout(() => {
inThrottle = false;
}, limit);
}
};
} // ← 这个 } 是 throttle 方法的闭合
};
// 核心逻辑
const Core = {
init() {
if (!Config.enabled) return;
// 检测冲突
if (this.detectConflicts()) return;
// 初始化观察者
this.initObservers();
// 初始扫描
this.initialScan();
},
detectConflicts() {
// 检测逻辑
return false;
},
initObservers() {
// 观察者初始化
},
initialScan() {
// 初始扫描逻辑
},
scanElement(element) {
// 元素扫描逻辑
}
};
// 用户界面
const UI = {
showNotification(message) {
GM_notification({
text: message,
title: '自动展开',
timeout: 3000
});
},
createConfigPanel() {
// 配置面板逻辑
}
};
// 初始化
Config.init();
Core.init();
// 注册菜单
GM_registerMenuCommand('⚙️ 自动展开配置', UI.createConfigPanel);
})();