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

Side by Side Diff: new-options.js

Issue 29346555: Issue 4156 - Adblocking filter only being removed in advanced tab fix (Closed)
Patch Set: Rebased to changeset #85 Created June 27, 2016, 1:32 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 | « 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 319 matching lines...) Expand 10 before | Expand all | Expand 10 after
330 collections.filterLists = new Collection( 330 collections.filterLists = new Collection(
331 [ 331 [
332 { 332 {
333 id: "all-filter-lists-table", 333 id: "all-filter-lists-table",
334 useOriginalTitle: true 334 useOriginalTitle: true
335 } 335 }
336 ]); 336 ]);
337 337
338 function updateLanguageCollections(subscription) 338 function updateLanguageCollections(subscription)
339 { 339 {
340 if (subscription.recommended == "ads") 340 if (subscription.disabled)
341 { 341 {
342 if (subscription.disabled) 342 collections.allLangs.addItems(subscription);
343 { 343 collections.langs.removeItem(subscription);
344 collections.allLangs.addItems(subscription); 344 }
345 collections.langs.removeItem(subscription); 345 else
346 } 346 {
347 else 347 collections.allLangs.removeItem(subscription);
348 { 348 collections.langs.addItems(subscription);
349 collections.allLangs.removeItem(subscription);
350 collections.langs.addItems(subscription);
351 }
352 } 349 }
353 } 350 }
354 351
355 function addSubscription(subscription) 352 function addSubscription(subscription)
356 { 353 {
357 var collection; 354 var collection;
358 if (subscription.recommended) 355 if (subscription.recommended)
359 { 356 {
360 if (subscription.recommended != "ads") 357 if (subscription.recommended != "ads")
361 collection = collections.popular; 358 collection = collections.popular;
362 else if (subscription.disabled == false) 359 else if (subscription.disabled == false)
363 collection = collections.langs; 360 collection = collections.langs;
364 else 361 else
365 collection = collections.allLangs; 362 collection = collections.allLangs;
366 } 363 }
367 else if (subscription.url == acceptableAdsUrl) 364 else if (subscription.url == acceptableAdsUrl)
368 collection = collections.acceptableAds; 365 collection = collections.acceptableAds;
369 else 366 else
370 collection = collections.custom; 367 collection = collections.custom;
371 368
372 collection.addItems(subscription); 369 collection.addItems(subscription);
373 subscriptionsMap[subscription.url] = subscription; 370 subscriptionsMap[subscription.url] = subscription;
374 updateTooltips(); 371 updateTooltips();
375 } 372 }
376 373
377 function updateSubscription(subscription) 374 function updateSubscription(subscription)
378 { 375 {
379 var knownSubscription = subscriptionsMap[subscription.url];
380 for (var property in subscription)
381 {
382 if (property == "title" && subscription.recommended)
383 knownSubscription.originalTitle = subscription.title;
384 else
385 knownSubscription[property] = subscription[property];
386 }
387
388 for (var name in collections) 376 for (var name in collections)
389 collections[name].updateItem(knownSubscription); 377 collections[name].updateItem(subscription);
390
391 return knownSubscription;
392 } 378 }
393 379
394 function updateFilter(filter) 380 function updateFilter(filter)
395 { 381 {
396 var match = filter.text.match(/^@@\|\|([^\/:]+)\^\$document$/); 382 var match = filter.text.match(/^@@\|\|([^\/:]+)\^\$document$/);
397 if (match && !filtersMap[filter.text]) 383 if (match && !filtersMap[filter.text])
398 { 384 {
399 filter.title = match[1]; 385 filter.title = match[1];
400 collections.whitelist.addItems(filter); 386 collections.whitelist.addItems(filter);
401 } 387 }
(...skipping 494 matching lines...) Expand 10 before | Expand all | Expand 10 after
896 collections.whitelist.removeItem(knownFilter); 882 collections.whitelist.removeItem(knownFilter);
897 collections.customFilters.removeItem(knownFilter); 883 collections.customFilters.removeItem(knownFilter);
898 delete filtersMap[filter.text]; 884 delete filtersMap[filter.text];
899 updateShareLink(); 885 updateShareLink();
900 break; 886 break;
901 } 887 }
902 } 888 }
903 889
904 function onSubscriptionMessage(action, subscription) 890 function onSubscriptionMessage(action, subscription)
905 { 891 {
892 if (subscription.url in subscriptionsMap)
893 {
894 var knownSubscription = subscriptionsMap[subscription.url];
895 for (var property in subscription)
896 {
897 if (property == "title" && knownSubscription.recommended)
898 knownSubscription.originalTitle = subscription.title;
899 else
900 knownSubscription[property] = subscription[property];
901 }
902 subscription = knownSubscription;
903 }
906 switch (action) 904 switch (action)
907 { 905 {
908 case "disabled": 906 case "disabled":
909 subscription = updateSubscription(subscription); 907 if (subscription.recommended == "ads")
910 updateLanguageCollections(subscription); 908 updateLanguageCollections(subscription);
909 updateSubscription(subscription);
911 break; 910 break;
912 case "downloading": 911 case "downloading":
913 case "downloadStatus": 912 case "downloadStatus":
914 case "homepage": 913 case "homepage":
915 case "lastDownload": 914 case "lastDownload":
916 case "title": 915 case "title":
917 updateSubscription(subscription); 916 updateSubscription(subscription);
918 break; 917 break;
919 case "added": 918 case "added":
920 if (subscription.url in subscriptionsMap) 919 if (subscription.recommended == "ads")
921 subscription = updateSubscription(subscription); 920 updateLanguageCollections(subscription);
921 else if (subscription.url in subscriptionsMap)
922 updateSubscription(subscription);
922 else 923 else
923 addSubscription(subscription); 924 addSubscription(subscription);
924 925
925 collections.filterLists.addItems(subscription); 926 collections.filterLists.addItems(subscription);
926 updateLanguageCollections(subscription);
927 break; 927 break;
928 case "removed": 928 case "removed":
929 var knownSubscription = subscriptionsMap[subscription.url];
930 if (subscription.url == acceptableAdsUrl || subscription.recommended) 929 if (subscription.url == acceptableAdsUrl || subscription.recommended)
931 { 930 {
932 subscription.disabled = true; 931 subscription.disabled = true;
933 onSubscriptionMessage("disabled", subscription); 932 onSubscriptionMessage("disabled", subscription);
934 } 933 }
935 else 934 else
936 { 935 {
937 collections.custom.removeItem(knownSubscription); 936 collections.custom.removeItem(subscription);
938 delete subscriptionsMap[subscription.url]; 937 delete subscriptionsMap[subscription.url];
939 } 938 }
940 collections.filterLists.removeItem(knownSubscription); 939 collections.filterLists.removeItem(subscription);
941 break; 940 break;
942 } 941 }
943 942
944 updateShareLink(); 943 updateShareLink();
945 } 944 }
946 945
947 function hidePref(key, value) 946 function hidePref(key, value)
948 { 947 {
949 var element = document.querySelector("[data-pref='" + key + "']"); 948 var element = document.querySelector("[data-pref='" + key + "']");
950 if (element) 949 if (element)
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after
1171 }); 1170 });
1172 ext.backgroundPage.sendMessage( 1171 ext.backgroundPage.sendMessage(
1173 { 1172 {
1174 type: "subscriptions.listen", 1173 type: "subscriptions.listen",
1175 filter: ["added", "disabled", "homepage", "lastDownload", "removed", 1174 filter: ["added", "disabled", "homepage", "lastDownload", "removed",
1176 "title", "downloadStatus", "downloading"] 1175 "title", "downloadStatus", "downloading"]
1177 }); 1176 });
1178 1177
1179 window.addEventListener("DOMContentLoaded", onDOMLoaded, false); 1178 window.addEventListener("DOMContentLoaded", onDOMLoaded, false);
1180 })(); 1179 })();
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