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

Side by Side Diff: popup.js

Issue 29532767: Issue 5593 - Use messaging in popup for prefs, whitelisting, and stats (Closed) Base URL: https://hg.adblockplus.org/adblockpluschrome/
Patch Set: Use messaging for prefs I/O Created Aug. 31, 2017, 5:07 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
« popup.html ('K') | « popup.html ('k') | skin/popup.css » ('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-present eyeo GmbH 3 * Copyright (C) 2006-present 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 "use strict"; 18 "use strict";
19 19
20 const {require} = ext.backgroundPage.getWindow(); 20 const {require} = ext.backgroundPage.getWindow();
21 21
22 const {Filter} = require("filterClasses"); 22 const {Filter} = require("filterClasses");
23 const {FilterStorage} = require("filterStorage"); 23 const {FilterStorage} = require("filterStorage");
24 const {Prefs} = require("prefs");
25 const {checkWhitelisted} = require("whitelisting"); 24 const {checkWhitelisted} = require("whitelisting");
26 const {getDecodedHostname} = require("url"); 25 const {getDecodedHostname} = require("url");
27 26
28 let page = null; 27 let page = null;
29 28
30 function onLoad() 29 function onLoad()
31 { 30 {
32 ext.pages.query({active: true, lastFocusedWindow: true}, pages => 31 ext.pages.query({active: true, lastFocusedWindow: true}, pages =>
33 { 32 {
34 page = pages[0]; 33 page = pages[0];
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 ); 76 );
78 document.getElementById("options").addEventListener("click", () => 77 document.getElementById("options").addEventListener("click", () =>
79 { 78 {
80 ext.showOptions(); 79 ext.showOptions();
81 }, false); 80 }, false);
82 81
83 // Set up collapsing of menu items 82 // Set up collapsing of menu items
84 for (let collapser of document.getElementsByClassName("collapse")) 83 for (let collapser of document.getElementsByClassName("collapse"))
85 { 84 {
86 collapser.addEventListener("click", toggleCollapse, false); 85 collapser.addEventListener("click", toggleCollapse, false);
87 if (!Prefs[collapser.dataset.option]) 86 chrome.runtime.sendMessage({
87 type: "prefs.get",
88 key: collapser.dataset.option
89 },
90 value =>
88 { 91 {
89 document.getElementById( 92 if (value)
90 collapser.dataset.collapsable 93 {
91 ).classList.add("collapsed"); 94 document.getElementById(
92 } 95 collapser.dataset.collapsible
96 ).classList.remove("collapsed");
97 }
98 });
93 } 99 }
94 } 100 }
95 101
96 function toggleEnabled() 102 function toggleEnabled()
97 { 103 {
98 let disabled = document.body.classList.toggle("disabled"); 104 let disabled = document.body.classList.toggle("disabled");
99 if (disabled) 105 if (disabled)
100 { 106 {
101 let host = getDecodedHostname(page.url).replace(/^www\./, ""); 107 let host = getDecodedHostname(page.url).replace(/^www\./, "");
102 let filter = Filter.fromText("@@||" + host + "^$document"); 108 let filter = Filter.fromText("@@||" + host + "^$document");
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 window.clearTimeout(activateClickHide.timeout); 144 window.clearTimeout(activateClickHide.timeout);
139 activateClickHide.timeout = null; 145 activateClickHide.timeout = null;
140 } 146 }
141 document.body.classList.remove("clickhide-active"); 147 document.body.classList.remove("clickhide-active");
142 page.sendMessage({type: "composer.content.finished"}); 148 page.sendMessage({type: "composer.content.finished"});
143 } 149 }
144 150
145 function toggleCollapse(event) 151 function toggleCollapse(event)
146 { 152 {
147 let collapser = event.currentTarget; 153 let collapser = event.currentTarget;
148 Prefs[collapser.dataset.option] = !Prefs[collapser.dataset.option]; 154 let collapsible = document.getElementById(collapser.dataset.collapsible);
149 collapser.parentNode.classList.toggle("collapsed"); 155 collapsible.classList.toggle("collapsed");
156 chrome.runtime.sendMessage({
157 type: "prefs.toggle",
158 key: collapser.dataset.option
159 });
150 } 160 }
151 161
152 document.addEventListener("DOMContentLoaded", onLoad, false); 162 document.addEventListener("DOMContentLoaded", onLoad, false);
OLDNEW
« popup.html ('K') | « popup.html ('k') | skin/popup.css » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld