Greasy Fork

来自缓存

Greasy Fork is available in English.

1688屏蔽搜索广告

删除1688广告商品,在原位留下空白

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         1688屏蔽搜索广告
// @version      0.11
// @description  删除1688广告商品,在原位留下空白
// @match        https://s.1688.com/selloffer/*
// @license      GPL-3.0+
// @namespace http://greasyfork.icu/users/1367202
// ==/UserScript==

(function () {
    const hostname = window.location.hostname;
    if (hostname === 's.1688.com') {
        process();
        const observer = new MutationObserver(process);
        observer.observe(document.body, { childList: true, subtree: true });
    }

    function process() {
        // 查找所有 main-img-icon 的 img 元素
        const mainImgIcons = document.querySelectorAll('img.main-img-icon');
        if (mainImgIcons.length > 0) {
            const offersToRemove = [];
            mainImgIcons.forEach(img => {
                // 获取其对应的 a.search-offer-wrapper.cardui-normal.search-offer-item.major-offer 父级元素
                const offerWrapper = img.closest('a.search-offer-wrapper.cardui-normal.search-offer-item.major-offer');
                if (offerWrapper && offerWrapper.parentNode) {
                    // 收集需要移除的广告父元素
                    offersToRemove.push(offerWrapper);
                }
            });
            // 一次性移除所有收集到的广告父元素
            offersToRemove.forEach(offer => offer.remove());
        }
    }
})();