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

Side by Side Diff: options.js

Issue 29384555: Issue 4978 - Avoid custom filters from being displayed multiple times (Closed)
Patch Set: Created March 15, 2017, 7:24 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 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 ["synchronize_connection_error", 85 ["synchronize_connection_error",
86 "filters_subscription_lastDownload_connectionError"], 86 "filters_subscription_lastDownload_connectionError"],
87 ["synchronize_invalid_data", 87 ["synchronize_invalid_data",
88 "filters_subscription_lastDownload_invalidData"], 88 "filters_subscription_lastDownload_invalidData"],
89 ["synchronize_checksum_mismatch", 89 ["synchronize_checksum_mismatch",
90 "filters_subscription_lastDownload_checksumMismatch"] 90 "filters_subscription_lastDownload_checksumMismatch"]
91 ]); 91 ]);
92 92
93 let delayedSubscriptionSelection = null; 93 let delayedSubscriptionSelection = null;
94 let acceptableAdsUrl; 94 let acceptableAdsUrl;
95 let specialSubscriptionBeingAdded = null;
95 96
96 // Loads options from localStorage and sets UI elements accordingly 97 // Loads options from localStorage and sets UI elements accordingly
97 function loadOptions() 98 function loadOptions()
98 { 99 {
99 // Set page title to i18n version of "Adblock Plus Options" 100 // Set page title to i18n version of "Adblock Plus Options"
100 document.title = i18n.getMessage("options"); 101 document.title = i18n.getMessage("options");
101 102
102 // Set links 103 // Set links
103 getPref("subscriptions_exceptionsurl", url => 104 getPref("subscriptions_exceptionsurl", url =>
104 { 105 {
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 // Load recommended subscriptions 187 // Load recommended subscriptions
187 loadRecommendations(); 188 loadRecommendations();
188 189
189 // Show user's filters 190 // Show user's filters
190 reloadFilters(); 191 reloadFilters();
191 } 192 }
192 $(loadOptions); 193 $(loadOptions);
193 194
194 function convertSpecialSubscription(subscription) 195 function convertSpecialSubscription(subscription)
195 { 196 {
197 specialSubscriptionBeingAdded = subscription.url;
196 getFilters(subscription.url, filters => 198 getFilters(subscription.url, filters =>
197 { 199 {
198 for (let filter of filters) 200 for (let filter of filters)
199 { 201 {
200 if (whitelistedDomainRegexp.test(filter.text)) 202 if (whitelistedDomainRegexp.test(filter.text))
201 appendToListBox("excludedDomainsBox", RegExp.$1); 203 appendToListBox("excludedDomainsBox", RegExp.$1);
202 else 204 else
203 appendToListBox("userFiltersBox", filter.text); 205 appendToListBox("userFiltersBox", filter.text);
204 } 206 }
207 specialSubscriptionBeingAdded = null;
205 }); 208 });
206 } 209 }
207 210
208 // Reloads the displayed subscriptions and filters 211 // Reloads the displayed subscriptions and filters
209 function reloadFilters() 212 function reloadFilters()
210 { 213 {
211 // Load user filter URLs 214 // Load user filter URLs
212 let container = document.getElementById("filterLists"); 215 let container = document.getElementById("filterLists");
213 while (container.lastChild) 216 while (container.lastChild)
214 container.removeChild(container.lastChild); 217 container.removeChild(container.lastChild);
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after
496 case "notifications_ignoredcategories": 499 case "notifications_ignoredcategories":
497 key = "shouldShowNotifications"; 500 key = "shouldShowNotifications";
498 value = value.indexOf("*") == -1; 501 value = value.indexOf("*") == -1;
499 break; 502 break;
500 } 503 }
501 let checkbox = document.getElementById(key); 504 let checkbox = document.getElementById(key);
502 if (checkbox) 505 if (checkbox)
503 checkbox.checked = value; 506 checkbox.checked = value;
504 } 507 }
505 508
506 function onFilterMessage(action, filter) 509 function onFilterMessage(action, filter, subscription)
507 { 510 {
511 // When the user adds a custom filter for the first time a special
512 // subscription is created automatically. When the happens we'll receive a
513 // message for the subscription first, then the filter. To avoid displaying
514 // the filter twice we have to be careful to ignore filter messages for a
515 // newly added subscription which we're still in the process of handling.
516 if (specialSubscriptionBeingAdded && subscription &&
517 subscription.url == specialSubscriptionBeingAdded)
518 {
519 return;
520 }
521
508 switch (action) 522 switch (action)
509 { 523 {
510 case "loaded": 524 case "loaded":
511 reloadFilters(); 525 reloadFilters();
512 break; 526 break;
513 case "added": 527 case "added":
514 if (whitelistedDomainRegexp.test(filter.text)) 528 if (whitelistedDomainRegexp.test(filter.text))
515 appendToListBox("excludedDomainsBox", RegExp.$1); 529 appendToListBox("excludedDomainsBox", RegExp.$1);
516 else 530 else
517 appendToListBox("userFiltersBox", filter.text); 531 appendToListBox("userFiltersBox", filter.text);
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
727 previous[0].classList.remove("focused"); 741 previous[0].classList.remove("focused");
728 742
729 let index = $("[href='#" + tab.id + "']").parent().index(); 743 let index = $("[href='#" + tab.id + "']").parent().index();
730 $("#tabs").tabs("select", index); 744 $("#tabs").tabs("select", index);
731 found.classList.add("focused"); 745 found.classList.add("focused");
732 } 746 }
733 break; 747 break;
734 } 748 }
735 break; 749 break;
736 case "filters.respond": 750 case "filters.respond":
737 onFilterMessage(message.action, message.args[0]); 751 onFilterMessage(message.action, message.args[0], message.args[1]);
738 break; 752 break;
739 case "prefs.respond": 753 case "prefs.respond":
740 onPrefMessage(message.action, message.args[0]); 754 onPrefMessage(message.action, message.args[0]);
741 break; 755 break;
742 case "subscriptions.respond": 756 case "subscriptions.respond":
743 onSubscriptionMessage(message.action, message.args[0]); 757 onSubscriptionMessage(message.action, message.args[0]);
744 break; 758 break;
745 } 759 }
746 }); 760 });
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