// ==UserScript== // @namespace GTBT // @name alibaba-ad-distinguish // @name:zh-CN 区分阿里巴巴广告 // @description make it easier to distinguish the ads in alibaba's search page // @description:zh-CN 让‘阿里巴巴’搜索页的广告易于分辨 // @version 1.2 // @match http://s.1688.com/* // @match https://s.1688.com/* // @grant none // @run-at document-end // @downloadURL none // ==/UserScript== /*eslint curly: ["off", "multi", "consistent"]*/ console.log('!!!!!!!!!!!!!!!!!!!alibaba-ad-remove!!!!!!!!!!!!!!!!!!!!!!!!!!'); (function () { function changeTreeBgColor(root, color) { if (!root) return; if (root.style) root.style.backgroundColor = color; for (let node of root.childNodes) { if (node.style) node.style.backgroundColor = color; changeTreeBgColor(node, color); } } function checkRemoveNodeAd(node) { if (node.nodeName !== 'LI') return; //console.log('check node', node); let ad = node.querySelector('.wsw-ball > a'); //console.log('ad ', ad); if (!ad || !ad.innerText.includes('广告')) { return; } let item = ad.closest('li'); console.log('weaken ad', item.id); //item.remove(); ad.setAttribute('style', 'color:yellow!important'); changeTreeBgColor(item, 'lightgray'); } function removeStaticNodesAd() { for (let node of document.querySelectorAll('#sm-offer-list li')) checkRemoveNodeAd(node); document.querySelectorAll('.sw-layout-side').forEach((e, i) => { console.log(`side ${i}. ${e}`); //e.style.backgroundColor = 'lightgray'; changeTreeBgColor(e, 'lightgray'); }); } function waitAndRemoveDynamicNodesAd() { let targetNode = document.querySelector('#sm-offer-list'); // Create an observer instance linked to the callback function new MutationObserver(function (mutationsList, observer) { for (let mutation of mutationsList) { if (mutation.type == 'childList') { //console.log('A child node has been added or removed.', mutation); for (let node of mutation.addedNodes) checkRemoveNodeAd(node); } } }).observe(targetNode, { attributes: false, childList: true, subtree: false }); targetNode = document.querySelector('.sw-layout-side .sm-widget-p4p'); // Create an observer instance linked to the callback function new MutationObserver(function (mutationsList, observer) { for (let mutation of mutationsList) { if (mutation.type == 'childList') { //console.log('A child node has been added or removed.', mutation); for (let node of mutation.addedNodes) changeTreeBgColor(node, 'lightgray'); } } }).observe(targetNode, { attributes: false, childList: true, subtree: false }); } //document.addEventListener('ready', waitAndRemove); removeStaticNodesAd(); waitAndRemoveDynamicNodesAd(); })(); console.log('!!!!!!!!!!!!!!!!!!!/alibaba-ad-remove!!!!!!!!!!!!!!!!!!!!!!!!!!');