Left: | ||
Right: |
OLD | NEW |
---|---|
(Empty) | |
1 /* | |
2 * This file is part of Adblock Plus <http://adblockplus.org/>, | |
3 * Copyright (C) 2006-2015 Eyeo GmbH | |
4 * | |
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 | |
7 * published by the Free Software Foundation. | |
8 * | |
9 * Adblock Plus is distributed in the hope that it will be useful, | |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 * GNU General Public License for more details. | |
13 * | |
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/>. | |
16 */ | |
17 | |
18 function generateFilter(request) | |
19 { | |
20 var filter = request.url.replace(/^[\w\-]+:\/+(?:www\.)?/, "||"); | |
21 | |
22 if (request.type == "POPUP") | |
23 { | |
24 filter += "$popup"; | |
25 | |
26 if (request.url == "about:blank") | |
27 filter += ",domain=" + request.docDomain; | |
28 } | |
29 | |
30 return filter; | |
31 } | |
32 | |
33 function createActionButton(action, label, filter, port) | |
34 { | |
35 var button = document.createElement("span"); | |
36 | |
37 button.textContent = label; | |
38 button.classList.add("action"); | |
39 | |
40 button.addEventListener("click", function() | |
41 { | |
42 port.postMessage({action: action, filter: filter}); | |
43 }); | |
44 | |
45 return button; | |
46 } | |
47 | |
48 function createRecord(request, filter, port) | |
Thomas Greiner
2015/01/12 10:37:54
Seems like HTML templates is what you'd want to us
Sebastian Noack
2015/01/12 11:55:07
Sounds good. I will look into it.
| |
49 { | |
50 var row = document.createElement("tr"); | |
51 row.dataset.type = request.type; | |
52 | |
53 var requestCell = document.createElement("td"); | |
54 row.appendChild(requestCell); | |
55 | |
56 var requestWrapper = document.createElement("div"); | |
57 requestWrapper.classList.add("request-wrapper"); | |
58 requestCell.appendChild(requestWrapper); | |
59 | |
60 var urlElement = document.createElement("div"); | |
61 urlElement.classList.add("url"); | |
62 urlElement.innerHTML = " "; | |
Thomas Greiner
2015/01/12 10:37:54
I assume you do this to ensure a minimum height fo
Sebastian Noack
2015/01/12 11:55:07
Doesn't seem to do the trick when using flexbox.
Thomas Greiner
2015/01/16 18:17:21
That's strange because it works for me when emptyi
Sebastian Noack
2015/02/04 14:17:29
I don't recall anymore what the particular problem
Thomas Greiner
2015/03/13 11:11:05
Assuring that the element has a minimum height is
Sebastian Noack
2015/03/13 13:07:38
I don't want a minimum height, I want each line to
| |
63 requestWrapper.appendChild(urlElement); | |
64 | |
65 var domainElement = document.createElement("div"); | |
66 domainElement.classList.add("domain"); | |
67 domainElement.textContent = request.docDomain; | |
68 requestWrapper.appendChild(domainElement); | |
69 | |
70 var typeElement = document.createElement("div"); | |
71 typeElement.classList.add("type"); | |
72 typeElement.textContent = request.type; | |
73 requestWrapper.appendChild(typeElement); | |
74 | |
75 var filterCell = document.createElement("td"); | |
76 row.appendChild(filterCell); | |
77 | |
78 var actionWrapper = document.createElement("div"); | |
79 actionWrapper.classList.add("action-wrapper"); | |
80 filterCell.appendChild(actionWrapper); | |
81 | |
82 var filterWrapper = document.createElement("div"); | |
83 filterWrapper.classList.add("filter-wrapper"); | |
84 actionWrapper.appendChild(filterWrapper); | |
85 | |
86 var filterElement = document.createElement("div"); | |
87 filterElement.innerHTML = " "; | |
88 filterElement.classList.add("filter"); | |
89 filterWrapper.appendChild(filterElement); | |
90 | |
91 var originElement = document.createElement("div"); | |
92 originElement.innerHTML = " "; | |
93 originElement.classList.add("origin"); | |
94 filterWrapper.appendChild(originElement); | |
95 | |
96 if (request.url) | |
Thomas Greiner
2015/01/12 10:37:54
Which requests don't have URLs associated to them?
Sebastian Noack
2015/01/12 11:55:07
Element hiding filter matches.
| |
97 { | |
98 urlElement.textContent = request.url; | |
99 | |
100 if ("openResource" in ext.devtools.panels && request.type != "POPUP") | |
Thomas Greiner
2015/01/12 10:37:54
Why would `ext.devtools.panels.openResource` not b
Sebastian Noack
2015/01/12 11:55:07
It's new in Chrome 38.
| |
101 { | |
102 urlElement.classList.add("resourceLink"); | |
103 urlElement.addEventListener("click", function() | |
Thomas Greiner
2015/01/12 10:37:54
No need to add an event listener to each row indiv
Sebastian Noack
2015/01/12 11:55:07
I know. But then I'd need to double check whether
Thomas Greiner
2015/01/16 18:17:21
I'd agree if `urlElement` had child elements that
Sebastian Noack
2015/02/04 14:17:29
I'd still need to check whether ext.devtools.panel
Thomas Greiner
2015/03/13 11:11:05
That makes sense. Separating the logic from the vi
| |
104 { | |
105 ext.devtools.panels.openResource(request.url); | |
106 }); | |
107 } | |
108 } | |
109 | |
110 if (filter) | |
111 { | |
112 filterElement.textContent = filter.text; | |
113 row.dataset.state = filter.whitelisted ? "whitelisted" : "blocked"; | |
114 | |
115 if (filter.subscription) | |
116 originElement.textContent = filter.subscription; | |
117 else | |
118 { | |
119 if (filter.userDefined) | |
120 originElement.textContent = "user-defined"; | |
121 else | |
122 originElement.textContent = "unnamed subscription"; | |
123 | |
124 originElement.classList.add("unnamed"); | |
125 } | |
126 | |
127 if (!filter.whitelisted && request.type != "ELEMHIDE") | |
128 actionWrapper.appendChild(createActionButton("add", "Whitelist request", " @@" + generateFilter(request), port)); | |
129 | |
130 if (filter.userDefined) | |
131 actionWrapper.appendChild(createActionButton("remove", "Remove filter", fi lter.text, port)); | |
132 } | |
133 else | |
134 actionWrapper.appendChild(createActionButton("add", "Block request", generat eFilter(request), port)); | |
135 | |
136 return row; | |
137 } | |
138 | |
139 document.addEventListener("DOMContentLoaded", function() | |
140 { | |
141 var port = ext.devtools.connect(); | |
142 var container = document.getElementById("items"); | |
143 var table = container.getElementsByTagName("table")[0]; | |
144 | |
145 port.onMessage.addListener(function(msg) | |
146 { | |
147 switch (msg.type) | |
148 { | |
149 case "add-record": | |
150 table.appendChild(createRecord(msg.request, msg.filter, port)); | |
151 break; | |
152 | |
153 case "update-record": | |
154 var oldRow = table.getElementsByTagName("tr")[msg.index]; | |
155 var newRow = createRecord(msg.request, msg.filter, port); | |
156 oldRow.parentNode.replaceChild(newRow, oldRow); | |
157 newRow.classList.add("changed"); | |
158 container.classList.add("has-changes"); | |
159 break; | |
160 | |
161 case "remove-record": | |
162 var row = table.getElementsByTagName("tr")[msg.index]; | |
163 row.parentNode.removeChild(row); | |
164 container.classList.add("has-changes"); | |
165 break; | |
166 | |
167 case "reset": | |
168 table.innerHTML = ""; | |
169 container.classList.remove("has-changes"); | |
170 break; | |
171 } | |
172 }); | |
173 | |
174 document.getElementById("reload").addEventListener("click", function() | |
175 { | |
176 ext.devtools.inspectedWindow.reload(); | |
177 }); | |
178 | |
179 document.getElementById("filter-state").addEventListener("change", function(ev ent) | |
180 { | |
181 container.dataset.filterState = event.target.value; | |
182 }); | |
183 | |
184 document.getElementById("filter-type").addEventListener("change", function(eve nt) | |
185 { | |
186 container.dataset.filterType = event.target.value; | |
187 }); | |
188 }); | |
OLD | NEW |