Files

56 lines
1.9 KiB
JavaScript

// ==UserScript==
// @name 强制暗黑模式 - 192.168.0.87 (V2.0 滤镜版)
// @namespace http://tampermonkey.net/
// @version 2.0
// @description 使用CSS滤镜强制反色,无视任何CSS优先级锁定。
// @author AI Assistant
// @match http://192.168.0.87:7575/*
// @grant none
// @run-at document-start
// ==/UserScript==
(function() {
'use strict';
// 1. 定义滤镜样式 (优先级高于任何CSS)
const filterCSS = `
/* 全局反色,模拟暗黑模式 */
html {
filter: invert(90%) hue-rotate(180deg) !important;
background-color: #000 !important;
}
/* 反转图片和视频,防止它们变成负片 */
img, video, canvas, svg {
filter: invert(100%) hue-rotate(180deg) !important;
}
/* 修正Lucide图标在滤镜下的显示 */
svg[data-lucide] {
filter: invert(100%) hue-rotate(180deg) brightness(1.2) !important;
}
`;
// 2. 注入函数
function injectFilter() {
if (document.getElementById('tm-dark-filter')) {
console.log('[DarkMode V2] 滤镜已存在');
return;
}
const style = document.createElement('style');
style.id = 'tm-dark-filter';
style.textContent = filterCSS;
(document.head || document.documentElement).appendChild(style);
console.log('[DarkMode V2] 滤镜样式已注入');
}
// 3. 立即执行
console.log('[DarkMode V2] 脚本启动, readyState:', document.readyState);
injectFilter();
// 4. 监听DOM变化,防止SPA动态内容丢失滤镜
const observer = new MutationObserver(() => {
injectFilter();
});
observer.observe(document.documentElement, { childList: true, subtree: true });
console.log('[DarkMode V2] MutationObserver 已启动');
})();