// ==UserScript== // @name CSDNock // @namespace http://tampermonkey.net/ // @version 0.1.11 // @icon https://raw.githubusercontent.com/Exisi/BlogNock/main/doc/icon/nock.ico // @description BlogNock系列,CSDN文章的标识优化 // @author Exisi // @license MIT License // @match *://blog.csdn.net/*/article/details/* // @match *://blog.csdn.net/article/details/* // @supportURL https://github.com/Exisi/BlogNock/issues/ // @grant GM_registerMenuCommand // @grant GM_setValue // @grant GM_getValue // ==/UserScript== (function () { "use strict"; const features = { recommend_type_download: { debug: false, enabled: GM_getValue("recommend_type_download", true), selector: ".recommend-item-box.type_download.clearfix", }, mark: { copyright: { debug: false, enabled: GM_getValue("copyright", true), selector: [".article-type-img", ".article-info-box", ".article-source-link a"], original: "https://greasyfork.org/rails/active_storage/representations/redirect/eyJfcmFpbHMiOnsiZGF0YSI6MTgyODU2LCJwdXIiOiJibG9iX2lkIn19--bf8a81cd3585e45966da770a24d41931c962feaf/eyJfcmFpbHMiOnsiZGF0YSI6eyJmb3JtYXQiOiJwbmciLCJyZXNpemVfdG9fbGltaXQiOlsyMDAsMjAwXX0sInB1ciI6InZhcmlhdGlvbiJ9fQ==--74d795a80595346362306a325643f8710996102f/original.png?locale=zh-CN", reprint: "https://greasyfork.org/rails/active_storage/representations/redirect/eyJfcmFpbHMiOnsiZGF0YSI6MTgyODU4LCJwdXIiOiJibG9iX2lkIn19--72f875da87789db58b6fb06d2daff816e1f573d6/eyJfcmFpbHMiOnsiZGF0YSI6eyJmb3JtYXQiOiJwbmciLCJyZXNpemVfdG9fbGltaXQiOlsyMDAsMjAwXX0sInB1ciI6InZhcmlhdGlvbiJ9fQ==--74d795a80595346362306a325643f8710996102f/reprint.png?locale=zh-CN", translate: "https://greasyfork.org/rails/active_storage/representations/redirect/eyJfcmFpbHMiOnsiZGF0YSI6MTgyODYyLCJwdXIiOiJibG9iX2lkIn19--29e83203fb481a249d5eb5b583c2d80bff0c82b2/eyJfcmFpbHMiOnsiZGF0YSI6eyJmb3JtYXQiOiJwbmciLCJyZXNpemVfdG9fbGltaXQiOlsyMDAsMjAwXX0sInB1ciI6InZhcmlhdGlvbiJ9fQ==--74d795a80595346362306a325643f8710996102f/translate.png?locale=zh-CN", }, datetime: { debug: false, enabled: GM_getValue("datetime", true), selector: [".time", ".up-time"], }, readtime: { debug: false, enabled: GM_getValue("readtime", true), selector: ["#content_views", ".bar-content", ".blog-content-box"], icon: ``, }, }, source_redirct: { debug: false, enabled: GM_getValue("source_redirct", true), selector: [".href-article-edit", ".article-type-img", ".article-source-link a"], }, unfixed_comment: { debug: false, enabled: GM_getValue("fixed_comment", true), selector: [".left-toolbox"], }, hidden_login: { debug: false, enabled: GM_getValue("hidden_login", true), selector: [".hasAvatar", ".passport-login-container", ".passport-login-box>img"], }, allow_copy: { debug: false, enabled: GM_getValue("allow_copy", true), selector: ["#content_views", "pre", "code"], }, unfold_code: { debug: false, enabled: GM_getValue("unfold_code", true), selector: [".hide-preCode-bt"], }, allow_copy_with_btn: { debug: false, enabled: GM_getValue("allow_copy_with_btn", true), selector: [".hljs-button.signin.active", "button.btn-code-notes.mdeditor", "code"], }, hidden_sidebar: { debug: false, enabled: GM_getValue("hidden_sidebar", true), selector: [".blog_container_aside", "#mainBox"], }, hidden: { ai_search_btn: { enabled: GM_getValue("ai_search_btn", true), selector: ["#toolbar-c-box-button.c-box"], }, article_search_tip: { enabled: GM_getValue("article_search_tip", true), selector: ["#articleSearchTip"], }, nav_vip_promotion_pic: { enabled: GM_getValue("nav_vip_promotion_pic", true), selector: [".toolbar-btn-vip img[src^='https://i-operation.csdnimg.cn']"], }, login_tips: { enabled: GM_getValue("login_tips", true), selector: [".passport-login-tip-container"], }, collection_tips: { enabled: GM_getValue("collection_tips", true), selector: [".tool-active-list", "#tool-active-list-collection"], }, side_toolbar: { enabled: GM_getValue("side_toolbar", true), selector: [".csdn-side-toolbar"], }, side_google_ad: { enabled: GM_getValue("side_google_ad", true), selector: [".box-shadow.mb8", "#footerRightAds"], }, side_ai_ad: { enabled: GM_getValue("side_ai_ad", true), selector: ["#swiper-remuneration-container"], }, write_guide_pic: { enabled: GM_getValue("write_guide_pic", true), selector: ["#asideWriteGuide"], }, recommend_vote: { enabled: GM_getValue("recommend_vote", true), selector: ["#asideNewNps"], }, latest_comments: { enabled: GM_getValue("latest_comment", true), selector: ["#asideNewComments"], }, bottom_recommend_article_vote: { enabled: GM_getValue("bottom_recommend_article_vote", true), selector: ["#recommendNps"], }, }, }; class MenuHandler { constructor() { const setModal = `
检测到源链接,5 秒后跳转。
`; document.body.appendChild(countdownTips); const progressBarContainer = document.createElement("div"); Object.assign(progressBarContainer.style, { position: "fixed", top: "0", left: "0", width: "100%", height: "2px", zIndex: "9999", }); const progressBar = document.createElement("div"); Object.assign(progressBar.style, { width: "100%", height: "100%", backgroundColor: "#00a4ff", }); progressBarContainer.appendChild(progressBar); document.body.appendChild(progressBarContainer); const link = document.createElement("a"); link.href = sourceUrl; link.style.display = "none"; document.body.appendChild(link); let countdown = 5; const countdownInterval = setInterval(() => { countdown -= 0.01; document.getElementById("countdown").innerText = Math.ceil(countdown); progressBar.style.width = `${(countdown / 5) * 100}%`; if (countdown <= 0) { clearInterval(countdownInterval); link.click(); } }, 10); document.getElementById("cancelButton").addEventListener("click", () => { clearInterval(countdownInterval); countdownTips.style.animation = "fadeOut 0.3s ease-out"; countdownTips.addEventListener("animationend", () => { countdownTips.remove(); }); progressBarContainer.remove(); link.remove(); }); } } }); } if (features.unfixed_comment.enabled) { errorNock.safeExecute("unfixed_comment", () => { const style = document.createElement("style"); style.textContent = `${features.unfixed_comment.selector[0]} { position: unset !important; }`; document.head.appendChild(style); }); } if (features.hidden_login.enabled && !document.querySelector(features.hidden_login.selector[0])) { errorNock.safeExecute("hidden_login", () => { const observer = new MutationObserver(() => { const loginModal = document.querySelector(features.hidden_login.selector[1]); if (!loginModal) { return; } loginModal.querySelector(features.hidden_login.selector[2]).click(); observer.disconnect(); }); observer.observe(document.body, { childList: true, subtree: true }); }); } if (features.allow_copy.enabled) { errorNock.safeExecute("allow_copy", () => { const contentView = document.querySelector(features.allow_copy.selector[0]); contentView.querySelectorAll("*").forEach((content) => { content.oncopy = (e) => e.stopPropagation(); }); const preTags = document.querySelectorAll(features.allow_copy.selector[1]); preTags.forEach((pre) => (pre.style.userSelect = "auto")); const codeTags = document.querySelectorAll(features.allow_copy.selector[2]); codeTags.forEach((code) => (code.style.userSelect = "auto")); }); } if (features.unfold_code.enabled) { errorNock.safeExecute("unfold_code", () => { const unfoldCodeBtns = document.querySelectorAll(features.unfold_code.selector[0]); unfoldCodeBtns.forEach((btn) => btn.click()); }); } if (features.allow_copy_with_btn.enabled) { errorNock.safeExecute("allow_copy_with_btn", () => { const codeCopyBtns = document.querySelectorAll(features.allow_copy_with_btn.selector[0]); codeCopyBtns.forEach((btn) => { btn.style.display = "none !important"; btn.style.position = "absolute"; btn.style.zIndex = "-1"; }); const aiCopyBtns = document.querySelectorAll(features.allow_copy_with_btn.selector[1]); aiCopyBtns.forEach((btn) => { btn.innerHTML = "复制"; btn.style.paddingLeft = "8px"; btn.style.backgroundImage = "none"; btn.onclick = (e) => { e.stopPropagation(); const codeBox = btn .closest("pre") .querySelector(features.allow_copy_with_btn.selector[2]); navigator.clipboard.writeText(codeBox.innerText); btn.innerHTML = "已复制"; setTimeout(() => (btn.innerHTML = "复制"), 1000); }; }); }); } if (features.hidden_sidebar.enabled) { errorNock.safeExecute("hidden_sidebar", () => { const style = document.createElement("style"); style.textContent = `${features.hidden_sidebar.selector[0]} { display: none !important; }`; document.head.appendChild(style); const main = document.querySelector(features.hidden_sidebar.selector[1]); main.style.display = "flex"; main.style.justifyContent = "center"; }); } const hiddenStyle = document.createElement("style"); document.head.appendChild(hiddenStyle); Object.entries(features.hidden).forEach(([key, option]) => { if (option.enabled) { const cssRule = `${option.selector} { display: none !important; }`; hiddenStyle.sheet.insertRule(cssRule); } }); function calculateTimeAgo(datetime) { const SECOND = 1000; const MINUTE = 60 * SECOND; const HOUR = 60 * MINUTE; const DAY = 24 * HOUR; const MONTH = 30 * DAY; const YEAR = 12 * MONTH; const postDate = new Date(datetime); const currentDate = new Date(); const timeDiff = currentDate - postDate; if (timeDiff >= YEAR) { return Math.floor(timeDiff / YEAR) + " 年前"; } if (timeDiff >= MONTH) { return Math.floor(timeDiff / MONTH) + " 个月前"; } if (timeDiff >= DAY) { return Math.floor(timeDiff / DAY) + " 天前"; } if (timeDiff >= HOUR) { return Math.floor(timeDiff / HOUR) + " 小时前"; } if (timeDiff >= MINUTE) { return Math.floor(timeDiff / MINUTE) + " 分钟前"; } return Math.floor(timeDiff / SECOND) + " 秒前"; } })();