[JavaScript] 纯文本查看 复制代码
// ==UserScript==
// @name Discuz! 论坛暗夜模式 - 增强版
// @Namespace http://tampermonkey.net/
// @Version 3.0
// @description 更全面的暗夜模式,覆盖更多元素
// @author YourName
// @match http*://www.52pojie.cn/*
// @match http*://bbs.ijingyi.com/*
// @grant GM_addStyle
// @grant GM_setValue
// @grant GM_getValue
// @run-at document-start
// ==/UserScript==
(function() {
'use strict';
// 主题配置
const THEMES = {
dark: {
name: '暗夜模式',
bgPrimary: '#121212',
bgSecondary: '#1e1e1e',
bgTertiary: '#2a2a2a',
textPrimary: '#e0e0e0',
textSecondary: '#b0b0b0',
textTertiary: '#888888',
borderColor: '#333333',
accentColor: '#4a90e2',
linkColor: '#6bb6ff',
hoverBg: '#2a2a2a',
selectionBg: 'rgba(74, 144, 226, 0.3)',
shadowColor: 'rgba(0, 0, 0, 0.5)'
},
light: {
name: '明亮模式',
bgPrimary: '#ffffff',
bgSecondary: '#f8f9fa',
bgTertiary: '#f0f0f0',
textPrimary: '#333333',
textSecondary: '#666666',
textTertiary: '#999999',
borderColor: '#e0e0e0',
accentColor: '#4a90e2',
linkColor: '#0066cc',
hoverBg: '#f5f5f5',
selectionBg: 'rgba(74, 144, 226, 0.2)',
shadowColor: 'rgba(0, 0, 0, 0.1)'
}
};
let currentTheme = GM_getValue('discuz_enhanced_theme', 'dark');
// 应用主题
function applyTheme(themeName) {
const theme = THEMES[themeName];
if (!theme) return;
const css = `
/* CSS变量 */
:root {
--bg-primary: ${theme.bgPrimary};
--bg-secondary: ${theme.bgSecondary};
--bg-tertiary: ${theme.bgTertiary};
--text-primary: ${theme.textPrimary};
--text-secondary: ${theme.textSecondary};
--text-tertiary: ${theme.textTertiary};
--border-color: ${theme.borderColor};
--accent-color: ${theme.accentColor};
--link-color: ${theme.linkColor};
--hover-bg: ${theme.hoverBg};
--selection-bg: ${theme.selectionBg};
--shadow-color: ${theme.shadowColor};
}
/* 基础过渡动画 */
* {
transition: background-color 0.3s ease,
color 0.3s ease,
border-color 0.3s ease,
box-shadow 0.3s ease !important;
}
/* 背景和文字基础样式 */
html, body, #wp, #ct, .wp, .ct,
#hd, #ft, .wp, .wrap, #scrolltop,
.bm, .bmw, .bm_c, .bm_h, .bm_h .y,
.pl, .tl, .ml, .fl, .xl, .pt, .t_l, .t_c, .t_r,
.b_l, .b_c, .b_r, .block, .frame {
background: var(--bg-primary) !important;
color: var(--text-primary) !important;
}
/* 次要背景区域 */
.bm_c, .bm_h, .bm_h .y,
.tl .th, .tl .th td,
.ml .th, .ml .th td,
.fl .th, .fl .th td,
.xl .th, .xl .th td,
.pt .th, .pt .th td,
.tbm .th, .tbm .th td,
.m_l .th, .m_l .th td,
.mlp .th, .mlp .th td,
.t_l, .t_c, .t_r, .b_l, .b_c, .b_r,
.plc .pi, .pls .pi, .plm .plc,
.p_pop, .p_pof, .p_opt,
.tip, .tip_c, .tip_h,
.dialog, .dialog_c, .dialog_h,
.popup, .popup-c, .popup-h,
.menu, .menu-c, .menu-h {
background: var(--bg-secondary) !important;
}
/* 帖子列表和帖子内容 */
#threadlist, .tl, .ml, .fl,
#postlist, .pl, .plin, .plhin,
.plc, .pls, .plm, .plhin .plc, .plhin .pls,
.t_f, .t_f td, .t_s, .t_s td,
.pct, .pcb, .pcht, .pcbs,
.t_msg, .t_msgfont, .t_msgfont_fix,
.postmessage, .message,
.t_f .quote, .t_f .blockquote,
.pcb .quote, .pcb .blockquote,
.pbn .quote, .pbn .blockquote,
.plhin .pct, .plhin .pcb {
background: var(--bg-secondary) !important;
color: var(--text-primary) !important;
border-color: var(--border-color) !important;
}
/* 标题样式 */
h1, h2, h3, h4, h5, h6,
.xs1, .xs2, .xs3,
.ts, .xw1, .s, .o,
em, cite, i, .emfont,
.t_l h3, .t_c h3, .t_r h3,
.ml h3, .tl h3, .xl h3, .fl h3,
.pt h3, .tbm h3, .m_l h3, .mlp h3,
.ts, .ts a, .ts span {
color: var(--text-primary) !important;
}
/* 次要文字 */
.xg1, .xg1 a,
.xg2, .xg2 a,
.xi1, .xi1 a,
.xi2, .xi2 a,
.xi3, .xi3 a,
.xi4, .xi4 a,
.xi5, .xi5 a,
.xi6, .xi6 a,
.gray, .small, .miniright,
.t_l .xg1, .t_l .xg2,
.t_c .xg1, .t_c .xg2,
.t_r .xg1, .t_r .xg2 {
color: var(--text-secondary) !important;
}
/* 三级文字 */
.xg3, .lighttxt, .lighttext,
.des, .description,
.t_l .xi8, .t_c .xi8, .t_r .xi8 {
color: var(--text-tertiary) !important;
}
/* 链接样式 */
a, a:link, a:visited, a:hover, a:active,
.xi2, .xi2 a, .xi3, .xi3 a,
.xi4, .xi4 a, .xi5, .xi5 a,
.xi6, .xi6 a, .xw1, .xw1 a,
.t_l a, .t_c a, .t_r a,
.ml a, .tl a, .xl a, .fl a,
.pt a, .tbm a, .m_l a, .mlp a,
.ts a, .ts a:link, .ts a:visited,
.ts a:hover, .ts a:active,
.s a, .s a:link, .s a:visited,
.s a:hover, .s a:active,
.subject, .subject a,
.common, .common a,
.reply a, .read a,
.author, .author a {
color: var(--link-color) !important;
}
a:hover {
background: var(--hover-bg) !important;
}
/* 边框样式 */
.b_l, .b_c, .b_r,
.t_l, .t_c, .t_r,
.tl, .tl .th, .tl .th td,
.ml, .ml .th, .ml .th td,
.fl, .fl .th, .fl .th td,
.xl, .xl .th, .xl .th td,
.pt, .pt .th, .pt .th td,
.tbm, .tbm .th, .tbm .th td,
.m_l, .m_l .th, .m_l .th td,
.mlp, .mlp .th, .mlp .th td,
.bm, .bm_c, .bm_h, .bm_h .y,
.plhin, .plhin .td, .pls, .plc,
#threadlist th, #threadlist td,
.t_f, .t_f td, .t_f .quote,
.t_f .blockquote, .pcb, .pcb .quote,
.pcb .blockquote, .pbn, .pbn .quote,
.pbn .blockquote,
.t_l, .t_c, .t_r, .b_l, .b_c, .b_r,
.newthread tr, .newthread th, .newthread td,
.threadlist th, .threadlist td,
.datatable tr, .datatable th, .datatable td,
.forumlist tr, .forumlist th, .forumlist td {
border-color: var(--border-color) !important;
}
/* 表格样式 */
table, th, td,
.tl .th, .tl .th td,
.ml .th, .ml .th td,
.fl .th, .fl .th td,
.xl .th, .xl .th td,
.pt .th, .pt .th td,
.tbm .th, .tbm .th td,
.m_l .th, .m_l .th td,
.mlp .th, .mlp .th td,
.datatable, .datatable th, .datatable td,
.threadlist, .threadlist th, .threadlist td,
.forumlist, .forumlist th, .forumlist td,
.datalist, .datalist th, .datalist td,
.postlist, .postlist th, .postlist td {
background: var(--bg-secondary) !important;
color: var(--text-primary) !important;
border-color: var(--border-color) !important;
}
/* 输入框和表单元素 */
input, textarea, select, button,
.px, .pt, .ps, .pc, .pn, .pnc,
.pf, .pf_l, .pf_r,
.login-btn, .reg-btn,
.search-input, .search-btn,
#fastpostmessage, #subject,
.tedt, .tedt .area, .tedt .pt,
.sinf, .sinf .px, .sinf .pt,
#username, #password, #email,
.ls, .lr, .ll, .lm, .lp .input,
.loginform input, .loginform textarea,
.registerform input, .registerform textarea,
.postform input, .postform textarea,
.searchform input, .searchform textarea {
background: var(--bg-tertiary) !important;
color: var(--text-primary) !important;
border: 1px solid var(--border-color) !important;
}
input:focus, textarea:focus, select:focus,
.px:focus, .pt:focus, .ps:focus,
.pc:focus, .tedt .pt:focus {
border-color: var(--accent-color) !important;
box-shadow: 0 0 0 2px rgba(74, 144, 226, 0.2) !important;
outline: none !important;
}
/* 按钮样式 */
.pn, .pnc, .pn em, .pnc em,
.login-btn, .reg-btn, .search-btn,
.fastpost-btn, .submit-btn,
button, input[type="button"],
input[type="submit"],
.postbtn, .replybtn, .newthread-btn,
.send-btn, .confirm-btn, .cancel-btn {
background: var(--accent-color) !important;
color: white !important;
border: none !important;
}
.pn:hover, .pnc:hover,
button:hover, input[type="button"]:hover,
input[type="submit"]:hover {
background: var(--link-color) !important;
}
/* 代码块和引用 */
.blockcode, .code, .quote,
.blockquote, .t_f .quote,
.t_f .blockcode, .pcb .quote,
.pcb .blockcode, .pbn .quote,
.pbn .blockcode,
.postmessage .quote, .postmessage .blockcode,
.message .quote, .message .blockcode {
background: var(--bg-tertiary) !important;
border: 1px solid var(--border-color) !important;
color: var(--text-primary) !important;
}
/* 图片处理 */
img, .avatar, .avtm, .avt img,
.plc .pi img, .pls .avatar img,
.attach-image img, .zoom img,
.postattach img, .postimg img,
.signature img, .sign img {
filter: brightness(0.9) contrast(1.1) !important;
transition: filter 0.3s ease !important;
}
img:hover {
filter: brightness(1) contrast(1) !important;
}
/* 表情符号保持原样 */
.smilies img, .emoji img,
.face img, .emot img,
.expression img, .emotion img {
filter: none !important;
}
/* 头像框 */
.pls .avatar img, .avt img,
.user-avatar img, .avatar img,
.header-avatar img, .u-avatar img {
border: 2px solid var(--border-color) !important;
border-radius: 50% !important;
}
/* 徽章和标签 */
.authicn, .userbadge, .groupicon,
.newthread-badge, .hotthread-badge,
.digest-badge, .attach-badge,
.thread-badge, .post-badge,
.user-badge, .rank-badge,
.vip, .vip-icon, .vip-badge,
.star, .star-badge, .level-badge {
background: var(--accent-color) !important;
color: white !important;
}
/* 评分和点赞 */
.rate, .ratel, .ratec,
.recommend, .recommend-c,
.agree, .agree-c, .agree-num,
.like, .like-c, .like-num,
.support, .support-c, .support-num,
.favorite, .favorite-c, .favorite-num {
background: var(--bg-tertiary) !important;
color: var(--text-primary) !important;
border-color: var(--border-color) !important;
}
/* 分页 */
.pg, .pg a, .pg strong, .pg label,
.pgb, .pgb a, .pgb strong,
.pgbtn, .pgbtn a, .pgbtn strong,
.pages, .pages a, .pages strong,
.pagebar, .pagebar a, .pagebar strong,
.paging, .paging a, .paging strong {
background: var(--bg-tertiary) !important;
color: var(--text-primary) !important;
border-color: var(--border-color) !important;
}
.pg strong, .pg a:hover,
.pgb strong, .pgb a:hover,
.pgbtn strong, .pgbtn a:hover,
.pages strong, .pages a:hover,
.pagebar strong, .pagebar a:hover,
.paging strong, .paging a:hover {
background: var(--accent-color) !important;
color: white !important;
}
/* 弹出菜单和对话框 */
.p_pop, .p_pof, .p_opt,
.tip, .tip_c, .tip_h,
.dialog, .dialog_c, .dialog_h,
.popup, .popup-c, .popup-h,
.menu, .menu-c, .menu-h,
.dropdown, .dropdown-menu,
.popover, .popover-content,
.modal, .modal-content, .modal-header,
.modal-body, .modal-footer {
background: var(--bg-secondary) !important;
border: 1px solid var(--border-color) !important;
color: var(--text-primary) !important;
box-shadow: 0 4px 12px var(--shadow-color) !important;
}
/* 导航栏 */
.nv, .nv a, .nv li,
.navbar, .navbar a, .navbar li,
.nav, .nav a, .nav li,
.header, .header a, .header li,
#hd, #hd a, #hd li,
.menu-hd, .menu-hd a, .menu-hd li,
.top-nav, .top-nav a, .top-nav li {
background: var(--bg-secondary) !important;
color: var(--text-primary) !important;
border-color: var(--border-color) !important;
}
/* 侧边栏 */
.sd, .sd_c, .sd_h,
.sidebar, .sidebar_c, .sidebar_h,
.aside, .aside_c, .aside_h,
.side, .side_c, .side_h {
background: var(--bg-secondary) !important;
color: var(--text-primary) !important;
border-color: var(--border-color) !important;
}
/* 用户信息和统计 */
.user-info, .user-stats,
.author-info, .author-stats,
.post-info, .post-stats,
.thread-info, .thread-stats,
.forum-info, .forum-stats,
.board-info, .board-stats {
background: var(--bg-tertiary) !important;
color: var(--text-primary) !important;
border-color: var(--border-color) !important;
}
/* 签名和版权 */
.sign, .signature,
.copyright, .footer-copyright,
.footer, .footer_c, .footer_h {
background: var(--bg-primary) !important;
color: var(--text-secondary) !important;
border-color: var(--border-color) !important;
}
/* 高亮和特殊状态 */
.highlight, .highlighted,
.focus, .focused,
.current, .active,
.selected, .on,
.new, .newpost,
.unread, .unreadpost {
background: var(--hover-bg) !important;
color: var(--text-primary) !important;
}
/* 滚动条(WebKit浏览器) */
::-webkit-scrollbar {
width: 10px;
height: 10px;
}
::-webkit-scrollbar-track {
background: var(--bg-primary) !important;
}
::-webkit-scrollbar-thumb {
background: var(--bg-tertiary) !important;
border-radius: 5px;
border: 2px solid var(--bg-primary);
}
::-webkit-scrollbar-thumb:hover {
background: var(--border-color) !important;
}
/* 主题切换按钮 */
.theme-switcher {
position: fixed !important;
top: 20px !important;
right: 20px !important;
z-index: 999999 !important;
background: var(--bg-secondary) !important;
border: 2px solid var(--border-color) !important;
border-radius: 50% !important;
width: 50px !important;
height: 50px !important;
display: flex !important;
align-items: center !important;
justify-content: center !important;
cursor: pointer !important;
box-shadow: 0 4px 12px var(--shadow-color) !important;
transition: all 0.3s ease !important;
}
.theme-switcher:hover {
transform: scale(1.1) !important;
box-shadow: 0 6px 16px var(--shadow-color) !important;
}
.theme-switcher svg {
width: 24px !important;
height: 24px !important;
fill: var(--text-primary) !important;
}
/* 自定义样式示例 */
.cl {
background: #000000 !important;
color: #ffffff !important;
}
/* 响应式设计 */
@media (max-width: 768px) {
.theme-switcher {
top: 15px !important;
right: 15px !important;
width: 40px !important;
height: 40px !important;
}
.theme-switcher svg {
width: 20px !important;
height: 20px !important;
}
}
`;
GM_addStyle(css);
}
// 创建切换按钮
function createButton() {
const button = document.createElement('div');
button.className = 'theme-switcher';
button.innerHTML = `
<svg viewBox="0 0 24 24">
<path d="M9 2c-1.05 0-2.05.16-3 .46 4.06 1.27 7 5.06 7 9.54 0 4.48-2.94 8.27-7 9.54.95.3 1.95.46 3 .46 5.52 0 10-4.48 10-10S14.52 2 9 2z"/>
</svg>
`;
button.addEventListener('click', () => {
const newTheme = currentTheme === 'dark' ? 'light' : 'dark';
currentTheme = newTheme;
GM_setValue('discuz_enhanced_theme', newTheme);
location.reload();
});
document.body.appendChild(button);
}
// 初始化
function init() {
// 应用主题
applyTheme(currentTheme);
// 等待DOM加载后创建按钮
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', () => {
setTimeout(createButton, 500);
});
} else {
setTimeout(createButton, 500);
}
// 监听动态加载的内容
const observer = new MutationObserver(() => {
// 动态内容加载后重新应用主题
setTimeout(() => {
applyTheme(currentTheme);
}, 100);
});
observer.observe(document.body, {
childList: true,
subtree: true
});
}
// 启动
init();
})();