This commit is contained in:
gorhill 2017-10-27 14:22:45 -04:00
parent 198f72a912
commit bbda2a9086
No known key found for this signature in database
GPG key ID: 25E1490B761470C2
22 changed files with 87 additions and 59 deletions

View file

@ -38,7 +38,7 @@
"content_scripts": [
{
"matches": ["http://*/*", "https://*/*"],
"js": ["js/vapi-client.js", "js/contentscript.js"],
"js": ["js/vapi.js", "js/vapi-client.js", "js/contentscript.js"],
"run_at": "document_start",
"all_frames": true
},

View file

@ -2,6 +2,7 @@
<html>
<head>
<meta charset="utf-8">
<script src="js/vapi.js"></script>
<script src="js/vapi-client.js"></script>
<script src="js/options_ui.js"></script>
<title></title>

View file

@ -28,8 +28,7 @@
(function() {
/******************************************************************************/
var vAPI = self.vAPI = self.vAPI || {};
/******************************************************************************/
var chrome = self.chrome;
var manifest = chrome.runtime.getManifest();

View file

@ -19,58 +19,21 @@
Home: https://github.com/gorhill/uBlock
*/
/* global HTMLDocument, XMLDocument */
// For non-background page
'use strict';
// For non background pages
/******************************************************************************/
(function(self) {
/******************************************************************************/
/******************************************************************************/
// https://github.com/chrisaljoudi/uBlock/issues/464
if ( document instanceof HTMLDocument === false ) {
// https://github.com/chrisaljoudi/uBlock/issues/1528
// A XMLDocument can be a valid HTML document.
if (
document instanceof XMLDocument === false ||
document.createElement('div') instanceof HTMLDivElement === false
) {
return;
}
}
// https://github.com/gorhill/uBlock/issues/1124
// Looks like `contentType` is on track to be standardized:
// https://dom.spec.whatwg.org/#concept-document-content-type
// https://forums.lanik.us/viewtopic.php?f=64&t=31522
// Skip text/plain documents.
var contentType = document.contentType || '';
if ( /^image\/|^text\/plain/.test(contentType) ) {
return;
}
/******************************************************************************/
// https://bugs.chromium.org/p/project-zero/issues/detail?id=1225&desc=6#c10
if ( !self.vAPI || self.vAPI.uBO !== true ) {
self.vAPI = { uBO: true };
}
var vAPI = self.vAPI;
var chrome = self.chrome;
// https://github.com/chrisaljoudi/uBlock/issues/456
// Already injected?
if ( vAPI.sessionId ) {
return;
}
// Skip if already injected.
if ( typeof vAPI === 'object' && !vAPI.clientScript ) { // >>>>>>>> start of HUGE-IF-BLOCK
/******************************************************************************/
/******************************************************************************/
vAPI.clientScript = true;
vAPI.randomToken = function() {
return String.fromCharCode(Date.now() % 26 + 97) +
@ -102,7 +65,6 @@ vAPI.shutdown = {
}
};
/******************************************************************************/
/******************************************************************************/
vAPI.messaging = {
@ -349,6 +311,4 @@ vAPI.shutdown.add(function() {
/******************************************************************************/
/******************************************************************************/
})(this);
/******************************************************************************/
} // <<<<<<<< end of HUGE-IF-BLOCK

View file

@ -28,12 +28,6 @@
(function(self) {
// https://bugs.chromium.org/p/project-zero/issues/detail?id=1225&desc=6#c10
if ( !self.vAPI || self.vAPI.uBO !== true ) {
self.vAPI = { uBO: true };
}
var vAPI = self.vAPI;
var chrome = self.chrome;
/******************************************************************************/

54
platform/chromium/vapi.js Normal file
View file

@ -0,0 +1,54 @@
/*******************************************************************************
uBlock Origin - a browser extension to block requests.
Copyright (C) 2017 The uBlock Origin authors
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see {http://www.gnu.org/licenses/}.
Home: https://github.com/gorhill/uBlock
*/
'use strict';
/* global HTMLDocument, XMLDocument */
// For background page, auxiliary pages, and content scripts.
/******************************************************************************/
// https://bugzilla.mozilla.org/show_bug.cgi?id=1408996#c9
var vAPI; // jshint ignore:line
// https://github.com/chrisaljoudi/uBlock/issues/464
// https://github.com/chrisaljoudi/uBlock/issues/1528
// A XMLDocument can be a valid HTML document.
// https://github.com/gorhill/uBlock/issues/1124
// Looks like `contentType` is on track to be standardized:
// https://dom.spec.whatwg.org/#concept-document-content-type
// https://forums.lanik.us/viewtopic.php?f=64&t=31522
// Skip text/plain documents.
if (
(document instanceof HTMLDocument ||
document instanceof XMLDocument &&
document.createElement('div') instanceof HTMLDivElement
) &&
(/^image\/|^text\/plain/.test(document.contentType || '') === false)
) {
vAPI = vAPI instanceof Object && vAPI.uBO === true ? vAPI : { uBO: true };
}
/******************************************************************************/

View file

@ -25,7 +25,7 @@
"content_scripts": [
{
"matches": ["http://*/*", "https://*/*"],
"js": ["js/vapi-client.js", "js/contentscript.js"],
"js": ["js/vapi.js", "js/vapi-client.js", "js/contentscript.js"],
"run_at": "document_start",
"all_frames": true
},

View file

@ -37,6 +37,7 @@
"file://*/*"
],
"js":[
"js/vapi.js",
"js/vapi-client.js",
"js/contentscript.js"
],

View file

@ -26,6 +26,7 @@
<input id="importFilePicker" type="file" accept="text/plain" class="hiddenFileInput">
</p>
<script src="js/vapi.js"></script>
<script src="js/vapi-common.js"></script>
<script src="js/vapi-client.js"></script>
<script src="js/udom.js"></script>

View file

@ -57,6 +57,7 @@
</ul>
</div>
<script src="js/vapi.js"></script>
<script src="js/vapi-common.js"></script>
<script src="js/vapi-client.js"></script>
<script src="js/udom.js"></script>

View file

@ -25,6 +25,7 @@
<li><a href="http://fontawesome.io" target="_blank">Font Awesome</a> by <a href="https://github.com/davegandy">Dave Gandy</a>
</ul>
<script src="js/vapi.js"></script>
<script src="js/vapi-common.js"></script>
<script src="js/vapi-client.js"></script>
<script src="js/udom.js"></script>

View file

@ -15,6 +15,7 @@
<button id="advancedSettingsApply" class="custom important" type="button" disabled="true" data-i18n="genericApplyChanges"></button>&ensp;
<p><textarea id="advancedSettings" dir="auto" spellcheck="false"></textarea>
<script src="js/vapi.js"></script>
<script src="js/vapi-common.js"></script>
<script src="js/vapi-client.js"></script>
<script src="js/udom.js"></script>

View file

@ -14,6 +14,7 @@
<div id="content"></div>
<script src="js/vapi.js"></script>
<script src="js/vapi-common.js"></script>
<script src="js/vapi-client.js"></script>
<script src="js/udom.js"></script>

View file

@ -8,6 +8,7 @@
<script src="js/polyfill.js"></script>
<script src="lib/punycode.js"></script>
<script src="lib/publicsuffixlist.js"></script>
<script src="js/vapi.js"></script>
<script src="js/vapi-common.js"></script>
<script src="js/vapi-background.js"></script>
<script src="js/vapi-webrequest.js"></script><!-- Forks can pick the webext, chromium, or their own implementation -->

View file

@ -24,6 +24,7 @@
<iframe id="iframe" src=""></iframe>
<script src="js/vapi.js"></script>
<script src="js/vapi-common.js"></script>
<script src="js/udom.js"></script>
<script src="js/i18n.js"></script>

View file

@ -166,6 +166,7 @@ body[dir="rtl"] #theURL > p > span {
</span>
</div>
<script src="js/vapi.js"></script>
<script src="js/vapi-common.js"></script>
<script src="js/vapi-client.js"></script>
<script src="js/udom.js"></script>

View file

@ -50,6 +50,7 @@
</ul>
</div>
<script src="js/vapi.js"></script>
<script src="js/vapi-common.js"></script>
<script src="js/vapi-client.js"></script>
<script src="js/udom.js"></script>

View file

@ -105,7 +105,13 @@
// https://github.com/chrisaljoudi/uBlock/issues/456
// https://github.com/gorhill/uBlock/issues/2029
if ( typeof vAPI !== 'undefined' ) { // >>>>>>>> start of HUGE-IF-BLOCK
if ( typeof vAPI === 'object' && !vAPI.contentScript ) { // >>>>>>>> start of HUGE-IF-BLOCK
/******************************************************************************/
/******************************************************************************/
/******************************************************************************/
vAPI.contentScript = true;
/******************************************************************************/
/******************************************************************************/

View file

@ -112,6 +112,7 @@
<div id="filterFinderDialogSentence1"><span><span></span><code></code><span></span></span></div>
</div>
<script src="js/vapi.js"></script>
<script src="js/vapi-common.js"></script>
<script src="js/vapi-client.js"></script>
<script src="js/udom.js"></script>

View file

@ -59,6 +59,7 @@
</div>
<script src="lib/punycode.js"></script>
<script src="js/vapi.js"></script>
<script src="js/vapi-common.js"></script>
<script src="js/vapi-client.js"></script>
<script src="js/udom.js"></script>

View file

@ -55,6 +55,7 @@
<p><button class="custom" type="button" id="reset" data-i18n="aboutResetDataButton"></button>
</div>
<script src="js/vapi.js"></script>
<script src="js/vapi-common.js"></script>
<script src="js/vapi-client.js"></script>
<script src="js/udom.js"></script>

View file

@ -28,6 +28,7 @@
<input id="importFilePicker" type="file" accept="text/plain" class="hiddenFileInput">
<script src="lib/punycode.js"></script>
<script src="js/vapi.js"></script>
<script src="js/vapi-common.js"></script>
<script src="js/vapi-client.js"></script>
<script src="js/udom.js"></script>