mirror of https://github.com/gorhill/uBlock.git
maybe this will address #150
This commit is contained in:
parent
6c80790975
commit
ff41aed7cf
|
@ -72,10 +72,10 @@ var reIPAddressNaive = /^\d+\.\d+\.\d+\.\d+$|^\[[\da-zA-Z:]+\]$/;
|
|||
|
||||
// Accurate tests
|
||||
// Source.: http://stackoverflow.com/questions/5284147/validating-ipv4-addresses-with-regexp/5284410#5284410
|
||||
var reIPv4 = /^((25[0-5]|2[0-4]\d|[01]?\d\d?)(\.|$)){4}/;
|
||||
//var reIPv4 = /^((25[0-5]|2[0-4]\d|[01]?\d\d?)(\.|$)){4}/;
|
||||
|
||||
// Source: http://forums.intermapper.com/viewtopic.php?p=1096#1096
|
||||
var reIPv6 = /^\s*((([0-9A-Fa-f]{1,4}:){7}([0-9A-Fa-f]{1,4}|:))|(([0-9A-Fa-f]{1,4}:){6}(:[0-9A-Fa-f]{1,4}|((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){5}(((:[0-9A-Fa-f]{1,4}){1,2})|:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){4}(((:[0-9A-Fa-f]{1,4}){1,3})|((:[0-9A-Fa-f]{1,4})?:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){3}(((:[0-9A-Fa-f]{1,4}){1,4})|((:[0-9A-Fa-f]{1,4}){0,2}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){2}(((:[0-9A-Fa-f]{1,4}){1,5})|((:[0-9A-Fa-f]{1,4}){0,3}:((25[0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}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){1}(((:[0-9A-Fa-f]{1,4}){1,6})|((:[0-9A-Fa-f]{1,4}){0,4}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(:(((:[0-9A-Fa-f]{1,4}){1,7})|((:[0-9A-Fa-f]{1,4}){0,5}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:)))(%.+)?\s*$/;
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
|
@ -366,11 +366,18 @@ var domainCachePrune = function() {
|
|||
}
|
||||
};
|
||||
|
||||
var domainCacheReset = function() {
|
||||
domainCache = {};
|
||||
domainCacheCount = 0;
|
||||
};
|
||||
|
||||
var domainCache = {};
|
||||
var domainCacheCount = 0;
|
||||
var domainCacheCountLowWaterMark = 75;
|
||||
var domainCacheCountHighWaterMark = 100;
|
||||
|
||||
psl.onModified.addListener(domainCacheReset);
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
URI.domainFromURI = function(uri) {
|
||||
|
|
|
@ -33,6 +33,8 @@
|
|||
|
||||
;(function(root) {
|
||||
|
||||
'use strict';
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
var exceptions = {};
|
||||
|
@ -45,6 +47,8 @@ var selfieMagic = 'iscjsfsaolnm';
|
|||
var cutoffLength = 256;
|
||||
var mustPunycode = /[^a-z0-9.-]/;
|
||||
|
||||
var onModifyListeners = [];
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
// In the context of this code, a domain is defined as:
|
||||
|
@ -234,6 +238,8 @@ function parse(text, toAscii) {
|
|||
}
|
||||
crystallize(exceptions);
|
||||
crystallize(rules);
|
||||
|
||||
callListeners(onModifyListeners);
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
|
@ -302,11 +308,39 @@ function fromSelfie(selfie) {
|
|||
}
|
||||
rules = selfie.rules;
|
||||
exceptions = selfie.exceptions;
|
||||
callListeners(onModifyListeners);
|
||||
return true;
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
var callListeners = function(listeners) {
|
||||
for ( var i = 0; i < listeners.length; i++ ) {
|
||||
listeners[i]();
|
||||
}
|
||||
};
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
var onModified = {
|
||||
addListener: function(callback) {
|
||||
if (
|
||||
typeof callback === 'function' &&
|
||||
onModifyListeners.indexOf(callback) === -1
|
||||
) {
|
||||
onModifyListeners.push(callback);
|
||||
}
|
||||
},
|
||||
removeListener: function(callback) {
|
||||
var pos = onModifyListeners.indexOf(callback);
|
||||
if ( pos !== -1 ) {
|
||||
onModifyListeners.splice(pos, 1);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
// Public API
|
||||
|
||||
root = root || window;
|
||||
|
@ -317,7 +351,8 @@ root.publicSuffixList = {
|
|||
'getDomain': getDomain,
|
||||
'getPublicSuffix': getPublicSuffix,
|
||||
'toSelfie': toSelfie,
|
||||
'fromSelfie': fromSelfie
|
||||
'fromSelfie': fromSelfie,
|
||||
'onModified': onModified
|
||||
};
|
||||
|
||||
/******************************************************************************/
|
||||
|
|
Loading…
Reference in New Issue