LEFT | RIGHT |
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; |
11 let selectedNode = null; | 11 let selectedNode = null; |
12 let advancedMode = false; | 12 let advancedMode = false; |
13 let treeView = null; | 13 let treeView = null; |
14 let stylesheetData; | 14 let stylesheetData; |
15 let previewStyle = null; | 15 let previewStyle = null; |
16 let doc; | 16 let doc; |
17 | 17 |
18 let abpURL = Cc["@adblockplus.org/abp/public;1"].getService(Ci.nsIURI); | 18 let abpURL = Cc["@adblockplus.org/abp/public;1"].getService(Ci.nsIURI); |
19 Cu.import(abpURL.spec); | 19 Cu.import(abpURL.spec); |
20 | 20 |
21 /******************* | 21 /******************* |
22 * NodeData object * | |
23 *******************/ | |
24 | |
25 function NodeData(node, parentNode) { | |
26 this.tagName = {value: node.tagName, checked: false}; | |
27 | |
28 if (typeof parentNode == "undefined") | |
29 parentNode = (node.parentNode && node.parentNode.nodeType == node.ELEMENT_NO
DE ? new NodeData(node.parentNode) : null); | |
30 this.parentNode = parentNode; | |
31 | |
32 var prevSibling = node.previousSibling; | |
33 while (prevSibling && prevSibling.nodeType != node.ELEMENT_NODE) | |
34 prevSibling = prevSibling.previousSibling; | |
35 this.prevSibling = (prevSibling ? new NodeData(prevSibling, this.parentNode) :
null); | |
36 | |
37 if (parentNode && !prevSibling) | |
38 this.firstChild = {checked: false}; | |
39 | |
40 var nextSibling = node.nextSibling; | |
41 while (nextSibling && nextSibling.nodeType != node.ELEMENT_NODE) | |
42 nextSibling = nextSibling.nextSibling; | |
43 if (parentNode && !nextSibling) | |
44 this.lastChild = {checked: false}; | |
45 | |
46 this.attributes = []; | |
47 for (var i = 0; i < node.attributes.length; i++) { | |
48 var attribute = node.attributes[i]; | |
49 var data = {name: attribute.name, value: attribute.value, selected: attribut
e.value, checked: false}; | |
50 if (data.name == "id" || data.name == "class") | |
51 this.attributes.unshift(data); | |
52 else | |
53 this.attributes.push(data); | |
54 } | |
55 | |
56 if (this.attributes.length >= 2 && this.attributes[1].name == "id") { | |
57 // Make sure ID attribute comes first | |
58 var tmp = this.attributes[1]; | |
59 this.attributes[1] = this.attributes[0]; | |
60 this.attributes[0] = tmp; | |
61 } | |
62 | |
63 this.customCSS = {selected: "", checked: false}; | |
64 } | |
65 | |
66 /******************* | |
67 * TreeView object * | 22 * TreeView object * |
68 *******************/ | 23 *******************/ |
69 | 24 |
70 function TreeView(tree) { | 25 function TreeView(tree) { |
71 var origView = tree.view; | 26 var origView = tree.view; |
72 this.getRowProperties = TreeView_getRowProperties; | 27 this.getRowProperties = TreeView_getRowProperties; |
73 this.getCellProperties = TreeView_getCellProperties; | 28 this.getCellProperties = TreeView_getCellProperties; |
74 | 29 |
75 createQIProxy(this, origView); | 30 createQIProxy(this, origView); |
76 | 31 |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
120 } | 75 } |
121 | 76 |
122 function TreeView_getCellProperties(row, col) { | 77 function TreeView_getCellProperties(row, col) { |
123 this.getRowProperties(row); | 78 this.getRowProperties(row); |
124 } | 79 } |
125 | 80 |
126 /********************* | 81 /********************* |
127 * General functions * | 82 * General functions * |
128 *********************/ | 83 *********************/ |
129 | 84 |
130 function init() { | 85 function init() |
131 let node = window.arguments[0]; | 86 { |
132 let domain = window.arguments[1]; | 87 nodeData = window.arguments[0]; |
133 if (node instanceof Node) | 88 let host = window.arguments[1]; |
134 { | |
135 doc = node.ownerDocument; | |
136 domain = doc.defaultView.location.hostname; | |
137 nodeData = new NodeData(node); | |
138 } | |
139 else | |
140 nodeData = node; | |
141 | 89 |
142 // Check whether element hiding group is disabled | 90 // Check whether element hiding group is disabled |
143 let subscription = AdblockPlus.getSubscription("~eh~"); | 91 let subscription = AdblockPlus.getSubscription("~eh~"); |
144 if (subscription && subscription.disabled) | 92 if (subscription && subscription.disabled) |
145 { | 93 { |
146 let warning = document.getElementById("groupDisabledWarning"); | 94 let warning = document.getElementById("groupDisabledWarning"); |
147 if (/\?1\?/.test(warning.textContent)) | 95 if (/\?1\?/.test(warning.textContent)) |
148 warning.textContent = warning.textContent.replace(/\?1\?/g, subscription.t
itle); | 96 warning.textContent = warning.textContent.replace(/\?1\?/g, subscription.t
itle); |
149 warning.hidden = false; | 97 warning.hidden = false; |
150 } | 98 } |
(...skipping 28 matching lines...) Expand all Loading... |
179 switch (Prefs.composer_defaultDomain) | 127 switch (Prefs.composer_defaultDomain) |
180 { | 128 { |
181 case 0: | 129 case 0: |
182 selectedDomain = ""; | 130 selectedDomain = ""; |
183 break; | 131 break; |
184 case 1: | 132 case 1: |
185 try | 133 try |
186 { | 134 { |
187 // EffectiveTLDService will throw for IP addresses, just go to the next
case then | 135 // EffectiveTLDService will throw for IP addresses, just go to the next
case then |
188 let effectiveTLD = Cc["@mozilla.org/network/effective-tld-service;1"].ge
tService(Ci.nsIEffectiveTLDService); | 136 let effectiveTLD = Cc["@mozilla.org/network/effective-tld-service;1"].ge
tService(Ci.nsIEffectiveTLDService); |
189 selectedDomain = effectiveTLD.getPublicSuffixFromHost(domain); | 137 selectedDomain = effectiveTLD.getPublicSuffixFromHost(host); |
190 break; | 138 break; |
191 } catch (e) {} | 139 } catch (e) {} |
192 case 2: | 140 case 2: |
193 try | 141 try |
194 { | 142 { |
195 // EffectiveTLDService will throw for IP addresses, just go to the next
case then | 143 // EffectiveTLDService will throw for IP addresses, just go to the next
case then |
196 let effectiveTLD = Cc["@mozilla.org/network/effective-tld-service;1"].ge
tService(Ci.nsIEffectiveTLDService); | 144 let effectiveTLD = Cc["@mozilla.org/network/effective-tld-service;1"].ge
tService(Ci.nsIEffectiveTLDService); |
197 selectedDomain = effectiveTLD.getBaseDomainFromHost(domain); | 145 selectedDomain = effectiveTLD.getBaseDomainFromHost(host); |
198 break; | 146 break; |
199 } catch (e) {} | 147 } catch (e) {} |
200 case 3: | 148 case 3: |
201 selectedDomain = domain.replace(/^www\./, ""); | 149 selectedDomain = host.replace(/^www\./, ""); |
202 break; | 150 break; |
203 default: | 151 default: |
204 selectedDomain = domain; | 152 selectedDomain = host; |
205 break; | 153 break; |
206 } | 154 } |
207 domainData = {value: domain, selected: selectedDomain}; | 155 domainData = {value: host, selected: selectedDomain}; |
208 | 156 |
209 fillDomains(domainData); | 157 fillDomains(domainData); |
210 fillNodes(nodeData); | 158 fillNodes(nodeData); |
211 setAdvancedMode(document.documentElement.getAttribute("advancedMode") == "true
"); | 159 setAdvancedMode(document.documentElement.getAttribute("advancedMode") == "true
"); |
212 updateExpression(); | 160 updateExpression(); |
213 | 161 |
214 setTimeout(function() { | 162 setTimeout(function() { |
215 document.getElementById("domainGroup").selectedItem.focus(); | 163 document.getElementById("domainGroup").selectedItem.focus(); |
216 if (document.getElementById("preview").checked) | 164 if (document.getElementById("preview").checked) |
217 togglePreview(true); | 165 togglePreview(true); |
(...skipping 415 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
633 | 581 |
634 fillAttributes(item.nodeData); | 582 fillAttributes(item.nodeData); |
635 } | 583 } |
636 | 584 |
637 function addExpression() | 585 function addExpression() |
638 { | 586 { |
639 AdblockPlus.addPatterns([document.getElementById("expression").value]); | 587 AdblockPlus.addPatterns([document.getElementById("expression").value]); |
640 | 588 |
641 togglePreview(false); | 589 togglePreview(false); |
642 } | 590 } |
LEFT | RIGHT |