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

Side by Side Diff: lib/main.js

Issue 6520005931827200: Issue 2259 - Removed non-standard JavaScript code from Element Hiding Helper (Closed)
Patch Set: Created April 1, 2015, 3:16 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 | « lib/inspectorObserver.js ('k') | lib/windowWrapper.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 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 Cu.import("resource://gre/modules/Services.jsm"); 7 Cu.import("resource://gre/modules/Services.jsm");
8 8
9 let {Prefs} = require("prefs"); 9 let {Prefs} = require("prefs");
10 let {WindowObserver} = require("windowObserver"); 10 let {WindowObserver} = require("windowObserver");
11 let {WindowWrapper} = require("windowWrapper"); 11 let {WindowWrapper} = require("windowWrapper");
12 12
13 // Check whether some preferences can still be found under their old locations 13 // Check whether some preferences can still be found under their old locations
14 Prefs.migrate("extensions.adblockplus.ehh-selectelement_key", "selectelement_key "); 14 Prefs.migrate("extensions.adblockplus.ehh-selectelement_key", "selectelement_key ");
15 Prefs.migrate("extensions.adblockplus.ehh.showhelp", "showhelp"); 15 Prefs.migrate("extensions.adblockplus.ehh.showhelp", "showhelp");
16 16
17 // Window types to attach to 17 // Window types to attach to
18 let knownWindowTypes = 18 let knownWindowTypes = Object.create(null);
Wladimir Palant 2015/04/01 19:01:14 Better: Set(["navigator:browser", "mail:3pane", "m
Sebastian Noack 2015/04/02 07:19:47 True.
19 { 19 knownWindowTypes["navigator:browser"] = true;
20 "navigator:browser": true, 20 knownWindowTypes["mail:3pane"] = true;
21 "mail:3pane": true, 21 knownWindowTypes["mail:messageWindow"] = true;
22 "mail:messageWindow": true,
23 __proto__: null
24 };
25 22
26 // Use random marker class 23 // Use random marker class
27 let elementMarkerClass = null; 24 let elementMarkerClass = null;
28 { 25 {
29 let rnd = []; 26 let rnd = [];
30 let offset = "a".charCodeAt(0); 27 let offset = "a".charCodeAt(0);
31 for (let i = 0; i < 20; i++) 28 for (let i = 0; i < 20; i++)
32 rnd.push(offset + Math.random() * 26); 29 rnd.push(offset + Math.random() * 26);
33 30
34 elementMarkerClass = String.fromCharCode.apply(String, rnd); 31 elementMarkerClass = String.fromCharCode.apply(String, rnd);
35 } 32 }
36 exports.elementMarkerClass = elementMarkerClass; 33 exports.elementMarkerClass = elementMarkerClass;
37 34
38 // Load CSS asynchronously 35 // Load CSS asynchronously
39 let request = Cc["@mozilla.org/xmlextras/xmlhttprequest;1"].createInstance(Ci.ns IXMLHttpRequest); 36 let request = Cc["@mozilla.org/xmlextras/xmlhttprequest;1"].createInstance(Ci.ns IXMLHttpRequest);
40 request.open("GET", "chrome://elemhidehelper/content/elementmarker.css"); 37 request.open("GET", "chrome://elemhidehelper/content/elementmarker.css");
41 request.overrideMimeType("text/plain"); 38 request.overrideMimeType("text/plain");
42 request.addEventListener("load", function(event) 39 request.addEventListener("load", function(event)
43 { 40 {
44 if (onShutdown.done) 41 if (onShutdown.done)
45 return; 42 return;
46 43
47 let data = event.target.responseText.replace(/%%CLASS%%/g, elementMarkerClass) ; 44 let data = event.target.responseText.replace(/%%CLASS%%/g, elementMarkerClass) ;
48 let styleService = Cc["@mozilla.org/content/style-sheet-service;1"].getService (Ci.nsIStyleSheetService); 45 let styleService = Cc["@mozilla.org/content/style-sheet-service;1"].getService (Ci.nsIStyleSheetService);
49 let styleURI = Services.io.newURI("data:text/css," + encodeURIComponent(data), null, null); 46 let styleURI = Services.io.newURI("data:text/css," + encodeURIComponent(data), null, null);
50 styleService.loadAndRegisterSheet(styleURI, Ci.nsIStyleSheetService.USER_SHEET ); 47 styleService.loadAndRegisterSheet(styleURI, Ci.nsIStyleSheetService.USER_SHEET );
51 onShutdown.add(function() styleService.unregisterSheet(styleURI, Ci.nsIStyleSh eetService.USER_SHEET)); 48 onShutdown.add(() => styleService.unregisterSheet(styleURI, Ci.nsIStyleSheetSe rvice.USER_SHEET));
52 }, false); 49 }, false);
53 request.send(null); 50 request.send(null);
54 51
55 // Load overlay asynchonously and start attaching to windows once done 52 // Load overlay asynchonously and start attaching to windows once done
56 request = Cc["@mozilla.org/xmlextras/xmlhttprequest;1"].createInstance(Ci.nsIJSX MLHttpRequest); 53 request = Cc["@mozilla.org/xmlextras/xmlhttprequest;1"].createInstance(Ci.nsIJSX MLHttpRequest);
57 request.open("GET", "chrome://elemhidehelper/content/overlay.xul"); 54 request.open("GET", "chrome://elemhidehelper/content/overlay.xul");
58 request.addEventListener("load", function(event) 55 request.addEventListener("load", function(event)
59 { 56 {
60 if (onShutdown.done) 57 if (onShutdown.done)
61 return; 58 return;
(...skipping 29 matching lines...) Expand all
91 if (element) 88 if (element)
92 element.parentNode.removeChild(element); 89 element.parentNode.removeChild(element);
93 90
94 for (let child = window.document.firstChild; child; child = child.nextSibl ing) 91 for (let child = window.document.firstChild; child; child = child.nextSibl ing)
95 if (child.nodeType == child.PROCESSING_INSTRUCTION_NODE && child.data.in dexOf("elemhidehelper-node") >= 0) 92 if (child.nodeType == child.PROCESSING_INSTRUCTION_NODE && child.data.in dexOf("elemhidehelper-node") >= 0)
96 child.parentNode.removeChild(child); 93 child.parentNode.removeChild(child);
97 } 94 }
98 }); 95 });
99 }, false); 96 }, false);
100 request.send(null); 97 request.send(null);
OLDNEW
« no previous file with comments | « lib/inspectorObserver.js ('k') | lib/windowWrapper.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld