Aizex Booster 是一款专门为 Aizex 镜像站 开发的浏览器扩展插件。它提供了一系列实用的增强功能,包括界面元素的显示与隐藏控制、整体界面布局优化及自定义头像等。这些功能能够有效提升用户的浏览体验,让界面使用更加流畅、高效且富有个性化特色。
当前为
// ==UserScript==
// @name Aizex增强插件
// @namespace https://www.klaio.top/
// @version 1.0.5
// @description Aizex Booster 是一款专门为 Aizex 镜像站 开发的浏览器扩展插件。它提供了一系列实用的增强功能,包括界面元素的显示与隐藏控制、整体界面布局优化及自定义头像等。这些功能能够有效提升用户的浏览体验,让界面使用更加流畅、高效且富有个性化特色。
// @author NianBroken
// @match *://*.mana-x.aizex.net/*
// @match *://*.arc-x.aizex.me/*
// @match *://*.leopard-x.memofun.net/*
// @grant GM_addStyle
// @run-at document-start
// @icon https://aizex.me/favicon.ico
// @homepageURL https://github.com/NianBroken/Aizex-Booster
// @supportURL https://github.com/NianBroken/Aizex-Booster/issues
// @copyright Copyright © 2025 NianBroken. All rights reserved.
// @license Apache-2.0 license
// ==/UserScript==
(function() {
'use strict';
// ===================================================================================
// ============================ 核心配置区域 (Core Configuration) ============================
// ===================================================================================
// 在此区域修改所有目标元素的选择器和行为,无需改动下方代码。
// 所有的元素选择器(selector)都应使用 JavaScript 的 document.querySelector 标准语法。
// ===================================================================================
const CONFIG = {
// =============================================================================
// 日志开关 (Logging Switch)
// 设置为 true: 在浏览器开发者工具的控制台(Console)中输出详细的操作日志,便于调试。
// 设置为 false: 关闭所有日志输出,用于日常稳定使用。
// =============================================================================
enableLogging: false,
// -----------------------------------------------------------------------------
// 1. 元素隐藏配置 (Element Hiding Configuration)
// -----------------------------------------------------------------------------
// - selector: 用于定位元素的 JavaScript 选择器。
// - hideMethod: 隐藏方式。
// - 'display': 隐藏元素且不保留其占用的空间 (CSS: display: none !important;)。
// - 'visibility': 隐藏元素但保留其占用的空间 (CSS: visibility: hidden !important;)。
// - enabled: 是否启用该条规则。
// -----------------------------------------------------------------------------
hideElements: [
{
selector: `#toggleButton`,
hideMethod: 'display',
enabled: true
},
{
selector: `#StatusSidebar`,
hideMethod: 'display',
enabled: true
},
{
selector: `#thread > div > div.flex.basis-auto.flex-col.-mb-\\(-\\-composer-overlap-px\\).\\[-\\-composer-overlap-px\\:24px\\].grow.overflow-hidden > div > div > div.\\@thread-xl\\/thread\\:pt-header-height.mt-1\\.5.flex.flex-col.text-sm.pb-25 > div:nth-child(5) > button`,
hideMethod: 'display',
enabled: true
}
],
// -----------------------------------------------------------------------------
// 2. 文本内容替换配置 (Text Replacement Configuration)
// -----------------------------------------------------------------------------
// - selector: 用于定位元素的 JavaScript 选择器。
// - newText: 要替换成的新文本内容。
// - enabled: 是否启用该条规则。
// -----------------------------------------------------------------------------
replaceText: [
{
selector: `#chat_limit`,
newText: 'Copyright © NianBroken. All rights reserved.',
enabled: true
}
],
// -----------------------------------------------------------------------------
// 3. 图片源替换配置 (Image Source Replacement Configuration)
// -----------------------------------------------------------------------------
// - selector: 用于定位元素的 JavaScript 选择器。
// - newSrc: 要替换成的新图片 URL。
// - enabled: 是否启用该条规则。
// -----------------------------------------------------------------------------
replaceImages: [
{
selector: `img[alt="User"][class*="rounded-xs"]`,
newSrc: 'https://www.klaio.top/images/avatar.jpg',
enabled: true
}
]
};
// ===================================================================================
// ============================ 脚本核心逻辑 (Core Script Logic) ===========================
// ============================ 请勿修改以下内容 (Do Not Modify Below) =========================
// ===================================================================================
/**
* 日志输出工具
* 根据 CONFIG.enableLogging 的值决定是否在控制台打印消息。
* @param {string} message - 要打印到控制台的消息
*/
function log(message) {
if (CONFIG.enableLogging) {
console.log(`[Aizex增强插件] ${new Date().toISOString()} - ${message}`);
}
}
/**
* 注入核心CSS样式
* 此函数在脚本启动时立即执行一次,注入用于隐藏元素的CSS规则。
* 通过添加自定义属性来触发这些预设的CSS规则,性能高且健壮。
*/
function injectBaseStyles() {
GM_addStyle(`
[data-nianbroken-hide-display="true"] {
display: none !important;
}
[data-nianbroken-hide-visibility="true"] {
visibility: hidden !important;
}
`);
log('核心CSS样式已成功注入。');
}
/**
* 应用所有配置的修改
* 这是脚本的核心执行函数,它会遍历CONFIG中的所有规则并应用它们。
* 此函数被设计为可以被反复、安全地调用,不会产生副作用。
*/
function applyAllModifications() {
log('开始执行一轮页面修改检查...');
// --- 1. 处理元素隐藏 ---
CONFIG.hideElements.forEach(item => {
if (!item.enabled) return;
try {
const element = document.querySelector(item.selector);
if (element) {
const attributeName = `data-nianbroken-hide-${item.hideMethod}`;
if (!element.hasAttribute(attributeName)) {
element.setAttribute(attributeName, 'true');
log(`成功应用隐藏规则于选择器: ${item.selector}`);
}
}
} catch (error) {
log(`错误:处理隐藏规则时出错。选择器: ${item.selector}。错误信息: ${error.message}`);
}
});
// --- 2. 处理文本替换 ---
CONFIG.replaceText.forEach(item => {
if (!item.enabled) return;
try {
const element = document.querySelector(item.selector);
if (element && element.textContent !== item.newText) {
element.textContent = item.newText;
log(`成功替换文本于选择器: ${item.selector}`);
}
} catch (error) {
log(`错误:处理文本替换时出错。选择器: ${item.selector}。错误信息: ${error.message}`);
}
});
// --- 3. 处理图片替换 ---
CONFIG.replaceImages.forEach(item => {
if (!item.enabled) return;
try {
const elements = document.querySelectorAll(item.selector);
elements.forEach(element => {
if (element && typeof element.src !== 'undefined' && element.src !== item.newSrc) {
element.src = item.newSrc;
element.setAttribute('data-nianbroken-src-modified', 'true');
log(`成功替换图片于选择器: ${item.selector}`);
}
});
} catch (error) {
log(`错误:处理图片替换时出错。选择器: ${item.selector}。错误信息: ${error.message}`);
}
});
}
/**
* 创建并启动一个MutationObserver来监视整个文档的变化。
* 这是实现“持久化”和“对抗性”的关键,确保无论页面如何动态变化,我们的修改始终生效。
*/
function setupMutationObserver() {
const observer = new MutationObserver(() => {
log('检测到页面DOM变化,重新应用所有修改...');
applyAllModifications();
});
const observerConfig = {
childList: true,
subtree: true,
attributes: true
};
const bodyObserver = new MutationObserver((mutations, obs) => {
if (document.body) {
log('检测到 <body> 元素已加载,启动主观察器。');
observer.observe(document.body, observerConfig);
applyAllModifications();
obs.disconnect();
}
});
bodyObserver.observe(document.documentElement, { childList: true });
log('脚本初始化完成,等待 <body> 加载...');
}
// ===================================================================================
// ================================ 脚本启动入口 (Script Entry Point) ================================
// ===================================================================================
log('Aizex增强插件开始运行...');
// 步骤 1: 立即注入CSS样式。
injectBaseStyles();
// 步骤 2: 启动我们的“守护进程”——MutationObserver。
setupMutationObserver();
// 步骤 3: 处理URL变化(针对单页面应用 SPA),主要用于日志记录。
let lastUrl = location.href;
new MutationObserver(() => {
const currentUrl = location.href;
if (currentUrl !== lastUrl) {
log(`检测到URL变化: 从 "${lastUrl}" 变为 "${currentUrl}"`);
lastUrl = currentUrl;
// 主MutationObserver会处理DOM变化,此处无需额外操作。
}
}).observe(document, { subtree: true, childList: true });
})();