Greasy Fork

蝦皮廣告封鎖器

蝦皮搜尋結果的前幾個商品廣告封鎖

目前为 2023-01-31 提交的版本。查看 最新版本

// ==UserScript==
// @name         蝦皮廣告封鎖器
// @namespace    https://greasyfork.org/scripts/437545
// @version      1.2
// @description  蝦皮搜尋結果的前幾個商品廣告封鎖
// @author       fmnijk
// @match        https://shopee.tw/*
// @icon         https://www.google.com/s2/favicons?domain=shopee.tw
// @grant        none
// @license      MIT
// @require      https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js
// ==/UserScript==


history.pushState = ( f => function pushState(){
    var ret = f.apply(this, arguments);
    window.dispatchEvent(new Event('pushstate'));
    window.dispatchEvent(new Event('locationchange'));
    return ret;
})(history.pushState);

history.replaceState = ( f => function replaceState(){
    var ret = f.apply(this, arguments);
    window.dispatchEvent(new Event('replacestate'));
    window.dispatchEvent(new Event('locationchange'));
    return ret;
})(history.replaceState);

window.addEventListener('popstate',()=>{
    window.dispatchEvent(new Event('locationchange'))
});

(function() {
    'use strict';
    // 定时器
    removead();
    window.addEventListener('locationchange', function (){
        removead();
    })
})();

function removead() {
        setIntervalX(() => {
            $(".col-xs-2-4.shopee-search-item-result__item").each(function() {
                //console.log($(".F7xq8U", $(this)).text());
                if ($(".F7xq8U", $(this)).text().indexOf("Ad") != -1){
                    $(this).hide();
                }
                if ($(".F7xq8U", $(this)).text().indexOf("廣告") != -1){
                    $(this).hide();
                }
            });
        }, 100, 20);
}

function setIntervalX(callback, delay, repetitions) {
    var x = 0;
    var intervalID = window.setInterval(function () {

        callback();

        if (++x === repetitions) {
            window.clearInterval(intervalID);
        }
    }, delay);
}