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

Powered by Google App Engine
This is Rietveld