OLD | NEW |
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 let lastFilterQuery = null; | 20 let lastFilterQuery = null; |
21 | 21 |
22 chrome.runtime.sendMessage({type: "types.get"}, | 22 chrome.runtime.sendMessage({type: "types.get"}, (filterTypes) => |
23 (filterTypes) => | 23 { |
| 24 let filterTypesElem = document.getElementById("filter-type"); |
| 25 let filterStyleElem = document.createElement("style"); |
| 26 for (let type of filterTypes) |
24 { | 27 { |
25 let filterTypesElem = document.getElementById("filter-type"); | 28 filterStyleElem.innerHTML += |
26 let filterStyleElem = document.createElement("style"); | 29 `#items[data-filter-type=${type}] tr:not([data-type=${type}])` + |
27 for (let type of filterTypes) | 30 "{display: none;}"; |
28 { | 31 let optionNode = document.createElement("option"); |
29 filterStyleElem.innerHTML += | 32 optionNode.appendChild(document.createTextNode(type)); |
30 `#items[data-filter-type=${type}] tr:not([data-type=${type}])` + | 33 filterTypesElem.appendChild(optionNode); |
31 "{display: none;}"; | 34 } |
32 let optionNode = document.createElement("option"); | 35 document.body.appendChild(filterStyleElem); |
33 optionNode.appendChild(document.createTextNode(type)); | 36 }); |
34 filterTypesElem.appendChild(optionNode); | |
35 } | |
36 document.body.appendChild(filterStyleElem); | |
37 }); | |
38 | 37 |
39 function generateFilter(request, domainSpecific) | 38 function generateFilter(request, domainSpecific) |
40 { | 39 { |
41 let filter = request.url.replace(/^[\w-]+:\/+(?:www\.)?/, "||"); | 40 let filter = request.url.replace(/^[\w-]+:\/+(?:www\.)?/, "||"); |
42 let options = []; | 41 let options = []; |
43 | 42 |
44 if (request.type == "POPUP") | 43 if (request.type == "POPUP") |
45 { | 44 { |
46 options.push("popup"); | 45 options.push("popup"); |
47 | 46 |
(...skipping 16 matching lines...) Expand all Loading... |
64 | 63 |
65 button.textContent = label; | 64 button.textContent = label; |
66 button.classList.add("action"); | 65 button.classList.add("action"); |
67 | 66 |
68 button.addEventListener("click", () => | 67 button.addEventListener("click", () => |
69 { | 68 { |
70 chrome.runtime.sendMessage({ | 69 chrome.runtime.sendMessage({ |
71 type: "filters." + action, | 70 type: "filters." + action, |
72 text: filter | 71 text: filter |
73 }); | 72 }); |
74 }, false); | 73 }); |
75 | 74 |
76 return button; | 75 return button; |
77 } | 76 } |
78 | 77 |
79 function createRecord(request, filter, template) | 78 function createRecord(request, filter, template) |
80 { | 79 { |
81 let row = document.importNode(template, true); | 80 let row = document.importNode(template, true); |
82 row.dataset.type = request.type; | 81 row.dataset.type = request.type; |
83 | 82 |
84 row.querySelector(".domain").textContent = request.docDomain; | 83 row.querySelector(".domain").textContent = request.docDomain; |
85 row.querySelector(".type").textContent = request.type; | 84 row.querySelector(".type").textContent = request.type; |
86 | 85 |
87 let urlElement = row.querySelector(".url"); | 86 let urlElement = row.querySelector(".url"); |
88 let actionWrapper = row.querySelector(".action-wrapper"); | 87 let actionWrapper = row.querySelector(".action-wrapper"); |
89 | 88 |
90 if (request.url) | 89 if (request.url) |
91 { | 90 { |
92 urlElement.textContent = request.url; | 91 urlElement.textContent = request.url; |
93 | 92 |
94 if (request.type != "POPUP") | 93 if (request.type != "POPUP") |
95 { | 94 { |
96 urlElement.classList.add("resourceLink"); | 95 urlElement.classList.add("resourceLink"); |
97 urlElement.addEventListener("click", () => | 96 urlElement.addEventListener("click", () => |
98 { | 97 { |
99 ext.devtools.panels.openResource(request.url); | 98 chrome.devtools.panels.openResource(request.url); |
100 }, false); | 99 }); |
101 } | 100 } |
102 } | 101 } |
103 | 102 |
104 if (filter) | 103 if (filter) |
105 { | 104 { |
106 let filterElement = row.querySelector(".filter"); | 105 let filterElement = row.querySelector(".filter"); |
107 let originElement = row.querySelector(".origin"); | 106 let originElement = row.querySelector(".origin"); |
108 | 107 |
109 filterElement.textContent = filter.text; | 108 filterElement.textContent = filter.text; |
110 row.dataset.state = filter.whitelisted ? "whitelisted" : "blocked"; | 109 row.dataset.state = filter.whitelisted ? "whitelisted" : "blocked"; |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
186 } | 185 } |
187 | 186 |
188 document.addEventListener("DOMContentLoaded", () => | 187 document.addEventListener("DOMContentLoaded", () => |
189 { | 188 { |
190 let container = document.getElementById("items"); | 189 let container = document.getElementById("items"); |
191 let table = container.querySelector("tbody"); | 190 let table = container.querySelector("tbody"); |
192 let template = document.querySelector("template").content.firstElementChild; | 191 let template = document.querySelector("template").content.firstElementChild; |
193 | 192 |
194 document.getElementById("reload").addEventListener("click", () => | 193 document.getElementById("reload").addEventListener("click", () => |
195 { | 194 { |
196 ext.devtools.inspectedWindow.reload(); | 195 chrome.devtools.inspectedWindow.reload(); |
197 }, false); | 196 }); |
198 | 197 |
199 document.getElementById("filter-state").addEventListener("change", (event) => | 198 document.getElementById("filter-state").addEventListener("change", (event) => |
200 { | 199 { |
201 container.dataset.filterState = event.target.value; | 200 container.dataset.filterState = event.target.value; |
202 }, false); | 201 }); |
203 | 202 |
204 document.getElementById("filter-type").addEventListener("change", (event) => | 203 document.getElementById("filter-type").addEventListener("change", (event) => |
205 { | 204 { |
206 container.dataset.filterType = event.target.value; | 205 container.dataset.filterType = event.target.value; |
207 }, false); | 206 }); |
208 | 207 |
209 ext.onMessage.addListener((message) => | 208 let port = chrome.runtime.connect({ |
| 209 name: "devtools-" + chrome.devtools.inspectedWindow.tabId |
| 210 }); |
| 211 |
| 212 port.onMessage.addListener((message) => |
210 { | 213 { |
211 switch (message.type) | 214 switch (message.type) |
212 { | 215 { |
213 case "add-record": | 216 case "add-record": |
214 table.appendChild(createRecord(message.request, message.filter, | 217 table.appendChild(createRecord(message.request, message.filter, |
215 template)); | 218 template)); |
216 break; | 219 break; |
217 | 220 |
218 case "update-record": | 221 case "update-record": |
219 let oldRow = table.getElementsByTagName("tr")[message.index]; | 222 let oldRow = table.getElementsByTagName("tr")[message.index]; |
(...skipping 29 matching lines...) Expand all Loading... |
249 lastFilterQuery = null; | 252 lastFilterQuery = null; |
250 break; | 253 break; |
251 } | 254 } |
252 }); | 255 }); |
253 | 256 |
254 // Since Chrome 54 the themeName is accessible, for earlier versions we must | 257 // Since Chrome 54 the themeName is accessible, for earlier versions we must |
255 // assume the default theme is being used. | 258 // assume the default theme is being used. |
256 // https://bugs.chromium.org/p/chromium/issues/detail?id=608869 | 259 // https://bugs.chromium.org/p/chromium/issues/detail?id=608869 |
257 let theme = chrome.devtools.panels.themeName || "default"; | 260 let theme = chrome.devtools.panels.themeName || "default"; |
258 document.body.classList.add(theme); | 261 document.body.classList.add(theme); |
259 }, false); | 262 }); |
OLD | NEW |