| 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-2015 Eyeo GmbH | 3 * Copyright (C) 2006-2015 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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 46 for (var j = 0; j < this.details.length; j++) | 46 for (var j = 0; j < this.details.length; j++) |
| 47 { | 47 { |
| 48 var table = E(this.details[j].id); | 48 var table = E(this.details[j].id); |
| 49 var template = table.querySelector("template"); | 49 var template = table.querySelector("template"); |
| 50 for (var i = 0; i < arguments.length; i++) | 50 for (var i = 0; i < arguments.length; i++) |
| 51 { | 51 { |
| 52 var item = arguments[i]; | 52 var item = arguments[i]; |
| 53 var text = item.title || item.url || item.text; | 53 var text = item.title || item.url || item.text; |
| 54 var listItem = document.createElement("li"); | 54 var listItem = document.createElement("li"); |
| 55 listItem.appendChild(document.importNode(template.content, true)); | 55 listItem.appendChild(document.importNode(template.content, true)); |
| 56 listItem.dataset.access = item.url || item.text; | 56 listItem.setAttribute("data-access", item.url || item.text); |
| 57 listItem.querySelector(".display").textContent = text; | 57 listItem.querySelector(".display").textContent = text; |
| 58 if (text) | 58 if (text) |
| 59 listItem.dataset.search = text.toLowerCase(); | 59 listItem.setAttribute("data-search", text.toLowerCase()); |
| 60 | 60 |
| 61 var control = listItem.querySelector(".control"); | 61 var control = listItem.querySelector(".control"); |
| 62 if (control) | 62 if (control) |
| 63 { | 63 { |
| 64 control.addEventListener("click", this.details[j].onClick, false); | 64 control.addEventListener("click", this.details[j].onClick, false); |
| 65 control.checked = item.disabled == false; | 65 control.checked = item.disabled == false; |
| 66 } | 66 } |
| 67 | 67 |
| 68 if (table.hasChildNodes()) | 68 if (table.hasChildNodes()) |
| 69 table.insertBefore(listItem, table.childNodes[this.items.indexOf(item)
]); | 69 table.insertBefore(listItem, table.childNodes[this.items.indexOf(item)
]); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 98 var template = table.querySelector("template"); | 98 var template = table.querySelector("template"); |
| 99 table.innerHTML = ""; | 99 table.innerHTML = ""; |
| 100 table.appendChild(template); | 100 table.appendChild(template); |
| 101 } | 101 } |
| 102 this.items.length = 0; | 102 this.items.length = 0; |
| 103 }; | 103 }; |
| 104 | 104 |
| 105 function onToggleSubscriptionClick(e) | 105 function onToggleSubscriptionClick(e) |
| 106 { | 106 { |
| 107 e.preventDefault(); | 107 e.preventDefault(); |
| 108 var subscriptionUrl = e.target.parentNode.dataset.access; | 108 var subscriptionUrl = e.target.parentNode.getAttribute("data-access"); |
| 109 if (!e.target.checked) | 109 if (!e.target.checked) |
| 110 removeSubscription(subscriptionUrl); | 110 removeSubscription(subscriptionUrl); |
| 111 else | 111 else |
| 112 addEnableSubscription(subscriptionUrl); | 112 addEnableSubscription(subscriptionUrl); |
| 113 } | 113 } |
| 114 | 114 |
| 115 function onAddLanguageSubscriptionClick(e) | 115 function onAddLanguageSubscriptionClick(e) |
| 116 { | 116 { |
| 117 e.preventDefault(); | 117 e.preventDefault(); |
| 118 var url = this.parentNode.dataset.access; | 118 var url = this.parentNode.getAttribute("data-access"); |
| 119 addEnableSubscription(url); | 119 addEnableSubscription(url); |
| 120 } | 120 } |
| 121 | 121 |
| 122 function onRemoveFilterClick() | 122 function onRemoveFilterClick() |
| 123 { | 123 { |
| 124 var filter = this.parentNode.dataset.access; | 124 var filter = this.parentNode.getAttribute("data-access"); |
| 125 removeFilter(filter); | 125 removeFilter(filter); |
| 126 } | 126 } |
| 127 | 127 |
| 128 collections.popular = new Collection( | 128 collections.popular = new Collection( |
| 129 [ | 129 [ |
| 130 { | 130 { |
| 131 id: "recommend-list-table", | 131 id: "recommend-list-table", |
| 132 onClick: onToggleSubscriptionClick | 132 onClick: onToggleSubscriptionClick |
| 133 } | 133 } |
| 134 ]); | 134 ]); |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 309 if (element.getAttribute("popular")) | 309 if (element.getAttribute("popular")) |
| 310 recommendation.isPopular = true; | 310 recommendation.isPopular = true; |
| 311 | 311 |
| 312 recommendationsMap[subscription.url] = recommendation; | 312 recommendationsMap[subscription.url] = recommendation; |
| 313 updateSubscription(subscription); | 313 updateSubscription(subscription); |
| 314 } | 314 } |
| 315 }, false); | 315 }, false); |
| 316 request.send(null); | 316 request.send(null); |
| 317 } | 317 } |
| 318 | 318 |
| 319 function onClick(e) |
| 320 { |
| 321 var element = e.target; |
| 322 while (true) |
| 323 { |
| 324 if (!element) |
| 325 return; |
| 326 |
| 327 if (element.hasAttribute("data-action")) |
| 328 break; |
| 329 |
| 330 element = element.parentElement; |
| 331 } |
| 332 |
| 333 switch (element.getAttribute("data-action")) |
| 334 { |
| 335 case "add-domain-exception": |
| 336 addWhitelistedDomain(); |
| 337 break; |
| 338 case "add-predefined-subscription": |
| 339 var dialog = E("dialog-content-predefined"); |
| 340 var title = dialog.querySelector("h3").textContent; |
| 341 var url = dialog.querySelector(".url").textContent; |
| 342 addEnableSubscription(url, title); |
| 343 document.body.removeAttribute("data-dialog"); |
| 344 break; |
| 345 case "cancel-domain-exception": |
| 346 E("whitelisting-textbox").value = ""; |
| 347 break; |
| 348 case "close-dialog": |
| 349 document.body.removeAttribute("data-dialog"); |
| 350 break; |
| 351 case "edit-custom-filters": |
| 352 editCustomFilters(); |
| 353 break; |
| 354 case "import-subscription": |
| 355 var url = E("blockingList-textbox").value; |
| 356 addEnableSubscription(url); |
| 357 document.body.removeAttribute("data-dialog"); |
| 358 break; |
| 359 case "open-dialog": |
| 360 openDialog(element.getAttribute("data-dialog")); |
| 361 break; |
| 362 case "switch-tab": |
| 363 document.body.setAttribute("data-tab", |
| 364 element.getAttribute("data-tab")); |
| 365 break; |
| 366 } |
| 367 } |
| 368 |
| 319 function onDOMLoaded() | 369 function onDOMLoaded() |
| 320 { | 370 { |
| 321 var recommendationTemplate = document.querySelector("#recommend-list-table t
emplate"); | 371 var recommendationTemplate = document.querySelector("#recommend-list-table t
emplate"); |
| 322 var popularText = ext.i18n.getMessage("options_popular"); | 372 var popularText = ext.i18n.getMessage("options_popular"); |
| 323 recommendationTemplate.content.querySelector(".popular").textContent = popul
arText; | 373 recommendationTemplate.content.querySelector(".popular").textContent = popul
arText; |
| 324 var languagesTemplate = document.querySelector("#all-lang-table template"); | 374 var languagesTemplate = document.querySelector("#all-lang-table template"); |
| 325 var buttonText = ext.i18n.getMessage("options_button_add"); | 375 var buttonText = ext.i18n.getMessage("options_button_add"); |
| 326 languagesTemplate.content.querySelector(".button-add span").textContent = bu
ttonText; | 376 languagesTemplate.content.querySelector(".button-add span").textContent = bu
ttonText; |
| 327 | 377 |
| 328 populateLists(); | 378 populateLists(); |
| 329 | 379 |
| 330 var tabList = document.querySelectorAll("#main-navigation-tabs li"); | |
| 331 for (var i = 0; i < tabList.length; i++) | |
| 332 { | |
| 333 tabList[i].addEventListener("click", function(e) | |
| 334 { | |
| 335 document.body.dataset.tab = e.currentTarget.dataset.show; | |
| 336 }, false); | |
| 337 } | |
| 338 | |
| 339 function onFindLanguageKeyUp() | 380 function onFindLanguageKeyUp() |
| 340 { | 381 { |
| 341 var searchStyle = E("search-style"); | 382 var searchStyle = E("search-style"); |
| 342 if (!this.value) | 383 if (!this.value) |
| 343 searchStyle.innerHTML = ""; | 384 searchStyle.innerHTML = ""; |
| 344 else | 385 else |
| 345 searchStyle.innerHTML = "#all-lang-table li:not([data-search*=\"" + this
.value.toLowerCase() + "\"]) { display: none; }"; | 386 searchStyle.innerHTML = "#all-lang-table li:not([data-search*=\"" + this
.value.toLowerCase() + "\"]) { display: none; }"; |
| 346 } | 387 } |
| 347 | 388 |
| 348 // Initialize navigation sidebar | 389 // Initialize navigation sidebar |
| (...skipping 12 matching lines...) Expand all Loading... |
| 361 }); | 402 }); |
| 362 | 403 |
| 363 getDocLink("contribute", function(link) | 404 getDocLink("contribute", function(link) |
| 364 { | 405 { |
| 365 document.querySelector("#tab-contribute a").setAttribute("href", link); | 406 document.querySelector("#tab-contribute a").setAttribute("href", link); |
| 366 }); | 407 }); |
| 367 | 408 |
| 368 updateShareLink(); | 409 updateShareLink(); |
| 369 | 410 |
| 370 // Initialize interactive UI elements | 411 // Initialize interactive UI elements |
| 412 document.body.addEventListener("click", onClick, false); |
| 371 var placeholderValue = ext.i18n.getMessage("options_dialog_language_find"); | 413 var placeholderValue = ext.i18n.getMessage("options_dialog_language_find"); |
| 372 E("find-language").setAttribute("placeholder", placeholderValue); | 414 E("find-language").setAttribute("placeholder", placeholderValue); |
| 373 E("add-blocking-list").addEventListener("click", function() | |
| 374 { | |
| 375 openDialog("customlist"); | |
| 376 }, false); | |
| 377 E("add-website-language").addEventListener("click", function() | |
| 378 { | |
| 379 openDialog("language"); | |
| 380 }, false); | |
| 381 E("dialog-close").addEventListener("click", function() | |
| 382 { | |
| 383 delete document.body.dataset.dialog; | |
| 384 }, false); | |
| 385 E("edit-ownBlockingList-button").addEventListener("click", editCustomFilters
, false); | |
| 386 E("find-language").addEventListener("keyup", onFindLanguageKeyUp, false); | 415 E("find-language").addEventListener("keyup", onFindLanguageKeyUp, false); |
| 387 E("whitelisting").addEventListener("click", function(e) | |
| 388 { | |
| 389 var id = e.target.id; | |
| 390 if (id == "whitelisting-add-icon" || id == "whitelisting-enter-icon") | |
| 391 addWhitelistedDomain(); | |
| 392 else if (id == "whitelisting-cancel-button") | |
| 393 E("whitelisting-textbox").value = ""; | |
| 394 }, false); | |
| 395 E("whitelisting-add-button").addEventListener("click", addWhitelistedDomain,
false); | |
| 396 E("whitelisting-textbox").addEventListener("keypress", function(e) | 416 E("whitelisting-textbox").addEventListener("keypress", function(e) |
| 397 { | 417 { |
| 398 // e.keyCode has been deprecated so we attempt to use e.key | 418 // e.keyCode has been deprecated so we attempt to use e.key |
| 399 // keyCode "13" corresponds to "Enter" | 419 // keyCode "13" corresponds to "Enter" |
| 400 if ((e.key && e.key == "Enter") || (!e.key && e.keyCode == 13)) | 420 if ((e.key && e.key == "Enter") || (!e.key && e.keyCode == 13)) |
| 401 addWhitelistedDomain(); | 421 addWhitelistedDomain(); |
| 402 }, false); | 422 }, false); |
| 403 E("import-blockingList-button").addEventListener("click", function() | |
| 404 { | |
| 405 var url = E("blockingList-textbox").value; | |
| 406 addEnableSubscription(url); | |
| 407 delete document.body.dataset.dialog; | |
| 408 }, false); | |
| 409 } | 423 } |
| 410 | 424 |
| 411 function openDialog(name) | 425 function openDialog(name) |
| 412 { | 426 { |
| 413 document.body.dataset.dialog = name; | 427 document.body.setAttribute("data-dialog", name); |
| 414 } | 428 } |
| 415 | 429 |
| 416 function populateLists() | 430 function populateLists() |
| 417 { | 431 { |
| 418 subscriptionsMap = Object.create(null); | 432 subscriptionsMap = Object.create(null); |
| 419 filtersMap = Object.create(null); | 433 filtersMap = Object.create(null); |
| 420 recommendationsMap = Object.create(null); | 434 recommendationsMap = Object.create(null); |
| 421 | 435 |
| 422 // Empty collections and lists | 436 // Empty collections and lists |
| 423 for (var property in collections) | 437 for (var property in collections) |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 597 } | 611 } |
| 598 updateShareLink(); | 612 updateShareLink(); |
| 599 }); | 613 }); |
| 600 break; | 614 break; |
| 601 case "title": | 615 case "title": |
| 602 // TODO: NYI | 616 // TODO: NYI |
| 603 break; | 617 break; |
| 604 } | 618 } |
| 605 } | 619 } |
| 606 | 620 |
| 607 function showAddSubscriptionDialog(subscription) | |
| 608 { | |
| 609 E("blockingList-textbox").value = subscription.url; | |
| 610 openDialog("customlist"); | |
| 611 } | |
| 612 | |
| 613 function updateShareLink() | 621 function updateShareLink() |
| 614 { | 622 { |
| 615 ext.backgroundPage.sendMessage( | 623 ext.backgroundPage.sendMessage( |
| 616 { | 624 { |
| 617 type: "filters.blocked", | 625 type: "filters.blocked", |
| 618 url: "https://platform.twitter.com/widgets/", | 626 url: "https://platform.twitter.com/widgets/", |
| 619 requestType: "SCRIPT", | 627 requestType: "SCRIPT", |
| 620 docDomain: "adblockplus.org", | 628 docDomain: "adblockplus.org", |
| 621 thirdParty: true | 629 thirdParty: true |
| 622 }, | 630 }, |
| (...skipping 17 matching lines...) Expand all Loading... |
| 640 link: link | 648 link: link |
| 641 }, callback); | 649 }, callback); |
| 642 } | 650 } |
| 643 | 651 |
| 644 ext.onMessage.addListener(function(message) | 652 ext.onMessage.addListener(function(message) |
| 645 { | 653 { |
| 646 switch (message.type) | 654 switch (message.type) |
| 647 { | 655 { |
| 648 case "app.listen": | 656 case "app.listen": |
| 649 if (message.action == "addSubscription") | 657 if (message.action == "addSubscription") |
| 650 showAddSubscriptionDialog(message.args[0]); | 658 { |
| 659 var subscription = message.args[0]; |
| 660 var dialog = E("dialog-content-predefined"); |
| 661 dialog.querySelector("h3").textContent = subscription.title || ""; |
| 662 dialog.querySelector(".url").textContent = subscription.url; |
| 663 openDialog("predefined"); |
| 664 } |
| 651 break; | 665 break; |
| 652 case "filters.listen": | 666 case "filters.listen": |
| 653 onFilterMessage(message.action, message.args[0]); | 667 onFilterMessage(message.action, message.args[0]); |
| 654 break; | 668 break; |
| 655 case "subscriptions.listen": | 669 case "subscriptions.listen": |
| 656 onSubscriptionMessage(message.action, message.args[0]); | 670 onSubscriptionMessage(message.action, message.args[0]); |
| 657 break; | 671 break; |
| 658 } | 672 } |
| 659 }); | 673 }); |
| 660 | 674 |
| 661 ext.backgroundPage.sendMessage( | 675 ext.backgroundPage.sendMessage( |
| 662 { | 676 { |
| 663 type: "app.listen", | 677 type: "app.listen", |
| 664 filter: ["addSubscription"] | 678 filter: ["addSubscription"] |
| 665 }); | 679 }); |
| 666 ext.backgroundPage.sendMessage( | 680 ext.backgroundPage.sendMessage( |
| 667 { | 681 { |
| 668 type: "filters.listen", | 682 type: "filters.listen", |
| 669 filter: ["added", "loaded", "removed"] | 683 filter: ["added", "loaded", "removed"] |
| 670 }); | 684 }); |
| 671 ext.backgroundPage.sendMessage( | 685 ext.backgroundPage.sendMessage( |
| 672 { | 686 { |
| 673 type: "subscriptions.listen", | 687 type: "subscriptions.listen", |
| 674 filter: ["added", "disabled", "homepage", "removed", "title"] | 688 filter: ["added", "disabled", "homepage", "removed", "title"] |
| 675 }); | 689 }); |
| 676 | 690 |
| 677 window.addEventListener("DOMContentLoaded", onDOMLoaded, false); | 691 window.addEventListener("DOMContentLoaded", onDOMLoaded, false); |
| 678 })(); | 692 })(); |
| OLD | NEW |