| Left: | ||
| Right: |
| 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 |
| 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 * GNU General Public License for more details. | 12 * GNU General Public License for more details. |
| 13 * | 13 * |
| 14 * You should have received a copy of the GNU General Public License | 14 * You should have received a copy of the GNU General Public License |
| 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. | 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
| 16 */ | 16 */ |
| 17 | 17 |
| 18 /* global $, i18n, i18n_timeDateStrings */ | |
| 19 | |
| 18 "use strict"; | 20 "use strict"; |
| 19 | 21 |
| 20 /** | 22 /** |
| 21 * Creates a wrapping function used to conveniently send a type of message. | 23 * Creates a wrapping function used to conveniently send a type of message. |
| 22 * | 24 * |
| 23 * @param {Object} baseMessage The part of the message that's always sent | 25 * @param {Object} baseMessage The part of the message that's always sent |
| 24 * @param {..string} paramKeys Any message keys that have dynamic values. The | 26 * @param {...string} paramKeys Any message keys that have dynamic values. The |
| 25 * returned function will take the corresponding | 27 * returned function will take the corresponding |
| 26 * values as arguments. | 28 * values as arguments. |
| 27 * @return The generated messaging function, optionally taking any values as | 29 * @return {function} The generated messaging function, optionally |
| 28 * specified by the paramKeys and finally an optional callback. | 30 * taking any values as specified by the paramKeys |
| 29 * (Although the value arguments are optional their index must be | 31 * and finally an optional callback. (Although the |
| 30 * maintained. E.g. if you omit the first value you must omit the | 32 * value arguments are optional their index must be |
| 31 * second too.) | 33 * maintained. E.g. if you omit the first value you |
| 34 * must omit the second too.) | |
| 32 */ | 35 */ |
| 33 function wrapper(baseMessage /* , [paramKeys] */) | 36 function wrapper(baseMessage, ...paramKeys) |
|
Sebastian Noack
2017/02/09 01:04:51
How about calling the rest arguments just "args" a
kzar
2017/02/20 10:27:33
Since paramKeys is a more useful name. (I used `ar
| |
| 34 { | 37 { |
| 35 let paramKeys = []; | 38 return function(...paramValues /* , callback */) |
| 36 for (let i = 1; i < arguments.length; i++) | |
| 37 paramKeys.push(arguments[i]); | |
| 38 | |
| 39 return function(/* [paramValues], callback */) | |
| 40 { | 39 { |
| 41 let message = Object.create(null); | 40 let message = Object.create(null); |
| 42 for (let key in baseMessage) | 41 for (let key in baseMessage) |
| 42 { | |
| 43 if (baseMessage.hasOwnProperty(key)) | 43 if (baseMessage.hasOwnProperty(key)) |
| 44 message[key] = baseMessage[key]; | 44 message[key] = baseMessage[key]; |
| 45 } | |
| 45 | 46 |
| 46 let paramValues = []; | |
| 47 let callback; | 47 let callback; |
| 48 | 48 |
| 49 if (arguments.length > 0) | 49 if (paramValues.length > 0) |
| 50 { | 50 { |
| 51 let lastArg = arguments[arguments.length - 1]; | 51 let lastArg = paramValues[paramValues.length - 1]; |
| 52 if (typeof lastArg == "function") | 52 if (typeof lastArg == "function") |
| 53 callback = lastArg; | 53 callback = lastArg; |
| 54 | 54 |
| 55 for (let i = 0; i < arguments.length - (callback ? 1 : 0); i++) | 55 for (let i = 0; i < paramValues.length - (callback ? 1 : 0); i++) |
| 56 message[paramKeys[i]] = arguments[i]; | 56 message[paramKeys[i]] = paramValues[i]; |
| 57 } | 57 } |
| 58 | 58 |
| 59 ext.backgroundPage.sendMessage(message, callback); | 59 ext.backgroundPage.sendMessage(message, callback); |
| 60 }; | 60 }; |
| 61 } | 61 } |
| 62 | 62 |
| 63 const getDocLink = wrapper({type: "app.get", what: "doclink"}, "link"); | 63 const getDocLink = wrapper({type: "app.get", what: "doclink"}, "link"); |
| 64 const getInfo = wrapper({type: "app.get"}, "what"); | 64 const getInfo = wrapper({type: "app.get"}, "what"); |
| 65 const getPref = wrapper({type: "prefs.get"}, "key"); | 65 const getPref = wrapper({type: "prefs.get"}, "key"); |
| 66 const togglePref = wrapper({type: "prefs.toggle"}, "key"); | 66 const togglePref = wrapper({type: "prefs.toggle"}, "key"); |
| 67 const getSubscriptions = wrapper({type: "subscriptions.get"}, | 67 const getSubscriptions = wrapper({type: "subscriptions.get"}, |
| 68 "downloadable", "special"); | 68 "downloadable", "special"); |
| 69 const removeSubscription = wrapper({type: "subscriptions.remove"}, "url"); | 69 const removeSubscription = wrapper({type: "subscriptions.remove"}, "url"); |
| 70 const addSubscription = wrapper({type: "subscriptions.add"}, | 70 const addSubscription = wrapper({type: "subscriptions.add"}, |
| 71 "url", "title", "homepage"); | 71 "url", "title", "homepage"); |
| 72 const toggleSubscription = wrapper({type: "subscriptions.toggle"}, | 72 const toggleSubscription = wrapper({type: "subscriptions.toggle"}, |
| 73 "url", "keepInstalled"); | 73 "url", "keepInstalled"); |
| 74 const updateSubscription = wrapper({type: "subscriptions.update"}, "url"); | 74 const updateSubscription = wrapper({type: "subscriptions.update"}, "url"); |
| 75 const importRawFilters = wrapper({type: "filters.importRaw"}, | 75 const importRawFilters = wrapper({type: "filters.importRaw"}, |
| 76 "text", "removeExisting"); | 76 "text", "removeExisting"); |
| 77 const addFilter = wrapper({type: "filters.add"}, "text"); | 77 const addFilter = wrapper({type: "filters.add"}, "text"); |
| 78 const getFilters = wrapper({type: "filters.get"}, "subscriptionUrl"); | 78 const getFilters = wrapper({type: "filters.get"}, "subscriptionUrl"); |
| 79 const removeFilter = wrapper({type: "filters.remove"}, "text"); | 79 const removeFilter = wrapper({type: "filters.remove"}, "text"); |
| 80 | 80 |
| 81 const whitelistedDomainRegexp = /^@@\|\|([^\/:]+)\^\$document$/; | 81 const whitelistedDomainRegexp = /^@@\|\|([^/:]+)\^\$document$/; |
| 82 const statusMessages = new Map([ | |
| 83 ["synchronize_invalid_url", | |
| 84 "filters_subscription_lastDownload_invalidURL"], | |
| 85 ["synchronize_connection_error", | |
| 86 "filters_subscription_lastDownload_connectionError"], | |
| 87 ["synchronize_invalid_data", | |
| 88 "filters_subscription_lastDownload_invalidData"], | |
| 89 ["synchronize_checksum_mismatch", | |
| 90 "filters_subscription_lastDownload_checksumMismatch"] | |
| 91 ]); | |
| 92 | |
| 82 let delayedSubscriptionSelection = null; | 93 let delayedSubscriptionSelection = null; |
| 83 | |
| 84 let acceptableAdsUrl; | 94 let acceptableAdsUrl; |
| 85 | 95 |
| 86 // Loads options from localStorage and sets UI elements accordingly | 96 // Loads options from localStorage and sets UI elements accordingly |
| 87 function loadOptions() | 97 function loadOptions() |
| 88 { | 98 { |
| 89 // Set page title to i18n version of "Adblock Plus Options" | 99 // Set page title to i18n version of "Adblock Plus Options" |
| 90 document.title = i18n.getMessage("options"); | 100 document.title = i18n.getMessage("options"); |
| 91 | 101 |
| 92 // Set links | 102 // Set links |
| 93 getPref("subscriptions_exceptionsurl", url => | 103 getPref("subscriptions_exceptionsurl", url => |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 140 // Popuplate option checkboxes | 150 // Popuplate option checkboxes |
| 141 initCheckbox("shouldShowBlockElementMenu"); | 151 initCheckbox("shouldShowBlockElementMenu"); |
| 142 initCheckbox("show_devtools_panel"); | 152 initCheckbox("show_devtools_panel"); |
| 143 initCheckbox("shouldShowNotifications", "notifications_ignoredcategories"); | 153 initCheckbox("shouldShowNotifications", "notifications_ignoredcategories"); |
| 144 | 154 |
| 145 getInfo("features", features => | 155 getInfo("features", features => |
| 146 { | 156 { |
| 147 if (!features.devToolsPanel) | 157 if (!features.devToolsPanel) |
| 148 document.getElementById("showDevtoolsPanelContainer").hidden = true; | 158 document.getElementById("showDevtoolsPanelContainer").hidden = true; |
| 149 }); | 159 }); |
| 150 getPref("notifications_showui", notifications_showui => | 160 getPref("notifications_showui", showNotificationsUI => |
| 151 { | 161 { |
| 152 if (!notifications_showui) | 162 if (!showNotificationsUI) |
| 153 document.getElementById("shouldShowNotificationsContainer").hidden = true; | 163 document.getElementById("shouldShowNotificationsContainer").hidden = true; |
| 154 }); | 164 }); |
| 155 | 165 |
| 156 // Register listeners in the background message responder | 166 // Register listeners in the background message responder |
| 157 ext.backgroundPage.sendMessage({ | 167 ext.backgroundPage.sendMessage({ |
| 158 type: "app.listen", | 168 type: "app.listen", |
| 159 filter: ["addSubscription", "focusSection"] | 169 filter: ["addSubscription", "focusSection"] |
| 160 }); | 170 }); |
| 161 ext.backgroundPage.sendMessage( | 171 ext.backgroundPage.sendMessage({ |
| 162 { | |
| 163 type: "filters.listen", | 172 type: "filters.listen", |
| 164 filter: ["added", "loaded", "removed"] | 173 filter: ["added", "loaded", "removed"] |
| 165 }); | 174 }); |
| 166 ext.backgroundPage.sendMessage( | 175 ext.backgroundPage.sendMessage({ |
| 167 { | |
| 168 type: "prefs.listen", | 176 type: "prefs.listen", |
| 169 filter: ["notifications_ignoredcategories", "notifications_showui", | 177 filter: ["notifications_ignoredcategories", "notifications_showui", |
| 170 "show_devtools_panel", "shouldShowBlockElementMenu"] | 178 "show_devtools_panel", "shouldShowBlockElementMenu"] |
| 171 }); | 179 }); |
| 172 ext.backgroundPage.sendMessage( | 180 ext.backgroundPage.sendMessage({ |
| 173 { | |
| 174 type: "subscriptions.listen", | 181 type: "subscriptions.listen", |
| 175 filter: ["added", "disabled", "homepage", "lastDownload", "removed", | 182 filter: ["added", "disabled", "homepage", "lastDownload", "removed", |
| 176 "title", "downloadStatus", "downloading"] | 183 "title", "downloadStatus", "downloading"] |
| 177 }); | 184 }); |
| 178 | 185 |
| 179 // Load recommended subscriptions | 186 // Load recommended subscriptions |
| 180 loadRecommendations(); | 187 loadRecommendations(); |
| 181 | 188 |
| 182 // Show user's filters | 189 // Show user's filters |
| 183 reloadFilters(); | 190 reloadFilters(); |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 306 | 313 |
| 307 let option = new Option(); | 314 let option = new Option(); |
| 308 let label = i18n.getMessage("filters_addSubscriptionOther_label"); | 315 let label = i18n.getMessage("filters_addSubscriptionOther_label"); |
| 309 option.text = label + "\u2026"; | 316 option.text = label + "\u2026"; |
| 310 option._data = null; | 317 option._data = null; |
| 311 list.appendChild(option); | 318 list.appendChild(option); |
| 312 | 319 |
| 313 list.selectedIndex = selectedIndex; | 320 list.selectedIndex = selectedIndex; |
| 314 | 321 |
| 315 if (delayedSubscriptionSelection) | 322 if (delayedSubscriptionSelection) |
| 316 startSubscriptionSelection.apply(null, delayedSubscriptionSelection); | 323 startSubscriptionSelection(...delayedSubscriptionSelection); |
| 317 }); | 324 }); |
| 318 } | 325 } |
| 319 | 326 |
| 320 function startSubscriptionSelection(title, url) | 327 function startSubscriptionSelection(title, url) |
| 321 { | 328 { |
| 322 let list = document.getElementById("subscriptionSelector"); | 329 let list = document.getElementById("subscriptionSelector"); |
| 323 if (list.length == 0) | 330 if (list.length == 0) |
| 324 { | 331 { |
| 325 delayedSubscriptionSelection = [title, url]; | 332 delayedSubscriptionSelection = [title, url]; |
| 326 return; | 333 return; |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 338 } | 345 } |
| 339 updateSubscriptionSelection(); | 346 updateSubscriptionSelection(); |
| 340 document.getElementById("addSubscriptionContainer").scrollIntoView(true); | 347 document.getElementById("addSubscriptionContainer").scrollIntoView(true); |
| 341 } | 348 } |
| 342 | 349 |
| 343 function updateSubscriptionSelection() | 350 function updateSubscriptionSelection() |
| 344 { | 351 { |
| 345 let list = document.getElementById("subscriptionSelector"); | 352 let list = document.getElementById("subscriptionSelector"); |
| 346 let data = list.options[list.selectedIndex]._data; | 353 let data = list.options[list.selectedIndex]._data; |
| 347 if (data) | 354 if (data) |
| 355 { | |
| 348 $("#customSubscriptionContainer").hide(); | 356 $("#customSubscriptionContainer").hide(); |
| 357 } | |
| 349 else | 358 else |
| 350 { | 359 { |
| 351 $("#customSubscriptionContainer").show(); | 360 $("#customSubscriptionContainer").show(); |
| 352 $("#customSubscriptionTitle").focus(); | 361 $("#customSubscriptionTitle").focus(); |
| 353 } | 362 } |
| 354 } | 363 } |
| 355 | 364 |
| 356 function addSubscriptionClicked() | 365 function addSubscriptionClicked() |
| 357 { | 366 { |
| 358 let list = document.getElementById("subscriptionSelector"); | 367 let list = document.getElementById("subscriptionSelector"); |
| 359 let data = list.options[list.selectedIndex]._data; | 368 let data = list.options[list.selectedIndex]._data; |
| 360 if (data) | 369 if (data) |
| 370 { | |
| 361 addSubscription(data.url, data.title, data.homepage); | 371 addSubscription(data.url, data.title, data.homepage); |
| 372 } | |
| 362 else | 373 else |
| 363 { | 374 { |
| 364 let url = document.getElementById("customSubscriptionLocation").value.trim() ; | 375 let url = document.getElementById("customSubscriptionLocation") |
| 376 .value.trim(); | |
| 365 if (!/^https?:/i.test(url)) | 377 if (!/^https?:/i.test(url)) |
| 366 { | 378 { |
| 367 alert(i18n.getMessage("global_subscription_invalid_location")); | 379 alert(i18n.getMessage("global_subscription_invalid_location")); |
| 368 $("#customSubscriptionLocation").focus(); | 380 $("#customSubscriptionLocation").focus(); |
| 369 return; | 381 return; |
| 370 } | 382 } |
| 371 | 383 |
| 372 let title = document.getElementById("customSubscriptionTitle").value.trim(); | 384 let title = document.getElementById("customSubscriptionTitle").value.trim(); |
| 373 if (!title) | 385 if (!title) |
| 374 title = url; | 386 title = url; |
| 375 | 387 |
| 376 addSubscription(url, title, null); | 388 addSubscription(url, title, null); |
| 377 } | 389 } |
| 378 | 390 |
| 379 $("#addSubscriptionContainer").hide(); | 391 $("#addSubscriptionContainer").hide(); |
| 380 $("#customSubscriptionContainer").hide(); | 392 $("#customSubscriptionContainer").hide(); |
| 381 $("#addSubscriptionButton").show(); | 393 $("#addSubscriptionButton").show(); |
| 382 } | 394 } |
| 383 | 395 |
| 384 function toggleAcceptableAds() | 396 function toggleAcceptableAds() |
| 385 { | 397 { |
| 386 toggleSubscription(acceptableAdsUrl, true); | 398 toggleSubscription(acceptableAdsUrl, true); |
| 387 } | 399 } |
| 388 | 400 |
| 389 function findSubscriptionElement(subscription) | 401 function findSubscriptionElement(subscription) |
| 390 { | 402 { |
| 391 for (let child of document.getElementById("filterLists").childNodes) | 403 for (let child of document.getElementById("filterLists").childNodes) |
| 404 { | |
| 392 if (child._subscription.url == subscription.url) | 405 if (child._subscription.url == subscription.url) |
| 393 return child; | 406 return child; |
| 407 } | |
| 394 return null; | 408 return null; |
| 395 } | 409 } |
| 396 | 410 |
| 397 function updateSubscriptionInfo(element, subscription) | 411 function updateSubscriptionInfo(element, subscription) |
| 398 { | 412 { |
| 399 if (subscription) | 413 if (subscription) |
| 400 element._subscription = subscription; | 414 element._subscription = subscription; |
| 401 else | 415 else |
| 402 subscription = element._subscription; | 416 subscription = element._subscription; |
| 403 | 417 |
| 404 let title = element.getElementsByClassName("subscriptionTitle")[0]; | 418 let title = element.getElementsByClassName("subscriptionTitle")[0]; |
| 405 title.textContent = subscription.title; | 419 title.textContent = subscription.title; |
| 406 title.setAttribute("title", subscription.url); | 420 title.setAttribute("title", subscription.url); |
| 407 if (subscription.homepage) | 421 if (subscription.homepage) |
| 408 title.href = subscription.homepage; | 422 title.href = subscription.homepage; |
| 409 else | 423 else |
| 410 title.href = subscription.url; | 424 title.href = subscription.url; |
| 411 | 425 |
| 412 let enabled = element.getElementsByClassName("subscriptionEnabled")[0]; | 426 let enabled = element.getElementsByClassName("subscriptionEnabled")[0]; |
| 413 enabled.checked = !subscription.disabled; | 427 enabled.checked = !subscription.disabled; |
| 414 | 428 |
| 415 let lastUpdate = element.getElementsByClassName("subscriptionUpdate")[0]; | 429 let lastUpdate = element.getElementsByClassName("subscriptionUpdate")[0]; |
| 416 lastUpdate.classList.remove("error"); | 430 lastUpdate.classList.remove("error"); |
| 417 | 431 |
| 418 let downloadStatus = subscription.downloadStatus; | 432 let {downloadStatus} = subscription; |
| 419 if (subscription.isDownloading) | 433 if (subscription.isDownloading) |
| 420 { | 434 { |
| 421 lastUpdate.textContent = i18n.getMessage("filters_subscription_lastDownload_ inProgress"); | 435 lastUpdate.textContent = i18n.getMessage( |
| 436 "filters_subscription_lastDownload_inProgress" | |
| 437 ); | |
| 422 } | 438 } |
| 423 else if (downloadStatus && downloadStatus != "synchronize_ok") | 439 else if (downloadStatus && downloadStatus != "synchronize_ok") |
| 424 { | 440 { |
| 425 let map = | 441 if (statusMessages.has(downloadStatus)) |
| 426 { | 442 { |
| 427 "synchronize_invalid_url": "filters_subscription_lastDownload_invalidURL" , | 443 lastUpdate.textContent = i18n.getMessage( |
| 428 "synchronize_connection_error": "filters_subscription_lastDownload_connec tionError", | 444 statusMessages.get(downloadStatus) |
| 429 "synchronize_invalid_data": "filters_subscription_lastDownload_invalidDat a", | 445 ); |
| 430 "synchronize_checksum_mismatch": "filters_subscription_lastDownload_check sumMismatch" | 446 } |
| 431 }; | 447 else |
| 432 if (downloadStatus in map) | 448 { |
| 433 lastUpdate.textContent = i18n.getMessage(map[downloadStatus]); | 449 lastUpdate.textContent = downloadStatus; |
| 434 else | 450 } |
| 435 lastUpdate.textContent = downloadStatus; | 451 lastUpdate.classList.add("error"); |
| 436 lastUpdate.classList.add("error"); | |
| 437 } | 452 } |
| 438 else if (subscription.lastDownload > 0) | 453 else if (subscription.lastDownload > 0) |
| 439 { | 454 { |
| 440 let timeDate = i18n_timeDateStrings(subscription.lastDownload * 1000); | 455 let timeDate = i18n_timeDateStrings(subscription.lastDownload * 1000); |
| 441 let messageID = (timeDate[1] ? "last_updated_at" : "last_updated_at_today"); | 456 let messageID = (timeDate[1] ? "last_updated_at" : "last_updated_at_today"); |
| 442 lastUpdate.textContent = i18n.getMessage(messageID, timeDate); | 457 lastUpdate.textContent = i18n.getMessage(messageID, timeDate); |
| 443 } | 458 } |
| 444 } | 459 } |
| 445 | 460 |
| 446 function onSubscriptionMessage(action, subscription) | 461 function onSubscriptionMessage(action, subscription) |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 473 element.parentNode.removeChild(element); | 488 element.parentNode.removeChild(element); |
| 474 break; | 489 break; |
| 475 } | 490 } |
| 476 } | 491 } |
| 477 | 492 |
| 478 function onPrefMessage(key, value) | 493 function onPrefMessage(key, value) |
| 479 { | 494 { |
| 480 switch (key) | 495 switch (key) |
| 481 { | 496 { |
| 482 case "notifications_showui": | 497 case "notifications_showui": |
| 483 document.getElementById("shouldShowNotificationsContainer").hidden = !valu e; | 498 document.getElementById( |
| 499 "shouldShowNotificationsContainer" | |
| 500 ).hidden = !value; | |
| 484 return; | 501 return; |
| 485 case "notifications_ignoredcategories": | 502 case "notifications_ignoredcategories": |
| 486 key = "shouldShowNotifications"; | 503 key = "shouldShowNotifications"; |
| 487 value = value.indexOf("*") == -1; | 504 value = value.indexOf("*") == -1; |
| 488 break; | 505 break; |
| 489 } | 506 } |
| 490 let checkbox = document.getElementById(key); | 507 let checkbox = document.getElementById(key); |
| 491 if (checkbox) | 508 if (checkbox) |
| 492 checkbox.checked = value; | 509 checkbox.checked = value; |
| 493 } | 510 } |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 530 let list = document.getElementById(boxId); | 547 let list = document.getElementById(boxId); |
| 531 let selector = "option[value=" + CSS.escape(text) + "]"; | 548 let selector = "option[value=" + CSS.escape(text) + "]"; |
| 532 for (let option of list.querySelectorAll(selector)) | 549 for (let option of list.querySelectorAll(selector)) |
| 533 list.removeChild(option); | 550 list.removeChild(option); |
| 534 } | 551 } |
| 535 | 552 |
| 536 function addWhitelistDomain(event) | 553 function addWhitelistDomain(event) |
| 537 { | 554 { |
| 538 event.preventDefault(); | 555 event.preventDefault(); |
| 539 | 556 |
| 540 let domain = document.getElementById("newWhitelistDomain").value.replace(/\s/g , ""); | 557 let domain = document.getElementById( |
| 558 "newWhitelistDomain" | |
| 559 ).value.replace(/\s/g, ""); | |
| 541 document.getElementById("newWhitelistDomain").value = ""; | 560 document.getElementById("newWhitelistDomain").value = ""; |
| 542 if (!domain) | 561 if (!domain) |
| 543 return; | 562 return; |
| 544 | 563 |
| 545 let filterText = "@@||" + domain + "^$document"; | 564 let filterText = "@@||" + domain + "^$document"; |
| 546 addFilter(filterText); | 565 addFilter(filterText); |
| 547 } | 566 } |
| 548 | 567 |
| 549 // Adds filter text that user typed to the selection box | 568 // Adds filter text that user typed to the selection box |
| 550 function addTypedFilter(event) | 569 function addTypedFilter(event) |
| 551 { | 570 { |
| 552 event.preventDefault(); | 571 event.preventDefault(); |
| 553 | 572 |
| 554 let element = document.getElementById("newFilter"); | 573 let element = document.getElementById("newFilter"); |
| 555 addFilter(element.value, errors => | 574 addFilter(element.value, errors => |
| 556 { | 575 { |
| 557 if (errors.length > 0) | 576 if (errors.length > 0) |
| 558 alert(errors.join("\n")); | 577 alert(errors.join("\n")); |
| 559 else | 578 else |
| 560 element.value = ""; | 579 element.value = ""; |
| 561 }); | 580 }); |
| 562 } | 581 } |
| 563 | 582 |
| 564 // Removes currently selected whitelisted domains | 583 // Removes currently selected whitelisted domains |
| 565 function removeSelectedExcludedDomain(event) | 584 function removeSelectedExcludedDomain(event) |
| 566 { | 585 { |
| 567 event.preventDefault(); | 586 event.preventDefault(); |
| 568 let remove = []; | 587 let remove = []; |
| 569 for (let option of document.getElementById("excludedDomainsBox").options) | 588 for (let option of document.getElementById("excludedDomainsBox").options) |
| 589 { | |
| 570 if (option.selected) | 590 if (option.selected) |
| 571 remove.push(option.value); | 591 remove.push(option.value); |
| 592 } | |
| 572 if (!remove.length) | 593 if (!remove.length) |
| 573 return; | 594 return; |
| 574 | 595 |
| 575 for (let domain of remove) | 596 for (let domain of remove) |
| 576 removeFilter("@@||" + domain + "^$document"); | 597 removeFilter("@@||" + domain + "^$document"); |
| 577 } | 598 } |
| 578 | 599 |
| 579 // Removes all currently selected filters | 600 // Removes all currently selected filters |
| 580 function removeSelectedFilters(event) | 601 function removeSelectedFilters(event) |
| 581 { | 602 { |
| 582 event.preventDefault(); | 603 event.preventDefault(); |
| 583 for (let option of document.querySelectorAll("#userFiltersBox > option:checked ")) | 604 let options = document.querySelectorAll("#userFiltersBox > option:checked"); |
| 605 for (let option of options) | |
| 584 removeFilter(option.value); | 606 removeFilter(option.value); |
| 585 } | 607 } |
| 586 | 608 |
| 587 // Shows raw filters box and fills it with the current user filters | 609 // Shows raw filters box and fills it with the current user filters |
| 588 function toggleFiltersInRawFormat(event) | 610 function toggleFiltersInRawFormat(event) |
| 589 { | 611 { |
| 590 event.preventDefault(); | 612 event.preventDefault(); |
| 591 | 613 |
| 592 let rawFilters = document.getElementById("rawFilters"); | 614 let rawFilters = document.getElementById("rawFilters"); |
| 593 let filters = []; | 615 let filters = []; |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 628 } | 650 } |
| 629 | 651 |
| 630 // Adds a subscription entry to the UI. | 652 // Adds a subscription entry to the UI. |
| 631 function addSubscriptionEntry(subscription) | 653 function addSubscriptionEntry(subscription) |
| 632 { | 654 { |
| 633 let template = document.getElementById("subscriptionTemplate"); | 655 let template = document.getElementById("subscriptionTemplate"); |
| 634 let element = template.cloneNode(true); | 656 let element = template.cloneNode(true); |
| 635 element.removeAttribute("id"); | 657 element.removeAttribute("id"); |
| 636 element._subscription = subscription; | 658 element._subscription = subscription; |
| 637 | 659 |
| 638 let removeButton = element.getElementsByClassName("subscriptionRemoveButton")[ 0]; | 660 let removeButton = element.getElementsByClassName( |
| 661 "subscriptionRemoveButton" | |
| 662 )[0]; | |
| 639 removeButton.setAttribute("title", removeButton.textContent); | 663 removeButton.setAttribute("title", removeButton.textContent); |
| 640 removeButton.textContent = "\xD7"; | 664 removeButton.textContent = "\xD7"; |
| 641 removeButton.addEventListener("click", () => | 665 removeButton.addEventListener("click", () => |
| 642 { | 666 { |
| 643 if (!confirm(i18n.getMessage("global_remove_subscription_warning"))) | 667 if (!confirm(i18n.getMessage("global_remove_subscription_warning"))) |
| 644 return; | 668 return; |
| 645 | 669 |
| 646 removeSubscription(subscription.url); | 670 removeSubscription(subscription.url); |
| 647 }, false); | 671 }, false); |
| 648 | 672 |
| 649 getPref("additional_subscriptions", additionalSubscriptions => | 673 getPref("additional_subscriptions", additionalSubscriptions => |
| 650 { | 674 { |
| 651 if (additionalSubscriptions.indexOf(subscription.url) != -1) | 675 if (additionalSubscriptions.indexOf(subscription.url) != -1) |
| 652 removeButton.style.visibility = "hidden"; | 676 removeButton.style.visibility = "hidden"; |
| 653 }); | 677 }); |
| 654 | 678 |
| 655 let enabled = element.getElementsByClassName("subscriptionEnabled")[0]; | 679 let enabled = element.getElementsByClassName("subscriptionEnabled")[0]; |
| 656 enabled.addEventListener("click", () => | 680 enabled.addEventListener("click", () => |
| 657 { | 681 { |
| 658 subscription.disabled = !subscription.disabled; | 682 subscription.disabled = !subscription.disabled; |
| 659 toggleSubscription(subscription.url, true); | 683 toggleSubscription(subscription.url, true); |
| 660 }, false); | 684 }, false); |
| 661 | 685 |
| 662 updateSubscriptionInfo(element); | 686 updateSubscriptionInfo(element); |
| 663 | 687 |
| 664 document.getElementById("filterLists").appendChild(element); | 688 document.getElementById("filterLists").appendChild(element); |
| 665 } | 689 } |
| 666 | 690 |
| 667 function setLinks(id) | 691 function setLinks(id, ...args) |
| 668 { | 692 { |
| 669 let element = document.getElementById(id); | 693 let element = document.getElementById(id); |
| 670 if (!element) | 694 if (!element) |
| 671 return; | 695 return; |
| 672 | 696 |
| 673 let links = element.getElementsByTagName("a"); | 697 let links = element.getElementsByTagName("a"); |
| 674 for (let i = 0; i < links.length; i++) | 698 for (let i = 0; i < links.length; i++) |
| 675 { | 699 { |
| 676 if (typeof arguments[i + 1] == "string") | 700 if (typeof args[i] == "string") |
| 677 { | 701 { |
| 678 links[i].href = arguments[i + 1]; | 702 links[i].href = args[i]; |
| 679 links[i].setAttribute("target", "_blank"); | 703 links[i].setAttribute("target", "_blank"); |
| 680 } | 704 } |
| 681 else if (typeof arguments[i + 1] == "function") | 705 else if (typeof args[i] == "function") |
| 682 { | 706 { |
| 683 links[i].href = "javascript:void(0);"; | 707 links[i].href = "javascript:void(0);"; |
| 684 links[i].addEventListener("click", arguments[i + 1], false); | 708 links[i].addEventListener("click", args[i], false); |
| 685 } | 709 } |
| 686 } | 710 } |
| 687 } | 711 } |
| 688 | 712 |
| 689 ext.onMessage.addListener(message => | 713 ext.onMessage.addListener(message => |
| 690 { | 714 { |
| 691 switch (message.type) | 715 switch (message.type) |
| 692 { | 716 { |
| 693 case "app.respond": | 717 case "app.respond": |
| 694 switch (message.action) | 718 switch (message.action) |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 721 onFilterMessage(message.action, message.args[0]); | 745 onFilterMessage(message.action, message.args[0]); |
| 722 break; | 746 break; |
| 723 case "prefs.respond": | 747 case "prefs.respond": |
| 724 onPrefMessage(message.action, message.args[0]); | 748 onPrefMessage(message.action, message.args[0]); |
| 725 break; | 749 break; |
| 726 case "subscriptions.respond": | 750 case "subscriptions.respond": |
| 727 onSubscriptionMessage(message.action, message.args[0]); | 751 onSubscriptionMessage(message.action, message.args[0]); |
| 728 break; | 752 break; |
| 729 } | 753 } |
| 730 }); | 754 }); |
| OLD | NEW |