起点中文网、B站、YouTube去除推荐;百度去除搜索热点列表;YouTube、网易云、B站去除评论;知乎去除首页推荐

这个脚本的功能有:起点中文网、B站、YouTube去除推荐;百度去除搜索热点列表;网易云、B站去除评论;知乎去除首页推荐

// ==UserScript==
// @name         起点中文网、B站、YouTube去除推荐;百度去除搜索热点列表;YouTube、网易云、B站去除评论;知乎去除首页推荐
// @namespace    https://greasyfork.org/
// @version      0.3.3
// @description  这个脚本的功能有:起点中文网、B站、YouTube去除推荐;百度去除搜索热点列表;网易云、B站去除评论;知乎去除首页推荐
// @author       sanjie27
// @match        https://book.qidian.com/*/*
// @match        https://www.qidian.com/
// @match        https://www.baidu.com/*
// @match        https://music.163.com/*
// @match        https://www.bilibili.com/*
// @match        https://www.zhihu.com/*
// @match        https://zhuanlan.zhihu.com/*
// @match        https://www.youtube.com/*
// @run-at       document_start
// @license      MIT
// ==/UserScript==


(function () {
    'use strict';
    let my_button = document.createElement("button");
    let flag = true;

    let create_button = function () {
        my_button.innerText = '是否显示推荐的列表?';
        my_button.style.cssText = "position:fixed;z-index:9999999;";
        document.body.insertBefore(my_button, document.body.firstChild);
    };

    let change_element = function (element, status) {
        if (document.getElementsByClassName(element)) {
            [...document.getElementsByClassName(element)].map(n => n.style.visibility = status);
        }
        if (document.getElementById(element)) {
            document.getElementById(element).style.visibility = status;
        }
    };

    // 要隐藏的元素的class或id
    let elements = ["m-rctlist f-cb", "g-wrap7", "m-sglist f-cb", "right-wrap fr", "nav-list site-nav fl", "like-more-list", "book-list-wrap mb10",//起点
                    "s-news-wrapper clearfix", "opr-recommends-merge-content", "cr-content", "rs",//百度
                    "recommend-list report-wrap-module report-scroll-module", "pop-live report-wrap-module report-scroll-module", "list-item reply-wrap is-top",//B站
                    "contents", "related"];//youtube

    // 要删除的评论的class
    let del = ["Topstory-mainColumn", "TopstoryTabs TopstoryPageHeader-tabs", "Tabs AppHeader-Tabs", "zu-top-nav", "AdblockBanner", "AdblockBanner-inner",//知乎
               "cmmts j-flag", "g-sd4",//网易云
               "list-item reply-wrap is-top",//B站
               "comments"//youtube
              ];

    create_button();
    my_button.addEventListener('click', function () {

        if (flag) {
            elements.forEach(function (i) {
                change_element(i, "hidden");
            });
            my_button.innerText = '已隐藏(再次点击显示)';
            my_button.style.color = 'green';
            flag = false;
        } else {
            elements.forEach(function (i) {
                change_element(i, "visible");
            });
            my_button.innerText = '已显示(再次点击隐藏)';
            my_button.style.color = 'red';
            flag = true;
        }
    });

    //在网易云音乐网站、知乎不显示按钮
    if (document.URL.indexOf("music") >= 0 || document.URL.indexOf("zhihu") >= 0) {
        my_button.remove();
    }

    //删除评论,删除知乎因使用adblock而出现的提示
    del.forEach(function (i) {
        Array.from(document.getElementsByClassName(i)).forEach(function(n) {n.parentNode.removeChild(n);});
     });
})();