// ==UserScript== // @name CSDN阅读美化(新、旧版兼容|去广告|自动全文|简洁) // @namespace http://www.csdn.net/ // @icon https://favicon.yandex.net/favicon/csdn.net // @version 0.0.8-20180328 // @description 自动阅读全文;去广告;布局及格式优化;优化内容推荐展示样式;图片居中;删除空段落;去除首行缩进;支持MathJax。(修改自新版CSDN阅读体验提升) // @author zhuzhuyule // @license GPL version 3 // @match http://blog.csdn.net/* // @match https://blog.csdn.net/* // @grant none // @run-at document-body // @downloadURL none // ==/UserScript== (function() { 'use strict'; //初始化一个 document.ready 事件 (function () { var ie = !!(window.attachEvent && !window.opera); var wk = /webkit\/(\d+)/i.test(navigator.userAgent) && (RegExp.$1 < 525); var fn = []; var run = function () { for (var i = 0; i < fn.length; i++) fn[i](); }; var d = document; d.ready = function (f) { if (!ie && !wk && d.addEventListener) return d.addEventListener('DOMContentLoaded', f, false); if (fn.push(f) > 1) return; if (ie) (function () { try { d.documentElement.doScroll('left'); run(); } catch (err) { setTimeout(arguments.callee,0); } })(); else if (wk) var t = setInterval(function () { if (/^(loaded|complete)$/.test(d.readyState)){ clearInterval(t); run(); } }, 0); }; })(); function getScrollTop(){ var scrollTop = 0, bodyScrollTop = 0, documentScrollTop = 0; if(document.body){ bodyScrollTop = document.body.scrollTop; } if(document.documentElement){ documentScrollTop = document.documentElement.scrollTop; } scrollTop = (bodyScrollTop - documentScrollTop > 0) ? bodyScrollTop : documentScrollTop; return scrollTop; } //文档的总高度 function getScrollHeight(){ var scrollHeight = 0, bodyScrollHeight = 0, documentScrollHeight = 0; if(document.body){ bodyScrollHeight = document.body.scrollHeight; } if(document.documentElement){ documentScrollHeight = document.documentElement.scrollHeight; } scrollHeight = (bodyScrollHeight - documentScrollHeight > 0) ? bodyScrollHeight : documentScrollHeight; return scrollHeight; } function getWindowHeight(){ var windowHeight = 0; if(document.compatMode == "CSS1Compat"){ windowHeight = document.documentElement.clientHeight; }else{ windowHeight = document.body.clientHeight; } return windowHeight; } function addStyle() { var s=''; //公共部分 s+='*{transition: opacity 1s, width 1s;}'; s+='h1 { "text-align": "center"; }'; s+='.article_content p { margin:1em 0; "line-height": "1.75em";"color":"#2F2F2F"}'; s+='.recommend_list { height: 90px; overflow-y: hidden; opacity:.2; }'; s+='.recommend_list.show { height:auto; overflow-y: visible;opacity:.2; }'; s+='.recommend_list:hover { opacity:1; }'; s+='.pulllog-box { display:none !important; }'; s+='article::after{content:"— The End —";color:#e0e0e0;text-align:center;width:100%;line-height:60px;margin-top:-40px;display:block;font-family:Monotype Corsiva,Blackadder ITC,Brush Script MT,Bradley Hand ITC,Bell MT;font-size:1.6em;padding-bottom:.6em;}'; //旧版本 s+='#homepageArticles ,#layerd,#nav_show_top_stop, .QRcodebg1'; s+='{ display: none !important; }'; s+='#com-quick-reply,#com-quick-collect,#com-d-top-a { min-width: 30px !important; width: 31px !important;}'; s+='#com-quick-reply:hover,#com-quick-collect:hover,#com-d-top-a:hover { width: 90px !important;}'; //新版本 s+='.fixRight,.extension_other,.fixRight_box,.persion_article,.yd_a_d_feed_cla'; s+='{ display: none !important;}'; s+='.article_content,.article_content p,.article_content p span:not([class^=MathJax] span):not([class^=MathJax]):not([id^=MathJax] span):not([id^=MathJax]) {"font-family": "Microsoft YaHei,Consolas";"font-size": "15px" }'; s+='.article_content p .MathJax { "font-size": "16px"; }'; s+='.article_content p img{ "display": "block";"margin": "0 auto" }'; //添加样式到 Head 中 var head = document.head || document.getElementsByTagName('head')[0]; if (head) { var style = document.createElement("style"); style.type = "text/css"; style.appendChild(document.createTextNode(s)); head.appendChild(style); } } function hidden(items) { var s= items.toString() + ' { display: none !important; }'; //添加样式到 Head 中 var head = document.head || document.getElementsByTagName('head')[0]; if (head) { var style = document.createElement("style"); style.type = "text/css"; style.appendChild(document.createTextNode(s)); head.appendChild(style); } } try { if ('blog.csdn.net' ==location.host){ //修改原来烦人的样式 addStyle(); document.ready(function(){ //自动展开全文 var btnMore = document.querySelector('.readall_box a.btn.read_more_btn'); if (btnMore) btnMore.click(); //优化推荐列表显示效果 var recommendList = document.querySelector('.recommend_list'); if (recommendList){ var func = function(){ this.classList.add('show'); recommendList.removeEventListener('mousemove',func); }; recommendList.addEventListener('mousemove',func); } //删除空白段落 var paragraph = document.querySelectorAll('.article_content p'); paragraph.forEach(function(item){ if(!item.innerText.trim() && !item.querySelector('img,a') ) item.parentElement.removeChild(item); }); window.addEventListener('scroll',()=>{ if(getScrollTop() + getWindowHeight() > getScrollHeight()-10){ document.querySelectorAll('dl[class=""]').forEach(function(item){ item.parentElement.removeChild(item); }); document.querySelectorAll('iframe').forEach(function(item){ if ((item.src && item.src.indexOf('pos.baidu.com')>0) ){ item.parentElement.removeChild(item); } }); } }); setTimeout(function(){ //CSDN var hideArr = []; document.querySelectorAll('div[id]').forEach(function(item){ if (item.id.startsWith('BAIDU_SSP')) hideArr.push('#' + item.id); }); document.querySelectorAll('dl[class=""]').forEach(function(item){ item.parentElement.removeChild(item); }); document.querySelectorAll('iframe').forEach(function(item){ if ((item.src && item.src.indexOf('pos.baidu.com')>0) ){ if(item.parentElement.id.length > 0) hideArr.push('#' + item.parentElement.id); else item.parentElement.style.display = 'none !important;'; } }); if (hideArr.length > 0) hidden(hideArr); },200); }); } } catch (e) { console.log(e); } })();