| Index: options.js |
| diff --git a/options.js b/options.js |
| index c7667b841390a2f15a95d295a48643c21dee7a33..25b18aa60d0f083d2bd04612cd1869607e39b6d0 100644 |
| --- a/options.js |
| +++ b/options.js |
| @@ -92,6 +92,7 @@ const statusMessages = new Map([ |
| let delayedSubscriptionSelection = null; |
| let acceptableAdsUrl; |
| +let specialSubscriptionBeingAdded = null; |
| // Loads options from localStorage and sets UI elements accordingly |
| function loadOptions() |
| @@ -193,6 +194,7 @@ $(loadOptions); |
| function convertSpecialSubscription(subscription) |
| { |
| + specialSubscriptionBeingAdded = subscription.url; |
| getFilters(subscription.url, filters => |
| { |
| for (let filter of filters) |
| @@ -202,6 +204,7 @@ function convertSpecialSubscription(subscription) |
| else |
| appendToListBox("userFiltersBox", filter.text); |
| } |
| + specialSubscriptionBeingAdded = null; |
| }); |
| } |
| @@ -503,8 +506,19 @@ function onPrefMessage(key, value) |
| checkbox.checked = value; |
| } |
| -function onFilterMessage(action, filter) |
| +function onFilterMessage(action, filter, subscription) |
| { |
| + // When the user adds a custom filter for the first time a special |
| + // subscription is created automatically. When the happens we'll receive a |
| + // message for the subscription first, then the filter. To avoid displaying |
| + // the filter twice we have to be careful to ignore filter messages for a |
| + // newly added subscription which we're still in the process of handling. |
| + if (specialSubscriptionBeingAdded && subscription && |
| + subscription.url == specialSubscriptionBeingAdded) |
| + { |
| + return; |
| + } |
| + |
| switch (action) |
| { |
| case "loaded": |
| @@ -734,7 +748,7 @@ ext.onMessage.addListener(message => |
| } |
| break; |
| case "filters.respond": |
| - onFilterMessage(message.action, message.args[0]); |
| + onFilterMessage(message.action, message.args[0], message.args[1]); |
| break; |
| case "prefs.respond": |
| onPrefMessage(message.action, message.args[0]); |