OLD | NEW |
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 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 $("#startSubscriptionSelection").click(startSubscriptionSelection); | 60 $("#startSubscriptionSelection").click(startSubscriptionSelection); |
61 $("#subscriptionSelector").change(updateSubscriptionSelection); | 61 $("#subscriptionSelector").change(updateSubscriptionSelection); |
62 $("#addSubscription").click(addSubscription); | 62 $("#addSubscription").click(addSubscription); |
63 $("#acceptableAds").click(allowAcceptableAds); | 63 $("#acceptableAds").click(allowAcceptableAds); |
64 $("#whitelistForm").submit(addWhitelistDomain); | 64 $("#whitelistForm").submit(addWhitelistDomain); |
65 $("#removeWhitelist").click(removeSelectedExcludedDomain); | 65 $("#removeWhitelist").click(removeSelectedExcludedDomain); |
66 $("#customFilterForm").submit(addTypedFilter); | 66 $("#customFilterForm").submit(addTypedFilter); |
67 $("#removeCustomFilter").click(removeSelectedFilters); | 67 $("#removeCustomFilter").click(removeSelectedFilters); |
68 $("#rawFiltersButton").click(toggleFiltersInRawFormat); | 68 $("#rawFiltersButton").click(toggleFiltersInRawFormat); |
69 $("#importRawFilters").click(importRawFiltersText); | 69 $("#importRawFilters").click(importRawFiltersText); |
70 FilterNotifier.addListener(onFilterChange); | 70 |
| 71 FilterNotifier.on("load", reloadFilters); |
| 72 FilterNotifier.on("subscription.title", onSubscriptionChange); |
| 73 FilterNotifier.on("subscription.disabled", onSubscriptionChange); |
| 74 FilterNotifier.on("subscription.homepage", onSubscriptionChange); |
| 75 FilterNotifier.on("subscription.lastDownload", onSubscriptionChange); |
| 76 FilterNotifier.on("subscription.downloadStatus", onSubscriptionChange); |
| 77 FilterNotifier.on("subscription.added", onSubscriptionAdded); |
| 78 FilterNotifier.on("subscription.removed", onSubscriptionRemoved); |
| 79 FilterNotifier.on("filter.added", onFilterAdded); |
| 80 FilterNotifier.on("filter.removed", onFilterRemoved); |
71 | 81 |
72 // Display jQuery UI elements | 82 // Display jQuery UI elements |
73 $("#tabs").tabs(); | 83 $("#tabs").tabs(); |
74 $("button").button(); | 84 $("button").button(); |
75 $(".refreshButton").button("option", "icons", {primary: "ui-icon-refresh"}); | 85 $(".refreshButton").button("option", "icons", {primary: "ui-icon-refresh"}); |
76 $(".addButton").button("option", "icons", {primary: "ui-icon-plus"}); | 86 $(".addButton").button("option", "icons", {primary: "ui-icon-plus"}); |
77 $(".removeButton").button("option", "icons", {primary: "ui-icon-minus"}); | 87 $(".removeButton").button("option", "icons", {primary: "ui-icon-minus"}); |
78 | 88 |
79 // Popuplate option checkboxes | 89 // Popuplate option checkboxes |
80 initCheckbox("shouldShowBlockElementMenu"); | 90 initCheckbox("shouldShowBlockElementMenu"); |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 | 178 |
169 // User-entered filters | 179 // User-entered filters |
170 var userFilters = backgroundPage.getUserFilters(); | 180 var userFilters = backgroundPage.getUserFilters(); |
171 populateList("userFiltersBox", userFilters.filters); | 181 populateList("userFiltersBox", userFilters.filters); |
172 populateList("excludedDomainsBox", userFilters.exceptions); | 182 populateList("excludedDomainsBox", userFilters.exceptions); |
173 } | 183 } |
174 | 184 |
175 // Cleans up when the options window is closed | 185 // Cleans up when the options window is closed |
176 function unloadOptions() | 186 function unloadOptions() |
177 { | 187 { |
178 FilterNotifier.removeListener(onFilterChange); | 188 FilterNotifier.off("load", reloadFilters); |
| 189 FilterNotifier.off("subscription.title", onSubscriptionChange); |
| 190 FilterNotifier.off("subscription.disabled", onSubscriptionChange); |
| 191 FilterNotifier.off("subscription.homepage", onSubscriptionChange); |
| 192 FilterNotifier.off("subscription.lastDownload", onSubscriptionChange); |
| 193 FilterNotifier.off("subscription.downloadStatus", onSubscriptionChange); |
| 194 FilterNotifier.off("subscription.added", onSubscriptionAdded); |
| 195 FilterNotifier.off("subscription.removed", onSubscriptionRemoved); |
| 196 FilterNotifier.off("filter.added", onFilterAdded); |
| 197 FilterNotifier.off("filter.removed", onFilterRemoved); |
179 } | 198 } |
180 | 199 |
181 function initCheckbox(id, descriptor) | 200 function initCheckbox(id, descriptor) |
182 { | 201 { |
183 var checkbox = document.getElementById(id); | 202 var checkbox = document.getElementById(id); |
184 if (descriptor && descriptor.get) | 203 if (descriptor && descriptor.get) |
185 checkbox.checked = descriptor.get(); | 204 checkbox.checked = descriptor.get(); |
186 else | 205 else |
187 checkbox.checked = Prefs[id]; | 206 checkbox.checked = Prefs[id]; |
188 | 207 |
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
414 lastUpdate.classList.add("error"); | 433 lastUpdate.classList.add("error"); |
415 } | 434 } |
416 else if (subscription.lastDownload > 0) | 435 else if (subscription.lastDownload > 0) |
417 { | 436 { |
418 var timeDate = i18n_timeDateStrings(subscription.lastDownload * 1000); | 437 var timeDate = i18n_timeDateStrings(subscription.lastDownload * 1000); |
419 var messageID = (timeDate[1] ? "last_updated_at" : "last_updated_at_today"); | 438 var messageID = (timeDate[1] ? "last_updated_at" : "last_updated_at_today"); |
420 lastUpdate.textContent = i18n.getMessage(messageID, timeDate); | 439 lastUpdate.textContent = i18n.getMessage(messageID, timeDate); |
421 } | 440 } |
422 } | 441 } |
423 | 442 |
424 function onFilterChange(action, item, param1, param2) | 443 function onSubscriptionChange(subscription) |
425 { | 444 { |
426 switch (action) | 445 var element = findSubscriptionElement(subscription); |
| 446 if (element) |
| 447 updateSubscriptionInfo(element); |
| 448 } |
| 449 |
| 450 function onSubscriptionAdded(subscription) |
| 451 { |
| 452 if (subscription instanceof SpecialSubscription) |
427 { | 453 { |
428 case "load": | 454 for (var i = 0; i < subscription.filters.length; i++) |
429 reloadFilters(); | 455 onFilterChange("filter.added", subscription.filters[i]); |
430 break; | 456 } |
431 case "subscription.title": | 457 else if (subscription.url == Prefs.subscriptions_exceptionsurl) |
432 case "subscription.disabled": | 458 $("#acceptableAds").prop("checked", true); |
433 case "subscription.homepage": | 459 else if (!findSubscriptionElement(subscription)) |
434 case "subscription.lastDownload": | 460 addSubscriptionEntry(subscription); |
435 case "subscription.downloadStatus": | 461 } |
436 var element = findSubscriptionElement(item); | 462 |
437 if (element) | 463 function onSubscriptionRemoved(subscription) |
438 updateSubscriptionInfo(element); | 464 { |
439 break; | 465 if (subscription instanceof SpecialSubscription) |
440 case "subscription.added": | 466 { |
441 if (item instanceof SpecialSubscription) | 467 for (var i = 0; i < subscription.filters.length; i++) |
442 { | 468 onFilterChange("filter.removed", subscription.filters[i]); |
443 for (var i = 0; i < item.filters.length; i++) | 469 } |
444 onFilterChange("filter.added", item.filters[i]); | 470 else if (subscription.url == Prefs.subscriptions_exceptionsurl) |
445 } | 471 $("#acceptableAds").prop("checked", false); |
446 else if (item.url == Prefs.subscriptions_exceptionsurl) | 472 else |
447 $("#acceptableAds").prop("checked", true); | 473 { |
448 else if (!findSubscriptionElement(item)) | 474 var element = findSubscriptionElement(subscription); |
449 addSubscriptionEntry(item); | 475 if (element) |
450 break; | 476 element.parentNode.removeChild(element); |
451 case "subscription.removed": | |
452 if (item instanceof SpecialSubscription) | |
453 { | |
454 for (var i = 0; i < item.filters.length; i++) | |
455 onFilterChange("filter.removed", item.filters[i]); | |
456 } | |
457 else if (item.url == Prefs.subscriptions_exceptionsurl) | |
458 $("#acceptableAds").prop("checked", false); | |
459 else | |
460 { | |
461 var element = findSubscriptionElement(item); | |
462 if (element) | |
463 element.parentNode.removeChild(element); | |
464 } | |
465 break; | |
466 case "filter.added": | |
467 if (item instanceof WhitelistFilter && /^@@\|\|([^\/:]+)\^\$document$/.tes
t(item.text)) | |
468 appendToListBox("excludedDomainsBox", RegExp.$1); | |
469 else | |
470 appendToListBox("userFiltersBox", item.text); | |
471 break; | |
472 case "filter.removed": | |
473 if (item instanceof WhitelistFilter && /^@@\|\|([^\/:]+)\^\$document$/.tes
t(item.text)) | |
474 removeFromListBox("excludedDomainsBox", RegExp.$1); | |
475 else | |
476 removeFromListBox("userFiltersBox", item.text); | |
477 break; | |
478 } | 477 } |
479 } | 478 } |
480 | 479 |
| 480 function onFilterAdded(filter) |
| 481 { |
| 482 if (filter instanceof WhitelistFilter && |
| 483 /^@@\|\|([^\/:]+)\^\$document$/.test(filter.text)) |
| 484 appendToListBox("excludedDomainsBox", RegExp.$1); |
| 485 else |
| 486 appendToListBox("userFiltersBox", filter.text); |
| 487 } |
| 488 |
| 489 function onFilterRemoved(filter) |
| 490 { |
| 491 if (filter instanceof WhitelistFilter && |
| 492 /^@@\|\|([^\/:]+)\^\$document$/.test(filter.text)) |
| 493 removeFromListBox("excludedDomainsBox", RegExp.$1); |
| 494 else |
| 495 removeFromListBox("userFiltersBox", filter.text); |
| 496 } |
| 497 |
481 // Populates a list box with a number of entries | 498 // Populates a list box with a number of entries |
482 function populateList(id, entries) | 499 function populateList(id, entries) |
483 { | 500 { |
484 var list = document.getElementById(id); | 501 var list = document.getElementById(id); |
485 while (list.lastChild) | 502 while (list.lastChild) |
486 list.removeChild(list.lastChild); | 503 list.removeChild(list.lastChild); |
487 | 504 |
488 entries.sort(); | 505 entries.sort(); |
489 for (var i = 0; i < entries.length; i++) | 506 for (var i = 0; i < entries.length; i++) |
490 { | 507 { |
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
703 links[i].href = arguments[i + 1]; | 720 links[i].href = arguments[i + 1]; |
704 links[i].setAttribute("target", "_blank"); | 721 links[i].setAttribute("target", "_blank"); |
705 } | 722 } |
706 else if (typeof arguments[i + 1] == "function") | 723 else if (typeof arguments[i + 1] == "function") |
707 { | 724 { |
708 links[i].href = "javascript:void(0);"; | 725 links[i].href = "javascript:void(0);"; |
709 links[i].addEventListener("click", arguments[i + 1], false); | 726 links[i].addEventListener("click", arguments[i + 1], false); |
710 } | 727 } |
711 } | 728 } |
712 } | 729 } |
OLD | NEW |