用TamperMonkey去掉cdsn中的广告

最近CSDN需要登录后才能查看更多内容,有点影响心情

解决方案

添加一段书签

javascript:(function(){document.getElementById('article_content').style.height='auto';document.getElementsByClassName('hide-article-box')[0].style.display='none';}())

在网页里面点一下就行了

进阶版

每次点一下还是有点麻烦,还是使用了一个chorme插件TamperMonkey来自动执行代码,下面的代码隐藏掉一些碍眼的广告和推荐(CSDN自带JQuery)

// ==UserScript==
// @name         BOLCK CSDN
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  try to take over the world!
// @author       WozHuang
// @match        https://blog.csdn.net/*
// @grant        none
// @run-at       document-end
// ==/UserScript==

function rm(elementArray){
    for(let element of elementArray){
        element && element.parentNode.removeChild(element);
        //element.style.display='none';
    }
}

(function() {
    'use strict';
    var old_onload = window.onload;
    var temp
    window.onload=function(){
        old_onload && old_onload();
        (function(){
            (temp = document.getElementById('article_content')) && (temp.style.height='auto');
            (temp = document.getElementsByClassName('hide-article-box')[0]) && (temp.style.display='none');
        }())
        rm([
            document.getElementsByClassName('adblock')[0],
            document.getElementById('csdn-toolbar'),
            document.getElementById('asideProfile').parentNode,
            document.getElementsByClassName('pulllog-box')[0],
            document.getElementsByClassName('recommend-right')[0],
            document.getElementsByClassName('tool-box')[0],
            document.getElementsByClassName('fourth_column')[0],
            document.getElementsByClassName('comment-box')[0],
            document.getElementById('dmp_ad_58'),
        ]);
        var main = document.getElementsByTagName('main')[0];
        main && (main.style.float='none');
        main && (main.style.margin='0px auto');
        var $ = window.$;
        if(!$){alert('There are no jQuery');}
        $(function(){
            var rec_box = $(".recommend-box");
            rec_box.css("opacity","0.1");
            rec_box.css("overflow","hidden");
            rec_box.css("height","100px");
        });
        $(".recommend-box").hover(function(){
            $(this).css("opacity","1");
            $(this).css("height","auto");
        },function(){
            $(this).css("opacity","0.1");
        });
    };
})();
原文地址:https://www.cnblogs.com/wozho/p/10044975.html