Block inline script detecting devtools on edge/chromium - javascript

I am running the chromium version of edge, and have installed ublock origin, and I just wondering how I could disable this script from being loaded on a site. either through overrides or ublock origin preferably
<script data-cfasync="false" type="text/javascript">
if (-1 != navigator.userAgent.indexOf("Chrome") || -1 != navigator.userAgent.indexOf("Safari") || -1 != navigator.userAgent.indexOf("MSIE") || -1 != navigator.userAgent.indexOf("coc_coc_browser")) {
var checkStatus, element = new Image;
Object.defineProperty(element, "id", {
get: function() {
throw checkStatus = "on", new Error("Dev tools checker")
}
}), setInterval(function() {
checkStatus = "off", console.dir(element), "on" == checkStatus && (-1 != window.location.href.indexOf("?ep=")) && (window.location.href = window.location.href.split("watching.html")[0])
}, 1e3)
} - 1 != navigator.userAgent.indexOf("Firefox") && window.addEventListener("devtoolschange", e => {
1 == e.detail.isOpen && (-1 != window.location.href.indexOf("?ep=")) && (window.location.href = window.location.href.split("watching.html")[0])
});
! function() {
"use strict";
const i = {
isOpen: !1,
orientation: void 0
},
e = (i, e) => {
window.dispatchEvent(new CustomEvent("devtoolschange", {
detail: {
isOpen: i,
orientation: e
}
}))
};
setInterval(() => {
const n = window.outerWidth - window.innerWidth > 160,
o = window.outerHeight - window.innerHeight > 160,
t = n ? "vertical" : "horizontal";
o && n || !(window.Firebug && window.Firebug.chrome && window.Firebug.chrome.isInitialized || n || o) ? (i.isOpen && e(!1, void 0), i.isOpen = !1, i.orientation = void 0) : (i.isOpen && i.orientation === t || e(!0, t), i.isOpen = !0, i.orientation = t)
}, 500), "undefined" != typeof module && module.exports ? module.exports = i : window.devtools = i
}();
window.addEventListener("devtoolschange", e => {
e.detail.isOpen && (-1 != window.location.href.indexOf("?ep=")) && (window.location.href = window.location.href.split("watching.html")[0])
});
</script>

If it is a separate js file, you can block specific js files to load. Open DevTools -> network tab -> select file and right click -> choose block Request URL.
But if it is loaded on the page, I think this will not be possible. If you choose to disable javascript, then all the script content of the page will not work, which will affect the overall operation of the page.

uBO has some nice tools to stop these.
Have a look at https://github.com/uBlockOrigin/uBlock-issues/wiki/Resources-Library

Related

Issue with checking if item is in DOM and the executing the javascript function

I'm making a webpage that has two different navbars... Lets say I named them navbar1 and navbar2.. soo the navbar1 is being used on the home page of the web site and navbar2 on all other sub pages... I have written a pure Javascript function that checks if the navbar1 exists in DOM and if it does then it does something... if navbar1 doesent exist in DOM it should ignore that part of code and move forward with the rest...
so now I have this issue that I spent several hours now trying to resolve... and I just can figure it out... When I go to the home page the code works... everything that should happen to navbar1 happens... but if I go to a subpage that doesn't use navbar1 I get this error in the console: "Cannot read properties of null (reading 'getBoundingClientRect')"
I would apreciate some help... and if it matters I don't have much experience with javascript so :)
So here's my JS code...
function docReady(fn) {
if (document.readyState === "complete" || document.readyState === "interactive") {
setTimeout(fn, 1);
} else {
document.addEventListener("DOMContentLoaded", fn);
}
}
docReady(function() {
var className = "scroll";
var scrollTrigger = 60;
var navTogler = document.getElementById('navbar-toggler');
var navbar1 = document.getElementById('navbar1');
var isInViewport = function (elem) {
var bounding = elem.getBoundingClientRect();
return (
bounding.top >= 0 &&
bounding.left >= 0 &&
bounding.bottom <= (window.innerHeight || document.documentElement.clientHeight) &&
bounding.right <= (window.innerWidth || document.documentElement.clientWidth)
);
};
if (isInViewport(navbar1)) {
navTogler.addEventListener('click', classToggle);
function classToggle() {
navbar1.classList.toggle('has-bg');
if (navbar1.classList.contains('has-bg')) {
document.getElementsByClassName("logo")[0].src="./assets/images/Logo_blue.svg";
document.getElementsByClassName("search")[0].src="./assets/images/search-blue.svg";
}
if (navbar1.classList.contains('scroll') && navbar1.classList.contains('has-bg')) {
document.getElementsByClassName("logo")[0].src="./assets/images/Logo_blue.svg";
document.getElementsByClassName("search")[0].src="./assets/images/search-blue.svg";
}
if (!navbar1.classList.contains('scroll') && !navbar1.classList.contains('has-bg')) {
document.getElementsByClassName("logo")[0].src="./assets/images/Logo_White.svg";
document.getElementsByClassName("search")[0].src="./assets/images/search.svg";
}
else {
// console.log("something");
}
}
window.onscroll = function() {
if (window.scrollY >= scrollTrigger || window.pageYOffset >= scrollTrigger) {
document.getElementById("navbar1").classList.add(className);
document.getElementsByClassName("logo")[0].src="./assets/images/Logo_blue.svg";
document.getElementsByClassName("search")[0].src="./assets/images/search-blue.svg";
}
else {
document.getElementById("navbar1").classList.remove(className);
document.getElementsByClassName("logo")[0].src="./assets/images/Logo_White.svg";
document.getElementsByClassName("search")[0].src="./assets/images/search.svg";
}
};
}
var swiper = new Swiper(".mySwiper", {
slidesPerView: 3,
grid: {
rows: 2,
},
spaceBetween: 30,
pagination: {
el: ".swiper-pagination",
clickable: true,
},
});
console.log("hello swiper");
});
isInViewport() should return false if the element doesn't exist.
var isInViewport = function (elem) {
if (!elem) {
return false;
}
var bounding = elem.getBoundingClientRect();
return (
bounding.top >= 0 &&
bounding.left >= 0 &&
bounding.bottom <= (window.innerHeight || document.documentElement.clientHeight) &&
bounding.right <= (window.innerWidth || document.documentElement.clientWidth)
);
};

Javascript Image Slider - How to keep moving on mouse hover

I found a javascript image slider here: https://codepen.io/EricPorter/pen/XaOEpP and wanted to use it for my project.
I narrowed down the script to what I wanted below. It's exactly what I am looking to do except one thing. It pauses on mouse hover.
I have tried a few different things, but I cannot figure out how to keep the script sliding on mouse hover. I am somewhat limited in JS, I typically use vendor scripts and adjust as needed, if you could give a solution and explain the piece that is pausing it on mouse hover, I would greatly appreciate it.
Thank you in advance!
! function(o) {
"use strict";
o.fn.sliderResponsive = function(i) {
var n, e = o.extend({
slidePause: 4e3,
fadeSpeed: 600,
autoPlay: "on",
showArrows: "on",
hideDots: "on",
hoverZoom: "off",
titleBarTop: "off"
}, i),
d = o(this),
s = d.find("> div").length,
t = 0;
function f() {
n = setInterval(function() {
l()
}, e.slidePause)
}
function l() {
(t = d.find(".show").index() + 1) > s - 1 && (t = 0), a()
}
function a() {
d.find(".show").removeClass("show").fadeOut(), d.find("> div").eq(t).fadeIn(e.fadeSpeed).addClass("show"), d.find("> ul").find(".showli").removeClass("showli"), d.find("> ul > li").eq(t).addClass("showli")
}
return d.append("<ul></ul>"), d.find("> div").each(function() {
d.find("> ul").append("<li></li>")
}), d.find("div:first-of-type").addClass("show"), d.find("li:first-of-type").addClass("showli"), d.find("> div").not(".show").fadeOut(), "on" === e.autoPlay && f(), "on" === e.showArrows && d.addClass("showArrows"), "on" === e.hideDots && d.addClass("hideDots"), "off" === e.hoverZoom && d.addClass("hoverZoomOff"), "on" === e.titleBarTop && d.addClass("titleBarTop"), d.mouseover(function() {
"on" === e.autoPlay && clearInterval(n)
}), d.mouseout(function() {
"on" === e.autoPlay && f()
}), d.find("> .right").click(l), d.find("> .left").click(function() {
(t = d.find(".show").index() - 1) < 0 && (t = s - 1);
a()
}), d.find(" > ul > li").click(function() {
t = o(this).index(), a(o(this).index())
}), d
}
}(jQuery), $(document).ready(function() {
$("#slider3").sliderResponsive({
hoverZoom: "on"
})
});
You can add a new property to the settings object like below and then check for if the new property is set to on or off in the onmouseover and onmouseout functions.
Note: check the three comments in the code below
! function(o) {
"use strict";
o.fn.sliderResponsive = function(i) {
var n, e = o.extend({
slidePause: 4e3,
fadeSpeed: 600,
autoPlay: "on",
showArrows: "on",
hideDots: "on",
hoverZoom: "off",
titleBarTop: "off",
hoverStopPlay: "off" // <-- Add new property
}, i),
d = o(this),
s = d.find("> div").length,
t = 0;
function f() {
n = setInterval(function() {
l()
}, e.slidePause)
}
function l() {
(t = d.find(".show").index() + 1) > s - 1 && (t = 0), a()
}
function a() {
d.find(".show").removeClass("show").fadeOut(), d.find("> div").eq(t).fadeIn(e.fadeSpeed).addClass("show"), d.find("> ul").find(".showli").removeClass("showli"), d.find("> ul > li").eq(t).addClass("showli")
}
return d.append("<ul></ul>"), d.find("> div").each(function() {
d.find("> ul").append("<li></li>")
}), d.find("div:first-of-type").addClass("show"), d.find("li:first-of-type").addClass("showli"), d.find("> div").not(".show").fadeOut(), "on" === e.autoPlay && f(), "on" === e.showArrows && d.addClass("showArrows"), "on" === e.hideDots && d.addClass("hideDots"), "off" === e.hoverZoom && d.addClass("hoverZoomOff"), "on" === e.titleBarTop && d.addClass("titleBarTop"), d.mouseover(function() {
if("on" === e.autoPlay && e.hoverStopPlay === "on") { // <-- Add new condition
clearInterval(n);
}
}), d.mouseout(function() {
if("on" === e.autoPlay && e.hoverStopPlay === "on") { // <-- Add new condition
f();
}
}), d.find("> .right").click(l), d.find("> .left").click(function() {
(t = d.find(".show").index() - 1) < 0 && (t = s - 1);
a()
}), d.find(" > ul > li").click(function() {
t = o(this).index(), a(o(this).index())
}), d
}
}(jQuery), $(document).ready(function() {
$("#slider3").sliderResponsive({
hoverZoom: "on"
})
});

How to circumvent a "blockadblock" script with a benign adblock friendly substitute?

A website I interact with employs the following adblock detection script (beautified for readability):
! function(t) {
var e = function(e) {
this._options = {
checkOnLoad: !1,
resetOnEnd: !1,
loopCheckTime: 50,
loopMaxNumber: 5,
baitClass: "pub_300x250 pub_300x250m pub_728x90 text-ad textAd text_ad text_ads text-ads text-ad-links",
baitStyle: "width: 1px !important; height: 1px !important; position: absolute !important; left: -10000px !important; top: -1000px !important;",
debug: !1
}, this._var = {
version: "3.2.1",
bait: null,
checking: !1,
loop: null,
loopNumber: 0,
event: {
detected: [],
notDetected: []
}
}, void 0 !== e && this.setOption(e);
var o = this,
i = function() {
setTimeout(function() {
o._options.checkOnLoad === !0 && (o._options.debug === !0 && o._log("onload->eventCallback", "A check loading is launched"), null === o._var.bait && o._creatBait(), setTimeout(function() {
o.check()
}, 1))
}, 1)
};
void 0 !== t.addEventListener ? t.addEventListener("load", i, !1) : t.attachEvent("onload", i)
};
e.prototype._options = null, e.prototype._var = null, e.prototype._bait = null, e.prototype._log = function(t, e) {
console.log("[BlockAdBlock][" + t + "] " + e)
}, e.prototype.setOption = function(t, e) {
if (void 0 !== e) {
var o = t;
t = {}, t[o] = e
}
for (var i in t) this._options[i] = t[i], this._options.debug === !0 && this._log("setOption", 'The option "' + i + '" he was assigned to "' + t[i] + '"');
return this
}, e.prototype._creatBait = function() {
var e = document.createElement("div");
e.setAttribute("class", this._options.baitClass), e.setAttribute("style", this._options.baitStyle), this._var.bait = t.document.body.appendChild(e), this._var.bait.offsetParent, this._var.bait.offsetHeight, this._var.bait.offsetLeft, this._var.bait.offsetTop, this._var.bait.offsetWidth, this._var.bait.clientHeight, this._var.bait.clientWidth, this._options.debug === !0 && this._log("_creatBait", "Bait has been created")
}, e.prototype._destroyBait = function() {
t.document.body.removeChild(this._var.bait), this._var.bait = null, this._options.debug === !0 && this._log("_destroyBait", "Bait has been removed")
}, e.prototype.check = function(t) {
if (void 0 === t && (t = !0), this._options.debug === !0 && this._log("check", "An audit was requested " + (t === !0 ? "with a" : "without") + " loop"), this._var.checking === !0) return this._options.debug === !0 && this._log("check", "A check was canceled because there is already an ongoing"), !1;
this._var.checking = !0, null === this._var.bait && this._creatBait();
var e = this;
return this._var.loopNumber = 0, t === !0 && (this._var.loop = setInterval(function() {
e._checkBait(t)
}, this._options.loopCheckTime)), setTimeout(function() {
e._checkBait(t)
}, 1), this._options.debug === !0 && this._log("check", "A check is in progress ..."), !0
}, e.prototype._checkBait = function(e) {
var o = !1;
if (null === this._var.bait && this._creatBait(), (null !== t.document.body.getAttribute("abp") || null === this._var.bait.offsetParent || 0 == this._var.bait.offsetHeight || 0 == this._var.bait.offsetLeft || 0 == this._var.bait.offsetTop || 0 == this._var.bait.offsetWidth || 0 == this._var.bait.clientHeight || 0 == this._var.bait.clientWidth) && (o = !0), void 0 !== t.getComputedStyle) {
var i = t.getComputedStyle(this._var.bait, null);
!i || "none" != i.getPropertyValue("display") && "hidden" != i.getPropertyValue("visibility") || (o = !0)
}
this._options.debug === !0 && this._log("_checkBait", "A check (" + (this._var.loopNumber + 1) + "/" + this._options.loopMaxNumber + " ~" + (1 + this._var.loopNumber * this._options.loopCheckTime) + "ms) was conducted and detection is " + (o === !0 ? "positive" : "negative")), e === !0 && (this._var.loopNumber++, this._var.loopNumber >= this._options.loopMaxNumber && this._stopLoop()), o === !0 ? (this._stopLoop(), this._destroyBait(), this.emitEvent(!0), e === !0 && (this._var.checking = !1)) : (null === this._var.loop || e === !1) && (this._destroyBait(), this.emitEvent(!1), e === !0 && (this._var.checking = !1))
}, e.prototype._stopLoop = function(t) {
clearInterval(this._var.loop), this._var.loop = null, this._var.loopNumber = 0, this._options.debug === !0 && this._log("_stopLoop", "A loop has been stopped")
}, e.prototype.emitEvent = function(t) {
this._options.debug === !0 && this._log("emitEvent", "An event with a " + (t === !0 ? "positive" : "negative") + " detection was called");
var e = this._var.event[t === !0 ? "detected" : "notDetected"];
for (var o in e) this._options.debug === !0 && this._log("emitEvent", "Call function " + (parseInt(o) + 1) + "/" + e.length), e.hasOwnProperty(o) && e[o]();
return this._options.resetOnEnd === !0 && this.clearEvent(), this
}, e.prototype.clearEvent = function() {
this._var.event.detected = [], this._var.event.notDetected = [], this._options.debug === !0 && this._log("clearEvent", "The event list has been cleared")
}, e.prototype.on = function(t, e) {
return this._var.event[t === !0 ? "detected" : "notDetected"].push(e), this._options.debug === !0 && this._log("on", 'A type of event "' + (t === !0 ? "detected" : "notDetected") + '" was added'), this
}, e.prototype.onDetected = function(t) {
return this.on(!0, t)
}, e.prototype.onNotDetected = function(t) {
return this.on(!1, t)
}, t.BlockAdBlock = e, void 0 === t.blockAdBlock && (t.blockAdBlock = new e({
checkOnLoad: !0,
resetOnEnd: !0
}))
}(window);
The site design is such that this script cannot be blocked without halting the functionality of the site. I haven't consented to any EULA with this site and I believe I'm well within my rights to tamper with my client side code. I simply wish to circumvent this script with a benign adblock friendly substitute.
Essentially, I'd like to inject a user-defined script that will simulate the adblock notification event and give the server the impression that I have clicked through the following popup notification:
The approach I'd like try for this problem was suggested by #jake-holzinger. He remarked the script might be subverted by forcing the e class prototype to trigger the opposite adblock detection code, i.e. by overwritting e.prototype.onDetected with e.prototype.onNotDetected; although, I assume the same effect can be achieved by flipping the Boolean? As he explains it, this subverted code should be executed prior to the load event, but only after the above default code is run (I could be misinterpreting this part).
As a novice with JavaScript, I find these instructions a bit terse and opaque. In particular, I'm not entirely sure what the control flow is supposed to look like here. It seems like the default blockadblock script should be run (not blocked or replaced), but for some reason this needs to take place before the subverted code? Is the "subverted code" in this case a perfect replica of the blockadblock script, with the only difference being the inverted event names; or Boolean? What does it mean for the subverted code to be run before the load event? Isn't this already the case? Or do I need restructure the code to achieve this effect?

Hide irrelavent buttons when over <pre> tag

I am new with TinyMCE, but I managed to make a button, which buts a <pre><code>...</code></pre> tag with some code.
In there users can only write source code, but if they use a button like bold, then it gets bold..
I have been trying to figure out a way to disable that, and found out that it was possible to disable buttons when you was over a special tag.
So I was wondering, if anyone knew how that was possible??
I have this plugin, which example do it:
https://code.google.com/p/tinymce-pre-plugin/
If you look at the video you can see what I mean, he goes over the <pre><code>...</code></pre> tag right after 0:40.
You can see the source of the plugin file here:
(function() {
tinymce.PluginManager.requireLangPack('pre');
tinymce.create('tinymce.plugins.PrePlugin', {
init : function(ed, url) {
var t = this;
t.editor = ed;
ed.addCommand('mcePre', function() {
ed.windowManager.open({
file : url + '/dialog.htm',
width : 500 + parseInt(ed.getLang('pre.delta_width', 0)),
height : 300 + parseInt(ed.getLang('pre.delta_height', 0)),
inline : 1
}, {
plugin_url : url
});
});
ed.addButton('pre', {
title : 'pre.desc',
cmd : 'mcePre',
image : url + '/img/pre.gif'
});
ed.onNodeChange.add(function(ed, cm, n) {
cm.setActive('pre', n.nodeName == 'CODE');
if(n.nodeName == 'CODE') t._setDisabled(1);
else t._setDisabled(0);
var notEmptyNode = n.innerHTML.replace(new RegExp('<\/?[^>]+>', 'gi'), '').replace(new RegExp(' ', 'gi'), '').match(/.*?[\S].*?/);
if(notEmptyNode && n.nodeName != 'CODE')
cm.setDisabled('pre', true);
});
},
createControl : function(n, cm) {
return null;
},
getInfo : function() {
return {
longname : 'Pre plugin',
author : 'Marchenko Alexandr',
authorurl : 'http://webdiz.com.ua',
infourl : 'http://webdiz.com.ua',
version : "1.0"
};
},
_block : function(ed, e) {
var k = e.keyCode;
// Don't block arrow keys, pg up/down, and F1-F12
if (k == 46 || (k > 32 && k < 41) || (k > 111 && k < 124))
return;
if (e.preventDefault) {
e.preventDefault();
e.stopPropagation();
}
else {
e.returnValue = false;
e.cancelBubble = true;
}
return false;
},
_setDisabled : function(s) {
var t = this, ed = t.editor;
tinymce.each(ed.controlManager.controls, function(c) {
if(c.settings.cmd != 'mcePre') {
c.setDisabled(s);
}
});
if (s !== t.disabled) {
if (s) {
ed.onKeyDown.addToTop(t._block);
ed.onKeyPress.addToTop(t._block);
ed.onKeyUp.addToTop(t._block);
ed.onPaste.addToTop(t._block);
} else {
ed.onKeyDown.remove(t._block);
ed.onKeyPress.remove(t._block);
ed.onKeyUp.remove(t._block);
ed.onPaste.remove(t._block);
}
t.disabled = s;
}
}
});
// Register plugin
tinymce.PluginManager.add('pre', tinymce.plugins.PrePlugin);
})();
I found out.
This is the code which does this:
ed.onNodeChange.add(function(ed, cm, n) {
cm.setActive('pre', n.nodeName == 'PRE');
if(n.nodeName == 'PRE') t._setDisabled(1);
else t._setDisabled(0);
var notEmptyNode = n.innerHTML.replace(new RegExp('<\/?[^>]+>', 'gi'), '').replace(new RegExp(' ', 'gi'), '').match(/.*?[\S].*?/);
if(notEmptyNode && n.nodeName != 'PRE')
cm.setDisabled('pre', true);
});
Change PRE to whatever tag should be set for, but it disable all buttons, only the active buttons stays, but also no text can be written then.

Javascript error in jssh in Firefox 4.0b1

Using this Javascript through jssh compiled and built for the new Firefox 4.0 beta 1 returns an odd message. Here is the code (sorry if it's a little messy).
In summary the code checks all frames of a Firefox window which is a test page of our unit tests for a <td> element that has an onclick which contains the phrase Goodbye Wonderful, instead of getting a failed response back we are receiving this odd nserror at the end which we cannot explain.
var firefoxWindow = getWindows()[0];
var browser = firefoxWindow.getBrowser();
var doc = browser.contentDocument;
var elem = null;
var elems = doc.getElementsByTagName('td');
for(a=0;a < elems.length;a++){ if( ((elems[a] !== null && elems[a].hasAttributes() === true && elems[a].getAttribute('onclick') !== null && elems[a].getAttribute('onclick').toString().match(/doNothing/gim) !== null && elems[a].getAttribute('onclick').toString().match(/Goodbye Wonderful/gim).length >= 0) || (elems[a] !== null && elems[a].onclick !== null && elems[a].onclick.toString().match(/Goodbye Wonderful/gim) !== null && elems[a].onclick.toString().match(/Goodbye Wonderful/gim).length >= 0))) { elem = elems[a]; } }
var found = false;
var window = null;
for(var i=0; i < firefoxWindow.frames.length; i++){if(firefoxWindow.frames[i].toString().toLowerCase().indexOf('object window') > -1){window = firefoxWindow.frames[i]; break;}}
function recursiveSearch(frames){ for(var i=0; i<frames.length; i++){var elems = frames[i].document.getElementsByTagName('td'); for(a=0;a < elems.length;a++){ if( ((elems[a] !== null && elems[a].hasAttributes() === true && elems[a].getAttribute('onclick') !== null && elems[a].getAttribute('onclick').toString().match(/Goodbye Wonderful/gim) !== null && elems[a].getAttribute('onclick').toString().match(/Goodbye Wonderful/gim).length >= 0) || (elems[a] !== null && elems[a].onclick !== null && elems[a].onclick.toString().match(/Goodbye Wonderful/gim) !== null && elems[a].onclick.toString().match(/Goodbye Wonderful/gim).length >= 0))) { elem = elems[a]; } } if(elem){found = true; return;} else{ if(frames[i].frames.length>0){recursiveSearch(frames[i].frames);}}}}if(!elem && window.frames.length > 0){ recursiveSearch(window.frames); }var origColor = '';if(elem !== null){origColor = elem.style.backgroundColor;if(origColor === null){origColor = '';} elem.style.backgroundColor = 'yellow';}
Here is the return message from jssh :
Received: uncaught exception: [Exception... "Component is not available" nsresult: "0x80040111 (NS_ERROR_NOT_AVAILABLE)" location: "JS frame :: interactive :: <TOP_LEVEL> :: line 1" data: no]
JSSh is no longer supported in Firefox 4 and is a mess to handle, switching to mozrepl since it's written mostly in javascript and adding my own javascript commands directly to the extension seems to be a better way of accomplishing certain things.

Categories

Resources