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

Delta Between Two Patch Sets: lib/elemHideExceptions.js

Issue 29783618: Issue 6665 - Split out element hiding exceptions into their own module (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Left Patch Set: Created May 17, 2018, 3:46 a.m.
Right Patch Set: Add lib/elemHideExceptions.js Created Aug. 7, 2018, 2:18 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « lib/elemHideEmulation.js ('k') | lib/filterListener.js » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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-present eyeo GmbH 3 * Copyright (C) 2006-present 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 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 let {selector} = exception; 64 let {selector} = exception;
65 let list = exceptions.get(selector); 65 let list = exceptions.get(selector);
66 if (list) 66 if (list)
67 list.push(exception); 67 list.push(exception);
68 else 68 else
69 exceptions.set(selector, [exception]); 69 exceptions.set(selector, [exception]);
70 70
71 knownExceptions.add(exception); 71 knownExceptions.add(exception);
72 72
73 this.emit("added", exception); 73 this.emit("added", exception);
74
75 FilterNotifier.emit("elemhideupdate");
74 }, 76 },
75 77
76 /** 78 /**
77 * Removes an element hiding exception 79 * Removes an element hiding exception
78 * @param {ElemHideException} exception 80 * @param {ElemHideException} exception
79 */ 81 */
80 remove(exception) 82 remove(exception)
81 { 83 {
82 if (!knownExceptions.has(exception)) 84 if (!knownExceptions.has(exception))
83 return; 85 return;
84 86
85 let list = exceptions.get(exception.selector); 87 let list = exceptions.get(exception.selector);
86 let index = list.indexOf(exception); 88 let index = list.indexOf(exception);
87 if (index >= 0) 89 if (index >= 0)
88 list.splice(index, 1); 90 list.splice(index, 1);
89 91
90 knownExceptions.delete(exception); 92 knownExceptions.delete(exception);
91 93
92 this.emit("removed", exception); 94 this.emit("removed", exception);
95
96 FilterNotifier.emit("elemhideupdate");
93 }, 97 },
94 98
95 /** 99 /**
96 * Checks whether any exception rules are registered for a selector 100 * Checks whether any exception rules are registered for a selector
97 * @param {string} selector 101 * @param {string} selector
98 * @returns {boolean} 102 * @returns {boolean}
99 */ 103 */
100 hasExceptions(selector) 104 hasExceptions(selector)
101 { 105 {
102 return exceptions.has(selector); 106 return exceptions.has(selector);
103 }, 107 },
104 108
105 /** 109 /**
106 * Checks whether an exception rule is registered for a filter on a particular 110 * Checks whether an exception rule is registered for a selector on a
107 * domain. 111 * particular domain.
108 * @param {ElemHideFilter|ElemHideEmulationFilter} filter 112 * @param {string} selector
109 * @param {?string} docDomain 113 * @param {?string} docDomain
110 * @return {?ElemHideException} 114 * @return {?ElemHideException}
111 */ 115 */
112 getException(filter, docDomain) 116 getException(selector, docDomain)
113 { 117 {
114 let list = exceptions.get(filter.selector); 118 let list = exceptions.get(selector);
115 if (!list) 119 if (!list)
116 return null; 120 return null;
117 121
118 for (let i = list.length - 1; i >= 0; i--) 122 for (let i = list.length - 1; i >= 0; i--)
119 { 123 {
120 if (list[i].isActiveOnDomain(docDomain)) 124 if (list[i].isActiveOnDomain(docDomain))
121 return list[i]; 125 return list[i];
122 } 126 }
123 127
124 return null; 128 return null;
125 } 129 }
126 }); 130 });
LEFTRIGHT

Powered by Google App Engine
This is Rietveld