NOTICE: By continued use of this site you understand and agree to the binding Terms of Service and Privacy Policy.
// ==UserScript==
// @name CSDN小助手
// @description 助你畅游CSDN
// @version 1.1
// @namespace https://openuserjs.org/users/tutu
// @author tutu
// @license MIT
// @copyright 2021, tutu (https://openuserjs.org/users/tutu)
// @note 去除推广广告, 免登陆粘贴复制(双击复制), 去掉关注博主即可阅读全文限制
// @match https://blog.csdn.net/*
// @icon https://www.google.com/s2/favicons?domain=csdn.net
// @require https://csdnimg.cn/release/blogv2/dist/components/js/edit_copy_code-1320dfe85c.min.js
// @require https://openuserjs.org/src/libs/tutu/AD_Blocker.js
// @grant none
// @note 1.1 讲广告推广分离成单独的库
// ==/UserScript==
function execFnDelay(fn, delay = 1e3){
const feed = setTimeout(function(){
clearTimeout(feed)
fn()
}, delay)
}
(function() {
'use strict';
const isLogin = !!document.querySelector('.toolbar-btn-login.toolbar-subMenu-box');
const timeoutFeed = setTimeout(function(){
clearTimeout(timeoutFeed)
// 去掉关注博主即可阅读全文
const hideArticleBox = document.querySelector('.hide-article-box')
if(hideArticleBox){
// hideArticleBox.remove();
}
// 未登录时处理
if (!isLogin){
const copyFn = window.mdcp || hljs
//hljs.copyCode = hljs.copyCode || window.mdcp.copyCode
// 登录后复制tick
const codeSections = document.querySelectorAll('code.prism,code.hljs');
codeSections.forEach(section => {
const parentNode = section.parentNode || document.createElement('pre');
// 登录和复制按钮用的是一个div
const signBtn = parentNode.querySelector('.signin')
if (signBtn){
signBtn.className = 'hljs-button'
signBtn.setAttribute('data-title', '双击复制');
/* signBtn.onclick = function(event) {
//copyFn.copyCode(event)
}*/
}
// 手动复制
parentNode.style.userSelect = 'auto'
section.style.userSelect = 'auto'
// 代码区域单击时会,去掉点击事件
//section.removeAttribute('onclick')
section.onclick = function(event) {
copyFn.copyCode(event)
}
let copyBtn = parentNode.querySelector('.hljs-button')
section.ondblclick = function(event) {
//evt = event
copyBtn && copyBtn.click(event);
execFnDelay(function(){
copyBtn.setAttribute('data-title', '双击复制')
})
};
})
}
}, 2e3)
})();