// ==UserScript== // @name 贴吧广告过滤登录去除 // @namespace noting // @version 0.7.4 // @description 贴吧广告过滤,没有登录强行关闭登录 // @author Time // @match https://tieba.baidu.com/* // @grant none // @license Time // @downloadURL none // ==/UserScript== (function() { var options = { expensionName: "贴吧广告过滤登录去除", interval: 300, development: false, isDomRemove: false, show : false, matching: "tieba.baidu.com", loginDom: "tiebaCustomPassLogin", avdTextClass: "label_text", avdText: "广告", avdIds: ["pagelet_frs-aside/pagelet/fengchao_ad","banner_pb_customize","plat_recom_carousel"], avdDom: ["fengchao-wrap-feed","head_banner","head_ad_pop","l_banner","j_couplet","card_banner","bus-top-activity-wrap"], }; var log = function(error){ if(options.development){ console.log(options.expensionName,error); } } var detectionAvd = new Array(); var existAvd = function(avd) { if (!detectionAvd.find(item => item._this === avd)) return false; return true; }; var addAvd = function(avd) { if (!avd) return; if (existAvd(avd)) return; var model = { _this: avd, hide: null }; var hideFunction = function() { if (!avd || !avd.style) return; if(options.show){ avd.style.display = ""; return; } if (avd.style.display == "none") return; if (!options.isDomRemove) { avd.style.display = "none"; } else { avd.remove(); } } model.hide = hideFunction; detectionAvd.push(model); }; var host = window.location.host; if (host.indexOf(options.matching) == -1) return; var detectLogin = function() { var login = document.getElementById(options.loginDom); if (login == null) return; addAvd(login); }; var detectAdvertisement = function() { var snifferAvd = function(type, parameter) { if (!parameter || !type) return; var advPrameterArray = new Array(); if (typeof(parameter) == 'string') advPrameterArray.push(parameter); else if (Array.isArray(parameter)) advPrameterArray = parameter; for (var adv = 0; adv < advPrameterArray.length; adv++) { var advElement = undefined; switch (type) { case 1: advElement = document.getElementsByClassName(advPrameterArray[adv]); break; case 2: advElement = [document.getElementById(advPrameterArray[adv])]; break; default: break; } if (!advElement) continue; if (advElement.length > 0) { for (var i = 0; i < advElement.length; i++) { //advElement[i].remove(); addAvd(advElement[i]); } } else { addAvd(advElement); } } } snifferAvd(1, options.avdDom); snifferAvd(2, options.avdIds); var classAvdText = document.getElementsByClassName(options.avdTextClass); if (classAvdText.length > 0) { for (var i = 0; i < classAvdText.length; i++) { if (classAvdText[i].innerText == options.avdText) { var node = classAvdText[i]; if (!node.parentNode) continue; var avdNode = node.parentNode; if (!avdNode.parentNode) continue; var parentfather = avdNode.parentNode; addAvd(avdNode); } } } }; var avdHandler = function() { for (var i = 0; i < detectionAvd.length; i++) { try { detectionAvd[i].hide(); //if (detectionAvd[i]._this) { // detectionAvd.splice(i, 1) //} } catch(ex) { log(ex); } } }; //新建一个div元素节点 var div=document.createElement("div"); div.innerText = " 贴吧广告过滤登录去除 \r\n 显示/隐藏广告:\r\n"; div.style = "position: absolute;height: 60px;width: 200px;top: 150px;border: 1px solid;left: 5px;text-align: center;"; var checkbox = document.createElement('input'); checkbox.type = "checkbox"; checkbox.addEventListener( 'click', function(){ if(options.show) { options.show = false; } else { options.show = true; } } ); div.appendChild(checkbox); document.body.appendChild(div); setInterval(function() { detectLogin(); detectAdvertisement(); avdHandler(); log(detectionAvd); },options.interval); })();