// ==UserScript== // @name CSDN Focus // @description CSDN页面重置, 支持黑暗模式, 无弹窗无广告无任何干扰, 自动展开文章和评论,一键复制, 外链直达! 同步支持脚本之家, 简书 // @version 2.2.1 // @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/* // @match www.jianshu.com/* // // @grant GM_setValue // @grant GM_getValue // @license MIT // @compatible Chrome Latest // @compatible Safari Latest // @compatible Firefox Partial support // @downloadURL none // ==/UserScript== (function () { 'use strict'; const finnWidth = GM_getValue('FinnData') && GM_getValue('FinnData').finnWidth || 1000; const csdn = `
`; const jb51 = ``; const jianshu = `` 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"); } if (key === "aside_pin") { val ? h.setAttribute("aside_pin", true) : h.removeAttribute("aside_pin"); } const B = Reflect.set(target, key, val); GM_setValue('FinnData', FinnData); return B; } }) if (location.host === "www.jb51.net") { _Ds = jb51 } else if (location.host === "www.jianshu.com") { _Ds = jianshu } else { _Ds = csdn; window.addEventListener("DOMContentLoaded", () => { mainBox.addEventListener('click', e => { let ev = e.target; if (ev.nodeName === 'A') { if (ev.host && !ev.host.includes("csdn")) { e.stopImmediatePropagation(); window.open(ev.href); e.preventDefault(); } } }, true); pinBtn.onclick =()=> FinnData.aside_pin = !FinnData.aside_pin $("#darkBtn").click(() => { FinnData.dark = !FinnData.dark }) $("#FinnTop").click(() => { $("body,html").animate({ scrollTop: 0 }, 300) }); mainBox.addEventListener("mousedown", e => { if (e.target !== mainBox) return; let startX = e.clientX, offsetWidth = mainBox.offsetWidth; const maxSize = window.innerWidth * 0.88; mainBox.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 - 20; l = l < maxSize ? l : maxSize; FinnData.finnWidth = l; h.style.setProperty('--finn-width', l + "px"); } document.onmouseup = () => { mainBox.style.userSelect = "auto"; document.onmousemove = null; document.onmouseup = null; } }, true) }) // window.onload=()=>$("div.hljs-button.signin").each(function(){$(this).attr({"data-title":"复制","onclick":"mdcp.copyCode"})}) window.onload=function(){ document.querySelectorAll(".hljs-button.signin").forEach((e) => { e.setAttribute("data-title", "复制"); e.onclick = function (e) { e.stopPropagation(); navigator.clipboard .writeText(this.parentNode.innerText) .then(() => {this.setAttribute("data-title", "复制成功") }) .catch((err) => console.log('操作失败: '+err)); }; }); } } function ins() { h = h||document.documentElement; h.insertAdjacentHTML('afterbegin', _Ds); FinnData.dark && h.setAttribute("darkMode", true); FinnData.aside_pin && h.setAttribute("aside_pin", true); } if (!h) { let OB = new MutationObserver(ins); OB.observe(document, { childList: true }) } else { ins() } })();