// ==UserScript== // @name CSDN Focus // @description 🌚 黑暗模式上线, 一键变天 | CSDN, 脚本之家 无弹窗无广告无任何干扰, 自动展开文章和评论, 外链直达! 隐藏属性等你发现, 不试一下? 😃 // @version 1.9.2 // @author Finn // @namespace https://github.com/Germxu // @homepage https://github.com/Germxu/Scripts-for-TamperMonkey // @supportURL https://github.com/Germxu/Scripts-for-TamperMonkey/issues/new // @run-at document-start // @match blog.csdn.net/*/article/details/* // @match *.blog.csdn.net/article/details/* // @match www.jb51.net/article/* // // @grant GM_setValue // @grant GM_getValue // @license MIT // @compatible Chrome 54+ // @compatible Safari Latest // @compatible Firefox Latest // // @note V1.9 UI更新: 清理了侧边栏的无用内容, 保留目录, 以及其他细节的优化 // @note V1.8 Bugfix: 修复了尺寸调整时黑暗模式退出的问题以及不跟手问题 // @note V1.7 重要更新: 支持拉伸调节内容宽度, 尺寸限定: 888 ~ 80% // @note V1.6 重要更新: 修复了一直以来可能出现的运行不成功和后台加载脚本失败的问题 // @note V1.5 重要更新: 添加黑暗模式, 一键切换, 优化精简大量静态代码,修复隐性Bug // @downloadURL none // ==/UserScript== (function () { 'use strict'; const finnWidth = GM_getValue('FinnData') && GM_getValue('FinnData').finnWidth || 1000; const csdn = `
`; const jb51 = ``; let h = document.documentElement, _Ds; let FinnData = new Proxy(GM_getValue('FinnData', {}), { set(target, key, val) { if (key === "dark") { val ? h.setAttribute("darkMode", true) : h.removeAttribute("darkMode"); } const B = Reflect.set(target, key, val); GM_setValue('FinnData', FinnData); return B; } }) if (location.host === "www.jb51.net") { _Ds = jb51; } else { _Ds = csdn; window.addEventListener("DOMContentLoaded", () => { mainBox.addEventListener('click', e => { let ev = e.target; if (ev.nodeName.toLocaleLowerCase() === 'a') { if (ev.host && ev.host.indexOf("csdn") === -1) { e.stopImmediatePropagation(); window.open(ev.href); e.preventDefault(); } } }, true); $("#darkBtn").click(() => { FinnData.dark = !FinnData.dark }) $("#FinnTop").click(() => { $("body,html").animate({ scrollTop: 0 }, 300) }); let resize = mainBox; resize.addEventListener("mousedown", e => { if (e.target !== mainBox) return; let startX = e.clientX, offsetWidth = resize.offsetWidth; const maxSize = window.innerWidth * 0.8; resize.style.userSelect = "none"; e.stopPropagation(); document.onmousemove = e => { let endX = e.clientX; let moveLen = (startX / maxSize < 0.5) ? startX - endX : endX - startX; let l = offsetWidth + moveLen * 2 - 40; l = l < 888 ? 888 : l > maxSize ? maxSize : l; FinnData.finnWidth = l; h.style.setProperty('--finn-width', l + "px"); } document.onmouseup = () => { resize.style.userSelect = "auto"; document.onmousemove = null; document.onmouseup = null; } }, true) }) } function ins() { h = h||document.documentElement; h.insertAdjacentHTML('afterbegin', _Ds); FinnData.dark && h.setAttribute("darkMode", true); } if (!h) { let OB = new MutationObserver(ins); OB.observe(document, { childList: true }) } else { ins() } })();