diff options
author | gorhill <rhill@raymondhill.net> | 2015-04-29 10:29:44 -0400 |
---|---|---|
committer | gorhill <rhill@raymondhill.net> | 2015-04-29 10:29:44 -0400 |
commit | ff41aed7cfc1c23387cd16b35d711f47e33ef008 (patch) | |
tree | 76c75ba41d7752f9eaa9cbd9edaa07cd0dd6ca29 /src/lib | |
parent | 6c807909752401be44f126de0e5fafd9b6f6d179 (diff) | |
download | uBlock-ff41aed7cfc1c23387cd16b35d711f47e33ef008.zip uBlock-ff41aed7cfc1c23387cd16b35d711f47e33ef008.tar.gz uBlock-ff41aed7cfc1c23387cd16b35d711f47e33ef008.tar.bz2 |
maybe this will address #150
Diffstat (limited to 'src/lib')
-rw-r--r-- | src/lib/publicsuffixlist.js | 37 |
1 files changed, 36 insertions, 1 deletions
diff --git a/src/lib/publicsuffixlist.js b/src/lib/publicsuffixlist.js index fa18037..908f7c4 100644 --- a/src/lib/publicsuffixlist.js +++ b/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 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 }; /******************************************************************************/ |