CSDN去除广告
// ==UserScript==
// @name CSDN去除广告
// @namespace https://bbs.tampermonkey.net.cn/
// @version 0.1.2
// @description 简简单单CSDN去除广告、免登陆复制、自动关闭那该死的登录弹框
// @author Zhou
// @match https://*.blog.csdn.net/*
// @grant GM_addStyle
// @grant unsafeWindow
// ==/UserScript==
(function() {
'use strict';
const $ = window.unsafeWindow.jQuery;
let styleStr = `
.mb8,#remuneration,#asideWriteGuide,#asideAds,#asideNewNps,#recommendNps,#footerRightAds,#blogExtensionBox,#dmp_ad_58,
.csdn-side-toolbar>*:not([data-type="gotop"]),
.toolbar-btns .toolbar-btn:not(.toolbar-btn-login),
.programmer1Box,
#recommendAdBox,
.passport-login-tip-container,
.toolbar-advert,
.tool-active-list {display: none !important;}
.list-type-box { padding: 0px 4px; background: #21940d;border-radius: 2px;color: #fff;font-weight: 500;font-size: 12px;margin-right: 5px;}
#content_views pre,#content_views pre code {
user-select: unset;
}
`
if (window.innerWidth <= 1200) {
styleStr += `.blog_container_aside {display: none;} .nodata .container main {width: 100%}`
}
GM_addStyle(styleStr)
function loginModule() {
const loginBtn = $('.toolbar-btns .toolbar-btn-login')
let btnClick = false
loginBtn.on('click', () => btnClick = true)
const mutation = new MutationObserver((mon) => {
const lgm = mon.find(m => $(m.addedNodes[0]).hasClass('passport-login-container'))
if (lgm) {
const dom = $(lgm.addedNodes[0])
if (!btnClick) dom.remove()
else dom.find('img').one('click', () => btnClick = false)
}
})
mutation.observe(document.body, { childList: true })
}
document.addEventListener('copy', (e) => {
e.stopPropagation();
}, true)
$('.hljs-button.signin').attr('data-title', '复制').removeClass('active').removeAttr('onClick').on('click', function(e) {
navigator.clipboard.writeText($(this).parent()[0].innerText.replace(/[\u00A0]/gi, " ")).then(res => {
$(this).attr('data-title', '复制成功')
setTimeout(() => {
$(this).attr('data-title', '复制')
}, 3000)
})
})
loginModule()
$('.hide-article-box').find('.btn-readmore').removeClass('no-login').find('.follow-text').text('展开全文')
function footerList() {
function fn() {
const list = $('.recommend-item-box')
list.each((i, el) => {
if($(el).find('.list-type-box')[0]) return
const url = $(el).attr('data-url') || ''
if (!url) return
if (url.indexOf('blog.csdn.net') !== -1) {
$(el).prepend(`<div class="list-type-box">博</div>`)
} else if (url.indexOf('download.csdn.net') !== -1) {
$(el).prepend(`<div class="list-type-box">文</div>`)
} else if (url.indexOf('edu.csdn.net') !== -1) {
$(el).prepend(`<div class="list-type-box">育</div>`)
} else {
$(el).prepend(`<div class="list-type-box">其</div>`)
}
})
}
setTimeout(() => {
fn()
}, 5000)
}
footerList()
})();