| Left: | ||
| Right: |
| LEFT | RIGHT |
|---|---|
| 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 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 75 var importRawFilters = wrapper({type: "filters.importRaw"}, | 75 var importRawFilters = wrapper({type: "filters.importRaw"}, |
| 76 "text", "removeExisting"); | 76 "text", "removeExisting"); |
| 77 var addFilter = wrapper({type: "filters.add"}, "text"); | 77 var addFilter = wrapper({type: "filters.add"}, "text"); |
| 78 var getFilters = wrapper({type: "filters.get"}, "subscriptionUrl"); | 78 var getFilters = wrapper({type: "filters.get"}, "subscriptionUrl"); |
| 79 var removeFilter = wrapper({type: "filters.remove"}, "text"); | 79 var removeFilter = wrapper({type: "filters.remove"}, "text"); |
| 80 | 80 |
| 81 var i18n = ext.i18n; | 81 var i18n = ext.i18n; |
| 82 var whitelistedDomainRegexp = /^@@\|\|([^\/:]+)\^\$document$/; | 82 var whitelistedDomainRegexp = /^@@\|\|([^\/:]+)\^\$document$/; |
| 83 var delayedSubscriptionSelection = null; | 83 var delayedSubscriptionSelection = null; |
| 84 | 84 |
| 85 var acceptableAdsUrl; | |
| 86 | |
| 85 // Loads options and sets UI elements accordingly | 87 // Loads options and sets UI elements accordingly |
| 86 function loadOptions() | 88 function loadOptions() |
| 87 { | 89 { |
| 88 // Set page title to i18n version of "Adblock Plus Options" | 90 // Set page title to i18n version of "Adblock Plus Options" |
| 89 document.title = i18n.getMessage("options"); | 91 document.title = i18n.getMessage("options"); |
| 90 | 92 |
| 91 // Set links | 93 // Set links |
| 92 getPref("subscriptions_exceptionsurl", function(url) | 94 getPref("subscriptions_exceptionsurl", function(url) |
| 93 { | 95 { |
| 94 $("#acceptableAdsLink").attr("href", url); | 96 acceptableAdsUrl = url; |
| 97 $("#acceptableAdsLink").attr("href", acceptableAdsUrl); | |
| 95 }); | 98 }); |
| 96 getDocLink("acceptable_ads", function(url) | 99 getDocLink("acceptable_ads", function(url) |
| 97 { | 100 { |
| 98 $("#acceptableAdsDocs").attr("href", url); | 101 $("#acceptableAdsDocs").attr("href", url); |
| 99 }); | 102 }); |
| 100 getDocLink("filterdoc", function(url) | 103 getDocLink("filterdoc", function(url) |
| 101 { | 104 { |
| 102 setLinks("filter-must-follow-syntax", url); | 105 setLinks("filter-must-follow-syntax", url); |
| 103 }); | 106 }); |
| 104 getInfo("application", function(application) | 107 getInfo("application", function(application) |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 153 }); | 156 }); |
| 154 getPref("notifications_showui", function(notifications_showui) | 157 getPref("notifications_showui", function(notifications_showui) |
| 155 { | 158 { |
| 156 if (!notifications_showui) | 159 if (!notifications_showui) |
| 157 document.getElementById("shouldShowNotificationsContainer").hidden = true; | 160 document.getElementById("shouldShowNotificationsContainer").hidden = true; |
| 158 }); | 161 }); |
| 159 | 162 |
| 160 // Register listeners in the background message responder | 163 // Register listeners in the background message responder |
| 161 ext.backgroundPage.sendMessage({ | 164 ext.backgroundPage.sendMessage({ |
| 162 type: "app.listen", | 165 type: "app.listen", |
| 163 filter: ["addSubscription", "switchToOptionsSection"] | 166 filter: ["addSubscription", "focusSection"] |
| 164 }); | 167 }); |
| 165 ext.backgroundPage.sendMessage( | 168 ext.backgroundPage.sendMessage( |
| 166 { | 169 { |
| 167 type: "filters.listen", | 170 type: "filters.listen", |
| 168 filter: ["added", "loaded", "removed"] | 171 filter: ["added", "loaded", "removed"] |
| 169 }); | 172 }); |
| 170 ext.backgroundPage.sendMessage( | 173 ext.backgroundPage.sendMessage( |
| 171 { | 174 { |
| 172 type: "prefs.listen", | 175 type: "prefs.listen", |
| 173 filter: ["notifications_ignoredcategories", "notifications_showui", | 176 filter: ["notifications_ignoredcategories", "notifications_showui", |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 190 $(loadOptions); | 193 $(loadOptions); |
| 191 | 194 |
| 192 // Reloads the displayed subscriptions and filters | 195 // Reloads the displayed subscriptions and filters |
| 193 function reloadFilters() | 196 function reloadFilters() |
| 194 { | 197 { |
| 195 // Load user filter URLs | 198 // Load user filter URLs |
| 196 var container = document.getElementById("filterLists"); | 199 var container = document.getElementById("filterLists"); |
| 197 while (container.lastChild) | 200 while (container.lastChild) |
| 198 container.removeChild(container.lastChild); | 201 container.removeChild(container.lastChild); |
| 199 | 202 |
| 200 getPref("subscriptions_exceptionsurl", function(acceptableAdsUrl) | 203 getSubscriptions(true, false, function(subscriptions) |
| 201 { | 204 { |
| 202 getSubscriptions(true, false, function(subscriptions) | 205 for (var i = 0; i < subscriptions.length; i++) |
| 203 { | 206 { |
| 204 for (var i = 0; i < subscriptions.length; i++) | 207 var subscription = subscriptions[i]; |
| 205 { | 208 if (subscription.url == acceptableAdsUrl) |
| 206 var subscription = subscriptions[i]; | 209 $("#acceptableAds").prop("checked", !subscription.disabled); |
| 207 if (subscription.url == acceptableAdsUrl) | 210 else |
| 208 $("#acceptableAds").prop("checked", !subscription.disabled); | 211 addSubscriptionEntry(subscription); |
| 209 else | 212 } |
| 210 addSubscriptionEntry(subscription); | |
| 211 } | |
| 212 }); | |
| 213 }); | 213 }); |
| 214 | 214 |
| 215 // User-entered filters | 215 // User-entered filters |
| 216 getSubscriptions(false, true, function(subscriptions) | 216 getSubscriptions(false, true, function(subscriptions) |
| 217 { | 217 { |
| 218 clearListBox("userFiltersBox"); | 218 clearListBox("userFiltersBox"); |
| 219 clearListBox("excludedDomainsBox"); | 219 clearListBox("excludedDomainsBox"); |
| 220 | 220 |
| 221 for (var i = 0; i < subscriptions.length; i++) | 221 for (var i = 0; i < subscriptions.length; i++) |
| 222 getFilters(subscriptions[i].url, function(filters) | 222 getFilters(subscriptions[i].url, function(filters) |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 385 addSubscription(url, title, null); | 385 addSubscription(url, title, null); |
| 386 } | 386 } |
| 387 | 387 |
| 388 $("#addSubscriptionContainer").hide(); | 388 $("#addSubscriptionContainer").hide(); |
| 389 $("#customSubscriptionContainer").hide(); | 389 $("#customSubscriptionContainer").hide(); |
| 390 $("#addSubscriptionButton").show(); | 390 $("#addSubscriptionButton").show(); |
| 391 } | 391 } |
| 392 | 392 |
| 393 function toggleAcceptableAds() | 393 function toggleAcceptableAds() |
| 394 { | 394 { |
| 395 getPref("subscriptions_exceptionsurl", function(url) | 395 toggleSubscription(acceptableAdsUrl, true); |
| 396 { | |
| 397 toggleSubscription(url, true); | |
| 398 }); | |
| 399 } | 396 } |
| 400 | 397 |
| 401 function findSubscriptionElement(subscription) | 398 function findSubscriptionElement(subscription) |
| 402 { | 399 { |
| 403 var children = document.getElementById("filterLists").childNodes; | 400 var children = document.getElementById("filterLists").childNodes; |
| 404 for (var i = 0; i < children.length; i++) | 401 for (var i = 0; i < children.length; i++) |
| 405 if (children[i]._subscription.url == subscription.url) | 402 if (children[i]._subscription.url == subscription.url) |
| 406 return children[i]; | 403 return children[i]; |
| 407 return null; | 404 return null; |
| 408 } | 405 } |
| 409 | 406 |
| 410 function updateSubscriptionInfo(element, subscription, downloading) | 407 function updateSubscriptionInfo(element, subscription) |
| 411 { | 408 { |
| 412 if (subscription) | 409 if (subscription) |
| 413 element._subscription = subscription; | 410 element._subscription = subscription; |
| 414 else | 411 else |
| 415 subscription = element._subscription; | 412 subscription = element._subscription; |
| 416 | 413 |
| 417 var title = element.getElementsByClassName("subscriptionTitle")[0]; | 414 var title = element.getElementsByClassName("subscriptionTitle")[0]; |
| 418 title.textContent = subscription.title; | 415 title.textContent = subscription.title; |
| 419 title.setAttribute("title", subscription.url); | 416 title.setAttribute("title", subscription.url); |
| 420 if (subscription.homepage) | 417 if (subscription.homepage) |
| 421 title.href = subscription.homepage; | 418 title.href = subscription.homepage; |
| 422 else | 419 else |
| 423 title.href = subscription.url; | 420 title.href = subscription.url; |
| 424 | 421 |
| 425 var enabled = element.getElementsByClassName("subscriptionEnabled")[0]; | 422 var enabled = element.getElementsByClassName("subscriptionEnabled")[0]; |
| 426 enabled.checked = !subscription.disabled; | 423 enabled.checked = !subscription.disabled; |
| 427 | 424 |
| 428 var lastUpdate = element.getElementsByClassName("subscriptionUpdate")[0]; | 425 var lastUpdate = element.getElementsByClassName("subscriptionUpdate")[0]; |
| 429 lastUpdate.classList.remove("error"); | 426 lastUpdate.classList.remove("error"); |
| 430 | 427 |
| 431 var downloadStatus = subscription.downloadStatus; | 428 var downloadStatus = subscription.downloadStatus; |
| 432 if (downloading) | 429 if (subscription.isDownloading) |
| 433 { | 430 { |
| 434 lastUpdate.textContent = i18n.getMessage("filters_subscription_lastDownload_ inProgress"); | 431 lastUpdate.textContent = i18n.getMessage("filters_subscription_lastDownload_ inProgress"); |
| 435 } | 432 } |
| 436 else if (downloadStatus && downloadStatus != "synchronize_ok") | 433 else if (downloadStatus && downloadStatus != "synchronize_ok") |
| 437 { | 434 { |
| 438 var map = | 435 var map = |
| 439 { | 436 { |
| 440 "synchronize_invalid_url": "filters_subscription_lastDownload_invalidURL" , | 437 "synchronize_invalid_url": "filters_subscription_lastDownload_invalidURL" , |
| 441 "synchronize_connection_error": "filters_subscription_lastDownload_connec tionError", | 438 "synchronize_connection_error": "filters_subscription_lastDownload_connec tionError", |
| 442 "synchronize_invalid_data": "filters_subscription_lastDownload_invalidDat a", | 439 "synchronize_invalid_data": "filters_subscription_lastDownload_invalidDat a", |
| 443 "synchronize_checksum_mismatch": "filters_subscription_lastDownload_check sumMismatch" | 440 "synchronize_checksum_mismatch": "filters_subscription_lastDownload_check sumMismatch" |
| 444 }; | 441 }; |
| 445 if (downloadStatus in map) | 442 if (downloadStatus in map) |
| 446 lastUpdate.textContent = i18n.getMessage(map[downloadStatus]); | 443 lastUpdate.textContent = i18n.getMessage(map[downloadStatus]); |
| 447 else | 444 else |
| 448 lastUpdate.textContent = downloadStatus; | 445 lastUpdate.textContent = downloadStatus; |
| 449 lastUpdate.classList.add("error"); | 446 lastUpdate.classList.add("error"); |
| 450 } | 447 } |
| 451 else if (subscription.lastDownload > 0) | 448 else if (subscription.lastDownload > 0) |
| 452 { | 449 { |
| 453 var timeDate = i18n_timeDateStrings(subscription.lastDownload * 1000); | 450 var timeDate = i18n_timeDateStrings(subscription.lastDownload * 1000); |
| 454 var messageID = (timeDate[1] ? "last_updated_at" : "last_updated_at_today"); | 451 var messageID = (timeDate[1] ? "last_updated_at" : "last_updated_at_today"); |
| 455 lastUpdate.textContent = i18n.getMessage(messageID, timeDate); | 452 lastUpdate.textContent = i18n.getMessage(messageID, timeDate); |
| 456 } | 453 } |
| 457 } | 454 } |
| 458 | 455 |
| 459 function onSubscriptionMessage(action, subscription) | 456 function onSubscriptionMessage(action, subscription) |
| 460 { | 457 { |
| 461 var element = findSubscriptionElement(subscription); | 458 var element = findSubscriptionElement(subscription); |
| 462 var downloading = false; | |
| 463 | 459 |
| 464 switch (action) | 460 switch (action) |
| 465 { | 461 { |
| 462 case "disabled": | |
| 466 case "downloading": | 463 case "downloading": |
| 467 downloading = true; | 464 case "downloadStatus": |
|
Sebastian Noack
2016/04/06 08:50:17
What if the subscription is already/still download
kzar
2016/04/06 09:33:20
Done.
| |
| 468 case "title": | |
| 469 case "disabled": | |
| 470 case "homepage": | 465 case "homepage": |
| 471 case "lastDownload": | 466 case "lastDownload": |
| 472 case "downloadStatus": | 467 case "title": |
| 473 if (element) | 468 if (element) |
| 474 updateSubscriptionInfo(element, subscription, downloading); | 469 updateSubscriptionInfo(element, subscription); |
| 475 break; | 470 break; |
| 476 case "added": | 471 case "added": |
| 477 getPref("subscriptions_exceptionsurl", function(acceptableAdsUrl) | 472 if (subscription.url == acceptableAdsUrl) |
| 478 { | 473 $("#acceptableAds").prop("checked", true); |
| 479 if (subscription.url == acceptableAdsUrl) | 474 else if (!element) |
| 480 $("#acceptableAds").prop("checked", true); | 475 addSubscriptionEntry(subscription); |
| 481 else if (!element) | |
| 482 addSubscriptionEntry(subscription); | |
| 483 }); | |
| 484 break; | 476 break; |
| 485 case "removed": | 477 case "removed": |
| 486 getPref("subscriptions_exceptionsurl", function(acceptableAdsUrl) | 478 if (subscription.url == acceptableAdsUrl) |
| 487 { | 479 $("#acceptableAds").prop("checked", false); |
| 488 if (subscription.url == acceptableAdsUrl) | 480 else if (element) |
| 489 $("#acceptableAds").prop("checked", false); | 481 element.parentNode.removeChild(element); |
| 490 else if (element) | |
| 491 element.parentNode.removeChild(element); | |
| 492 }); | |
| 493 break; | 482 break; |
| 494 } | 483 } |
| 495 } | 484 } |
| 496 | 485 |
| 497 function onPrefMessage(key, value) | 486 function onPrefMessage(key, value) |
| 498 { | 487 { |
| 499 switch (key) | 488 switch (key) |
| 500 { | 489 { |
| 501 case "notifications_showui": | 490 case "notifications_showui": |
| 502 document.getElementById("shouldShowNotificationsContainer").hidden = !valu e; | 491 document.getElementById("shouldShowNotificationsContainer").hidden = !valu e; |
| (...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 720 { | 709 { |
| 721 switch (message.type) | 710 switch (message.type) |
| 722 { | 711 { |
| 723 case "app.respond": | 712 case "app.respond": |
| 724 switch (message.action) | 713 switch (message.action) |
| 725 { | 714 { |
| 726 case "addSubscription": | 715 case "addSubscription": |
| 727 var subscription = message.args[0]; | 716 var subscription = message.args[0]; |
| 728 startSubscriptionSelection(subscription.title, subscription.url); | 717 startSubscriptionSelection(subscription.title, subscription.url); |
| 729 break; | 718 break; |
| 730 case "switchToOptionsSection": | 719 case "focusSection": |
| 731 var tabs = document.getElementsByClassName("ui-tabs-panel"); | 720 var tabs = document.getElementsByClassName("ui-tabs-panel"); |
| 732 for (var i = 0; i < tabs.length; i++) | 721 for (var i = 0; i < tabs.length; i++) |
| 733 { | 722 { |
| 734 var found = tabs[i].querySelector( | 723 var found = tabs[i].querySelector( |
| 735 "[data-section='" + message.args[0] + "']" | 724 "[data-section='" + message.args[0] + "']" |
| 736 ); | 725 ); |
| 737 if (!found) | 726 if (!found) |
| 738 continue; | 727 continue; |
| 739 | 728 |
| 740 var previous = document.getElementsByClassName("focused"); | 729 var previous = document.getElementsByClassName("focused"); |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 752 onFilterMessage(message.action, message.args[0]); | 741 onFilterMessage(message.action, message.args[0]); |
| 753 break; | 742 break; |
| 754 case "prefs.respond": | 743 case "prefs.respond": |
| 755 onPrefMessage(message.action, message.args[0]); | 744 onPrefMessage(message.action, message.args[0]); |
| 756 break; | 745 break; |
| 757 case "subscriptions.respond": | 746 case "subscriptions.respond": |
| 758 onSubscriptionMessage(message.action, message.args[0]); | 747 onSubscriptionMessage(message.action, message.args[0]); |
| 759 break; | 748 break; |
| 760 } | 749 } |
| 761 }); | 750 }); |
| LEFT | RIGHT |