Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Delta Between Two Patch Sets: new-options.js

Issue 29445590: Issue 5255 - Advanced tab (HTML, strings and functionality) (Closed)
Left Patch Set: Removed unnecessary function call Created July 12, 2017, 3:31 p.m.
Right Patch Set: Fixed nits Created July 14, 2017, 5:43 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « new-options.html ('k') | skin/new-options.css » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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-2017 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 /* globals checkShareResource, getDocLink, i18nFormatDateTime, openSharePopup, 18 /* globals checkShareResource, getDocLink, i18nFormatDateTime, openSharePopup,
19 E */ 19 E */
20 20
21 "use strict"; 21 "use strict";
22 22
23 { 23 {
24 let subscriptionsMap = Object.create(null); 24 let subscriptionsMap = Object.create(null);
25 let filtersMap = Object.create(null); 25 let filtersMap = Object.create(null);
26 let collections = Object.create(null); 26 let collections = Object.create(null);
27 let acceptableAdsUrl = null; 27 let acceptableAdsUrl = null;
28 let isCustomFiltersLoaded = false; 28 let isCustomFiltersLoaded = false;
29 let {getMessage} = ext.i18n; 29 let {getMessage} = ext.i18n;
30 let customFiltersArray = []; 30 let customFilters = [];
31 let filterErrors = new Map([ 31 let filterErrors = new Map([
32 ["synchronize_invalid_url", 32 ["synchronize_invalid_url",
33 "options_filterList_lastDownload_invalidURL"], 33 "options_filterList_lastDownload_invalidURL"],
34 ["synchronize_connection_error", 34 ["synchronize_connection_error",
35 "options_filterList_lastDownload_connectionError"], 35 "options_filterList_lastDownload_connectionError"],
36 ["synchronize_invalid_data", 36 ["synchronize_invalid_data",
37 "options_filterList_lastDownload_invalidData"], 37 "options_filterList_lastDownload_invalidData"],
38 ["synchronize_checksum_mismatch", 38 ["synchronize_checksum_mismatch",
39 "options_filterList_lastDownload_checksumMismatch"] 39 "options_filterList_lastDownload_checksumMismatch"]
40 ]); 40 ]);
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
254 let lastUpdateDate = new Date(item.lastDownload * 1000); 254 let lastUpdateDate = new Date(item.lastDownload * 1000);
255 let monthName = lastUpdateDate.toLocaleString(undefined, 255 let monthName = lastUpdateDate.toLocaleString(undefined,
256 {month: "short"}); 256 {month: "short"});
257 let day = lastUpdateDate.getDate(); 257 let day = lastUpdateDate.getDate();
258 day = day < 10 ? "0" + day : day; 258 day = day < 10 ? "0" + day : day;
259 lastUpdateElement.textContent = day + " " + monthName + " " + 259 lastUpdateElement.textContent = day + " " + monthName + " " +
260 lastUpdateDate.getFullYear(); 260 lastUpdateDate.getFullYear();
261 } 261 }
262 else if (sinceUpdate > hourInMs) 262 else if (sinceUpdate > hourInMs)
263 { 263 {
264 let placeholder = [Math.round(sinceUpdate / hourInMs)];
265 lastUpdateElement.textContent = 264 lastUpdateElement.textContent =
266 getMessage("options_filterList_hours", placeholder); 265 getMessage("options_filterList_hours");
267 } 266 }
268 else if (sinceUpdate > minuteInMs) 267 else if (sinceUpdate > minuteInMs)
269 { 268 {
270 let placeholder = [Math.round(sinceUpdate / minuteInMs)];
271 lastUpdateElement.textContent = 269 lastUpdateElement.textContent =
272 getMessage("options_filterList_minutes", placeholder); 270 getMessage("options_filterList_minutes");
273 } 271 }
274 else 272 else
275 { 273 {
276 lastUpdateElement.textContent = 274 lastUpdateElement.textContent =
277 getMessage("options_filterList_now"); 275 getMessage("options_filterList_now");
278 } 276 }
279 element.classList.remove("show-message"); 277 element.classList.remove("show-message");
280 } 278 }
281 } 279 }
282 280
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
428 function updateFilter(filter) 426 function updateFilter(filter)
429 { 427 {
430 let match = filter.text.match(whitelistedDomainRegexp); 428 let match = filter.text.match(whitelistedDomainRegexp);
431 if (match && !filtersMap[filter.text]) 429 if (match && !filtersMap[filter.text])
432 { 430 {
433 filter.title = match[1]; 431 filter.title = match[1];
434 collections.whitelist.addItem(filter); 432 collections.whitelist.addItem(filter);
435 } 433 }
436 else 434 else
437 { 435 {
438 customFiltersArray.push(filter.text); 436 customFilters.push(filter.text);
439 if (isCustomFiltersLoaded) 437 if (isCustomFiltersLoaded)
440 updateCustomFiltersUi(); 438 updateCustomFiltersUi();
441 } 439 }
442 440
443 filtersMap[filter.text] = filter; 441 filtersMap[filter.text] = filter;
444 } 442 }
445 443
446 function removeCustomFilter(text) 444 function removeCustomFilter(text)
447 { 445 {
448 let index = customFiltersArray.indexOf(text); 446 let index = customFilters.indexOf(text);
449 if (index >= 0) 447 if (index >= 0)
450 customFiltersArray.splice(index, 1); 448 customFilters.splice(index, 1);
451 449
452 updateCustomFiltersUi(); 450 updateCustomFiltersUi();
453 } 451 }
454 452
455 function updateCustomFiltersUi() 453 function updateCustomFiltersUi()
456 { 454 {
457 let customFiltersListElement = E("custom-filters-raw"); 455 let customFiltersListElement = E("custom-filters-raw");
458 customFiltersListElement.value = ""; 456 customFiltersListElement.value = customFilters.join("\n");
459 customFiltersListElement.value = customFiltersArray.join("\n");
460 } 457 }
461 458
462 function loadRecommendations() 459 function loadRecommendations()
463 { 460 {
464 fetch("subscriptions.xml") 461 fetch("subscriptions.xml")
465 .then((response) => 462 .then((response) =>
466 { 463 {
467 return response.text(); 464 return response.text();
468 }) 465 })
469 .then((text) => 466 .then((text) =>
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
536 else 533 else
537 location.href = link; 534 location.href = link;
538 }); 535 });
539 } 536 }
540 537
541 function switchTab(id) 538 function switchTab(id)
542 { 539 {
543 location.hash = id; 540 location.hash = id;
544 } 541 }
545 542
546 function execAction(action, element, event) 543 function execAction(action, element)
547 { 544 {
548 switch (action) 545 switch (action)
549 { 546 {
550 case "add-domain-exception": 547 case "add-domain-exception":
551 addWhitelistedDomain(); 548 addWhitelistedDomain();
552 break; 549 break;
553 case "add-language-subscription": 550 case "add-language-subscription":
554 addEnableSubscription(findParentData(element, "access", false)); 551 addEnableSubscription(findParentData(element, "access", false));
555 break; 552 break;
556 case "add-predefined-subscription": { 553 case "add-predefined-subscription": {
557 let dialog = E("dialog-content-predefined"); 554 let dialog = E("dialog-content-predefined");
558 let title = dialog.querySelector("h3").textContent; 555 let title = dialog.querySelector("h3").textContent;
559 let url = dialog.querySelector(".url").textContent; 556 let url = dialog.querySelector(".url").textContent;
560 addEnableSubscription(url, title); 557 addEnableSubscription(url, title);
561 closeDialog(); 558 closeDialog();
562 break; 559 break;
563 } 560 }
564 case "cancel-custom-filters": 561 case "cancel-custom-filters":
565 updateCustomFiltersUi();
566 setCustomFiltersView("read"); 562 setCustomFiltersView("read");
567 break; 563 break;
568 case "close-dialog": 564 case "close-dialog":
569 closeDialog(); 565 closeDialog();
570 break; 566 break;
571 case "edit-custom-filters": 567 case "edit-custom-filters":
572 setCustomFiltersView("write"); 568 setCustomFiltersView("write");
573 break; 569 break;
574 case "import-subscription": { 570 case "import-subscription": {
575 let url = E("blockingList-textbox").value; 571 let url = E("blockingList-textbox").value;
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
654 ext.backgroundPage.sendMessage({ 650 ext.backgroundPage.sendMessage({
655 type: "subscriptions.update", 651 type: "subscriptions.update",
656 url: findParentData(element, "access", false) 652 url: findParentData(element, "access", false)
657 }); 653 });
658 break; 654 break;
659 } 655 }
660 } 656 }
661 657
662 function setCustomFiltersView(mode) 658 function setCustomFiltersView(mode)
663 { 659 {
664 let customFilters = E("custom-filters"); 660 let customFiltersElement = E("custom-filters-raw");
665 let customFiltersListElement = E("custom-filters-raw"); 661 updateCustomFiltersUi();
666 if (mode == "read") 662 if (mode == "read")
667 { 663 {
668 customFiltersListElement.disabled = true; 664 customFiltersElement.disabled = true;
669 if (!customFiltersListElement.value) 665 if (!customFiltersElement.value)
670 { 666 {
671 setCustomFiltersView("empty"); 667 setCustomFiltersView("empty");
672 return; 668 return;
673 } 669 }
674 } 670 }
675 else if (mode == "write") 671 else if (mode == "write")
676 { 672 {
677 updateCustomFiltersUi(); 673 customFiltersElement.disabled = false;
678 customFiltersListElement.disabled = false; 674 }
679 } 675
680 676 E("custom-filters").dataset.mode = mode;
681 customFilters.dataset.mode = mode;
682 } 677 }
683 678
684 function onClick(e) 679 function onClick(e)
685 { 680 {
686 let context = document.querySelector(".show-context-menu"); 681 let context = document.querySelector(".show-context-menu");
687 if (context) 682 if (context)
688 context.classList.remove("show-context-menu"); 683 context.classList.remove("show-context-menu");
689 684
690 let actions = findParentData(e.target, "action", false); 685 let actions = findParentData(e.target, "action", false);
691 if (!actions) 686 if (!actions)
692 return; 687 return;
693 688
694 actions = actions.split(","); 689 actions = actions.split(",");
695 for (let action of actions) 690 for (let action of actions)
696 { 691 {
697 execAction(action, e.target, e); 692 execAction(action, e.target);
698 } 693 }
699 } 694 }
700 695
701 function getKey(e) 696 function getKey(e)
702 { 697 {
703 // e.keyCode has been deprecated so we attempt to use e.key 698 // e.keyCode has been deprecated so we attempt to use e.key
704 if ("key" in e) 699 if ("key" in e)
705 return e.key; 700 return e.key;
706 return getKey.keys[e.keyCode]; 701 return getKey.keys[e.keyCode];
707 } 702 }
(...skipping 26 matching lines...) Expand all
734 { 729 {
735 if (key == "ArrowLeft" || key == "ArrowUp") 730 if (key == "ArrowLeft" || key == "ArrowUp")
736 element = element.previousElementSibling || container.lastElementChild; 731 element = element.previousElementSibling || container.lastElementChild;
737 else if (key == "ArrowRight" || key == "ArrowDown") 732 else if (key == "ArrowRight" || key == "ArrowDown")
738 element = element.nextElementSibling || container.firstElementChild; 733 element = element.nextElementSibling || container.firstElementChild;
739 } 734 }
740 735
741 let actions = container.getAttribute("data-action").split(","); 736 let actions = container.getAttribute("data-action").split(",");
742 for (let action of actions) 737 for (let action of actions)
743 { 738 {
744 execAction(action, element, e); 739 execAction(action, element);
745 } 740 }
746 } 741 }
747 742
748 function selectTabItem(tabId, container, focus) 743 function selectTabItem(tabId, container, focus)
749 { 744 {
750 // Show tab content 745 // Show tab content
751 document.body.setAttribute("data-tab", tabId); 746 document.body.setAttribute("data-tab", tabId);
752 747
753 // Select tab 748 // Select tab
754 let tabList = container.querySelector("[role='tablist']"); 749 let tabList = container.querySelector("[role='tablist']");
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
821 816
822 updateShareLink(); 817 updateShareLink();
823 updateTooltips(); 818 updateTooltips();
824 819
825 // Initialize interactive UI elements 820 // Initialize interactive UI elements
826 document.body.addEventListener("click", onClick, false); 821 document.body.addEventListener("click", onClick, false);
827 document.body.addEventListener("keyup", onKeyUp, false); 822 document.body.addEventListener("keyup", onKeyUp, false);
828 let placeholderValue = getMessage("options_dialog_language_find"); 823 let placeholderValue = getMessage("options_dialog_language_find");
829 E("find-language").setAttribute("placeholder", placeholderValue); 824 E("find-language").setAttribute("placeholder", placeholderValue);
830 E("find-language").addEventListener("keyup", onFindLanguageKeyUp, false); 825 E("find-language").addEventListener("keyup", onFindLanguageKeyUp, false);
831 let exampleValue = getMessage("options_whitelist_placeholder_example", 826 let exampleValue = getMessage("options_whitelist_placeholder_example",
832 ["www.example.com"]); 827 ["www.example.com"]);
833 E("whitelisting-textbox").setAttribute("placeholder", exampleValue); 828 E("whitelisting-textbox").setAttribute("placeholder", exampleValue);
834 E("whitelisting-textbox").addEventListener("keyup", (e) => 829 E("whitelisting-textbox").addEventListener("keyup", (e) =>
835 { 830 {
836 E("whitelisting-add-button").disabled = !e.target.value; 831 E("whitelisting-add-button").disabled = !e.target.value;
837 }, false); 832 }, false);
838 833
839 // Advanced tab 834 // Advanced tab
840 let customize = document.querySelectorAll("#customize li[data-pref]"); 835 let customize = document.querySelectorAll("#customize li[data-pref]");
841 customize = Array.prototype.map.call(customize, (checkbox) => 836 customize = Array.prototype.map.call(customize, (checkbox) =>
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
995 ext.backgroundPage.sendMessage({ 990 ext.backgroundPage.sendMessage({
996 type: "filters.get", 991 type: "filters.get",
997 subscriptionUrl: subscription.url 992 subscriptionUrl: subscription.url
998 }, 993 },
999 (filters) => 994 (filters) =>
1000 { 995 {
1001 for (let filter of filters) 996 for (let filter of filters)
1002 updateFilter(filter); 997 updateFilter(filter);
1003 998
1004 isCustomFiltersLoaded = true; 999 isCustomFiltersLoaded = true;
1005 updateCustomFiltersUi();
1006 setCustomFiltersView("read"); 1000 setCustomFiltersView("read");
1007 }); 1001 });
1008 } 1002 }
1009 }); 1003 });
1010 loadRecommendations(); 1004 loadRecommendations();
1011 ext.backgroundPage.sendMessage({ 1005 ext.backgroundPage.sendMessage({
1012 type: "prefs.get", 1006 type: "prefs.get",
1013 key: "subscriptions_exceptionsurl" 1007 key: "subscriptions_exceptionsurl"
1014 }, 1008 },
1015 (url) => 1009 (url) =>
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
1049 if (domain.value) 1043 if (domain.value)
1050 { 1044 {
1051 sendMessageHandleErrors({ 1045 sendMessageHandleErrors({
1052 type: "filters.add", 1046 type: "filters.add",
1053 text: "@@||" + domain.value.toLowerCase() + "^$document" 1047 text: "@@||" + domain.value.toLowerCase() + "^$document"
1054 }); 1048 });
1055 } 1049 }
1056 1050
1057 domain.value = ""; 1051 domain.value = "";
1058 E("whitelisting-add-button").disabled = true; 1052 E("whitelisting-add-button").disabled = true;
1059 }
1060
1061 function editCustomFilters()
saroyanm 2017/07/14 17:11:07 This is not used anymore.
1062 {
1063 if (!isCustomFiltersLoaded)
1064 {
1065 console.error("Custom filters are not loaded");
1066 return;
1067 }
1068
1069 E("custom-filters").classList.add("mode-edit");
1070 let filterTexts = [];
1071 for (let customFilterItem of collections.customFilters.items)
1072 filterTexts.push(customFilterItem.text);
1073 E("custom-filters-raw").value = filterTexts.join("\n");
1074 } 1053 }
1075 1054
1076 function addEnableSubscription(url, title, homepage) 1055 function addEnableSubscription(url, title, homepage)
1077 { 1056 {
1078 let messageType = null; 1057 let messageType = null;
1079 let knownSubscription = subscriptionsMap[url]; 1058 let knownSubscription = subscriptionsMap[url];
1080 if (knownSubscription && knownSubscription.disabled == true) 1059 if (knownSubscription && knownSubscription.disabled == true)
1081 messageType = "subscriptions.toggle"; 1060 messageType = "subscriptions.toggle";
1082 else 1061 else
1083 messageType = "subscriptions.add"; 1062 messageType = "subscriptions.add";
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after
1376 }); 1355 });
1377 ext.backgroundPage.sendMessage({ 1356 ext.backgroundPage.sendMessage({
1378 type: "subscriptions.listen", 1357 type: "subscriptions.listen",
1379 filter: ["added", "disabled", "homepage", "lastDownload", "removed", 1358 filter: ["added", "disabled", "homepage", "lastDownload", "removed",
1380 "title", "downloadStatus", "downloading"] 1359 "title", "downloadStatus", "downloading"]
1381 }); 1360 });
1382 1361
1383 window.addEventListener("DOMContentLoaded", onDOMLoaded, false); 1362 window.addEventListener("DOMContentLoaded", onDOMLoaded, false);
1384 window.addEventListener("hashchange", onHashChange, false); 1363 window.addEventListener("hashchange", onHashChange, false);
1385 } 1364 }
LEFTRIGHT

Powered by Google App Engine
This is Rietveld