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

Delta Between Two Patch Sets: devtools-panel.js

Issue 29368730: Issue 4136 - Support Chrome's dark devtools theme (Closed)
Left Patch Set: Created Dec. 19, 2016, 1:11 p.m.
Right Patch Set: Addressed feedback Created Jan. 5, 2017, 4:22 p.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 | « no previous file | skin/devtools-panel.css » ('j') | no next file with change/comment »
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-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 "use strict"; 18 "use strict";
19 19
20 var lastFilterQuery = null;
21
20 function generateFilter(request, domainSpecific) 22 function generateFilter(request, domainSpecific)
21 { 23 {
22 var filter = request.url.replace(/^[\w\-]+:\/+(?:www\.)?/, "||"); 24 var filter = request.url.replace(/^[\w\-]+:\/+(?:www\.)?/, "||");
23 var options = []; 25 var options = [];
24 26
25 if (request.type == "POPUP") 27 if (request.type == "POPUP")
26 { 28 {
27 options.push("popup"); 29 options.push("popup");
28 30
29 if (request.url == "about:blank") 31 if (request.url == "about:blank")
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 if (filter.userDefined) 112 if (filter.userDefined)
111 actionWrapper.appendChild(createActionButton( 113 actionWrapper.appendChild(createActionButton(
112 "remove", "Remove rule", filter.text 114 "remove", "Remove rule", filter.text
113 )); 115 ));
114 } 116 }
115 else 117 else
116 actionWrapper.appendChild(createActionButton( 118 actionWrapper.appendChild(createActionButton(
117 "add", "Block item", generateFilter(request, request.specificOnly) 119 "add", "Block item", generateFilter(request, request.specificOnly)
118 )); 120 ));
119 121
122 if (lastFilterQuery && shouldFilterRow(row, lastFilterQuery))
123 row.classList.add("filtered-by-search");
124
120 return row; 125 return row;
126 }
127
128 function shouldFilterRow(row, query)
129 {
130 var elementsToSearch = [
131 row.getElementsByClassName("url"),
132 row.getElementsByClassName("filter"),
133 row.getElementsByClassName("origin"),
134 row.getElementsByClassName("type")
135 ];
136
137 for (var elements of elementsToSearch)
138 {
139 for (var element of elements)
140 {
141 if (element.innerText.search(query) != -1)
142 return false;
143 }
144 }
145 return true;
146 }
147
148 function performSearch(table, query)
149 {
150 for (var row of table.rows)
151 {
152 if (shouldFilterRow(row, query))
153 row.classList.add("filtered-by-search");
154 else
155 row.classList.remove("filtered-by-search");
156 }
157 }
158
159 function cancelSearch(table)
160 {
161 for (var row of table.rows)
162 row.classList.remove("filtered-by-search");
121 } 163 }
122 164
123 document.addEventListener("DOMContentLoaded", function() 165 document.addEventListener("DOMContentLoaded", function()
124 { 166 {
125 var container = document.getElementById("items"); 167 var container = document.getElementById("items");
126 var table = container.querySelector("tbody"); 168 var table = container.querySelector("tbody");
127 var template = document.querySelector("template").content.firstElementChild; 169 var template = document.querySelector("template").content.firstElementChild;
128 170
129 document.getElementById("reload").addEventListener("click", function() 171 document.getElementById("reload").addEventListener("click", function()
130 { 172 {
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 container.classList.add("has-changes"); 205 container.classList.add("has-changes");
164 break; 206 break;
165 207
166 case "reset": 208 case "reset":
167 table.innerHTML = ""; 209 table.innerHTML = "";
168 container.classList.remove("has-changes"); 210 container.classList.remove("has-changes");
169 break; 211 break;
170 } 212 }
171 }); 213 });
172 214
215 window.addEventListener("message", function(event)
216 {
217 switch(event.data.type)
218 {
219 case "performSearch":
220 performSearch(table, event.data.queryString);
221 lastFilterQuery = event.data.queryString;
222 break;
223 case "cancelSearch":
224 cancelSearch(table);
225 lastFilterQuery = null;
226 break;
227 }
228 });
229
173 // Since Chrome 54 the themeName is accessible, for earlier versions we must 230 // Since Chrome 54 the themeName is accessible, for earlier versions we must
174 // assume the default theme is being used. 231 // assume the default theme is being used.
175 // https://bugs.chromium.org/p/chromium/issues/detail?id=608869 232 // https://bugs.chromium.org/p/chromium/issues/detail?id=608869
176 let theme = chrome.devtools.panels.themeName || "default"; 233 let theme = chrome.devtools.panels.themeName || "default";
177 document.body.classList.add(theme); 234 document.body.classList.add(theme);
178 }, false); 235 }, false);
LEFTRIGHT

Powered by Google App Engine
This is Rietveld