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

Delta Between Two Patch Sets: devtools-panel.js

Issue 29573905: Issue 4580 - Replace ext.devtools with devtools Base URL: https://hg.adblockplus.org/adblockplusui/
Left Patch Set: Fix ESLint errors Created Oct. 11, 2017, 11:47 p.m.
Right Patch Set: Rebase Created Oct. 18, 2017, 1:37 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « devtools-panel.html ('k') | ext/background.js » ('j') | polyfill.js » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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 browser.runtime.sendMessage({type: "types.get"}, (filterTypes) =>
23 (filterTypes) => 23 {
24 { 24 let filterTypesElem = document.getElementById("filter-type");
25 let filterTypesElem = document.getElementById("filter-type"); 25 let filterStyleElem = document.createElement("style");
26 let filterStyleElem = document.createElement("style"); 26 for (let type of filterTypes)
27 for (let type of filterTypes) 27 {
28 { 28 filterStyleElem.innerHTML +=
29 filterStyleElem.innerHTML += 29 `#items[data-filter-type=${type}] tr:not([data-type=${type}])` +
30 `#items[data-filter-type=${type}] tr:not([data-type=${type}])` + 30 "{display: none;}";
31 "{display: none;}"; 31 let optionNode = document.createElement("option");
32 let optionNode = document.createElement("option"); 32 optionNode.appendChild(document.createTextNode(type));
33 optionNode.appendChild(document.createTextNode(type)); 33 filterTypesElem.appendChild(optionNode);
34 filterTypesElem.appendChild(optionNode); 34 }
35 } 35 document.body.appendChild(filterStyleElem);
36 document.body.appendChild(filterStyleElem); 36 });
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 12 matching lines...) Expand all
60 59
61 function createActionButton(action, label, filter) 60 function createActionButton(action, label, filter)
62 { 61 {
63 let button = document.createElement("span"); 62 let button = document.createElement("span");
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 browser.runtime.sendMessage({
71 type: "filters." + action, 70 type: "filters." + action,
72 text: filter 71 text: filter
73 }); 72 });
74 }); 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 chrome.devtools.panels.openResource(request.url); 98 browser.devtools.panels.openResource(request.url);
100 }); 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;
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 chrome.devtools.inspectedWindow.reload(); 195 browser.devtools.inspectedWindow.reload();
197 }); 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 }); 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 }); 206 });
208 207
209 ext.onMessage.addListener((message) => 208 let port = browser.runtime.connect({
209 name: "devtools-" + browser.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 27 matching lines...) Expand all
247 case "cancelSearch": 250 case "cancelSearch":
248 cancelSearch(table); 251 cancelSearch(table);
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 = browser.devtools.panels.themeName || "default";
258 document.body.classList.add(theme); 261 document.body.classList.add(theme);
259 }); 262 });
LEFTRIGHT

Powered by Google App Engine
This is Rietveld