gorhill 10 years ago
parent
commit
f815223f27
  1. 7
      src/js/uritools.js
  2. 45
      src/lib/publicsuffixlist.js

7
src/js/uritools.js

@ -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.onChanged.addListener(domainCacheReset);
/******************************************************************************/
URI.domainFromURI = function(uri) {

45
src/lib/publicsuffixlist.js

@ -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 onChangedListeners = [];
/******************************************************************************/
// In the context of this code, a domain is defined as:
@ -234,6 +238,8 @@ function parse(text, toAscii) {
}
crystallize(exceptions);
crystallize(rules);
callListeners(onChangedListeners);
}
/******************************************************************************/
@ -302,11 +308,47 @@ function fromSelfie(selfie) {
}
rules = selfie.rules;
exceptions = selfie.exceptions;
callListeners(onChangedListeners);
return true;
}
/******************************************************************************/
var addListener = function(listeners, callback) {
if ( typeof callback !== 'function' ) {
return;
}
if ( listeners.indexOf(callback) === -1 ) {
listeners.push(callback);
}
};
var removeListener = function(listeners, callback) {
var pos = listeners.indexOf(callback);
if ( pos !== -1 ) {
listeners.splice(pos, 1);
}
};
var callListeners = function(listeners) {
for ( var i = 0; i < listeners.length; i++ ) {
listeners[i]();
}
};
/******************************************************************************/
var onChanged = {
addListener: function(callback) {
addListener(onChangedListeners, callback);
},
removeListener: function(callback) {
removeListener(onChangedListeners, callback);
}
};
/******************************************************************************/
// Public API
root = root || window;
@ -317,7 +359,8 @@ root.publicSuffixList = {
'getDomain': getDomain,
'getPublicSuffix': getPublicSuffix,
'toSelfie': toSelfie,
'fromSelfie': fromSelfie
'fromSelfie': fromSelfie,
'onChanged': onChanged
};
/******************************************************************************/

Loading…
Cancel
Save