Index: lib/filterListener.js |
diff --git a/lib/filterListener.js b/lib/filterListener.js |
index d56e82545b8fa0562ffa1681a5273c51e737837d..53caad215096ed151c6bf3cd437871f0a4ab4aac 100644 |
--- a/lib/filterListener.js |
+++ b/lib/filterListener.js |
@@ -15,27 +15,28 @@ |
* along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
*/ |
+"use strict"; |
+ |
/** |
- * @fileOverview Component synchronizing filter storage with Matcher instances and ElemHide. |
+ * @fileOverview Component synchronizing filter storage with Matcher |
+ * instances and ElemHide. |
*/ |
-"use strict"; |
- |
Cu.import("resource://gre/modules/XPCOMUtils.jsm"); |
Cu.import("resource://gre/modules/Services.jsm"); |
-let {FilterStorage} = require("filterStorage"); |
-let {FilterNotifier} = require("filterNotifier"); |
-let {ElemHide} = require("elemHide"); |
-let {ElemHideEmulation} = require("elemHideEmulation"); |
-let {defaultMatcher} = require("matcher"); |
-let {ActiveFilter, RegExpFilter, ElemHideBase, ElemHideEmulationFilter} = |
- require("filterClasses"); |
-let {Prefs} = require("prefs"); |
+const {FilterStorage} = require("filterStorage"); |
+const {FilterNotifier} = require("filterNotifier"); |
+const {ElemHide} = require("elemHide"); |
+const {ElemHideEmulation} = require("elemHideEmulation"); |
+const {defaultMatcher} = require("matcher"); |
+const {ActiveFilter, RegExpFilter, |
+ ElemHideBase, ElemHideEmulationFilter} = require("filterClasses"); |
+const {Prefs} = require("prefs"); |
/** |
* Increases on filter changes, filters will be saved if it exceeds 1. |
- * @type Integer |
+ * @type {number} |
*/ |
let isDirty = 0; |
@@ -43,15 +44,16 @@ let isDirty = 0; |
* This object can be used to change properties of the filter change listeners. |
* @class |
*/ |
-let FilterListener = |
-{ |
+let FilterListener = { |
/** |
- * Increases "dirty factor" of the filters and calls FilterStorage.saveToDisk() |
- * if it becomes 1 or more. Save is executed delayed to prevent multiple |
- * subsequent calls. If the parameter is 0 it forces saving filters if any |
- * changes were recorded after the previous save. |
+ * Increases "dirty factor" of the filters and calls |
+ * FilterStorage.saveToDisk() if it becomes 1 or more. Save is |
+ * executed delayed to prevent multiple subsequent calls. If the |
+ * parameter is 0 it forces saving filters if any changes were |
+ * recorded after the previous save. |
+ * @param {number} factor |
*/ |
- setDirty: function(/**Integer*/ factor) |
+ setDirty(factor) |
{ |
if (factor == 0 && isDirty > 0) |
isDirty = 1; |
@@ -69,11 +71,11 @@ let FilterListener = |
* Observer listening to history purge actions. |
* @class |
*/ |
-let HistoryPurgeObserver = |
-{ |
- observe: function(subject, topic, data) |
+let HistoryPurgeObserver = { |
+ observe(subject, topic, data) |
{ |
- if (topic == "browser:purge-session-history" && Prefs.clearStatsOnHistoryPurge) |
+ if (topic == "browser:purge-session-history" && |
+ Prefs.clearStatsOnHistoryPurge) |
{ |
FilterStorage.resetHitCounts(); |
FilterListener.setDirty(0); // Force saving to disk |
@@ -81,7 +83,9 @@ let HistoryPurgeObserver = |
Prefs.recentReports = []; |
} |
}, |
- QueryInterface: XPCOMUtils.generateQI([Ci.nsISupportsWeakReference, Ci.nsIObserver]) |
+ QueryInterface: XPCOMUtils.generateQI( |
+ [Ci.nsISupportsWeakReference, Ci.nsIObserver] |
+ ) |
}; |
/** |
@@ -113,10 +117,12 @@ function init() |
FilterStorage.loadFromDisk(); |
- Services.obs.addObserver(HistoryPurgeObserver, "browser:purge-session-history", true); |
- onShutdown.add(function() |
+ Services.obs.addObserver(HistoryPurgeObserver, |
+ "browser:purge-session-history", true); |
+ onShutdown.add(() => |
{ |
- Services.obs.removeObserver(HistoryPurgeObserver, "browser:purge-session-history"); |
+ Services.obs.removeObserver(HistoryPurgeObserver, |
+ "browser:purge-session-history"); |
}); |
} |
init(); |
@@ -133,8 +139,10 @@ function addFilter(filter) |
let hasEnabled = false; |
for (let i = 0; i < filter.subscriptions.length; i++) |
+ { |
if (!filter.subscriptions[i].disabled) |
hasEnabled = true; |
+ } |
if (!hasEnabled) |
return; |
@@ -163,8 +171,10 @@ function removeFilter(filter) |
{ |
let hasEnabled = false; |
for (let i = 0; i < filter.subscriptions.length; i++) |
+ { |
if (!filter.subscriptions[i].disabled) |
hasEnabled = true; |
+ } |
if (hasEnabled) |
return; |
} |
@@ -197,9 +207,8 @@ function addFilters(filters) |
let current = (Math.random() * len) | 0; |
let step; |
do |
- { |
step = primes[(Math.random() * primes.length) | 0]; |
- } while (len % step == 0); |
+ while (len % step == 0); |
Wladimir Palant
2017/03/02 14:06:52
Ok, this is bad. I never even knew that you could
kzar
2017/03/08 12:33:36
Done.
|
for (let i = 0; i < len; i++, current = (current + step) % len) |
addFilter(filters[current]); |
@@ -298,8 +307,10 @@ function onLoad() |
ElemHide.clear(); |
ElemHideEmulation.clear(); |
for (let subscription of FilterStorage.subscriptions) |
+ { |
if (!subscription.disabled) |
addFilters(subscription.filters); |
+ } |
} |
function onSave() |