Last active
August 1, 2017 13:05
-
-
Save slacker/07d2e48b5c73a95828c3ccb61e98f959 to your computer and use it in GitHub Desktop.
A Greasemonkey script for allowing AdBlock/uBlock on HotsLogs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Hotslogs Bypass | |
// @version 1.3 | |
// @description Stops redirects | |
// @author https://github.com/slacker | |
// @match https://www.hotslogs.com/* | |
// @grant none | |
// @run-at document-start | |
// ==/UserScript== | |
// Thanks to http://stackoverflow.com/questions/3972038/stop-execution-of-javascript-function-client-side-or-tweak-it/10468821#10468821 | |
checkForBadJavascripts ( [ | |
[ false, /window\.location\s=/, null ], | |
[ false, /window\.location\.replace/, null], | |
[ false, /jqueryWindow\.attr\("location"/, null] | |
// [ false, /MonkeyBroker/, null ] | |
] ); | |
function checkForBadJavascripts (controlArray) { | |
/*--- Note that this is a self-initializing function. The controlArray | |
parameter is only active for the FIRST call. After that, it is an | |
event listener. | |
The control array row is defines like so: | |
[bSearchSrcAttr, identifyingRegex, callbackFunction] | |
Where: | |
bSearchSrcAttr True to search the SRC attribute of a script tag | |
false to search the TEXT content of a script tag. | |
identifyingRegex A valid regular expression that should be unique | |
to that particular script tag. | |
callbackFunction An optional function to execute when the script is | |
found. Use null if not needed. | |
*/ | |
if ( ! controlArray.length) return null; | |
checkForBadJavascripts = function (zEvent) { | |
for (var J = controlArray.length - 1; J >= 0; --J) { | |
var bSearchSrcAttr = controlArray[J][0]; | |
var identifyingRegex = controlArray[J][1]; | |
if (bSearchSrcAttr) { | |
if (identifyingRegex.test (zEvent.target.src) ) { | |
stopBadJavascript (J); | |
return false; | |
} | |
} | |
else { | |
if (identifyingRegex.test (zEvent.target.textContent) ) { | |
stopBadJavascript (J); | |
return false; | |
} | |
} | |
} | |
function stopBadJavascript (controlIndex) { | |
zEvent.stopPropagation (); | |
zEvent.preventDefault (); | |
var callbackFunction = controlArray[J][2]; | |
if (typeof callbackFunction == "function") | |
callbackFunction (); | |
//--- Remove the node just to clear clutter from Firebug inspection. | |
zEvent.target.parentNode.removeChild (zEvent.target); | |
//--- Script is intercepted, remove it from the list. | |
controlArray.splice (J, 1); | |
if ( ! controlArray.length) { | |
//--- All done, remove the listener. | |
window.removeEventListener ( | |
'beforescriptexecute', checkForBadJavascripts, true | |
); | |
} | |
} | |
} | |
/*--- Use the "beforescriptexecute" event to monitor scipts as they are loaded. | |
See https://developer.mozilla.org/en/DOM/element.onbeforescriptexecute | |
Note that it does not work on acripts that are dynamically created. | |
*/ | |
window.addEventListener ('beforescriptexecute', checkForBadJavascripts, true); | |
return checkForBadJavascripts; | |
} | |
function addJS_Node (text, s_URL, funcToRun) { | |
var D = document; | |
var scriptNode = D.createElement ('script'); | |
scriptNode.type = "text/javascript"; | |
if (text) scriptNode.textContent = text; | |
if (s_URL) scriptNode.src = s_URL; | |
if (funcToRun) scriptNode.textContent = '(' + funcToRun.toString() + ')()'; | |
var targ = D.getElementsByTagName ('head')[0] || D.body || D.documentElement; | |
//--- Don't error check here. if DOM not available, should throw error. | |
targ.appendChild (scriptNode); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment