Skip to content

Commit

Permalink
Main page and subpage loading logic are not the same
Browse files Browse the repository at this point in the history
  • Loading branch information
wolfcon committed Oct 1, 2021
1 parent 390b051 commit f934391
Showing 1 changed file with 67 additions and 4 deletions.
71 changes: 67 additions & 4 deletions RIP-hltv-BET.user.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
// @name RIP HLTV BET
// @name:zh-CN HLTV 广告去除插件
// @namespace https://github.com/wolfcon/RIP-HLTV-BET
// @version 1.0
// @version 1.1
// @description Remove hltv.org Annoy AD
// @description:zh-cn 清除那些🤮背景赌博广告.
// @author Frank
// @require https://code.jquery.com/jquery-3.6.0.min.js
// @match https://www.hltv.org/*
// @match https://*.hltv.org/*
// @icon https://www.hltv.org/img/static/favicon/favicon-32x32.png
// @license MIT
// @run-at document-body
Expand All @@ -17,7 +17,67 @@ const filters = [
'[class*="yabo"]'
];

(function () {
function waitForKeyElements (
selectorTxt, actionFunction, bWaitOnce, iframeSelector
) {
var targetNodes, btargetsFound;

if (typeof iframeSelector == "undefined")
targetNodes = $(selectorTxt);
else
targetNodes = $(iframeSelector).contents ()
.find (selectorTxt);

if (targetNodes && targetNodes.length > 0) {
btargetsFound = true;
targetNodes.each ( function () {
var jThis = $(this);
var alreadyFound = jThis.data ('alreadyFound') || false;

if (!alreadyFound) {
//--- Call the payload function.
var cancelFound = actionFunction (jThis);
if (cancelFound)
btargetsFound = false;
else
jThis.data ('alreadyFound', true);
}
} );
}
else {
btargetsFound = false;
}

//--- Get the timer-control variable for this selector.
var controlObj = waitForKeyElements.controlObj || {};
var controlKey = selectorTxt.replace (/[^\w]/g, "_");
var timeControl = controlObj [controlKey];

//--- Now set or clear the timer as appropriate.
if (btargetsFound && bWaitOnce && timeControl) {
//--- The only condition where we need to clear the timer.
clearInterval (timeControl);
delete controlObj [controlKey]
}
else {
//--- Set a timer, if needed.
if ( ! timeControl) {
timeControl = setInterval ( function () {
waitForKeyElements(selectorTxt,
actionFunction,
bWaitOnce,
iframeSelector
);
},
300
);
controlObj [controlKey] = timeControl;
}
}
waitForKeyElements.controlObj = controlObj;
}

function removeAll() {
'use strict';

function removeNonOfficialSiteElement(element) {
Expand Down Expand Up @@ -58,4 +118,7 @@ const filters = [
filters.forEach(filter => {
removeClassElement(filter);
});
})();
};

removeAll();
waitForKeyElements("div,aside", removeAll);

0 comments on commit f934391

Please sign in to comment.