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; |
| 11 let nodeID; |
11 let selectedNode = null; | 12 let selectedNode = null; |
12 let advancedMode = false; | 13 let advancedMode = false; |
13 let treeView = null; | 14 let treeView = null; |
14 let stylesheetData; | 15 let stylesheetData; |
15 let previewStyle = null; | 16 let previewStyle = null; |
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 * TreeView object * | 22 * TreeView object * |
23 *******************/ | 23 *******************/ |
24 | 24 |
25 function TreeView(tree) { | 25 function TreeView(tree) { |
26 var origView = tree.view; | 26 var origView = tree.view; |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 function TreeView_getCellProperties(row, col) { | 77 function TreeView_getCellProperties(row, col) { |
78 this.getRowProperties(row); | 78 this.getRowProperties(row); |
79 } | 79 } |
80 | 80 |
81 /********************* | 81 /********************* |
82 * General functions * | 82 * General functions * |
83 *********************/ | 83 *********************/ |
84 | 84 |
85 function init() | 85 function init() |
86 { | 86 { |
87 nodeData = window.arguments[0]; | 87 let host; |
88 let host = window.arguments[1]; | 88 ({host, nodeData, nodeID} = window.arguments[0]); |
89 | 89 |
90 // Check whether element hiding group is disabled | 90 // Check whether element hiding group is disabled |
91 let subscription = AdblockPlus.getSubscription("~eh~"); | 91 let subscription = AdblockPlus.getSubscription("~eh~"); |
92 if (subscription && subscription.disabled) | 92 if (subscription && subscription.disabled) |
93 { | 93 { |
94 let warning = document.getElementById("groupDisabledWarning"); | 94 let warning = document.getElementById("groupDisabledWarning"); |
95 if (/\?1\?/.test(warning.textContent)) | 95 if (/\?1\?/.test(warning.textContent)) |
96 warning.textContent = warning.textContent.replace(/\?1\?/g, subscription.t
itle); | 96 warning.textContent = warning.textContent.replace(/\?1\?/g, subscription.t
itle); |
97 warning.hidden = false; | 97 warning.hidden = false; |
98 } | 98 } |
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
304 | 304 |
305 stylesheetData = expression + "{display: none !important;}"; | 305 stylesheetData = expression + "{display: none !important;}"; |
306 expression = domainData.selected + "##" + expression; | 306 expression = domainData.selected + "##" + expression; |
307 | 307 |
308 document.getElementById("expression").value = expression; | 308 document.getElementById("expression").value = expression; |
309 | 309 |
310 var tree = document.getElementById("nodes-tree"); | 310 var tree = document.getElementById("nodes-tree"); |
311 if (tree.view && tree.view.selection) | 311 if (tree.view && tree.view.selection) |
312 tree.treeBoxObject.invalidateRow(tree.view.selection.currentIndex); | 312 tree.treeBoxObject.invalidateRow(tree.view.selection.currentIndex); |
313 | 313 |
314 if (previewStyle) | 314 if (document.getElementById("preview").checked) |
315 previewStyle.textContent = stylesheetData; | 315 togglePreview(true); |
316 } | 316 } |
317 | 317 |
318 function escapeChar(dummy, match) | 318 function escapeChar(dummy, match) |
319 { | 319 { |
320 return "\\" + match.charCodeAt(0).toString(16) + " "; | 320 return "\\" + match.charCodeAt(0).toString(16) + " "; |
321 } | 321 } |
322 | 322 |
323 function fillDomains(domainData) { | 323 function fillDomains(domainData) { |
324 var list = document.getElementById("domainGroup"); | 324 var list = document.getElementById("domainGroup"); |
325 | 325 |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
484 } | 484 } |
485 | 485 |
486 if (advancedMode) | 486 if (advancedMode) |
487 { | 487 { |
488 // Add custom CSS entry | 488 // Add custom CSS entry |
489 node = createAttribute("advanced", nodeData.customCSS, list.getAttribute("_l
abelcustom"), nodeData.customCSS.selected); | 489 node = createAttribute("advanced", nodeData.customCSS, list.getAttribute("_l
abelcustom"), nodeData.customCSS.selected); |
490 list.appendChild(node); | 490 list.appendChild(node); |
491 } | 491 } |
492 } | 492 } |
493 | 493 |
494 function togglePreview(preview) { | 494 function togglePreview(preview, forgetNode) |
495 if (preview) { | 495 { |
496 if (!previewStyle || !previewStyle.parentNode) { | 496 Services.mm.broadcastAsyncMessage("ElemHideHelper:Preview", { |
497 previewStyle = doc.createElementNS("http://www.w3.org/1999/xhtml", "style"
); | 497 nodeID: nodeID, |
498 previewStyle.setAttribute("type", "text/css"); | 498 stylesheetData: preview ? stylesheetData : null, |
499 doc.documentElement.appendChild(previewStyle); | 499 forgetNode: !!forgetNode |
500 } | 500 }); |
501 previewStyle.textContent = stylesheetData; | |
502 } | |
503 else { | |
504 try | |
505 { | |
506 if (previewStyle && previewStyle.parentNode) | |
507 previewStyle.parentNode.removeChild(previewStyle); | |
508 } | |
509 catch (e) | |
510 { | |
511 // if the window was closed (reloaded) we end up with dead object referenc
e | |
512 // https://bugzilla.mozilla.org/show_bug.cgi?id=695480 | |
513 // just ignore this case | |
514 } | |
515 previewStyle = null; | |
516 } | |
517 } | 501 } |
518 | 502 |
519 function changeDomain(node) { | 503 function changeDomain(node) { |
520 domainData.selected = node.getAttribute("value"); | 504 domainData.selected = node.getAttribute("value"); |
521 updateExpression(); | 505 updateExpression(); |
522 } | 506 } |
523 | 507 |
524 function toggleAttr(node) { | 508 function toggleAttr(node) { |
525 node.attr.checked = node.checked; | 509 node.attr.checked = node.checked; |
526 updateExpression(); | 510 updateExpression(); |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
581 | 565 |
582 fillAttributes(item.nodeData); | 566 fillAttributes(item.nodeData); |
583 } | 567 } |
584 | 568 |
585 function addExpression() | 569 function addExpression() |
586 { | 570 { |
587 AdblockPlus.addPatterns([document.getElementById("expression").value]); | 571 AdblockPlus.addPatterns([document.getElementById("expression").value]); |
588 | 572 |
589 togglePreview(false); | 573 togglePreview(false); |
590 } | 574 } |
OLD | NEW |