mirror of
https://github.com/gorhill/uMatrix.git
synced 2024-05-19 03:33:17 +12:00
remove many unused functions
This commit is contained in:
parent
fa795dd446
commit
86019cd064
|
@ -294,12 +294,6 @@ vAPI.tabs.replace = function(tabId, url) {
|
|||
|
||||
/******************************************************************************/
|
||||
|
||||
vAPI.tabs.remove = function(tabId) {
|
||||
chrome.tabs.remove(tabId, resetLastError);
|
||||
};
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
vAPI.tabs.reload = function(tabId, bypassCache) {
|
||||
if ( typeof tabId !== 'number' || tabId < 0 ) { return; }
|
||||
chrome.tabs.reload(tabId, { bypassCache: bypassCache === true });
|
||||
|
@ -307,22 +301,6 @@ vAPI.tabs.reload = function(tabId, bypassCache) {
|
|||
|
||||
/******************************************************************************/
|
||||
|
||||
vAPI.tabs.injectScript = function(tabId, details, callback) {
|
||||
var onScriptExecuted = function() {
|
||||
resetLastError();
|
||||
if ( typeof callback === 'function' ) {
|
||||
callback();
|
||||
}
|
||||
};
|
||||
if ( tabId ) {
|
||||
chrome.tabs.executeScript(tabId, details, onScriptExecuted);
|
||||
} else {
|
||||
chrome.tabs.executeScript(details, onScriptExecuted);
|
||||
}
|
||||
};
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
// Must read: https://code.google.com/p/chromium/issues/detail?id=410868#c8
|
||||
|
||||
// https://github.com/chrisaljoudi/uBlock/issues/19
|
||||
|
@ -562,21 +540,6 @@ vAPI.net = {
|
|||
/******************************************************************************/
|
||||
/******************************************************************************/
|
||||
|
||||
vAPI.contextMenu = {
|
||||
create: function(details, callback) {
|
||||
this.menuId = details.id;
|
||||
this.callback = callback;
|
||||
chrome.contextMenus.create(details);
|
||||
chrome.contextMenus.onClicked.addListener(this.callback);
|
||||
},
|
||||
remove: function() {
|
||||
chrome.contextMenus.onClicked.removeListener(this.callback);
|
||||
chrome.contextMenus.remove(this.menuId);
|
||||
}
|
||||
};
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
vAPI.lastError = function() {
|
||||
return chrome.runtime.lastError;
|
||||
};
|
||||
|
@ -584,28 +547,6 @@ vAPI.lastError = function() {
|
|||
/******************************************************************************/
|
||||
/******************************************************************************/
|
||||
|
||||
// This is called only once, when everything has been loaded in memory after
|
||||
// the extension was launched. It can be used to inject content scripts
|
||||
// in already opened web pages, to remove whatever nuisance could make it to
|
||||
// the web pages before uBlock was ready.
|
||||
|
||||
vAPI.onLoadAllCompleted = function() {
|
||||
};
|
||||
|
||||
/******************************************************************************/
|
||||
/******************************************************************************/
|
||||
|
||||
vAPI.punycodeHostname = function(hostname) {
|
||||
return hostname;
|
||||
};
|
||||
|
||||
vAPI.punycodeURL = function(url) {
|
||||
return url;
|
||||
};
|
||||
|
||||
/******************************************************************************/
|
||||
/******************************************************************************/
|
||||
|
||||
vAPI.browserData = {};
|
||||
|
||||
/******************************************************************************/
|
||||
|
@ -616,17 +557,6 @@ vAPI.browserData.clearCache = function(callback) {
|
|||
chrome.browsingData.removeCache({ since: 0 }, callback);
|
||||
};
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
// Not supported on Chromium
|
||||
|
||||
vAPI.browserData.clearOrigin = function(domain, callback) {
|
||||
// unsupported on Chromium
|
||||
if ( typeof callback === 'function' ) {
|
||||
callback(undefined);
|
||||
}
|
||||
};
|
||||
|
||||
/******************************************************************************/
|
||||
/******************************************************************************/
|
||||
|
||||
|
|
116
src/js/httpsb.js
116
src/js/httpsb.js
|
@ -61,93 +61,6 @@
|
|||
return hn === '' ? '*' : hn;
|
||||
};
|
||||
|
||||
µMatrix.scopeFromURL = µMatrix.hostnameFromURL;
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
µMatrix.evaluateURL = function(srcURL, desHostname, type) {
|
||||
var srcHostname = this.URI.hostnameFromURI(srcURL);
|
||||
return this.tMatrix.evaluateCellZXY(srcHostname, desHostname, type);
|
||||
};
|
||||
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
// Whitelist something
|
||||
|
||||
µMatrix.whitelistTemporarily = function(srcHostname, desHostname, type) {
|
||||
this.tMatrix.whitelistCell(srcHostname, desHostname, type);
|
||||
};
|
||||
|
||||
µMatrix.whitelistPermanently = function(srcHostname, desHostname, type) {
|
||||
if ( this.pMatrix.whitelistCell(srcHostname, desHostname, type) ) {
|
||||
this.saveMatrix();
|
||||
}
|
||||
};
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
// Auto-whitelisting the `all` cell is a serious action, hence this will be
|
||||
// done only from within a scope.
|
||||
|
||||
µMatrix.autoWhitelistAllTemporarily = function(pageURL) {
|
||||
var srcHostname = this.URI.hostnameFromURI(pageURL);
|
||||
if ( this.mustBlock(srcHostname, '*', '*') === false ) {
|
||||
return false;
|
||||
}
|
||||
this.tMatrix.whitelistCell(srcHostname, '*', '*');
|
||||
return true;
|
||||
};
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
// Blacklist something
|
||||
|
||||
µMatrix.blacklistTemporarily = function(srcHostname, desHostname, type) {
|
||||
this.tMatrix.blacklistCell(srcHostname, desHostname, type);
|
||||
};
|
||||
|
||||
µMatrix.blacklistPermanently = function(srcHostname, desHostname, type) {
|
||||
if ( this.pMatrix.blacklist(srcHostname, desHostname, type) ) {
|
||||
this.saveMatrix();
|
||||
}
|
||||
};
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
// Remove something from both black and white lists.
|
||||
|
||||
µMatrix.graylistTemporarily = function(srcHostname, desHostname, type) {
|
||||
this.tMatrix.graylistCell(srcHostname, desHostname, type);
|
||||
};
|
||||
|
||||
µMatrix.graylistPermanently = function(srcHostname, desHostname, type) {
|
||||
if ( this.pMatrix.graylistCell(srcHostname, desHostname, type) ) {
|
||||
this.saveMatrix();
|
||||
}
|
||||
};
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
// TODO: Should type be transposed by the caller or in place here? Not an
|
||||
// issue at this point but to keep in mind as this function is called
|
||||
// more and more from different places.
|
||||
|
||||
µMatrix.filterRequest = function(fromURL, type, toURL) {
|
||||
// Block request?
|
||||
var srcHostname = this.hostnameFromURL(fromURL);
|
||||
var desHostname = this.hostnameFromURL(toURL);
|
||||
|
||||
// If no valid hostname, use the hostname of the source.
|
||||
// For example, this case can happen with data URI.
|
||||
if ( desHostname === '' ) {
|
||||
desHostname = srcHostname;
|
||||
}
|
||||
|
||||
// Blocked by matrix filtering?
|
||||
return this.mustBlock(srcHostname, desHostname, type);
|
||||
};
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
µMatrix.mustBlock = function(srcHostname, desHostname, type) {
|
||||
|
@ -160,35 +73,6 @@
|
|||
|
||||
/******************************************************************************/
|
||||
|
||||
// Commit temporary permissions.
|
||||
|
||||
µMatrix.commitPermissions = function(persist) {
|
||||
this.pMatrix.assign(this.tMatrix);
|
||||
if ( persist ) {
|
||||
this.saveMatrix();
|
||||
}
|
||||
};
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
// Reset all rules to their default state.
|
||||
|
||||
µMatrix.revertAllRules = function() {
|
||||
this.tMatrix.assign(this.pMatrix);
|
||||
};
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
µMatrix.turnOff = function() {
|
||||
vAPI.app.start();
|
||||
};
|
||||
|
||||
µMatrix.turnOn = function() {
|
||||
vAPI.app.stop();
|
||||
};
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
µMatrix.formatCount = function(count) {
|
||||
if ( typeof count !== 'number' ) {
|
||||
return '';
|
||||
|
|
|
@ -106,10 +106,6 @@ function onMessage(request, sender, callback) {
|
|||
µm.gotoExtensionURL(request);
|
||||
break;
|
||||
|
||||
case 'gotoURL':
|
||||
µm.gotoURL(request);
|
||||
break;
|
||||
|
||||
case 'graylistMatrixCell':
|
||||
µm.tMatrix.graylistCell(
|
||||
request.srcHostname,
|
||||
|
|
|
@ -49,9 +49,7 @@ var reRFC3986 = /^([^:\/?#]+:)?(\/\/[^\/?#]*)?([^?#]*)(\?[^#]*)?(#.*)?/;
|
|||
// Derived
|
||||
var reSchemeFromURI = /^[^:\/?#]+:/;
|
||||
var reAuthorityFromURI = /^(?:[^:\/?#]+:)?(\/\/[^\/?#]+)/;
|
||||
var reOriginFromURI = /^(?:[^:\/?#]+:)?(?:\/\/[^\/?#]+)/;
|
||||
var reCommonHostnameFromURL = /^https?:\/\/([0-9a-z_][0-9a-z._-]*[0-9a-z])\//;
|
||||
var rePathFromURI = /^(?:[^:\/?#]+:)?(?:\/\/[^\/?#]*)?([^?#]*)/;
|
||||
var reMustNormalizeHostname = /[^0-9a-z._-]/;
|
||||
|
||||
// These are to parse authority field, not parsed by above official regex
|
||||
|
@ -70,7 +68,6 @@ var reHostFromAuthority = /^(?:[^@]*@)?([^:]+)(?::\d*)?$/;
|
|||
var reIPv6FromAuthority = /^(?:[^@]*@)?(\[[0-9a-f:]+\])(?::\d*)?$/i;
|
||||
|
||||
// Coarse (but fast) tests
|
||||
var reValidHostname = /^([a-z\d]+(-*[a-z\d]+)*)(\.[a-z\d]+(-*[a-z\d])*)*$/;
|
||||
var reIPAddressNaive = /^\d+\.\d+\.\d+\.\d+$|^\[[\da-zA-Z:]+\]$/;
|
||||
|
||||
// Accurate tests
|
||||
|
@ -229,13 +226,6 @@ URI.assemble = function(bits) {
|
|||
|
||||
/******************************************************************************/
|
||||
|
||||
URI.originFromURI = function(uri) {
|
||||
var matches = reOriginFromURI.exec(uri);
|
||||
return matches !== null ? matches[0].toLowerCase() : '';
|
||||
};
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
URI.schemeFromURI = function(uri) {
|
||||
var matches = reSchemeFromURI.exec(uri);
|
||||
if ( matches === null ) {
|
||||
|
@ -247,16 +237,11 @@ URI.schemeFromURI = function(uri) {
|
|||
/******************************************************************************/
|
||||
|
||||
const reNetworkScheme = /^(?:https?|wss?|ftps?)\b/;
|
||||
const reNetworkURI = /^(?:ftps?|https?|wss?):\/\//;
|
||||
|
||||
URI.isNetworkScheme = function(scheme) {
|
||||
return reNetworkScheme.test(scheme);
|
||||
};
|
||||
|
||||
URI.isNetworkURI = function(uri) {
|
||||
return reNetworkURI.test(uri);
|
||||
};
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
URI.isSecureScheme = function(scheme) {
|
||||
|
@ -267,16 +252,6 @@ URI.reSecureScheme = /^(?:https|wss|ftps)\b/;
|
|||
|
||||
/******************************************************************************/
|
||||
|
||||
URI.authorityFromURI = function(uri) {
|
||||
var matches = reAuthorityFromURI.exec(uri);
|
||||
if ( !matches ) {
|
||||
return '';
|
||||
}
|
||||
return matches[1].slice(2).toLowerCase();
|
||||
};
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
// The most used function, so it better be fast.
|
||||
|
||||
// https://github.com/gorhill/uBlock/issues/1559
|
||||
|
@ -325,21 +300,10 @@ URI.domainFromHostname = function(hostname) {
|
|||
return domainCacheAdd(hostname, hostname);
|
||||
};
|
||||
|
||||
URI.domain = function() {
|
||||
return this.domainFromHostname(this.hostname);
|
||||
};
|
||||
|
||||
// It is expected that there is higher-scoped `publicSuffixList` lingering
|
||||
// somewhere. Cache it. See <https://github.com/gorhill/publicsuffixlist.js>.
|
||||
var psl = publicSuffixList;
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
URI.pathFromURI = function(uri) {
|
||||
var matches = rePathFromURI.exec(uri);
|
||||
return matches !== null ? matches[1] : '';
|
||||
};
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
// Trying to alleviate the worries of looking up too often the domain name from
|
||||
|
@ -435,92 +399,6 @@ URI.normalizedURI = function() {
|
|||
|
||||
/******************************************************************************/
|
||||
|
||||
URI.rootURL = function() {
|
||||
if ( !this.hostname ) {
|
||||
return '';
|
||||
}
|
||||
return this.assemble(this.schemeBit | this.hostnameBit);
|
||||
};
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
URI.isValidHostname = function(hostname) {
|
||||
var r;
|
||||
try {
|
||||
r = reValidHostname.test(hostname);
|
||||
}
|
||||
catch (e) {
|
||||
return false;
|
||||
}
|
||||
return r;
|
||||
};
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
// Return the parent domain. For IP address, there is no parent domain.
|
||||
|
||||
URI.parentHostnameFromHostname = function(hostname) {
|
||||
// `locahost` => ``
|
||||
// `example.org` => `example.org`
|
||||
// `www.example.org` => `example.org`
|
||||
// `tomato.www.example.org` => `example.org`
|
||||
var domain = this.domainFromHostname(hostname);
|
||||
|
||||
// `locahost` === `` => bye
|
||||
// `example.org` === `example.org` => bye
|
||||
// `www.example.org` !== `example.org` => stay
|
||||
// `tomato.www.example.org` !== `example.org` => stay
|
||||
if ( domain === '' || domain === hostname ) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
// Parent is hostname minus first label
|
||||
return hostname.slice(hostname.indexOf('.') + 1);
|
||||
};
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
// Return all possible parent hostnames which can be derived from `hostname`,
|
||||
// ordered from direct parent up to domain inclusively.
|
||||
|
||||
URI.parentHostnamesFromHostname = function(hostname) {
|
||||
// TODO: I should create an object which is optimized to receive
|
||||
// the list of hostnames by making it reusable (junkyard etc.) and which
|
||||
// has its own element counter property in order to avoid memory
|
||||
// alloc/dealloc.
|
||||
var domain = this.domainFromHostname(hostname);
|
||||
if ( domain === '' || domain === hostname ) {
|
||||
return [];
|
||||
}
|
||||
var nodes = [];
|
||||
var pos;
|
||||
for (;;) {
|
||||
pos = hostname.indexOf('.');
|
||||
if ( pos < 0 ) {
|
||||
break;
|
||||
}
|
||||
hostname = hostname.slice(pos + 1);
|
||||
nodes.push(hostname);
|
||||
if ( hostname === domain ) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return nodes;
|
||||
};
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
// Return all possible hostnames which can be derived from `hostname`,
|
||||
// ordered from self up to domain inclusively.
|
||||
|
||||
URI.allHostnamesFromHostname = function(hostname) {
|
||||
var nodes = this.parentHostnamesFromHostname(hostname);
|
||||
nodes.unshift(hostname);
|
||||
return nodes;
|
||||
};
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
URI.toString = function() {
|
||||
return this.assemble();
|
||||
};
|
||||
|
|
|
@ -23,12 +23,6 @@
|
|||
|
||||
/******************************************************************************/
|
||||
|
||||
µMatrix.gotoURL = function(details) {
|
||||
vAPI.tabs.open(details);
|
||||
};
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
µMatrix.gotoExtensionURL = function(details) {
|
||||
if ( details.url.startsWith('logger-ui.html') ) {
|
||||
if ( details.shiftKey ) {
|
||||
|
@ -85,26 +79,6 @@
|
|||
|
||||
/******************************************************************************/
|
||||
|
||||
µMatrix.setToArray = typeof Array.from === 'function' ?
|
||||
Array.from :
|
||||
function(dict) {
|
||||
var out = [],
|
||||
entries = dict.values(),
|
||||
entry;
|
||||
for (;;) {
|
||||
entry = entries.next();
|
||||
if ( entry.done ) { break; }
|
||||
out.push(entry.value);
|
||||
}
|
||||
return out;
|
||||
};
|
||||
|
||||
µMatrix.setFromArray = function(arr) {
|
||||
return new Set(arr);
|
||||
};
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
µMatrix.toMap = function(input) {
|
||||
if ( input instanceof Map ) {
|
||||
return input;
|
||||
|
|
Loading…
Reference in a new issue