gqz / 百度清爽

// ==UserScript==
// @name         百度清爽
// @namespace    https://openuserjs.org/scripts/gqz/%E7%99%BE%E5%BA%A6%E6%B8%85%E7%88%BD
// @version      0.1.3
// @description  try to take over the world!
// @author       You
// @match        https://www.baidu.com/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=baidu.com
// @grant        none
// @run-at       document-start
// @updateURL https://openuserjs.org/meta/gqz/百度清爽.meta.js
// @copyright 2023, gqz (https://openuserjs.org/users/gqz)
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';
     console.log('Baidu Clear Init')
     var css =`
      .EC_result{
         display:none !important;
         height:0px !important;
      }
      #searchTag{
        display:none !important;
         height:0px !important;
     }
     .c-container > .san-card[tpl="feed-ad"]{
        height:0px !important;
        overflow: hidden;
     }
     #con-ar > div{
       display:none;
     }
      #con-ceiling-wrapper{
        display:block !important;
      }
     
#content_right > div {
    height:0px !important;
    overflow: hidden;
}
     `;

    function addStyle(){
        if(document.getElementById('yhstyle')===null){
            var node = document.createElement("style");
            node.type = "text/css";
            node.id='yhstyle'
            node.appendChild(document.createTextNode(css));
            var heads = document.getElementsByTagName("body");
            heads[0].appendChild(node);
        }
    }
    addStyle()

    var throttle = function(func, delay) {
            var prev = Date.now();
            return function() {
                var context = this;
                var args = arguments;
                var now = Date.now();
                if (now - prev >= delay) {
                    func.apply(context, args);
                    prev = Date.now();
                }
            }
        }

var interval = null;
var intervalNum = 0;

document.addEventListener("DOMContentLoaded", () => {
  jQuery('.c-container').has('.c-gap-left:contains("广告")').remove()

    $("#su").on('click', function(){

        interval = setInterval(function(){
            addStyle()
            intervalNum++;
            jQuery('.c-container').has('.c-gap-left:contains("广告")').remove()
            if(intervalNum > 200){
               interval!==null && clearInterval(interval);
            }
        },20)

        });
});

window.addEventListener("scroll",  throttle(function () {
    interval!==null &&  clearInterval(interval);
    jQuery('.c-container').has('.c-gap-left:contains("广告")').remove()
},400))

})();