// ==UserScript==
// @name CSDN Focus
// @description 🌚 黑暗模式上线, 一键变天 | CSDN, 脚本之家 无弹窗无广告无任何干扰, 自动展开文章和评论, 外链直达! 隐藏属性等你发现, 不试一下? 😃
// @version 1.8.8
// @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+
//
// @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 = `
TOP
`;
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", () => {
document.querySelector(".blog_container_aside").setAttribute("username", username);
mainBox.addEventListener('click', e => {
let ev = e.target;
if (ev.nodeName.toLocaleLowerCase() === 'a') {
if (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 => {
let startX = e.clientX,
offsetWidth = resize.offsetWidth;
const maxSize = window.innerWidth * 0.8;
if (e.target !== mainBox) return;
resize.style.userSelect = "none";
e.stopPropagation();
document.onmousemove = e => {
let endX = e.clientX;
var moveLen = (startX / maxSize < 0.5) ? startX - endX : endX - startX;
let l = offsetWidth + moveLen - 40;
l = l < 888 ? 888 : l > maxSize ? maxSize : l;
FinnData.finnWidth = l;
document.querySelector('html').style.setProperty('--finn-width', l + "px");
}
document.onmouseup = e => {
resize.style.userSelect = "auto";
e.stopPropagation();
document.onmousemove = null;
document.onmouseup = null;
resize.releaseCapture && resize.releaseCapture();
}
resize.setCapture && resize.setCapture();
}, true)
})
}
function ins() {
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()
}
})();