aboutsummaryrefslogtreecommitdiffstats
path: root/js/vapi-common.js
diff options
context:
space:
mode:
authorJesús <heckyel@hyperbola.info>2022-04-06 10:38:06 +0800
committerJesús <heckyel@hyperbola.info>2022-04-06 10:38:06 +0800
commit8aeb670be1d252807252ee2bfe99b15b81c3e28d (patch)
treeced0973165449d620c5c40876c37ab16b17655f9 /js/vapi-common.js
parent5aa99a2ea2b683ba35eb36dfc54efd79f3cfcb85 (diff)
downloadematrix-8aeb670be1d252807252ee2bfe99b15b81c3e28d.tar.lz
ematrix-8aeb670be1d252807252ee2bfe99b15b81c3e28d.tar.xz
ematrix-8aeb670be1d252807252ee2bfe99b15b81c3e28d.zip
update from upstream
Diffstat (limited to 'js/vapi-common.js')
-rw-r--r--js/vapi-common.js142
1 files changed, 71 insertions, 71 deletions
diff --git a/js/vapi-common.js b/js/vapi-common.js
index db48206..d541070 100644
--- a/js/vapi-common.js
+++ b/js/vapi-common.js
@@ -2,7 +2,7 @@
ηMatrix - a browser extension to black/white list requests.
Copyright (C) 2014-2019 The uMatrix/uBlock Origin authors
- Copyright (C) 2019-2020 Alessio Vanni
+ Copyright (C) 2019-2022 Alessio Vanni
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
@@ -17,7 +17,7 @@
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://libregit.spks.xyz/heckyel/ematrix
+ Home: https://gitlab.com/vannilla/ematrix
uMatrix Home: https://github.com/gorhill/uMatrix
*/
@@ -32,86 +32,86 @@ Cu.import('resource://gre/modules/Services.jsm');
(function (self) {
if (self.vAPI === undefined) {
- self.vAPI = vAPI;
+ self.vAPI = vAPI;
}
vAPI.setTimeout = vAPI.setTimeout || function (callback, delay, extra) {
- return setTimeout(function (a) {
- callback(a);
- }, delay, extra);
+ return setTimeout(function (a) {
+ callback(a);
+ }, delay, extra);
};
// http://www.w3.org/International/questions/qa-scripts#directions
let setScriptDirection = function(language) {
- let dir =
- ['ar', 'he', 'fa', 'ps', 'ur'].indexOf(language) !== -1
- ? 'rtl'
- : 'ltr';
+ let dir =
+ ['ar', 'he', 'fa', 'ps', 'ur'].indexOf(language) !== -1
+ ? 'rtl'
+ : 'ltr';
- document.body.setAttribute('dir', dir);
+ document.body.setAttribute('dir', dir);
};
vAPI.download = function (details) {
- if (!details.url) {
+ if (!details.url) {
return;
- }
+ }
- let a = document.createElement('a');
- a.href = details.url;
- a.setAttribute('download', details.filename || '');
- a.dispatchEvent(new MouseEvent('click'));
+ let a = document.createElement('a');
+ a.href = details.url;
+ a.setAttribute('download', details.filename || '');
+ a.dispatchEvent(new MouseEvent('click'));
};
vAPI.insertHTML = (function () {
- const parser = Cc['@mozilla.org/parserutils;1']
+ const parser = Cc['@mozilla.org/parserutils;1']
.getService(Ci.nsIParserUtils);
- // https://github.com/gorhill/uBlock/issues/845
- // Apparently dashboard pages execute with `about:blank` principal.
+ // https://github.com/gorhill/uBlock/issues/845
+ // Apparently dashboard pages execute with `about:blank` principal.
- return function (node, html) {
+ return function (node, html) {
while (node.firstChild) {
- node.removeChild(node.firstChild);
+ node.removeChild(node.firstChild);
}
- let parsed =
- parser.parseFragment(html,
- parser.SanitizerAllowStyle,
- false,
- Services.io.newURI('about:blank',
- null, null),
- document.documentElement);
+ let parsed =
+ parser.parseFragment(html,
+ parser.SanitizerAllowStyle,
+ false,
+ Services.io.newURI('about:blank',
+ null, null),
+ document.documentElement);
node.appendChild(parsed);
- };
+ };
})();
vAPI.getURL = function (path) {
- return 'chrome://'
- + location.host
- + '/content/'
- + path.replace(/^\/+/, '');
+ return 'chrome://'
+ + location.host
+ + '/content/'
+ + path.replace(/^\/+/, '');
};
vAPI.i18n = (function () {
- let stringBundle =
- Services.strings.createBundle('chrome://'
- + location.host
- + '/locale/messages.properties');
+ let stringBundle =
+ Services.strings.createBundle('chrome://'
+ + location.host
+ + '/locale/messages.properties');
- return function (s) {
+ return function (s) {
try {
- return stringBundle.GetStringFromName(s);
+ return stringBundle.GetStringFromName(s);
} catch (ex) {
- return '';
+ return '';
}
- };
+ };
})();
setScriptDirection(navigator.language);
vAPI.closePopup = function() {
- sendAsyncMessage(location.host + ':closePopup');
+ sendAsyncMessage(location.host + ':closePopup');
};
// A localStorage-like object which should be accessible from the
@@ -119,50 +119,50 @@ Cu.import('resource://gre/modules/Services.jsm');
// This storage is optional, but it is nice to have, for a more polished user
// experience.
vAPI.localStorage = {
- pbName: '',
- pb: null,
- str: Cc['@mozilla.org/supports-string;1']
+ pbName: '',
+ pb: null,
+ str: Cc['@mozilla.org/supports-string;1']
.createInstance(Ci.nsISupportsString),
- init: function (pbName) {
+ init: function (pbName) {
this.pbName = pbName;
this.pb = Services.prefs.getBranch(pbName);
- },
- getItem: function (key) {
+ },
+ getItem: function (key) {
try {
- return this.pb
- .getComplexValue(key,
- Ci.nsISupportsString).data;
+ return this.pb
+ .getComplexValue(key,
+ Ci.nsISupportsString).data;
} catch (ex) {
- return null;
+ return null;
}
- },
- setItem: function (key, value) {
+ },
+ setItem: function (key, value) {
this.str.data = value;
this.pb.setComplexValue(key,
- Ci.nsISupportsString,
- this.str);
- },
- getBool: function (key) {
+ Ci.nsISupportsString,
+ this.str);
+ },
+ getBool: function (key) {
try {
- return this.pb.getBoolPref(key);
+ return this.pb.getBoolPref(key);
} catch (ex) {
- return null;
+ return null;
}
- },
- setBool: function (key, value) {
+ },
+ setBool: function (key, value) {
this.pb.setBoolPref(key, value);
- },
- setDefaultBool: function (key, defaultValue) {
+ },
+ setDefaultBool: function (key, defaultValue) {
Services.prefs.getDefaultBranch(this.pbName)
- .setBoolPref(key, defaultValue);
- },
- removeItem: function (key) {
+ .setBoolPref(key, defaultValue);
+ },
+ removeItem: function (key) {
this.pb.clearUserPref(key);
- },
- clear: function () {
+ },
+ clear: function () {
this.pb.deleteBranch('');
- }
+ }
};
vAPI.localStorage.init('extensions.' + location.host + '.');