移除蝦皮廣告 (Remove Shopee Ads)

移除蝦皮廣告,移除那些容易誤點的廣告,避免使用者誤點商品。

安裝腳本?
作者推薦腳本

您可能也會喜歡 蝦皮票券管理

安裝腳本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         移除蝦皮廣告 (Remove Shopee Ads)
// @version      1.5.0
// @description  移除蝦皮廣告,移除那些容易誤點的廣告,避免使用者誤點商品。
// @author       Danny H.
// @match        https://shopee.tw/*
// @match        https://shopee.vn/*
// @match        https://shopee.co.id/*
// @match        https://shopee.com.my/*
// @match        https://shopee.co.th/*
// @match        https://shopee.ph/*
// @match        https://shopee.sg/*
// @match        https://shopee.com.br/*
// @icon         https://freepngimg.com/save/109004-shopee-logo-free-transparent-image-hq/128x128
// @grant        GM_addStyle
// @license      MIT
// @require      https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js
// @namespace    https://greasyfork.org/users/1166167
// ==/UserScript==

(function() {
    'use strict';

    // 新增高亮樣式
    GM_addStyle(`
        .highlight-region {
            background-color: yellow !important;
            font-weight: bold;
        }
    `);

    // 處理廣告移除
    function removeAds() {
        const $ads = $(':contains("AD"), :contains("Ad"), :contains("廣告")');
        $ads.each(function() {
            $(this).closest('.col-xs-2-4.shopee-search-item-result__item').hide();
            $(this).closest('.shopee_ic').hide();
            $(this).closest('.shopee_ic').parent().hide();
            $(this).closest('.Qnex0a').hide();
            $(this).closest('.QDF8HH.col-xs-2').hide();
            $(this).closest('.shopee-header-section.shopee-header-section--simple').hide();
        });
    }

    // 高亮特定區域
    function highlightRegions() {
        $('span.align-middle').each(function() {
            const text = $(this).text();
            if (text.includes("桃園市蘆竹區") || text.includes("桃園市大園區")) {
                $(this).addClass('highlight-region');
            }
        });
    }

    // 初始化 DOM 監聽
    function initObserver() {
        const observer = new MutationObserver((mutations) => {
            mutations.forEach((mutation) => {
                if (mutation.type === 'childList') {
                    setTimeout(() => {
                        removeAds();
                        highlightRegions();
                    }, 500);  // 每次 DOM 變化後延遲 500ms 執行
                }
            });
        });

        const config = { childList: true, subtree: true };
        observer.observe(document.body, config);
    }

    function onPageLoad() {
        setTimeout(() => {
            removeAds();
            highlightRegions();
            initObserver();
        }, 500);  // 頁面加載完成後延遲 500ms 執行
    }

    if (document.readyState === 'loading') {
        document.addEventListener('DOMContentLoaded', onPageLoad);
    } else {
        onPageLoad();
    }

    // 應對網址變更
    window.addEventListener('locationchange', () => setTimeout(() => {
        removeAds();
        highlightRegions();
    }, 500));
})();