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

Side by Side Diff: popup.js

Issue 29371763: Issue 4795 - Use modern JavaScript syntax (Closed)
Patch Set: Created Jan. 13, 2017, 12:11 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
OLDNEW
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-2016 Eyeo GmbH 3 * Copyright (C) 2006-2016 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
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details. 12 * GNU General Public License for more details.
13 * 13 *
14 * You should have received a copy of the GNU General Public License 14 * You should have received a copy of the GNU General Public License
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
16 */ 16 */
17 17
18 var backgroundPage = ext.backgroundPage.getWindow(); 18 let backgroundPage = ext.backgroundPage.getWindow();
19 var require = backgroundPage.require; 19 let require = backgroundPage.require;
20 20
21 var Filter = require("filterClasses").Filter; 21 let Filter = require("filterClasses").Filter;
22 var FilterStorage = require("filterStorage").FilterStorage; 22 let FilterStorage = require("filterStorage").FilterStorage;
23 var Prefs = require("prefs").Prefs; 23 let Prefs = require("prefs").Prefs;
24 var checkWhitelisted = require("whitelisting").checkWhitelisted; 24 let checkWhitelisted = require("whitelisting").checkWhitelisted;
25 var getDecodedHostname = require("url").getDecodedHostname; 25 let getDecodedHostname = require("url").getDecodedHostname;
26 26
27 var page = null; 27 let page = null;
28 28
29 function onLoad() 29 function onLoad()
30 { 30 {
31 ext.pages.query({active: true, lastFocusedWindow: true}, function(pages) 31 ext.pages.query({active: true, lastFocusedWindow: true}, pages =>
32 { 32 {
33 page = pages[0]; 33 page = pages[0];
34 34
35 // Mark page as 'local' or 'nohtml' to hide non-relevant elements 35 // Mark page as 'local' or 'nohtml' to hide non-relevant elements
36 if (!page || (page.url.protocol != "http:" && 36 if (!page || (page.url.protocol != "http:" &&
37 page.url.protocol != "https:")) 37 page.url.protocol != "https:"))
38 document.body.classList.add("local"); 38 document.body.classList.add("local");
39 else if (!require("filterComposer").isPageReady(page)) 39 else if (!require("filterComposer").isPageReady(page))
40 { 40 {
41 document.body.classList.add("nohtml"); 41 document.body.classList.add("nohtml");
42 require("messaging").getPort(window).on( 42 require("messaging").getPort(window).on(
43 "composer.ready", function(message, sender) 43 "composer.ready", (message, sender) =>
44 { 44 {
45 if (sender.page.id == page.id) 45 if (sender.page.id == page.id)
46 document.body.classList.remove("nohtml"); 46 document.body.classList.remove("nohtml");
47 } 47 }
48 ); 48 );
49 } 49 }
50 50
51 // Ask content script whether clickhide is active. If so, show cancel button . 51 // Ask content script whether clickhide is active. If so, show cancel button .
52 // If that isn't the case, ask background.html whether it has cached filters . If so, 52 // If that isn't the case, ask background.html whether it has cached filters . If so,
53 // ask the user whether she wants those filters. 53 // ask the user whether she wants those filters.
54 // Otherwise, we are in default state. 54 // Otherwise, we are in default state.
55 if (page) 55 if (page)
56 { 56 {
57 if (checkWhitelisted(page)) 57 if (checkWhitelisted(page))
58 document.body.classList.add("disabled"); 58 document.body.classList.add("disabled");
59 59
60 page.sendMessage({type: "composer.content.getState"}, function(response) 60 page.sendMessage({type: "composer.content.getState"}, response =>
61 { 61 {
62 if (response && response.active) 62 if (response && response.active)
63 document.body.classList.add("clickhide-active"); 63 document.body.classList.add("clickhide-active");
64 }); 64 });
65 } 65 }
66 }); 66 });
67 67
68 document.getElementById("enabled").addEventListener("click", toggleEnabled, fa lse); 68 document.getElementById("enabled").addEventListener("click", toggleEnabled, fa lse);
69 document.getElementById("clickhide").addEventListener("click", activateClickHi de, false); 69 document.getElementById("clickhide").addEventListener("click", activateClickHi de, false);
70 document.getElementById("clickhide-cancel").addEventListener("click", cancelCl ickHide, false); 70 document.getElementById("clickhide-cancel").addEventListener("click", cancelCl ickHide, false);
71 document.getElementById("options").addEventListener("click", function() 71 document.getElementById("options").addEventListener("click", () =>
72 { 72 {
73 ext.showOptions(); 73 ext.showOptions();
74 }, false); 74 }, false);
75 75
76 // Set up collapsing of menu items 76 // Set up collapsing of menu items
77 var collapsers = document.getElementsByClassName("collapse"); 77 for (let collapser of document.getElementsByClassName("collapse"))
78 for (var i = 0; i < collapsers.length; i++)
79 { 78 {
80 var collapser = collapsers[i];
81 collapser.addEventListener("click", toggleCollapse, false); 79 collapser.addEventListener("click", toggleCollapse, false);
82 if (!Prefs[collapser.dataset.option]) 80 if (!Prefs[collapser.dataset.option])
83 document.getElementById(collapser.dataset.collapsable).classList.add("coll apsed"); 81 document.getElementById(collapser.dataset.collapsable).classList.add("coll apsed");
84 } 82 }
85 } 83 }
86 84
87 function toggleEnabled() 85 function toggleEnabled()
88 { 86 {
89 var disabled = document.body.classList.toggle("disabled"); 87 let disabled = document.body.classList.toggle("disabled");
90 if (disabled) 88 if (disabled)
91 { 89 {
92 var host = getDecodedHostname(page.url).replace(/^www\./, ""); 90 let host = getDecodedHostname(page.url).replace(/^www\./, "");
93 var filter = Filter.fromText("@@||" + host + "^$document"); 91 let filter = Filter.fromText("@@||" + host + "^$document");
94 if (filter.subscriptions.length && filter.disabled) 92 if (filter.subscriptions.length && filter.disabled)
95 filter.disabled = false; 93 filter.disabled = false;
96 else 94 else
97 { 95 {
98 filter.disabled = false; 96 filter.disabled = false;
99 FilterStorage.addFilter(filter); 97 FilterStorage.addFilter(filter);
100 } 98 }
101 } 99 }
102 else 100 else
103 { 101 {
104 // Remove any exception rules applying to this URL 102 // Remove any exception rules applying to this URL
105 var filter = checkWhitelisted(page); 103 let filter = checkWhitelisted(page);
106 while (filter) 104 while (filter)
107 { 105 {
108 FilterStorage.removeFilter(filter); 106 FilterStorage.removeFilter(filter);
109 if (filter.subscriptions.length) 107 if (filter.subscriptions.length)
110 filter.disabled = true; 108 filter.disabled = true;
111 filter = checkWhitelisted(page); 109 filter = checkWhitelisted(page);
112 } 110 }
113 } 111 }
114 } 112 }
115 113
(...skipping 12 matching lines...) Expand all
128 { 126 {
129 window.clearTimeout(activateClickHide.timeout); 127 window.clearTimeout(activateClickHide.timeout);
130 activateClickHide.timeout = null; 128 activateClickHide.timeout = null;
131 } 129 }
132 document.body.classList.remove("clickhide-active"); 130 document.body.classList.remove("clickhide-active");
133 page.sendMessage({type: "composer.content.finished"}); 131 page.sendMessage({type: "composer.content.finished"});
134 } 132 }
135 133
136 function toggleCollapse(event) 134 function toggleCollapse(event)
137 { 135 {
138 var collapser = event.currentTarget; 136 let collapser = event.currentTarget;
139 Prefs[collapser.dataset.option] = !Prefs[collapser.dataset.option]; 137 Prefs[collapser.dataset.option] = !Prefs[collapser.dataset.option];
140 collapser.parentNode.classList.toggle("collapsed"); 138 collapser.parentNode.classList.toggle("collapsed");
141 } 139 }
142 140
143 document.addEventListener("DOMContentLoaded", onLoad, false); 141 document.addEventListener("DOMContentLoaded", onLoad, false);
OLDNEW
« chrome/ext/common.js ('K') | « options.js ('k') | qunit/common.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld