From 3f074d7908c405bb24aa9d303b010253ecbdec03 Mon Sep 17 00:00:00 2001 From: Raymond Hill Date: Mon, 30 Sep 2019 07:50:35 -0400 Subject: [PATCH] Use `self` when testing for `vAPI` presence --- platform/chromium/vapi-client.js | 3 ++- platform/chromium/vapi.js | 20 ++++++++++++-------- src/js/contentscript.js | 10 +++++----- 3 files changed, 19 insertions(+), 14 deletions(-) diff --git a/platform/chromium/vapi-client.js b/platform/chromium/vapi-client.js index 25b021ef5..c8a934dec 100644 --- a/platform/chromium/vapi-client.js +++ b/platform/chromium/vapi-client.js @@ -227,7 +227,8 @@ vAPI.messaging = { this.extended = vAPI.messaging.send('vapi', { what: 'extendClient' }).then(( ) => { - return vAPI instanceof Object && this.extensions.length !== 0; + return self.vAPI instanceof Object && + this.extensions.length !== 0; }).catch(( ) => { }); } diff --git a/platform/chromium/vapi.js b/platform/chromium/vapi.js index 7933b40a2..a95ae60e6 100644 --- a/platform/chromium/vapi.js +++ b/platform/chromium/vapi.js @@ -36,7 +36,7 @@ if ( self.browser instanceof Object ) { /******************************************************************************/ // https://bugzilla.mozilla.org/show_bug.cgi?id=1408996#c9 -var vAPI = window.vAPI; // jshint ignore:line +var vAPI = self.vAPI; // jshint ignore:line // https://github.com/chrisaljoudi/uBlock/issues/464 // https://github.com/chrisaljoudi/uBlock/issues/1528 @@ -50,15 +50,19 @@ var vAPI = window.vAPI; // jshint ignore:line // Skip text/plain documents. if ( - (document instanceof HTMLDocument || - document instanceof XMLDocument && - document.createElement('div') instanceof HTMLDivElement + ( + document instanceof HTMLDocument || + document instanceof XMLDocument && + document.createElement('div') instanceof HTMLDivElement ) && - (/^image\/|^text\/plain/.test(document.contentType || '') === false) + ( + /^image\/|^text\/plain/.test(document.contentType || '') === false + ) && + ( + self.vAPI instanceof Object === false || vAPI.uBO !== true + ) ) { - vAPI = window.vAPI = vAPI instanceof Object && vAPI.uBO === true - ? vAPI - : { uBO: true }; + self.vAPI = { uBO: true }; } diff --git a/src/js/contentscript.js b/src/js/contentscript.js index f0510a9dc..42b83e25f 100644 --- a/src/js/contentscript.js +++ b/src/js/contentscript.js @@ -148,7 +148,7 @@ vAPI.SafeAnimationFrame = function(callback) { vAPI.SafeAnimationFrame.prototype = { start: function(delay) { - if ( vAPI instanceof Object === false ) { return; } + if ( self.vAPI instanceof Object === false ) { return; } if ( delay === undefined ) { if ( this.fid === undefined ) { this.fid = requestAnimationFrame(( ) => { this.onRAF(); } ); @@ -1063,7 +1063,7 @@ vAPI.domCollapser = (function() { const domWatcherInterface = { onDOMCreated: function() { - if ( vAPI instanceof Object === false ) { return; } + if ( self.vAPI instanceof Object === false ) { return; } if ( vAPI.domCollapser instanceof Object === false ) { if ( vAPI.domWatcher instanceof Object ) { vAPI.domWatcher.removeListener(domWatcherInterface); @@ -1343,11 +1343,11 @@ vAPI.domSurveyor = (function() { const domWatcherInterface = { onDOMCreated: function() { if ( - vAPI instanceof Object === false || + self.vAPI instanceof Object === false || vAPI.domSurveyor instanceof Object === false || vAPI.domFilterer instanceof Object === false ) { - if ( vAPI instanceof Object ) { + if ( self.vAPI instanceof Object ) { if ( vAPI.domWatcher instanceof Object ) { vAPI.domWatcher.removeListener(domWatcherInterface); } @@ -1400,7 +1400,7 @@ vAPI.bootstrap = (function() { // This can happen on Firefox. For instance: // https://github.com/gorhill/uBlock/issues/1893 if ( window.location === null ) { return; } - if ( vAPI instanceof Object === false ) { return; } + if ( self.vAPI instanceof Object === false ) { return; } vAPI.messaging.send('contentscript', { what: 'shouldRenderNoscriptTags',