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 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
63 | 63 |
64 Collection.prototype._getItemTitle = function(item, i) | 64 Collection.prototype._getItemTitle = function(item, i) |
65 { | 65 { |
66 if (item.url == acceptableAdsUrl) | 66 if (item.url == acceptableAdsUrl) |
67 return getMessage("options_acceptableAds_description"); | 67 return getMessage("options_acceptableAds_description"); |
68 if (this.details[i].useOriginalTitle && item.originalTitle) | 68 if (this.details[i].useOriginalTitle && item.originalTitle) |
69 return item.originalTitle; | 69 return item.originalTitle; |
70 return item.title || item.url || item.text; | 70 return item.title || item.url || item.text; |
71 }; | 71 }; |
72 | 72 |
73 Collection.prototype.addItems = function() | 73 Collection.prototype.addItem = function(item) |
74 { | 74 { |
75 var length = Array.prototype.push.apply(this.items, arguments); | 75 if (this.items.indexOf(item) >= 0) |
76 if (length == 0) | |
77 return; | 76 return; |
78 | 77 |
| 78 this.items.push(item); |
79 this.items.sort(function(a, b) | 79 this.items.sort(function(a, b) |
80 { | 80 { |
81 // Make sure that Acceptable Ads is always last, since it cannot be | 81 // Make sure that Acceptable Ads is always last, since it cannot be |
82 // disabled, but only be removed. That way it's grouped together with | 82 // disabled, but only be removed. That way it's grouped together with |
83 // the "Own filter list" which cannot be disabled either at the bottom | 83 // the "Own filter list" which cannot be disabled either at the bottom |
84 // of the filter lists in the Advanced tab. | 84 // of the filter lists in the Advanced tab. |
85 if (a.url == acceptableAdsUrl) | 85 if (a.url == acceptableAdsUrl) |
86 return 1; | 86 return 1; |
87 if (b.url == acceptableAdsUrl) | 87 if (b.url == acceptableAdsUrl) |
88 return -1; | 88 return -1; |
89 | 89 |
90 var aTitle = this._getItemTitle(a, 0).toLowerCase(); | 90 var aTitle = this._getItemTitle(a, 0).toLowerCase(); |
91 var bTitle = this._getItemTitle(b, 0).toLowerCase(); | 91 var bTitle = this._getItemTitle(b, 0).toLowerCase(); |
92 return aTitle.localeCompare(bTitle); | 92 return aTitle.localeCompare(bTitle); |
93 }.bind(this)); | 93 }.bind(this)); |
94 | 94 |
95 for (var j = 0; j < this.details.length; j++) | 95 for (var j = 0; j < this.details.length; j++) |
96 { | 96 { |
97 var table = E(this.details[j].id); | 97 var table = E(this.details[j].id); |
98 var template = table.querySelector("template"); | 98 var template = table.querySelector("template"); |
99 for (var i = 0; i < arguments.length; i++) | 99 var listItem = document.createElement("li"); |
100 { | 100 listItem.appendChild(document.importNode(template.content, true)); |
101 var item = arguments[i]; | 101 listItem.setAttribute("aria-label", this._getItemTitle(item, j)); |
102 var listItem = document.createElement("li"); | 102 listItem.setAttribute("data-access", item.url || item.text); |
103 listItem.appendChild(document.importNode(template.content, true)); | 103 listItem.setAttribute("role", "section"); |
104 listItem.setAttribute("aria-label", this._getItemTitle(item, j)); | 104 |
105 listItem.setAttribute("data-access", item.url || item.text); | 105 var label = listItem.querySelector(".display"); |
106 listItem.setAttribute("role", "section"); | 106 if (item.recommended && label.hasAttribute("data-tooltip")) |
107 | 107 { |
108 var label = listItem.querySelector(".display"); | 108 var tooltipId = label.getAttribute("data-tooltip"); |
109 if (item.recommended && label.hasAttribute("data-tooltip")) | 109 tooltipId = tooltipId.replace("%value%", item.recommended); |
110 { | 110 label.setAttribute("data-tooltip", tooltipId); |
111 var tooltipId = label.getAttribute("data-tooltip"); | 111 } |
112 tooltipId = tooltipId.replace("%value%", item.recommended); | 112 |
113 label.setAttribute("data-tooltip", tooltipId); | 113 var controls = listItem.querySelectorAll(".control"); |
| 114 for (var k = 0; k < controls.length; k++) |
| 115 { |
| 116 if (controls[k].hasAttribute("title")) |
| 117 { |
| 118 var titleValue = getMessage(controls[k].getAttribute("title")); |
| 119 controls[k].setAttribute("title", titleValue) |
114 } | 120 } |
115 | 121 } |
116 var controls = listItem.querySelectorAll(".control"); | 122 |
117 for (var k = 0; k < controls.length; k++) | 123 this._setEmpty(table, null); |
118 { | 124 if (table.hasChildNodes()) |
119 if (controls[k].hasAttribute("title")) | 125 { |
120 { | 126 table.insertBefore(listItem, |
121 var titleValue = getMessage(controls[k].getAttribute("title")); | 127 table.childNodes[this.items.indexOf(item)]); |
122 controls[k].setAttribute("title", titleValue) | 128 } |
123 } | 129 else |
124 } | 130 table.appendChild(listItem); |
125 | 131 this.updateItem(item); |
126 this._setEmpty(table, null); | |
127 if (table.hasChildNodes()) | |
128 { | |
129 table.insertBefore(listItem, | |
130 table.childNodes[this.items.indexOf(item)]); | |
131 } | |
132 else | |
133 table.appendChild(listItem); | |
134 this.updateItem(item); | |
135 } | |
136 } | 132 } |
137 return length; | 133 return length; |
138 }; | 134 }; |
139 | 135 |
140 Collection.prototype.removeItem = function(item) | 136 Collection.prototype.removeItem = function(item) |
141 { | 137 { |
142 var index = this.items.indexOf(item); | 138 var index = this.items.indexOf(item); |
143 if (index == -1) | 139 if (index == -1) |
144 return; | 140 return; |
145 | 141 |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
328 } | 324 } |
329 ]); | 325 ]); |
330 collections.filterLists = new Collection( | 326 collections.filterLists = new Collection( |
331 [ | 327 [ |
332 { | 328 { |
333 id: "all-filter-lists-table", | 329 id: "all-filter-lists-table", |
334 useOriginalTitle: true | 330 useOriginalTitle: true |
335 } | 331 } |
336 ]); | 332 ]); |
337 | 333 |
338 function updateLanguageCollections(subscription) | 334 function toggleShowLanguage(subscription) |
339 { | 335 { |
340 if (subscription.disabled) | 336 if (subscription.recommended == "ads") |
341 { | 337 { |
342 collections.allLangs.addItems(subscription); | 338 if (subscription.disabled) |
343 collections.langs.removeItem(subscription); | 339 { |
344 } | 340 collections.allLangs.addItem(subscription); |
345 else | 341 collections.langs.removeItem(subscription); |
346 { | 342 } |
347 collections.allLangs.removeItem(subscription); | 343 else |
348 collections.langs.addItems(subscription); | 344 { |
| 345 collections.allLangs.removeItem(subscription); |
| 346 collections.langs.addItem(subscription); |
| 347 } |
349 } | 348 } |
350 } | 349 } |
351 | 350 |
352 function addSubscription(subscription) | 351 function addSubscription(subscription) |
353 { | 352 { |
354 var collection; | 353 var collection; |
355 if (subscription.recommended) | 354 if (subscription.recommended) |
356 { | 355 { |
357 if (subscription.recommended != "ads") | 356 if (subscription.recommended != "ads") |
358 collection = collections.popular; | 357 collection = collections.popular; |
359 else if (subscription.disabled == false) | 358 else if (subscription.disabled == false) |
360 collection = collections.langs; | 359 collection = collections.langs; |
361 else | 360 else |
362 collection = collections.allLangs; | 361 collection = collections.allLangs; |
363 } | 362 } |
364 else if (subscription.url == acceptableAdsUrl) | 363 else if (subscription.url == acceptableAdsUrl) |
365 collection = collections.acceptableAds; | 364 collection = collections.acceptableAds; |
366 else | 365 else |
367 collection = collections.custom; | 366 collection = collections.custom; |
368 | 367 |
369 collection.addItems(subscription); | 368 collection.addItem(subscription); |
370 subscriptionsMap[subscription.url] = subscription; | 369 subscriptionsMap[subscription.url] = subscription; |
| 370 toggleShowLanguage(subscription); |
371 updateTooltips(); | 371 updateTooltips(); |
372 } | 372 } |
373 | 373 |
374 function updateSubscription(subscription) | 374 function updateSubscription(subscription) |
375 { | 375 { |
376 for (var name in collections) | 376 for (var name in collections) |
377 collections[name].updateItem(subscription); | 377 collections[name].updateItem(subscription); |
| 378 |
| 379 toggleShowLanguage(subscription); |
378 } | 380 } |
379 | 381 |
380 function updateFilter(filter) | 382 function updateFilter(filter) |
381 { | 383 { |
382 var match = filter.text.match(/^@@\|\|([^\/:]+)\^\$document$/); | 384 var match = filter.text.match(/^@@\|\|([^\/:]+)\^\$document$/); |
383 if (match && !filtersMap[filter.text]) | 385 if (match && !filtersMap[filter.text]) |
384 { | 386 { |
385 filter.title = match[1]; | 387 filter.title = match[1]; |
386 collections.whitelist.addItems(filter); | 388 collections.whitelist.addItem(filter); |
387 } | 389 } |
388 else | 390 else |
389 collections.customFilters.addItems(filter); | 391 collections.customFilters.addItem(filter); |
390 | 392 |
391 filtersMap[filter.text] = filter; | 393 filtersMap[filter.text] = filter; |
392 } | 394 } |
393 | 395 |
394 function loadRecommendations() | 396 function loadRecommendations() |
395 { | 397 { |
396 fetch("subscriptions.xml") | 398 fetch("subscriptions.xml") |
397 .then(function(response) | 399 .then(function(response) |
398 { | 400 { |
399 return response.text(); | 401 return response.text(); |
400 }) | 402 }) |
401 .then(function(text) | 403 .then(function(text) |
402 { | 404 { |
403 var list = document.getElementById("subscriptionSelector"); | 405 var list = document.getElementById("subscriptionSelector"); |
404 var doc = new DOMParser().parseFromString(text, "application/xml"); | 406 var doc = new DOMParser().parseFromString(text, "application/xml"); |
405 var elements = doc.documentElement.getElementsByTagName("subscription"); | 407 var elements = doc.documentElement.getElementsByTagName("subscription"); |
406 for (var i = 0; i < elements.length; i++) | 408 for (var i = 0; i < elements.length; i++) |
407 { | 409 { |
408 var element = elements[i]; | 410 var element = elements[i]; |
409 var type = element.getAttribute("type"); | 411 var type = element.getAttribute("type"); |
410 var subscription = { | 412 var subscription = { |
411 disabled: null, | 413 disabled: true, |
412 downloadStatus: null, | 414 downloadStatus: null, |
413 homepage: null, | 415 homepage: null, |
414 originalTitle: element.getAttribute("title"), | 416 originalTitle: element.getAttribute("title"), |
415 recommended: type, | 417 recommended: type, |
416 url: element.getAttribute("url") | 418 url: element.getAttribute("url") |
417 }; | 419 }; |
418 | 420 |
419 var prefix = element.getAttribute("prefixes"); | 421 var prefix = element.getAttribute("prefixes"); |
420 if (prefix) | 422 if (prefix) |
421 { | 423 { |
(...skipping 27 matching lines...) Expand all Loading... |
449 { | 451 { |
450 ext.backgroundPage.sendMessage(message, function(errors) | 452 ext.backgroundPage.sendMessage(message, function(errors) |
451 { | 453 { |
452 if (errors.length > 0) | 454 if (errors.length > 0) |
453 alert(errors.join("\n")); | 455 alert(errors.join("\n")); |
454 else if (onSuccess) | 456 else if (onSuccess) |
455 onSuccess(); | 457 onSuccess(); |
456 }); | 458 }); |
457 } | 459 } |
458 | 460 |
| 461 function openDocLink(id) |
| 462 { |
| 463 getDocLink(id, function(link) |
| 464 { |
| 465 if (id == "share-general") |
| 466 openSharePopup(link); |
| 467 else |
| 468 location.href = link; |
| 469 }); |
| 470 } |
| 471 |
| 472 function switchTab(id) |
| 473 { |
| 474 location.hash = id; |
| 475 } |
| 476 |
459 function onClick(e) | 477 function onClick(e) |
460 { | 478 { |
461 var context = document.querySelector(".show-context-menu"); | 479 var context = document.querySelector(".show-context-menu"); |
462 if (context) | 480 if (context) |
463 context.classList.remove("show-context-menu"); | 481 context.classList.remove("show-context-menu"); |
464 | 482 |
465 var element = e.target; | 483 var element = e.target; |
466 while (true) | 484 while (true) |
467 { | 485 { |
468 if (!element) | 486 if (!element) |
469 return; | 487 return; |
470 | 488 |
471 if (element.hasAttribute("data-action")) | 489 if (element.hasAttribute("data-action")) |
472 break; | 490 break; |
473 | 491 |
474 element = element.parentElement; | 492 element = element.parentElement; |
475 } | 493 } |
476 | 494 |
| 495 var element = findParentData(e.target, "action", true); |
477 var actions = element.getAttribute("data-action").split(","); | 496 var actions = element.getAttribute("data-action").split(","); |
478 for (var i = 0; i < actions.length; i++) | 497 for (var i = 0; i < actions.length; i++) |
479 { | 498 { |
480 switch (actions[i]) | 499 switch (actions[i]) |
481 { | 500 { |
482 case "add-domain-exception": | 501 case "add-domain-exception": |
483 addWhitelistedDomain(); | 502 addWhitelistedDomain(); |
484 break; | 503 break; |
485 case "add-predefined-subscription": | 504 case "add-predefined-subscription": |
486 var dialog = E("dialog-content-predefined"); | 505 var dialog = E("dialog-content-predefined"); |
(...skipping 19 matching lines...) Expand all Loading... |
506 case "edit-domain-exception": | 525 case "edit-domain-exception": |
507 document.querySelector("#whitelisting .controls").classList.add("mode-
edit"); | 526 document.querySelector("#whitelisting .controls").classList.add("mode-
edit"); |
508 E("whitelisting-textbox").focus(); | 527 E("whitelisting-textbox").focus(); |
509 break; | 528 break; |
510 case "import-subscription": | 529 case "import-subscription": |
511 var url = E("blockingList-textbox").value; | 530 var url = E("blockingList-textbox").value; |
512 addEnableSubscription(url); | 531 addEnableSubscription(url); |
513 closeDialog(); | 532 closeDialog(); |
514 break; | 533 break; |
515 case "open-dialog": | 534 case "open-dialog": |
516 openDialog(element.getAttribute("data-dialog")); | 535 var dialog = findParentData(element, "dialog", false); |
| 536 openDialog(dialog); |
| 537 break; |
| 538 case "open-doclink": |
| 539 var doclink = findParentData(element, "doclink", false); |
| 540 openDocLink(doclink); |
517 break; | 541 break; |
518 case "save-custom-filters": | 542 case "save-custom-filters": |
519 sendMessageHandleErrors( | 543 sendMessageHandleErrors( |
520 { | 544 { |
521 type: "filters.importRaw", | 545 type: "filters.importRaw", |
522 text: E("custom-filters-raw").value, | 546 text: E("custom-filters-raw").value, |
523 removeExisting: true | 547 removeExisting: true |
524 }, | 548 }, |
525 function() | 549 function() |
526 { | 550 { |
527 E("custom-filters").classList.remove("mode-edit"); | 551 E("custom-filters").classList.remove("mode-edit"); |
528 }); | 552 }); |
529 break; | 553 break; |
530 case "switch-tab": | 554 case "switch-tab": |
531 document.body.setAttribute("data-tab", | 555 var tabId = findParentData(e.target, "tab", false); |
532 element.getAttribute("data-tab")); | 556 switchTab(tabId); |
533 break; | 557 break; |
534 case "toggle-pref": | 558 case "toggle-pref": |
535 ext.backgroundPage.sendMessage( | 559 ext.backgroundPage.sendMessage( |
536 { | 560 { |
537 type: "prefs.toggle", | 561 type: "prefs.toggle", |
538 key: findParentData(element, "pref", false) | 562 key: findParentData(element, "pref", false) |
539 }); | 563 }); |
540 break; | 564 break; |
541 case "update-all-subscriptions": | 565 case "update-all-subscriptions": |
542 ext.backgroundPage.sendMessage( | 566 ext.backgroundPage.sendMessage( |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
590 ext.backgroundPage.sendMessage( | 614 ext.backgroundPage.sendMessage( |
591 { | 615 { |
592 type: "filters.remove", | 616 type: "filters.remove", |
593 text: findParentData(element, "access", false) | 617 text: findParentData(element, "access", false) |
594 }); | 618 }); |
595 break; | 619 break; |
596 } | 620 } |
597 } | 621 } |
598 } | 622 } |
599 | 623 |
| 624 function getKey(e) |
| 625 { |
| 626 // e.keyCode has been deprecated so we attempt to use e.key |
| 627 if ("key" in e) |
| 628 return e.key; |
| 629 return getKey.keys[e.keyCode]; |
| 630 } |
| 631 getKey.keys = { |
| 632 9: "Tab", |
| 633 13: "Enter", |
| 634 27: "Escape", |
| 635 37: "ArrowLeft", |
| 636 38: "ArrowUp", |
| 637 39: "ArrowRight", |
| 638 40: "ArrowDown" |
| 639 }; |
| 640 |
| 641 function onKeyUp(e) |
| 642 { |
| 643 var key = getKey(e); |
| 644 var element = document.activeElement; |
| 645 if (!key || !element) |
| 646 return; |
| 647 |
| 648 var container = findParentData(element, "action", true); |
| 649 if (!container || !container.hasAttribute("data-keys")) |
| 650 return; |
| 651 |
| 652 var keys = container.getAttribute("data-keys").split(" "); |
| 653 if (keys.indexOf(key) < 0) |
| 654 return; |
| 655 |
| 656 switch (container.getAttribute("data-action")) |
| 657 { |
| 658 case "add-domain-exception": |
| 659 addWhitelistedDomain(); |
| 660 break; |
| 661 case "open-doclink": |
| 662 var doclink = findParentData(element, "doclink", false); |
| 663 openDocLink(doclink); |
| 664 break; |
| 665 case "switch-tab": |
| 666 if (key == "Enter") |
| 667 { |
| 668 var tabId = findParentData(element, "tab", false); |
| 669 switchTab(tabId); |
| 670 } |
| 671 else if (element.hasAttribute("aria-selected")) |
| 672 { |
| 673 if (key == "ArrowLeft" || key == "ArrowUp") |
| 674 { |
| 675 element = element.previousElementSibling |
| 676 || container.lastElementChild; |
| 677 } |
| 678 else if (key == "ArrowRight" || key == "ArrowDown") |
| 679 { |
| 680 element = element.nextElementSibling |
| 681 || container.firstElementChild; |
| 682 } |
| 683 |
| 684 var tabId = findParentData(element, "tab", false); |
| 685 switchTab(tabId); |
| 686 } |
| 687 break; |
| 688 } |
| 689 } |
| 690 |
| 691 function selectTabItem(tabId, container, focus) |
| 692 { |
| 693 // Show tab content |
| 694 document.body.setAttribute("data-tab", tabId); |
| 695 |
| 696 // Select tab |
| 697 var tabList = container.querySelector("[role='tablist']"); |
| 698 if (!tabList) |
| 699 return null; |
| 700 |
| 701 var previousTab = tabList.querySelector("[aria-selected]"); |
| 702 previousTab.removeAttribute("aria-selected"); |
| 703 previousTab.setAttribute("tabindex", -1); |
| 704 |
| 705 var tab = tabList.querySelector("li[data-tab='" + tabId + "']"); |
| 706 tab.setAttribute("aria-selected", true); |
| 707 tab.setAttribute("tabindex", 0); |
| 708 |
| 709 var tabContentId = tab.getAttribute("aria-controls"); |
| 710 var tabContent = document.getElementById(tabContentId); |
| 711 |
| 712 // Select sub tabs |
| 713 if (tab.hasAttribute("data-subtab")) |
| 714 selectTabItem(tab.getAttribute("data-subtab"), tabContent, false); |
| 715 |
| 716 if (tab && focus) |
| 717 tab.focus(); |
| 718 |
| 719 return tabContent; |
| 720 } |
| 721 |
| 722 function onHashChange() |
| 723 { |
| 724 var hash = location.hash.substr(1); |
| 725 if (!hash) |
| 726 return; |
| 727 |
| 728 // Select tab and parent tabs |
| 729 var tabIds = hash.split("-"); |
| 730 var tabContent = document.body; |
| 731 for (var i = 0; i < tabIds.length; i++) |
| 732 { |
| 733 var tabId = tabIds.slice(0, i + 1).join("-"); |
| 734 tabContent = selectTabItem(tabId, tabContent, true); |
| 735 if (!tabContent) |
| 736 break; |
| 737 } |
| 738 } |
| 739 |
600 function onDOMLoaded() | 740 function onDOMLoaded() |
601 { | 741 { |
602 populateLists(); | 742 populateLists(); |
603 function onFindLanguageKeyUp() | 743 function onFindLanguageKeyUp() |
604 { | 744 { |
605 var searchStyle = E("search-style"); | 745 var searchStyle = E("search-style"); |
606 if (!this.value) | 746 if (!this.value) |
607 searchStyle.innerHTML = ""; | 747 searchStyle.innerHTML = ""; |
608 else | 748 else |
609 searchStyle.innerHTML = "#all-lang-table li:not([data-search*=\"" + this
.value.toLowerCase() + "\"]) { display: none; }"; | 749 searchStyle.innerHTML = "#all-lang-table li:not([data-search*=\"" + this
.value.toLowerCase() + "\"]) { display: none; }"; |
610 } | 750 } |
611 | 751 |
612 function getKey(e) | |
613 { | |
614 // e.keyCode has been deprecated so we attempt to use e.key | |
615 if ("key" in e) | |
616 return e.key; | |
617 return getKey.keys[e.keyCode]; | |
618 } | |
619 getKey.keys = { | |
620 9: "Tab", | |
621 13: "Enter", | |
622 27: "Escape" | |
623 }; | |
624 | |
625 // Initialize navigation sidebar | 752 // Initialize navigation sidebar |
626 ext.backgroundPage.sendMessage( | 753 ext.backgroundPage.sendMessage( |
627 { | 754 { |
628 type: "app.get", | 755 type: "app.get", |
629 what: "addonVersion" | 756 what: "addonVersion" |
630 }, | 757 }, |
631 function(addonVersion) | 758 function(addonVersion) |
632 { | 759 { |
633 E("abp-version").textContent = addonVersion; | 760 E("abp-version").textContent = addonVersion; |
634 }); | 761 }); |
635 getDocLink("releases", function(link) | 762 getDocLink("releases", function(link) |
636 { | 763 { |
637 E("link-version").setAttribute("href", link); | 764 E("link-version").setAttribute("href", link); |
638 }); | 765 }); |
639 | 766 |
640 getDocLink("contribute", function(link) | |
641 { | |
642 document.querySelector("#tab-contribute a").setAttribute("href", link); | |
643 }); | |
644 | |
645 updateShareLink(); | 767 updateShareLink(); |
646 updateTooltips(); | 768 updateTooltips(); |
647 | 769 |
648 // Initialize interactive UI elements | 770 // Initialize interactive UI elements |
649 document.body.addEventListener("click", onClick, false); | 771 document.body.addEventListener("click", onClick, false); |
| 772 document.body.addEventListener("keyup", onKeyUp, false); |
650 var placeholderValue = getMessage("options_dialog_language_find"); | 773 var placeholderValue = getMessage("options_dialog_language_find"); |
651 E("find-language").setAttribute("placeholder", placeholderValue); | 774 E("find-language").setAttribute("placeholder", placeholderValue); |
652 E("find-language").addEventListener("keyup", onFindLanguageKeyUp, false); | 775 E("find-language").addEventListener("keyup", onFindLanguageKeyUp, false); |
653 E("whitelisting-textbox").addEventListener("keypress", function(e) | 776 E("whitelisting-textbox").addEventListener("keypress", function(e) |
654 { | 777 { |
655 if (getKey(e) == "Enter") | 778 if (getKey(e) == "Enter") |
656 addWhitelistedDomain(); | 779 addWhitelistedDomain(); |
657 }, false); | 780 }, false); |
658 | 781 |
659 // Advanced tab | 782 // Advanced tab |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
727 } | 850 } |
728 } | 851 } |
729 else if (e.target.classList.contains("focus-last")) | 852 else if (e.target.classList.contains("focus-last")) |
730 { | 853 { |
731 e.preventDefault(); | 854 e.preventDefault(); |
732 this.querySelector(".focus-first").focus(); | 855 this.querySelector(".focus-first").focus(); |
733 } | 856 } |
734 break; | 857 break; |
735 } | 858 } |
736 }, false); | 859 }, false); |
| 860 |
| 861 onHashChange(); |
737 } | 862 } |
738 | 863 |
739 var focusedBeforeDialog = null; | 864 var focusedBeforeDialog = null; |
740 function openDialog(name) | 865 function openDialog(name) |
741 { | 866 { |
742 var dialog = E("dialog"); | 867 var dialog = E("dialog"); |
743 dialog.setAttribute("aria-hidden", false); | 868 dialog.setAttribute("aria-hidden", false); |
744 dialog.setAttribute("aria-labelledby", "dialog-title-" + name); | 869 dialog.setAttribute("aria-labelledby", "dialog-title-" + name); |
745 document.body.setAttribute("data-dialog", name); | 870 document.body.setAttribute("data-dialog", name); |
746 | 871 |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
897 if (property == "title" && knownSubscription.recommended) | 1022 if (property == "title" && knownSubscription.recommended) |
898 knownSubscription.originalTitle = subscription.title; | 1023 knownSubscription.originalTitle = subscription.title; |
899 else | 1024 else |
900 knownSubscription[property] = subscription[property]; | 1025 knownSubscription[property] = subscription[property]; |
901 } | 1026 } |
902 subscription = knownSubscription; | 1027 subscription = knownSubscription; |
903 } | 1028 } |
904 switch (action) | 1029 switch (action) |
905 { | 1030 { |
906 case "disabled": | 1031 case "disabled": |
907 if (subscription.recommended == "ads") | |
908 updateLanguageCollections(subscription); | |
909 updateSubscription(subscription); | 1032 updateSubscription(subscription); |
910 break; | 1033 break; |
911 case "downloading": | 1034 case "downloading": |
912 case "downloadStatus": | 1035 case "downloadStatus": |
913 case "homepage": | 1036 case "homepage": |
914 case "lastDownload": | 1037 case "lastDownload": |
915 case "title": | 1038 case "title": |
916 updateSubscription(subscription); | 1039 updateSubscription(subscription); |
917 break; | 1040 break; |
918 case "added": | 1041 case "added": |
919 if (subscription.recommended == "ads") | 1042 if (subscription.url in subscriptionsMap) |
920 updateLanguageCollections(subscription); | |
921 else if (subscription.url in subscriptionsMap) | |
922 updateSubscription(subscription); | 1043 updateSubscription(subscription); |
923 else | 1044 else |
924 addSubscription(subscription); | 1045 addSubscription(subscription); |
925 | 1046 |
926 collections.filterLists.addItems(subscription); | 1047 collections.filterLists.addItem(subscription); |
927 break; | 1048 break; |
928 case "removed": | 1049 case "removed": |
929 if (subscription.url == acceptableAdsUrl || subscription.recommended) | 1050 if (subscription.url == acceptableAdsUrl || subscription.recommended) |
930 { | 1051 { |
931 subscription.disabled = true; | 1052 subscription.disabled = true; |
932 onSubscriptionMessage("disabled", subscription); | 1053 onSubscriptionMessage("disabled", subscription); |
933 } | 1054 } |
934 else | 1055 else |
935 { | 1056 { |
936 collections.custom.removeItem(subscription); | 1057 collections.custom.removeItem(subscription); |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
995 break; | 1116 break; |
996 | 1117 |
997 case "safari_contentblocker": | 1118 case "safari_contentblocker": |
998 E("restart-safari").setAttribute("aria-hidden", value || initial); | 1119 E("restart-safari").setAttribute("aria-hidden", value || initial); |
999 break; | 1120 break; |
1000 } | 1121 } |
1001 | 1122 |
1002 var checkbox = document.querySelector("[data-pref='" + key + "'] button[role
='checkbox']"); | 1123 var checkbox = document.querySelector("[data-pref='" + key + "'] button[role
='checkbox']"); |
1003 if (checkbox) | 1124 if (checkbox) |
1004 checkbox.setAttribute("aria-checked", value); | 1125 checkbox.setAttribute("aria-checked", value); |
1005 } | |
1006 | |
1007 function onShareLinkClick(e) | |
1008 { | |
1009 e.preventDefault(); | |
1010 | |
1011 getDocLink("share-general", openSharePopup); | |
1012 } | 1126 } |
1013 | 1127 |
1014 function updateShareLink() | 1128 function updateShareLink() |
1015 { | 1129 { |
1016 var shareResources = [ | 1130 var shareResources = [ |
1017 "https://facebook.com/plugins/like.php?", | 1131 "https://facebook.com/plugins/like.php?", |
1018 "https://platform.twitter.com/widgets/", | 1132 "https://platform.twitter.com/widgets/", |
1019 "https://apis.google.com/se/0/_/+1/fastbutton?" | 1133 "https://apis.google.com/se/0/_/+1/fastbutton?" |
1020 ]; | 1134 ]; |
1021 var isAnyBlocked = false; | 1135 var isAnyBlocked = false; |
1022 var checksRemaining = shareResources.length; | 1136 var checksRemaining = shareResources.length; |
1023 | 1137 |
1024 function onResult(isBlocked) | 1138 function onResult(isBlocked) |
1025 { | 1139 { |
1026 isAnyBlocked |= isBlocked; | 1140 isAnyBlocked |= isBlocked; |
1027 if (!--checksRemaining) | 1141 if (!--checksRemaining) |
1028 { | 1142 { |
1029 // Hide the share tab if a script on the share page would be blocked | 1143 // Hide the share tab if a script on the share page would be blocked |
1030 var tab = E("tab-share"); | 1144 E("tab-share").hidden = isAnyBlocked; |
1031 if (isAnyBlocked) | |
1032 { | |
1033 tab.hidden = true; | |
1034 tab.removeEventListener("click", onShareLinkClick, false); | |
1035 } | |
1036 else | |
1037 tab.addEventListener("click", onShareLinkClick, false); | |
1038 } | 1145 } |
1039 } | 1146 } |
1040 | 1147 |
1041 for (var i = 0; i < shareResources.length; i++) | 1148 for (var i = 0; i < shareResources.length; i++) |
1042 checkShareResource(shareResources[i], onResult); | 1149 checkShareResource(shareResources[i], onResult); |
1043 } | 1150 } |
1044 | 1151 |
1045 function getMessages(id) | 1152 function getMessages(id) |
1046 { | 1153 { |
1047 var messages = []; | 1154 var messages = []; |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1169 "shouldShowBlockElementMenu"] | 1276 "shouldShowBlockElementMenu"] |
1170 }); | 1277 }); |
1171 ext.backgroundPage.sendMessage( | 1278 ext.backgroundPage.sendMessage( |
1172 { | 1279 { |
1173 type: "subscriptions.listen", | 1280 type: "subscriptions.listen", |
1174 filter: ["added", "disabled", "homepage", "lastDownload", "removed", | 1281 filter: ["added", "disabled", "homepage", "lastDownload", "removed", |
1175 "title", "downloadStatus", "downloading"] | 1282 "title", "downloadStatus", "downloading"] |
1176 }); | 1283 }); |
1177 | 1284 |
1178 window.addEventListener("DOMContentLoaded", onDOMLoaded, false); | 1285 window.addEventListener("DOMContentLoaded", onDOMLoaded, false); |
| 1286 window.addEventListener("hashchange", onHashChange, false); |
1179 })(); | 1287 })(); |
LEFT | RIGHT |