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-2017 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, i18nTimeDateStrings */ |
| 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) |
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.assign(Object.create(null), baseMessage); |
42 for (let key in baseMessage) | |
43 if (baseMessage.hasOwnProperty(key)) | |
44 message[key] = baseMessage[key]; | |
45 | |
46 let paramValues = []; | |
47 let callback; | 41 let callback; |
48 | 42 |
49 if (arguments.length > 0) | 43 if (paramValues.length > 0) |
50 { | 44 { |
51 let lastArg = arguments[arguments.length - 1]; | 45 let lastArg = paramValues[paramValues.length - 1]; |
52 if (typeof lastArg == "function") | 46 if (typeof lastArg == "function") |
53 callback = lastArg; | 47 callback = lastArg; |
54 | 48 |
55 for (let i = 0; i < arguments.length - (callback ? 1 : 0); i++) | 49 for (let i = 0; i < paramValues.length - (callback ? 1 : 0); i++) |
56 message[paramKeys[i]] = arguments[i]; | 50 message[paramKeys[i]] = paramValues[i]; |
57 } | 51 } |
58 | 52 |
59 // Edge 38.14393 silently fails when sendMessage is called with a callback | 53 // Edge 38.14393 silently fails when sendMessage is called with a callback |
60 // parameter of undefined, so we work around that here. | 54 // parameter of undefined, so we work around that here. |
61 // https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/8504
730/ | 55 // https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/8504
730/ |
62 if (callback) | 56 if (callback) |
63 ext.backgroundPage.sendMessage(message, callback); | 57 ext.backgroundPage.sendMessage(message, callback); |
64 else | 58 else |
65 ext.backgroundPage.sendMessage(message); | 59 ext.backgroundPage.sendMessage(message); |
66 }; | 60 }; |
(...skipping 10 matching lines...) Expand all Loading... |
77 "url", "title", "homepage"); | 71 "url", "title", "homepage"); |
78 const toggleSubscription = wrapper({type: "subscriptions.toggle"}, | 72 const toggleSubscription = wrapper({type: "subscriptions.toggle"}, |
79 "url", "keepInstalled"); | 73 "url", "keepInstalled"); |
80 const updateSubscription = wrapper({type: "subscriptions.update"}, "url"); | 74 const updateSubscription = wrapper({type: "subscriptions.update"}, "url"); |
81 const importRawFilters = wrapper({type: "filters.importRaw"}, | 75 const importRawFilters = wrapper({type: "filters.importRaw"}, |
82 "text", "removeExisting"); | 76 "text", "removeExisting"); |
83 const addFilter = wrapper({type: "filters.add"}, "text"); | 77 const addFilter = wrapper({type: "filters.add"}, "text"); |
84 const getFilters = wrapper({type: "filters.get"}, "subscriptionUrl"); | 78 const getFilters = wrapper({type: "filters.get"}, "subscriptionUrl"); |
85 const removeFilter = wrapper({type: "filters.remove"}, "text"); | 79 const removeFilter = wrapper({type: "filters.remove"}, "text"); |
86 | 80 |
87 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 |
88 let delayedSubscriptionSelection = null; | 93 let delayedSubscriptionSelection = null; |
89 | |
90 let acceptableAdsUrl; | 94 let acceptableAdsUrl; |
91 | 95 |
92 // Loads options from localStorage and sets UI elements accordingly | 96 // Loads options from localStorage and sets UI elements accordingly |
93 function loadOptions() | 97 function loadOptions() |
94 { | 98 { |
95 // Set page title to i18n version of "Adblock Plus Options" | 99 // Set page title to i18n version of "Adblock Plus Options" |
96 document.title = i18n.getMessage("options"); | 100 document.title = i18n.getMessage("options"); |
97 | 101 |
98 // Set links | 102 // Set links |
99 getPref("subscriptions_exceptionsurl", url => | 103 getPref("subscriptions_exceptionsurl", url => |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
146 // Popuplate option checkboxes | 150 // Popuplate option checkboxes |
147 initCheckbox("shouldShowBlockElementMenu"); | 151 initCheckbox("shouldShowBlockElementMenu"); |
148 initCheckbox("show_devtools_panel"); | 152 initCheckbox("show_devtools_panel"); |
149 initCheckbox("shouldShowNotifications", "notifications_ignoredcategories"); | 153 initCheckbox("shouldShowNotifications", "notifications_ignoredcategories"); |
150 | 154 |
151 getInfo("features", features => | 155 getInfo("features", features => |
152 { | 156 { |
153 if (!features.devToolsPanel) | 157 if (!features.devToolsPanel) |
154 document.getElementById("showDevtoolsPanelContainer").hidden = true; | 158 document.getElementById("showDevtoolsPanelContainer").hidden = true; |
155 }); | 159 }); |
156 getPref("notifications_showui", notifications_showui => | 160 getPref("notifications_showui", showNotificationsUI => |
157 { | 161 { |
158 if (!notifications_showui) | 162 if (!showNotificationsUI) |
159 document.getElementById("shouldShowNotificationsContainer").hidden = true; | 163 document.getElementById("shouldShowNotificationsContainer").hidden = true; |
160 }); | 164 }); |
161 | 165 |
162 // Register listeners in the background message responder | 166 // Register listeners in the background message responder |
163 ext.backgroundPage.sendMessage({ | 167 ext.backgroundPage.sendMessage({ |
164 type: "app.listen", | 168 type: "app.listen", |
165 filter: ["addSubscription", "focusSection"] | 169 filter: ["addSubscription", "focusSection"] |
166 }); | 170 }); |
167 ext.backgroundPage.sendMessage( | 171 ext.backgroundPage.sendMessage({ |
168 { | |
169 type: "filters.listen", | 172 type: "filters.listen", |
170 filter: ["added", "loaded", "removed"] | 173 filter: ["added", "loaded", "removed"] |
171 }); | 174 }); |
172 ext.backgroundPage.sendMessage( | 175 ext.backgroundPage.sendMessage({ |
173 { | |
174 type: "prefs.listen", | 176 type: "prefs.listen", |
175 filter: ["notifications_ignoredcategories", "notifications_showui", | 177 filter: ["notifications_ignoredcategories", "notifications_showui", |
176 "show_devtools_panel", "shouldShowBlockElementMenu"] | 178 "show_devtools_panel", "shouldShowBlockElementMenu"] |
177 }); | 179 }); |
178 ext.backgroundPage.sendMessage( | 180 ext.backgroundPage.sendMessage({ |
179 { | |
180 type: "subscriptions.listen", | 181 type: "subscriptions.listen", |
181 filter: ["added", "disabled", "homepage", "lastDownload", "removed", | 182 filter: ["added", "disabled", "homepage", "lastDownload", "removed", |
182 "title", "downloadStatus", "downloading"] | 183 "title", "downloadStatus", "downloading"] |
183 }); | 184 }); |
184 | 185 |
185 // Load recommended subscriptions | 186 // Load recommended subscriptions |
186 loadRecommendations(); | 187 loadRecommendations(); |
187 | 188 |
188 // Show user's filters | 189 // Show user's filters |
189 reloadFilters(); | 190 reloadFilters(); |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
312 | 313 |
313 let option = new Option(); | 314 let option = new Option(); |
314 let label = i18n.getMessage("filters_addSubscriptionOther_label"); | 315 let label = i18n.getMessage("filters_addSubscriptionOther_label"); |
315 option.text = label + "\u2026"; | 316 option.text = label + "\u2026"; |
316 option._data = null; | 317 option._data = null; |
317 list.appendChild(option); | 318 list.appendChild(option); |
318 | 319 |
319 list.selectedIndex = selectedIndex; | 320 list.selectedIndex = selectedIndex; |
320 | 321 |
321 if (delayedSubscriptionSelection) | 322 if (delayedSubscriptionSelection) |
322 startSubscriptionSelection.apply(null, delayedSubscriptionSelection); | 323 startSubscriptionSelection(...delayedSubscriptionSelection); |
323 }); | 324 }); |
324 } | 325 } |
325 | 326 |
326 function startSubscriptionSelection(title, url) | 327 function startSubscriptionSelection(title, url) |
327 { | 328 { |
328 let list = document.getElementById("subscriptionSelector"); | 329 let list = document.getElementById("subscriptionSelector"); |
329 if (list.length == 0) | 330 if (list.length == 0) |
330 { | 331 { |
331 delayedSubscriptionSelection = [title, url]; | 332 delayedSubscriptionSelection = [title, url]; |
332 return; | 333 return; |
(...skipping 27 matching lines...) Expand all Loading... |
360 } | 361 } |
361 | 362 |
362 function addSubscriptionClicked() | 363 function addSubscriptionClicked() |
363 { | 364 { |
364 let list = document.getElementById("subscriptionSelector"); | 365 let list = document.getElementById("subscriptionSelector"); |
365 let data = list.options[list.selectedIndex]._data; | 366 let data = list.options[list.selectedIndex]._data; |
366 if (data) | 367 if (data) |
367 addSubscription(data.url, data.title, data.homepage); | 368 addSubscription(data.url, data.title, data.homepage); |
368 else | 369 else |
369 { | 370 { |
370 let url = document.getElementById("customSubscriptionLocation").value.trim()
; | 371 let url = document.getElementById("customSubscriptionLocation") |
| 372 .value.trim(); |
371 if (!/^https?:/i.test(url)) | 373 if (!/^https?:/i.test(url)) |
372 { | 374 { |
373 alert(i18n.getMessage("global_subscription_invalid_location")); | 375 alert(i18n.getMessage("global_subscription_invalid_location")); |
374 $("#customSubscriptionLocation").focus(); | 376 $("#customSubscriptionLocation").focus(); |
375 return; | 377 return; |
376 } | 378 } |
377 | 379 |
378 let title = document.getElementById("customSubscriptionTitle").value.trim(); | 380 let title = document.getElementById("customSubscriptionTitle").value.trim(); |
379 if (!title) | 381 if (!title) |
380 title = url; | 382 title = url; |
381 | 383 |
382 addSubscription(url, title, null); | 384 addSubscription(url, title, null); |
383 } | 385 } |
384 | 386 |
385 $("#addSubscriptionContainer").hide(); | 387 $("#addSubscriptionContainer").hide(); |
386 $("#customSubscriptionContainer").hide(); | 388 $("#customSubscriptionContainer").hide(); |
387 $("#addSubscriptionButton").show(); | 389 $("#addSubscriptionButton").show(); |
388 } | 390 } |
389 | 391 |
390 function toggleAcceptableAds() | 392 function toggleAcceptableAds() |
391 { | 393 { |
392 toggleSubscription(acceptableAdsUrl, true); | 394 toggleSubscription(acceptableAdsUrl, true); |
393 } | 395 } |
394 | 396 |
395 function findSubscriptionElement(subscription) | 397 function findSubscriptionElement(subscription) |
396 { | 398 { |
397 for (let child of document.getElementById("filterLists").childNodes) | 399 for (let child of document.getElementById("filterLists").childNodes) |
| 400 { |
398 if (child._subscription.url == subscription.url) | 401 if (child._subscription.url == subscription.url) |
399 return child; | 402 return child; |
| 403 } |
400 return null; | 404 return null; |
401 } | 405 } |
402 | 406 |
403 function updateSubscriptionInfo(element, subscription) | 407 function updateSubscriptionInfo(element, subscription) |
404 { | 408 { |
405 if (subscription) | 409 if (subscription) |
406 element._subscription = subscription; | 410 element._subscription = subscription; |
407 else | 411 else |
408 subscription = element._subscription; | 412 subscription = element._subscription; |
409 | 413 |
410 let title = element.getElementsByClassName("subscriptionTitle")[0]; | 414 let title = element.getElementsByClassName("subscriptionTitle")[0]; |
411 title.textContent = subscription.title; | 415 title.textContent = subscription.title; |
412 title.setAttribute("title", subscription.url); | 416 title.setAttribute("title", subscription.url); |
413 if (subscription.homepage) | 417 if (subscription.homepage) |
414 title.href = subscription.homepage; | 418 title.href = subscription.homepage; |
415 else | 419 else |
416 title.href = subscription.url; | 420 title.href = subscription.url; |
417 | 421 |
418 let enabled = element.getElementsByClassName("subscriptionEnabled")[0]; | 422 let enabled = element.getElementsByClassName("subscriptionEnabled")[0]; |
419 enabled.checked = !subscription.disabled; | 423 enabled.checked = !subscription.disabled; |
420 | 424 |
421 let lastUpdate = element.getElementsByClassName("subscriptionUpdate")[0]; | 425 let lastUpdate = element.getElementsByClassName("subscriptionUpdate")[0]; |
422 lastUpdate.classList.remove("error"); | 426 lastUpdate.classList.remove("error"); |
423 | 427 |
424 let downloadStatus = subscription.downloadStatus; | 428 let {downloadStatus} = subscription; |
425 if (subscription.isDownloading) | 429 if (subscription.isDownloading) |
426 { | 430 { |
427 lastUpdate.textContent = i18n.getMessage("filters_subscription_lastDownload_
inProgress"); | 431 lastUpdate.textContent = i18n.getMessage( |
| 432 "filters_subscription_lastDownload_inProgress" |
| 433 ); |
428 } | 434 } |
429 else if (downloadStatus && downloadStatus != "synchronize_ok") | 435 else if (downloadStatus && downloadStatus != "synchronize_ok") |
430 { | 436 { |
431 let map = | 437 if (statusMessages.has(downloadStatus)) |
432 { | 438 { |
433 "synchronize_invalid_url": "filters_subscription_lastDownload_invalidURL"
, | 439 lastUpdate.textContent = i18n.getMessage( |
434 "synchronize_connection_error": "filters_subscription_lastDownload_connec
tionError", | 440 statusMessages.get(downloadStatus) |
435 "synchronize_invalid_data": "filters_subscription_lastDownload_invalidDat
a", | 441 ); |
436 "synchronize_checksum_mismatch": "filters_subscription_lastDownload_check
sumMismatch" | 442 } |
437 }; | 443 else |
438 if (downloadStatus in map) | 444 lastUpdate.textContent = downloadStatus; |
439 lastUpdate.textContent = i18n.getMessage(map[downloadStatus]); | 445 lastUpdate.classList.add("error"); |
440 else | |
441 lastUpdate.textContent = downloadStatus; | |
442 lastUpdate.classList.add("error"); | |
443 } | 446 } |
444 else if (subscription.lastDownload > 0) | 447 else if (subscription.lastDownload > 0) |
445 { | 448 { |
446 let timeDate = i18n_timeDateStrings(subscription.lastDownload * 1000); | 449 let timeDate = i18nTimeDateStrings(subscription.lastDownload * 1000); |
447 let messageID = (timeDate[1] ? "last_updated_at" : "last_updated_at_today"); | 450 let messageID = (timeDate[1] ? "last_updated_at" : "last_updated_at_today"); |
448 lastUpdate.textContent = i18n.getMessage(messageID, timeDate); | 451 lastUpdate.textContent = i18n.getMessage(messageID, timeDate); |
449 } | 452 } |
450 } | 453 } |
451 | 454 |
452 function onSubscriptionMessage(action, subscription) | 455 function onSubscriptionMessage(action, subscription) |
453 { | 456 { |
454 let element = findSubscriptionElement(subscription); | 457 let element = findSubscriptionElement(subscription); |
455 | 458 |
456 switch (action) | 459 switch (action) |
(...skipping 22 matching lines...) Expand all Loading... |
479 element.parentNode.removeChild(element); | 482 element.parentNode.removeChild(element); |
480 break; | 483 break; |
481 } | 484 } |
482 } | 485 } |
483 | 486 |
484 function onPrefMessage(key, value) | 487 function onPrefMessage(key, value) |
485 { | 488 { |
486 switch (key) | 489 switch (key) |
487 { | 490 { |
488 case "notifications_showui": | 491 case "notifications_showui": |
489 document.getElementById("shouldShowNotificationsContainer").hidden = !valu
e; | 492 document.getElementById( |
| 493 "shouldShowNotificationsContainer" |
| 494 ).hidden = !value; |
490 return; | 495 return; |
491 case "notifications_ignoredcategories": | 496 case "notifications_ignoredcategories": |
492 key = "shouldShowNotifications"; | 497 key = "shouldShowNotifications"; |
493 value = value.indexOf("*") == -1; | 498 value = value.indexOf("*") == -1; |
494 break; | 499 break; |
495 } | 500 } |
496 let checkbox = document.getElementById(key); | 501 let checkbox = document.getElementById(key); |
497 if (checkbox) | 502 if (checkbox) |
498 checkbox.checked = value; | 503 checkbox.checked = value; |
499 } | 504 } |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
536 let list = document.getElementById(boxId); | 541 let list = document.getElementById(boxId); |
537 let selector = "option[value=" + CSS.escape(text) + "]"; | 542 let selector = "option[value=" + CSS.escape(text) + "]"; |
538 for (let option of list.querySelectorAll(selector)) | 543 for (let option of list.querySelectorAll(selector)) |
539 list.removeChild(option); | 544 list.removeChild(option); |
540 } | 545 } |
541 | 546 |
542 function addWhitelistDomain(event) | 547 function addWhitelistDomain(event) |
543 { | 548 { |
544 event.preventDefault(); | 549 event.preventDefault(); |
545 | 550 |
546 let domain = document.getElementById("newWhitelistDomain").value.replace(/\s/g
, ""); | 551 let domain = document.getElementById( |
| 552 "newWhitelistDomain" |
| 553 ).value.replace(/\s/g, ""); |
547 document.getElementById("newWhitelistDomain").value = ""; | 554 document.getElementById("newWhitelistDomain").value = ""; |
548 if (!domain) | 555 if (!domain) |
549 return; | 556 return; |
550 | 557 |
551 let filterText = "@@||" + domain + "^$document"; | 558 let filterText = "@@||" + domain + "^$document"; |
552 addFilter(filterText); | 559 addFilter(filterText); |
553 } | 560 } |
554 | 561 |
555 // Adds filter text that user typed to the selection box | 562 // Adds filter text that user typed to the selection box |
556 function addTypedFilter(event) | 563 function addTypedFilter(event) |
557 { | 564 { |
558 event.preventDefault(); | 565 event.preventDefault(); |
559 | 566 |
560 let element = document.getElementById("newFilter"); | 567 let element = document.getElementById("newFilter"); |
561 addFilter(element.value, errors => | 568 addFilter(element.value, errors => |
562 { | 569 { |
563 if (errors.length > 0) | 570 if (errors.length > 0) |
564 alert(errors.join("\n")); | 571 alert(errors.join("\n")); |
565 else | 572 else |
566 element.value = ""; | 573 element.value = ""; |
567 }); | 574 }); |
568 } | 575 } |
569 | 576 |
570 // Removes currently selected whitelisted domains | 577 // Removes currently selected whitelisted domains |
571 function removeSelectedExcludedDomain(event) | 578 function removeSelectedExcludedDomain(event) |
572 { | 579 { |
573 event.preventDefault(); | 580 event.preventDefault(); |
574 let remove = []; | 581 let remove = []; |
575 for (let option of document.getElementById("excludedDomainsBox").options) | 582 for (let option of document.getElementById("excludedDomainsBox").options) |
| 583 { |
576 if (option.selected) | 584 if (option.selected) |
577 remove.push(option.value); | 585 remove.push(option.value); |
| 586 } |
578 if (!remove.length) | 587 if (!remove.length) |
579 return; | 588 return; |
580 | 589 |
581 for (let domain of remove) | 590 for (let domain of remove) |
582 removeFilter("@@||" + domain + "^$document"); | 591 removeFilter("@@||" + domain + "^$document"); |
583 } | 592 } |
584 | 593 |
585 // Removes all currently selected filters | 594 // Removes all currently selected filters |
586 function removeSelectedFilters(event) | 595 function removeSelectedFilters(event) |
587 { | 596 { |
588 event.preventDefault(); | 597 event.preventDefault(); |
589 for (let option of document.querySelectorAll("#userFiltersBox > option:checked
")) | 598 let options = document.querySelectorAll("#userFiltersBox > option:checked"); |
| 599 for (let option of options) |
590 removeFilter(option.value); | 600 removeFilter(option.value); |
591 } | 601 } |
592 | 602 |
593 // Shows raw filters box and fills it with the current user filters | 603 // Shows raw filters box and fills it with the current user filters |
594 function toggleFiltersInRawFormat(event) | 604 function toggleFiltersInRawFormat(event) |
595 { | 605 { |
596 event.preventDefault(); | 606 event.preventDefault(); |
597 | 607 |
598 let rawFilters = document.getElementById("rawFilters"); | 608 let rawFilters = document.getElementById("rawFilters"); |
599 let filters = []; | 609 let filters = []; |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
634 } | 644 } |
635 | 645 |
636 // Adds a subscription entry to the UI. | 646 // Adds a subscription entry to the UI. |
637 function addSubscriptionEntry(subscription) | 647 function addSubscriptionEntry(subscription) |
638 { | 648 { |
639 let template = document.getElementById("subscriptionTemplate"); | 649 let template = document.getElementById("subscriptionTemplate"); |
640 let element = template.cloneNode(true); | 650 let element = template.cloneNode(true); |
641 element.removeAttribute("id"); | 651 element.removeAttribute("id"); |
642 element._subscription = subscription; | 652 element._subscription = subscription; |
643 | 653 |
644 let removeButton = element.getElementsByClassName("subscriptionRemoveButton")[
0]; | 654 let removeButton = element.getElementsByClassName( |
| 655 "subscriptionRemoveButton" |
| 656 )[0]; |
645 removeButton.setAttribute("title", removeButton.textContent); | 657 removeButton.setAttribute("title", removeButton.textContent); |
646 removeButton.textContent = "\xD7"; | 658 removeButton.textContent = "\xD7"; |
647 removeButton.addEventListener("click", () => | 659 removeButton.addEventListener("click", () => |
648 { | 660 { |
649 if (!confirm(i18n.getMessage("global_remove_subscription_warning"))) | 661 if (!confirm(i18n.getMessage("global_remove_subscription_warning"))) |
650 return; | 662 return; |
651 | 663 |
652 removeSubscription(subscription.url); | 664 removeSubscription(subscription.url); |
653 }, false); | 665 }, false); |
654 | 666 |
655 getPref("additional_subscriptions", additionalSubscriptions => | 667 getPref("additional_subscriptions", additionalSubscriptions => |
656 { | 668 { |
657 if (additionalSubscriptions.indexOf(subscription.url) != -1) | 669 if (additionalSubscriptions.indexOf(subscription.url) != -1) |
658 removeButton.style.visibility = "hidden"; | 670 removeButton.style.visibility = "hidden"; |
659 }); | 671 }); |
660 | 672 |
661 let enabled = element.getElementsByClassName("subscriptionEnabled")[0]; | 673 let enabled = element.getElementsByClassName("subscriptionEnabled")[0]; |
662 enabled.addEventListener("click", () => | 674 enabled.addEventListener("click", () => |
663 { | 675 { |
664 subscription.disabled = !subscription.disabled; | 676 subscription.disabled = !subscription.disabled; |
665 toggleSubscription(subscription.url, true); | 677 toggleSubscription(subscription.url, true); |
666 }, false); | 678 }, false); |
667 | 679 |
668 updateSubscriptionInfo(element); | 680 updateSubscriptionInfo(element); |
669 | 681 |
670 document.getElementById("filterLists").appendChild(element); | 682 document.getElementById("filterLists").appendChild(element); |
671 } | 683 } |
672 | 684 |
673 function setLinks(id) | 685 function setLinks(id, ...args) |
674 { | 686 { |
675 let element = document.getElementById(id); | 687 let element = document.getElementById(id); |
676 if (!element) | 688 if (!element) |
677 return; | 689 return; |
678 | 690 |
679 let links = element.getElementsByTagName("a"); | 691 let links = element.getElementsByTagName("a"); |
680 for (let i = 0; i < links.length; i++) | 692 for (let i = 0; i < links.length; i++) |
681 { | 693 { |
682 if (typeof arguments[i + 1] == "string") | 694 if (typeof args[i] == "string") |
683 { | 695 { |
684 links[i].href = arguments[i + 1]; | 696 links[i].href = args[i]; |
685 links[i].setAttribute("target", "_blank"); | 697 links[i].setAttribute("target", "_blank"); |
686 } | 698 } |
687 else if (typeof arguments[i + 1] == "function") | 699 else if (typeof args[i] == "function") |
688 { | 700 { |
689 links[i].href = "javascript:void(0);"; | 701 links[i].href = "javascript:void(0);"; |
690 links[i].addEventListener("click", arguments[i + 1], false); | 702 links[i].addEventListener("click", args[i], false); |
691 } | 703 } |
692 } | 704 } |
693 } | 705 } |
694 | 706 |
695 ext.onMessage.addListener(message => | 707 ext.onMessage.addListener(message => |
696 { | 708 { |
697 switch (message.type) | 709 switch (message.type) |
698 { | 710 { |
699 case "app.respond": | 711 case "app.respond": |
700 switch (message.action) | 712 switch (message.action) |
(...skipping 26 matching lines...) Expand all Loading... |
727 onFilterMessage(message.action, message.args[0]); | 739 onFilterMessage(message.action, message.args[0]); |
728 break; | 740 break; |
729 case "prefs.respond": | 741 case "prefs.respond": |
730 onPrefMessage(message.action, message.args[0]); | 742 onPrefMessage(message.action, message.args[0]); |
731 break; | 743 break; |
732 case "subscriptions.respond": | 744 case "subscriptions.respond": |
733 onSubscriptionMessage(message.action, message.args[0]); | 745 onSubscriptionMessage(message.action, message.args[0]); |
734 break; | 746 break; |
735 } | 747 } |
736 }); | 748 }); |
OLD | NEW |