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

Side by Side Diff: mobile-options.js

Issue 29544706: Noissue - Adapt check for devtools panel support for Firefox (Closed)
Patch Set: Rebase Created Sept. 15, 2017, 4:51 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 | « messageResponder.js ('k') | skin/mobile-options.css » ('j') | 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-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
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 ext.backgroundPage.sendMessage({type: "subscriptions.add", url, title}); 120 ext.backgroundPage.sendMessage({type: "subscriptions.add", url, title});
121 } 121 }
122 122
123 function uninstallSubscription(url) 123 function uninstallSubscription(url)
124 { 124 {
125 ext.backgroundPage.sendMessage({type: "subscriptions.remove", url}); 125 ext.backgroundPage.sendMessage({type: "subscriptions.remove", url});
126 } 126 }
127 127
128 /* Actions */ 128 /* Actions */
129 129
130 function setSubscription({disabled, title, url}, shouldAdd) 130 function setFilter({disabled, text}, action)
131 { 131 {
132 if (!whitelistFilter || text != whitelistFilter)
133 return;
134
135 get("#enabled").checked = (action == "remove" || disabled);
136 }
137
138 function setSubscription(subscription, action)
139 {
140 let {disabled, filters, title, url} = subscription;
132 if (disabled) 141 if (disabled)
142 {
143 action = "remove";
144 }
145
146 // Handle custom subscription
147 if (/^~user/.test(url))
148 {
149 for (let filter of filters)
150 {
151 setFilter(filter, action);
152 }
133 return; 153 return;
154 }
134 155
135 promisedAcceptableAdsUrl.then((acceptableAdsUrl) => 156 promisedAcceptableAdsUrl.then((acceptableAdsUrl) =>
136 { 157 {
158 // Update Acceptable Ads
137 if (url == acceptableAdsUrl) 159 if (url == acceptableAdsUrl)
138 { 160 {
139 get(`#${idAcceptableAds}`).checked = true; 161 get(`#${idAcceptableAds}`).checked = (action != "remove");
140 return; 162 return;
141 } 163 }
142 164
143 let listInstalled = get("#subscriptions-installed"); 165 let listInstalled = get("#subscriptions-installed");
144 let installed = get(`[data-url="${url}"]`, listInstalled); 166 let installed = get(`[data-url="${url}"]`, listInstalled);
145 167
146 if (installed) 168 // Remove subscription
169 if (action == "remove")
170 {
171 if (installed)
172 {
173 installed.parentNode.removeChild(installed);
174 }
175
176 let recommended = get(`#${idRecommended} [data-url="${url}"]`);
177 if (recommended)
178 {
179 recommended.classList.remove("installed");
180 }
181 }
182 // Update subscription
183 else if (installed)
147 { 184 {
148 let titleElement = get("span", installed); 185 let titleElement = get("span", installed);
149 titleElement.textContent = title || url; 186 titleElement.textContent = title || url;
150 } 187 }
151 else if (shouldAdd) 188 // Add subscription
189 else if (action == "add")
152 { 190 {
153 let element = create(listInstalled, "li", null, {"data-url": url}); 191 let element = create(listInstalled, "li", null, {"data-url": url});
154 create(element, "span", title || url); 192 create(element, "span", title || url);
155 create(element, "button", null, {class: "remove"}, 193 create(element, "button", null, {class: "remove"},
156 () => uninstallSubscription(url) 194 () => uninstallSubscription(url)
157 ); 195 );
158 196
159 let recommended = get(`#${idRecommended} [data-url="${url}"]`); 197 let recommended = get(`#${idRecommended} [data-url="${url}"]`);
160 if (recommended) 198 if (recommended)
161 { 199 {
162 recommended.classList.add("installed"); 200 recommended.classList.add("installed");
163 } 201 }
164 } 202 }
165 }); 203 });
166 } 204 }
167 205
168 function removeSubscription(url)
169 {
170 promisedAcceptableAdsUrl.then((acceptableAdsUrl) =>
171 {
172 if (url == acceptableAdsUrl)
173 {
174 get(`#${idAcceptableAds}`).checked = false;
175 return;
176 }
177
178 let installed = get(`#subscriptions-installed [data-url="${url}"]`);
179 if (installed)
180 {
181 installed.parentNode.removeChild(installed);
182 }
183
184 let recommended = get(`#${idRecommended} [data-url="${url}"]`);
185 if (recommended)
186 {
187 recommended.classList.remove("installed");
188 }
189 });
190 }
191
192 function setDialog(id, options) 206 function setDialog(id, options)
193 { 207 {
194 if (!id) 208 if (!id)
195 { 209 {
196 delete document.body.dataset.dialog; 210 delete document.body.dataset.dialog;
197 return; 211 return;
198 } 212 }
199 213
200 let fields = getAll(`#dialog-${id} input`); 214 let fields = getAll(`#dialog-${id} input`);
201 for (let field of fields) 215 for (let field of fields)
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 setDialog(dialogSubscribe, {title, url}); 252 setDialog(dialogSubscribe, {title, url});
239 } 253 }
240 ); 254 );
241 } 255 }
242 256
243 for (let subscription of installed) 257 for (let subscription of installed)
244 { 258 {
245 if (subscription.disabled) 259 if (subscription.disabled)
246 continue; 260 continue;
247 261
248 setSubscription(subscription, true); 262 setSubscription(subscription, "add");
249 } 263 }
250 }) 264 })
251 .catch((err) => console.error(err)); 265 .catch((err) => console.error(err));
252 } 266 }
253 267
254 /* Listeners */ 268 /* Listeners */
255 269
256 function onChange(ev) 270 function onChange(ev)
257 { 271 {
258 if (ev.target.id != idAcceptableAds) 272 if (ev.target.id != idAcceptableAds)
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
365 379
366 let toggle = get("#enabled"); 380 let toggle = get("#enabled");
367 toggle.checked = !whitelisted; 381 toggle.checked = !whitelisted;
368 382
369 get("#enabled-container").hidden = false; 383 get("#enabled-container").hidden = false;
370 break; 384 break;
371 } 385 }
372 break; 386 break;
373 } 387 }
374 case "filters.respond": { 388 case "filters.respond": {
375 let [filter] = msg.args; 389 let action = (msg.action == "added") ? "add" : "remove";
376 if (!whitelistFilter || filter.text != whitelistFilter) 390 setFilter(msg.args[0], action);
377 break;
378
379 get("#enabled").checked = (msg.action == "removed");
380 break; 391 break;
381 } 392 }
382 case "subscriptions.respond": { 393 case "subscriptions.respond": {
383 let [subscription] = msg.args; 394 let [subscription] = msg.args;
384 switch (msg.action) 395 switch (msg.action)
385 { 396 {
386 case "added": 397 case "added":
387 setSubscription(subscription, true);
388 break;
389 case "disabled": 398 case "disabled":
390 if (subscription.disabled) 399 setSubscription(subscription, "add");
391 {
392 removeSubscription(subscription.url);
393 }
394 else
395 {
396 setSubscription(subscription, true);
397 }
398 break; 400 break;
399 case "removed": 401 case "removed":
400 removeSubscription(subscription.url); 402 setSubscription(subscription, "remove");
401 break; 403 break;
402 case "title": 404 case "title":
403 // We're also receiving these messages for subscriptions that are 405 // We're also receiving these messages for subscriptions that are
404 // not installed so we shouldn't add those by accident 406 // not installed so we shouldn't add those by accident
405 setSubscription(subscription, false); 407 setSubscription(subscription, "update");
406 break; 408 break;
407 } 409 }
408 break; 410 break;
409 } 411 }
410 } 412 }
411 } 413 }
412 ext.onMessage.addListener(onMessage); 414 ext.onMessage.addListener(onMessage);
413 415
414 ext.backgroundPage.sendMessage({ 416 ext.backgroundPage.sendMessage({
415 type: "app.listen", 417 type: "app.listen",
(...skipping 22 matching lines...) Expand all
438 get("#dialog-subscribe [name='title']").setAttribute( 440 get("#dialog-subscribe [name='title']").setAttribute(
439 "placeholder", 441 "placeholder",
440 getMessage("mops_subscribe_title") 442 getMessage("mops_subscribe_title")
441 ); 443 );
442 444
443 get("#dialog-subscribe [name='url']").setAttribute( 445 get("#dialog-subscribe [name='url']").setAttribute(
444 "placeholder", 446 "placeholder",
445 getMessage("mops_subscribe_url") 447 getMessage("mops_subscribe_url")
446 ); 448 );
447 } 449 }
OLDNEW
« no previous file with comments | « messageResponder.js ('k') | skin/mobile-options.css » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld