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

Side by Side Diff: popup.js

Issue 29333344: Issue 3472 - Made sure that "Block element" option is shown after page load (Closed)
Patch Set: Created Jan. 8, 2016, 5:50 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 | « no previous file | no next file » | 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-2015 Eyeo GmbH 3 * Copyright (C) 2006-2015 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 var backgroundPage = ext.backgroundPage.getWindow();
19 var require = backgroundPage.require; 19 var require = backgroundPage.require;
20 20
21 var Filter = require("filterClasses").Filter; 21 var Filter = require("filterClasses").Filter;
22 var FilterStorage = require("filterStorage").FilterStorage; 22 var FilterStorage = require("filterStorage").FilterStorage;
23 var Prefs = require("prefs").Prefs; 23 var Prefs = require("prefs").Prefs;
24 var isPageWhitelisted = require("whitelisting").isPageWhitelisted; 24 var isPageWhitelisted = require("whitelisting").isPageWhitelisted;
25 var getDecodedHostname = require("url").getDecodedHostname; 25 var getDecodedHostname = require("url").getDecodedHostname;
26 26
27 var page = null; 27 var page = null;
28 28
29 function init() 29 function onLoad()
30 { 30 {
31 ext.pages.query({active: true, lastFocusedWindow: true}, function(pages) 31 ext.pages.query({active: true, lastFocusedWindow: true}, function(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 (!backgroundPage.htmlPages.has(page)) 39 else if (!backgroundPage.htmlPages.has(page))
(...skipping 10 matching lines...) Expand all
50 50
51 page.sendMessage({type: "get-clickhide-state"}, function(response) 51 page.sendMessage({type: "get-clickhide-state"}, function(response)
52 { 52 {
53 if (response && response.active) 53 if (response && response.active)
54 document.body.classList.add("clickhide-active"); 54 document.body.classList.add("clickhide-active");
55 }); 55 });
56 } 56 }
57 }); 57 });
58 58
59 // Attach event listeners 59 // Attach event listeners
60 ext.onMessage.addListener(onMessage);
60 document.getElementById("enabled").addEventListener("click", toggleEnabled, fa lse); 61 document.getElementById("enabled").addEventListener("click", toggleEnabled, fa lse);
61 document.getElementById("clickhide").addEventListener("click", activateClickHi de, false); 62 document.getElementById("clickhide").addEventListener("click", activateClickHi de, false);
62 document.getElementById("clickhide-cancel").addEventListener("click", cancelCl ickHide, false); 63 document.getElementById("clickhide-cancel").addEventListener("click", cancelCl ickHide, false);
63 document.getElementById("options").addEventListener("click", function() 64 document.getElementById("options").addEventListener("click", function()
64 { 65 {
65 ext.showOptions(); 66 ext.showOptions();
66 }, false); 67 }, false);
67 68
68 // Set up collapsing of menu items 69 // Set up collapsing of menu items
69 var collapsers = document.getElementsByClassName("collapse"); 70 var collapsers = document.getElementsByClassName("collapse");
70 for (var i = 0; i < collapsers.length; i++) 71 for (var i = 0; i < collapsers.length; i++)
71 { 72 {
72 var collapser = collapsers[i]; 73 var collapser = collapsers[i];
73 collapser.addEventListener("click", toggleCollapse, false); 74 collapser.addEventListener("click", toggleCollapse, false);
74 if (!Prefs[collapser.dataset.option]) 75 if (!Prefs[collapser.dataset.option])
75 document.getElementById(collapser.dataset.collapsable).classList.add("coll apsed"); 76 document.getElementById(collapser.dataset.collapsable).classList.add("coll apsed");
76 } 77 }
77 } 78 }
78 window.addEventListener("DOMContentLoaded", init, false); 79
80 function onUnload()
81 {
82 ext.onMessage.removeListener(onMessage);
83 }
84
85 function onMessage(message, sender, callback)
86 {
87 if (message.type == "report-html-page"
88 && backgroundPage.htmlPages.has(page))
Sebastian Noack 2016/01/09 00:01:50 This check is redundant. Or if you want to keep it
Thomas Greiner 2016/01/12 11:35:17 Unfortunately, it's not redundant. Any page could'
Sebastian Noack 2016/01/12 16:09:16 Acknowledged.
89 document.body.classList.remove("nohtml");
90 }
79 91
80 function toggleEnabled() 92 function toggleEnabled()
81 { 93 {
82 var disabled = document.body.classList.toggle("disabled"); 94 var disabled = document.body.classList.toggle("disabled");
83 if (disabled) 95 if (disabled)
84 { 96 {
85 var host = getDecodedHostname(page.url).replace(/^www\./, ""); 97 var host = getDecodedHostname(page.url).replace(/^www\./, "");
86 var filter = Filter.fromText("@@||" + host + "^$document"); 98 var filter = Filter.fromText("@@||" + host + "^$document");
87 if (filter.subscriptions.length && filter.disabled) 99 if (filter.subscriptions.length && filter.disabled)
88 filter.disabled = false; 100 filter.disabled = false;
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 document.body.classList.remove("clickhide-active"); 137 document.body.classList.remove("clickhide-active");
126 page.sendMessage({type: "clickhide-deactivate"}); 138 page.sendMessage({type: "clickhide-deactivate"});
127 } 139 }
128 140
129 function toggleCollapse(event) 141 function toggleCollapse(event)
130 { 142 {
131 var collapser = event.currentTarget; 143 var collapser = event.currentTarget;
132 Prefs[collapser.dataset.option] = !Prefs[collapser.dataset.option]; 144 Prefs[collapser.dataset.option] = !Prefs[collapser.dataset.option];
133 collapser.parentNode.classList.toggle("collapsed"); 145 collapser.parentNode.classList.toggle("collapsed");
134 } 146 }
147
148 document.addEventListener("DOMContentLoaded", onLoad, false);
149 window.addEventListener("unload", onUnload, false);
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld