Greasy Fork

Greasy Fork is available in English.

净化常用国内博客

纯净进行 Ctrl+C, 贯彻执行 write once run everywhere.源码:https://jsrun.net/dHsKp

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         净化常用国内博客
// @namespace    https://github.com/jackkke
// @namespace    https://gitee.com/jackkke
// @version      1.5
// @description  纯净进行 Ctrl+C, 贯彻执行 write once run everywhere.源码:https://jsrun.net/dHsKp
// @author       jackkke [email protected]
// @match        *://blog.csdn.net/*
// @match        *://www.cnblogs.com/*
// @match        *://www.jianshu.com/*
// @match        *://juejin.cn/*
// @match        *://www.oschina.net/*
// @match        *://segmentfault.com/*
// @match        *://www.jb51.net/*
// ==/UserScript==
(function () {
    'use strict';
    let blogSiteDb = {
        csdn: {
            siteId: 'csdn',
            remove_class: ['blog_container_aside', 'insert-baidu-box', 'first-recommend-box', 'second-recommend-box', 'blog-footer-bottom', 'template-box', 'recommend-nps-box', 'tool-QRcode', 'kind_person', 'csdn-common-logo-advert', 'toolbar-advert'],
            remove_id: ['asideHotArticle', 'asideNewComments', 'asideArchive', 'asideNewNps', 'asideSearchArticle',],
            remove_more: ['.csdn-side-toolbar a:not(:last-child)',],
            pro_styles: []
        },
        'cnblogs': {
            siteId: 'cnblogs',
            remove_class: [],
            remove_id: ['cnblogs_c1', 'under_post_card1', 'under_post_card2', 'sideBar'],
            remove_more: [],
            pro_styles: ['#mainContent{margin: 0;}', '.forFlow{margin: 15px;}']
        },
        'jianshu': {
            siteId: 'jianshu',
            remove_class: ['_13lIbp', 'ouvJEz:last-of-type', '_1jKNin'],
            remove_id: [],
            remove_more: ['footer', 'footer ~ div', 'aside',],
            pro_styles: []
        },
        'juejin': {
            siteId: 'juejin',
            remove_class: ['.extension', '.recommended-area', '.sidebar', '.article-suspended-panel'],
            remove_id: [],
            remove_more: [],
            pro_styles: []
        },
        'oschina': {
            siteId: 'oschina',
            remove_class: ['other-articles-box', 'detail-toolbar-box', 'sidebar-box', 'codeBlock'],
            remove_id: ['footer'],
            remove_more: [],
            pro_styles: []
        },
        'segmentfault': {
            siteId: 'segmentfault',
            remove_class: ['functional-area-left', 'right-side', 'recommend-list-wrap', 'border-width-2'],
            remove_id: ['#footer'],
            remove_more: [],
            pro_styles: []
        },
        'jb51': {
            siteId: 'jb51',
            remove_class: ['xgcomm', 'main-right', 'art_xg'],
            remove_id: ['footer', 'ewm', 'right-share'],
            remove_more: [],
            pro_styles: []
        }
    };
    let handle = function (host, type) {
        const hosts = host.split('.');
        const id = hosts[hosts.length - 2];
        if (blogSiteDb.hasOwnProperty(id)) {
            console.log('refine current site [' + id + '] by jackkke');
            if (type === 'style') {
                handleCss(blogSiteDb[id])
            } else if (type === 'javascript') {
                handleJs(blogSiteDb[id])
            } else {
                console.error('处理类型有误!')
            }
        }
    };
    let handleCss = function (db) {
        let style = document.createElement('style');
        db.remove_class.forEach(function (css) {
            style.appendChild(document.createTextNode('.' + css + '{display: none!important;}'))
        });
        db.remove_id.forEach(function (id) {
            style.appendChild(document.createTextNode('#' + id + '{display: none!important;}'))
        });
        db.remove_more.forEach(function (more) {
            style.appendChild(document.createTextNode(more + '{display: none!important;}'))
        });
        db.pro_styles.forEach(function (pro_style) {
            style.appendChild(document.createTextNode(pro_style))
        });
        document.getElementsByTagName('head')[0].appendChild(style)
    };
    let handleJs = function (db) {
        db.remove_class.forEach(function (css) {
            let elements = document.getElementsByClassName(css);
            if (elements && elements.length > 0) {
                Array.prototype.forEach.call(elements, function (element) {
                    element.remove()
                })
            }
        });
        db.remove_id.forEach(function (id) {
            document.getElementById(id).remove()
        })
    };
    handle(location.host, 'style');

    function newLoadHandler() {
        handle(location.host, 'javascript')
    }
    var oldLoadHandler = window.onload;
    window.onload = function () {
        if (oldLoadHandler) {
            oldLoadHandler()
        }
        newLoadHandler()
    }
})();