清除cnblog广告 清爽页面

2020/9/17 4:05:39油猴脚本Tampermonkey油猴

image.png

由于cnblog多是博主自定义主题,所以这里需要不断新增自定义更新才能尽量对多数页面进行清理。

// ==UserScript==
// @name         删除cnblog页面无关元素
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  try to take over the world!
// @author       You
// @match        https://www.cnblogs.com/**
// @grant        none
// ==/UserScript==

(function() {
    'use strict';
    clear()
    setInterval(()=>{
        clear()
    },1000)
    let style = document.createElement('style')
    style.innerHTML = `
        body{background:none;overflow:auto;}
        #main{min-height:100vh;}
        #main,#mainContent,.forFlow,#topics,.post>div,#topics .postTitle{width:768px !important;max-width:100% !important;border:0;}
        #cnblogs_post_body{margin:0 auto;}
        #mainContent .forFlow{margin:0;border-top:0;}
        .post{padding-right:20px}
        #topics .postTitle,h1{margin-bottom:2rem;text-align:center;font-size:20px;}
        #topics .postTitle a,h1 a{font-size:20px;}
        #centercontent{width:100%;padding:0;}
        @media print{#main,#mainContent,.forFlow,#topics,.post>div,#cnblogs_post_body{width:100% !important;}}
    `;
    document.body.appendChild(style)
    function clear(){
        [
            'script',
            '#rightAside',
            'iframe',
            'svg',
            '#MathJax_Message',
            'a[name="top"]',
            '#header',
            '#sideBar',
            '#footer',
            '#comment_form',
            '.postDesc',
            '#blog_post_info_block',
            '#top_nav',
            '#mytopmenu',
            '#leftcontent',
            '.footer',
        ].forEach(item=>{
            let arr = document.querySelectorAll(item);
            if(arr){
                let list = Array.from(arr)
                if(list.length>0){
                    list.forEach(el=>{
                        el.parentElement.removeChild(el)
                    })
                }
            }
        })
    }
    // Your code here...
})();