Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: lib/elemHide.js

Issue 29342974: Issue 4067 - Make filter "keys" generated for element hiding filters numeric (Closed)
Patch Set: Fixed remaining addFilter calls Created May 24, 2016, 12:40 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | lib/filterListener.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>, 2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-2016 Eyeo GmbH 3 * Copyright (C) 2006-2016 Eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
(...skipping 13 matching lines...) Expand all
24 var {Utils} = require("utils"); 24 var {Utils} = require("utils");
25 var {IO} = require("io"); 25 var {IO} = require("io");
26 var {Prefs} = require("prefs"); 26 var {Prefs} = require("prefs");
27 var {ElemHideException} = require("filterClasses"); 27 var {ElemHideException} = require("filterClasses");
28 var {FilterNotifier} = require("filterNotifier"); 28 var {FilterNotifier} = require("filterNotifier");
29 29
30 /** 30 /**
31 * Lookup table, filters by their associated key 31 * Lookup table, filters by their associated key
32 * @type Object 32 * @type Object
33 */ 33 */
34 var filterByKey = Object.create(null); 34 var filterByKey = [];
35 35
36 /** 36 /**
37 * Lookup table, keys of the filters by filter text 37 * Lookup table, keys of the filters by filter text
38 * @type Object 38 * @type Object
39 */ 39 */
40 var keyByFilter = Object.create(null); 40 var keyByFilter = Object.create(null);
41 41
42 /** 42 /**
43 * Nested lookup table, filter (or false if inactive) by filter text by domain 43 * Nested lookup table, filter (or false if inactive) by filter text by domain
44 * @type Object 44 * @type Object
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 let styleFile = IO.resolveFilePath(Prefs.data_directory); 109 let styleFile = IO.resolveFilePath(Prefs.data_directory);
110 styleFile.append("elemhide.css"); 110 styleFile.append("elemhide.css");
111 styleURL = Services.io.newFileURI(styleFile).QueryInterface(Ci.nsIFileURL); 111 styleURL = Services.io.newFileURI(styleFile).QueryInterface(Ci.nsIFileURL);
112 }, 112 },
113 113
114 /** 114 /**
115 * Removes all known filters 115 * Removes all known filters
116 */ 116 */
117 clear: function() 117 clear: function()
118 { 118 {
119 filterByKey = Object.create(null); 119 filterByKey = [];
120 keyByFilter = Object.create(null); 120 keyByFilter = Object.create(null);
121 filtersByDomain = Object.create(null); 121 filtersByDomain = Object.create(null);
122 knownExceptions = Object.create(null); 122 knownExceptions = Object.create(null);
123 exceptions = Object.create(null); 123 exceptions = Object.create(null);
124 ElemHide.isDirty = false; 124 ElemHide.isDirty = false;
125 ElemHide.unapply(); 125 ElemHide.unapply();
126 }, 126 },
127 127
128 /** 128 /**
129 * Add a new element hiding filter 129 * Add a new element hiding filter
(...skipping 10 matching lines...) Expand all
140 if (!(selector in exceptions)) 140 if (!(selector in exceptions))
141 exceptions[selector] = []; 141 exceptions[selector] = [];
142 exceptions[selector].push(filter); 142 exceptions[selector].push(filter);
143 knownExceptions[filter.text] = true; 143 knownExceptions[filter.text] = true;
144 } 144 }
145 else 145 else
146 { 146 {
147 if (filter.text in keyByFilter) 147 if (filter.text in keyByFilter)
148 return; 148 return;
149 149
150 let key; 150 let key = filterByKey.push(filter) - 1;
151 do {
152 key = Math.random().toFixed(15).substr(5);
153 } while (key in filterByKey);
154
155 filterByKey[key] = filter;
156 keyByFilter[filter.text] = key; 151 keyByFilter[filter.text] = key;
157 152
158 if (usingFiltersByDomain) 153 if (usingFiltersByDomain)
159 { 154 {
160 let domains = filter.domains || defaultDomains; 155 let domains = filter.domains || defaultDomains;
161 for (let domain in domains) 156 for (let domain in domains)
162 { 157 {
163 let filters = filtersByDomain[domain]; 158 let filters = filtersByDomain[domain];
164 if (!filters) 159 if (!filters)
165 filters = filtersByDomain[domain] = Object.create(null); 160 filters = filtersByDomain[domain] = Object.create(null);
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
327 }, 322 },
328 323
329 _generateCSSContent: function*() 324 _generateCSSContent: function*()
330 { 325 {
331 // Grouping selectors by domains 326 // Grouping selectors by domains
332 let domains = Object.create(null); 327 let domains = Object.create(null);
333 let hasFilters = false; 328 let hasFilters = false;
334 for (let key in filterByKey) 329 for (let key in filterByKey)
335 { 330 {
336 let filter = filterByKey[key]; 331 let filter = filterByKey[key];
332 let selector = filter.selector;
333 if (!selector)
334 continue;
335
337 let domain = filter.selectorDomain || ""; 336 let domain = filter.selectorDomain || "";
338 337
339 let list; 338 let list;
340 if (domain in domains) 339 if (domain in domains)
341 list = domains[domain]; 340 list = domains[domain];
342 else 341 else
343 { 342 {
344 list = Object.create(null); 343 list = Object.create(null);
345 domains[domain] = list; 344 domains[domain] = list;
346 } 345 }
347 list[filter.selector] = key; 346 list[selector] = key;
348 hasFilters = true; 347 hasFilters = true;
349 } 348 }
350 349
351 if (!hasFilters) 350 if (!hasFilters)
352 throw Cr.NS_ERROR_NOT_AVAILABLE; 351 throw Cr.NS_ERROR_NOT_AVAILABLE;
353 352
354 function escapeChar(match) 353 function escapeChar(match)
355 { 354 {
356 return "\\" + match.charCodeAt(0).toString(16) + " "; 355 return "\\" + match.charCodeAt(0).toString(16) + " ";
357 } 356 }
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
451 if (currentDomain == "") 450 if (currentDomain == "")
452 break; 451 break;
453 452
454 let nextDot = currentDomain.indexOf("."); 453 let nextDot = currentDomain.indexOf(".");
455 currentDomain = nextDot == -1 ? "" : currentDomain.substr(nextDot + 1); 454 currentDomain = nextDot == -1 ? "" : currentDomain.substr(nextDot + 1);
456 } 455 }
457 456
458 return selectors; 457 return selectors;
459 } 458 }
460 }; 459 };
OLDNEW
« no previous file with comments | « no previous file | lib/filterListener.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld