OLD | NEW |
1 /* | 1 /* |
2 * This Source Code is subject to the terms of the Mozilla Public License | 2 * This Source Code is subject to the terms of the Mozilla Public License |
3 * version 2.0 (the "License"). You can obtain a copy of the License at | 3 * version 2.0 (the "License"). You can obtain a copy of the License at |
4 * http://mozilla.org/MPL/2.0/. | 4 * http://mozilla.org/MPL/2.0/. |
5 */ | 5 */ |
6 | 6 |
7 let {Prefs} = require("prefs"); | 7 let {Prefs} = require("prefs"); |
8 | 8 |
9 let domainData; | 9 let domainData; |
10 let nodeData; | 10 let nodeData; |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 | 121 |
122 function TreeView_getCellProperties(row, col) { | 122 function TreeView_getCellProperties(row, col) { |
123 this.getRowProperties(row); | 123 this.getRowProperties(row); |
124 } | 124 } |
125 | 125 |
126 /********************* | 126 /********************* |
127 * General functions * | 127 * General functions * |
128 *********************/ | 128 *********************/ |
129 | 129 |
130 function init() { | 130 function init() { |
131 var element = window.arguments[0]; | 131 let node = window.arguments[0]; |
132 doc = element.ownerDocument; | 132 let domain = window.arguments[1]; |
133 var wnd = doc.defaultView; | 133 if (node instanceof Node) |
| 134 { |
| 135 doc = node.ownerDocument; |
| 136 domain = doc.defaultView.location.hostname; |
| 137 nodeData = new NodeData(node); |
| 138 } |
| 139 else |
| 140 nodeData = node; |
134 | 141 |
135 // Check whether element hiding group is disabled | 142 // Check whether element hiding group is disabled |
136 let subscription = AdblockPlus.getSubscription("~eh~"); | 143 let subscription = AdblockPlus.getSubscription("~eh~"); |
137 if (subscription && subscription.disabled) | 144 if (subscription && subscription.disabled) |
138 { | 145 { |
139 let warning = document.getElementById("groupDisabledWarning"); | 146 let warning = document.getElementById("groupDisabledWarning"); |
140 if (/\?1\?/.test(warning.textContent)) | 147 if (/\?1\?/.test(warning.textContent)) |
141 warning.textContent = warning.textContent.replace(/\?1\?/g, subscription.t
itle); | 148 warning.textContent = warning.textContent.replace(/\?1\?/g, subscription.t
itle); |
142 warning.hidden = false; | 149 warning.hidden = false; |
143 } | 150 } |
144 | 151 |
145 nodeData = new NodeData(element); | |
146 nodeData.tagName.checked = true; | 152 nodeData.tagName.checked = true; |
147 if (nodeData.attributes.length > 0) | 153 if (nodeData.attributes.length > 0) |
148 { | 154 { |
149 let maxLen = 0; | 155 let maxLen = 0; |
150 let bestAttr = null; | 156 let bestAttr = null; |
151 for (let i = 0; i < nodeData.attributes.length; i++) | 157 for (let i = 0; i < nodeData.attributes.length; i++) |
152 { | 158 { |
153 let len = nodeData.attributes[i].value.length; | 159 let len = nodeData.attributes[i].value.length; |
154 if ((nodeData.attributes[i].name == "id" || nodeData.attributes[i].name ==
"class") && len) | 160 if ((nodeData.attributes[i].name == "id" || nodeData.attributes[i].name ==
"class") && len) |
155 { | 161 { |
156 len = 0x7FFFFFFF; | 162 len = 0x7FFFFFFF; |
157 nodeData.tagName.checked = false; | 163 nodeData.tagName.checked = false; |
158 } | 164 } |
159 if (len > maxLen) | 165 if (len > maxLen) |
160 { | 166 { |
161 maxLen = len; | 167 maxLen = len; |
162 bestAttr = nodeData.attributes[i]; | 168 bestAttr = nodeData.attributes[i]; |
163 } | 169 } |
164 } | 170 } |
165 if (bestAttr) | 171 if (bestAttr) |
166 { | 172 { |
167 bestAttr.selected = bestAttr.value; | 173 bestAttr.selected = bestAttr.value; |
168 bestAttr.checked = true; | 174 bestAttr.checked = true; |
169 } | 175 } |
170 } | 176 } |
171 | 177 |
172 let domain = wnd.location.hostname; | |
173 let selectedDomain; | 178 let selectedDomain; |
174 switch (Prefs.composer_defaultDomain) | 179 switch (Prefs.composer_defaultDomain) |
175 { | 180 { |
176 case 0: | 181 case 0: |
177 selectedDomain = ""; | 182 selectedDomain = ""; |
178 break; | 183 break; |
179 case 1: | 184 case 1: |
180 try | 185 try |
181 { | 186 { |
182 // EffectiveTLDService will throw for IP addresses, just go to the next
case then | 187 // EffectiveTLDService will throw for IP addresses, just go to the next
case then |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
235 var escapedName = escapeName(attr.name); | 240 var escapedName = escapeName(attr.name); |
236 if (attr.selected != "") | 241 if (attr.selected != "") |
237 { | 242 { |
238 var op = "*="; | 243 var op = "*="; |
239 if (attr.selected == attr.value) | 244 if (attr.selected == attr.value) |
240 op = "="; | 245 op = "="; |
241 else if (attr.value.substr(0, attr.selected.length) == attr.selected) | 246 else if (attr.value.substr(0, attr.selected.length) == attr.selected) |
242 op = "^="; | 247 op = "^="; |
243 else if (attr.value.substr(attr.value.length - attr.selected.length) =
= attr.selected) | 248 else if (attr.value.substr(attr.value.length - attr.selected.length) =
= attr.selected) |
244 op = "$="; | 249 op = "$="; |
245 | 250 |
246 let useFallback = false; | 251 let useFallback = false; |
247 if (attr.name == "id" && op == "=") | 252 if (attr.name == "id" && op == "=") |
248 expression += "#" + escapeName(attr.selected).replace(/^([^a-zA-Z\\]
)/, escapeChar).replace(/\\(\s)$/, escapeChar); | 253 expression += "#" + escapeName(attr.selected).replace(/^([^a-zA-Z\\]
)/, escapeChar).replace(/\\(\s)$/, escapeChar); |
249 else if (attr.name == "class" && /\S/.test(attr.selected)) | 254 else if (attr.name == "class" && /\S/.test(attr.selected)) |
250 { | 255 { |
251 let knownClasses = new Set(attr.value.split(/\s+/)); | 256 let knownClasses = new Set(attr.value.split(/\s+/)); |
252 let classes = attr.selected.split(/\s+/).filter(cls => cls != ""); | 257 let classes = attr.selected.split(/\s+/).filter(cls => cls != ""); |
253 if (classes.every(cls => knownClasses.has(cls))) | 258 if (classes.every(cls => knownClasses.has(cls))) |
254 expression += "." + classes.map(escapeName).join("."); | 259 expression += "." + classes.map(escapeName).join("."); |
255 else | 260 else |
(...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
628 | 633 |
629 fillAttributes(item.nodeData); | 634 fillAttributes(item.nodeData); |
630 } | 635 } |
631 | 636 |
632 function addExpression() | 637 function addExpression() |
633 { | 638 { |
634 AdblockPlus.addPatterns([document.getElementById("expression").value]); | 639 AdblockPlus.addPatterns([document.getElementById("expression").value]); |
635 | 640 |
636 togglePreview(false); | 641 togglePreview(false); |
637 } | 642 } |
OLD | NEW |