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

Side by Side Diff: options.js

Issue 29339717: Issue 3915 - Properly handle special subscriptions (Closed)
Patch Set: Created April 14, 2016, 9:52 a.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 | « no previous file | no next file » | 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-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
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 }); 185 });
186 186
187 // Load recommended subscriptions 187 // Load recommended subscriptions
188 loadRecommendations(); 188 loadRecommendations();
189 189
190 // Show user's filters 190 // Show user's filters
191 reloadFilters(); 191 reloadFilters();
192 } 192 }
193 $(loadOptions); 193 $(loadOptions);
194 194
195 function convertSpecialSubscription(subscription)
196 {
197 getFilters(subscription.url, function(filters)
198 {
199 for (var j = 0; j < filters.length; j++)
200 {
201 var filter = filters[j].text;
202 if (whitelistedDomainRegexp.test(filter))
203 appendToListBox("excludedDomainsBox", RegExp.$1);
204 else
205 appendToListBox("userFiltersBox", filter);
206 }
207 });
208 }
209
195 // Reloads the displayed subscriptions and filters 210 // Reloads the displayed subscriptions and filters
196 function reloadFilters() 211 function reloadFilters()
197 { 212 {
198 // Load user filter URLs 213 // Load user filter URLs
199 var container = document.getElementById("filterLists"); 214 var container = document.getElementById("filterLists");
200 while (container.lastChild) 215 while (container.lastChild)
201 container.removeChild(container.lastChild); 216 container.removeChild(container.lastChild);
202 217
203 getSubscriptions(true, false, function(subscriptions) 218 getSubscriptions(true, false, function(subscriptions)
204 { 219 {
205 for (var i = 0; i < subscriptions.length; i++) 220 for (var i = 0; i < subscriptions.length; i++)
206 { 221 {
207 var subscription = subscriptions[i]; 222 var subscription = subscriptions[i];
208 if (subscription.url == acceptableAdsUrl) 223 if (subscription.url == acceptableAdsUrl)
209 $("#acceptableAds").prop("checked", !subscription.disabled); 224 $("#acceptableAds").prop("checked", !subscription.disabled);
210 else 225 else
211 addSubscriptionEntry(subscription); 226 addSubscriptionEntry(subscription);
212 } 227 }
213 }); 228 });
214 229
215 // User-entered filters 230 // User-entered filters
216 getSubscriptions(false, true, function(subscriptions) 231 getSubscriptions(false, true, function(subscriptions)
217 { 232 {
218 clearListBox("userFiltersBox"); 233 clearListBox("userFiltersBox");
219 clearListBox("excludedDomainsBox"); 234 clearListBox("excludedDomainsBox");
220 235
221 for (var i = 0; i < subscriptions.length; i++) 236 for (var i = 0; i < subscriptions.length; i++)
222 getFilters(subscriptions[i].url, function(filters) 237 convertSpecialSubscription(subscriptions[i]);
223 {
224 for (var j = 0; j < filters.length; j++)
225 {
226 var filter = filters[j].text;
227 if (whitelistedDomainRegexp.test(filter))
228 appendToListBox("excludedDomainsBox", RegExp.$1);
229 else
230 appendToListBox("userFiltersBox", filter);
231 }
232 });
233 }); 238 });
234 } 239 }
235 240
236 function initCheckbox(id, descriptor) 241 function initCheckbox(id, descriptor)
237 { 242 {
238 var checkbox = document.getElementById(id); 243 var checkbox = document.getElementById(id);
239 var key = descriptor && descriptor.key || id; 244 var key = descriptor && descriptor.key || id;
240 getPref(key, function(value) 245 getPref(key, function(value)
241 { 246 {
242 if (descriptor && descriptor.get) 247 if (descriptor && descriptor.get)
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after
462 case "disabled": 467 case "disabled":
463 case "downloading": 468 case "downloading":
464 case "downloadStatus": 469 case "downloadStatus":
465 case "homepage": 470 case "homepage":
466 case "lastDownload": 471 case "lastDownload":
467 case "title": 472 case "title":
468 if (element) 473 if (element)
469 updateSubscriptionInfo(element, subscription); 474 updateSubscriptionInfo(element, subscription);
470 break; 475 break;
471 case "added": 476 case "added":
472 if (subscription.url == acceptableAdsUrl) 477 if (subscription.url.indexOf("~user") == 0)
kzar 2016/04/14 09:55:22 I decided to go with your approach in the end, rat
478 convertSpecialSubscription(subscription);
479 else if (subscription.url == acceptableAdsUrl)
473 $("#acceptableAds").prop("checked", true); 480 $("#acceptableAds").prop("checked", true);
474 else if (!element) 481 else if (!element)
475 addSubscriptionEntry(subscription); 482 addSubscriptionEntry(subscription);
476 break; 483 break;
477 case "removed": 484 case "removed":
478 if (subscription.url == acceptableAdsUrl) 485 if (subscription.url == acceptableAdsUrl)
479 $("#acceptableAds").prop("checked", false); 486 $("#acceptableAds").prop("checked", false);
480 else if (element) 487 else if (element)
481 element.parentNode.removeChild(element); 488 element.parentNode.removeChild(element);
482 break; 489 break;
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after
741 onFilterMessage(message.action, message.args[0]); 748 onFilterMessage(message.action, message.args[0]);
742 break; 749 break;
743 case "prefs.respond": 750 case "prefs.respond":
744 onPrefMessage(message.action, message.args[0]); 751 onPrefMessage(message.action, message.args[0]);
745 break; 752 break;
746 case "subscriptions.respond": 753 case "subscriptions.respond":
747 onSubscriptionMessage(message.action, message.args[0]); 754 onSubscriptionMessage(message.action, message.args[0]);
748 break; 755 break;
749 } 756 }
750 }); 757 });
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld