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

Side by Side Diff: new-options.js

Issue 29478597: Issue 5326 - General tab (HTML, strings and functionality) (Closed)
Patch Set: Created Aug. 16, 2017, 2:12 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
OLDNEW
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 setLinks, E */ 19 setLinks, 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 acceptableAdsPrivacyUrl = null;
28 let isCustomFiltersLoaded = false; 29 let isCustomFiltersLoaded = false;
29 let {getMessage} = ext.i18n; 30 let {getMessage} = ext.i18n;
30 let customFilters = []; 31 let customFilters = [];
31 let filterErrors = new Map([ 32 let filterErrors = new Map([
32 ["synchronize_invalid_url", 33 ["synchronize_invalid_url",
33 "options_filterList_lastDownload_invalidURL"], 34 "options_filterList_lastDownload_invalidURL"],
34 ["synchronize_connection_error", 35 ["synchronize_connection_error",
35 "options_filterList_lastDownload_connectionError"], 36 "options_filterList_lastDownload_connectionError"],
36 ["synchronize_invalid_data", 37 ["synchronize_invalid_data",
37 "options_filterList_lastDownload_invalidData"], 38 "options_filterList_lastDownload_invalidData"],
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 { 77 {
77 let access = (item.url || item.text).replace(/'/g, "\\'"); 78 let access = (item.url || item.text).replace(/'/g, "\\'");
78 return function(container) 79 return function(container)
79 { 80 {
80 return container.querySelector("[data-access='" + access + "']"); 81 return container.querySelector("[data-access='" + access + "']");
81 }; 82 };
82 }; 83 };
83 84
84 Collection.prototype._getItemTitle = function(item, i) 85 Collection.prototype._getItemTitle = function(item, i)
85 { 86 {
86 if (item.url == acceptableAdsUrl)
87 return getMessage("options_acceptableAds_description");
88 if (this.details[i].useOriginalTitle && item.originalTitle) 87 if (this.details[i].useOriginalTitle && item.originalTitle)
89 return item.originalTitle; 88 return item.originalTitle;
90 return item.title || item.url || item.text; 89 return item.title || item.url || item.text;
91 }; 90 };
92 91
93 Collection.prototype._sortItems = function() 92 Collection.prototype._sortItems = function()
94 { 93 {
95 this.items.sort((a, b) => 94 this.items.sort((a, b) =>
96 { 95 {
97 // Make sure that Acceptable Ads is always last, since it cannot be 96 // Make sure that Acceptable Ads is always last, since it cannot be
98 // disabled, but only be removed. That way it's grouped together with 97 // disabled, but only be removed. That way it's grouped together with
99 // the "Own filter list" which cannot be disabled either at the bottom 98 // the "Own filter list" which cannot be disabled either at the bottom
100 // of the filter lists in the Advanced tab. 99 // of the filter lists in the Advanced tab.
101 if (a.url == acceptableAdsUrl) 100 if (isAcceptableAds(a.url))
102 return 1; 101 return 1;
103 if (b.url == acceptableAdsUrl) 102 if (isAcceptableAds(b.url))
104 return -1; 103 return -1;
105 104
106 // Make sure that newly added entries always appear on top in descending 105 // Make sure that newly added entries always appear on top in descending
107 // chronological order 106 // chronological order
108 let aTimestamp = a[timestampUI] || 0; 107 let aTimestamp = a[timestampUI] || 0;
109 let bTimestamp = b[timestampUI] || 0; 108 let bTimestamp = b[timestampUI] || 0;
110 if (aTimestamp || bTimestamp) 109 if (aTimestamp || bTimestamp)
111 return bTimestamp - aTimestamp; 110 return bTimestamp - aTimestamp;
112 111
113 let aTitle = this._getItemTitle(a, 0).toLowerCase(); 112 let aTitle = this._getItemTitle(a, 0).toLowerCase();
(...skipping 13 matching lines...) Expand all
127 { 126 {
128 let detail = this.details[j]; 127 let detail = this.details[j];
129 let table = E(detail.id); 128 let table = E(detail.id);
130 let template = table.querySelector("template"); 129 let template = table.querySelector("template");
131 let listItem = document.createElement("li"); 130 let listItem = document.createElement("li");
132 listItem.appendChild(document.importNode(template.content, true)); 131 listItem.appendChild(document.importNode(template.content, true));
133 listItem.setAttribute("aria-label", this._getItemTitle(item, j)); 132 listItem.setAttribute("aria-label", this._getItemTitle(item, j));
134 listItem.setAttribute("data-access", item.url || item.text); 133 listItem.setAttribute("data-access", item.url || item.text);
135 listItem.setAttribute("role", "section"); 134 listItem.setAttribute("role", "section");
136 135
137 let label = listItem.querySelector(".display"); 136 let tooltip = listItem.querySelector("[data-tooltip]");
138 if (item.recommended && label.hasAttribute("data-tooltip")) 137 if (tooltip)
139 { 138 {
140 let tooltipId = label.getAttribute("data-tooltip"); 139 let tooltipId = tooltip.getAttribute("data-tooltip");
141 tooltipId = tooltipId.replace("%value%", item.recommended); 140 tooltipId = tooltipId.replace("%value%", item.recommended);
142 label.setAttribute("data-tooltip", tooltipId); 141 if (getMessage(tooltipId))
142 {
143 tooltip.setAttribute("data-tooltip", tooltipId);
144 }
145 else
146 {
147 tooltip.parentNode.removeChild(tooltip);
148 }
143 } 149 }
144 150
145 for (let control of listItem.querySelectorAll(".control")) 151 for (let control of listItem.querySelectorAll(".control"))
146 { 152 {
147 if (control.hasAttribute("title")) 153 if (control.hasAttribute("title"))
148 { 154 {
149 let titleValue = getMessage(control.getAttribute("title")); 155 let titleValue = getMessage(control.getAttribute("title"));
150 control.setAttribute("title", titleValue); 156 control.setAttribute("title", titleValue);
151 } 157 }
152 } 158 }
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 this._sortItems(); 213 this._sortItems();
208 let access = (item.url || item.text).replace(/'/g, "\\'"); 214 let access = (item.url || item.text).replace(/'/g, "\\'");
209 for (let i = 0; i < this.details.length; i++) 215 for (let i = 0; i < this.details.length; i++)
210 { 216 {
211 let table = E(this.details[i].id); 217 let table = E(this.details[i].id);
212 let element = table.querySelector("[data-access='" + access + "']"); 218 let element = table.querySelector("[data-access='" + access + "']");
213 if (!element) 219 if (!element)
214 continue; 220 continue;
215 221
216 let title = this._getItemTitle(item, i); 222 let title = this._getItemTitle(item, i);
217 element.querySelector(".display").textContent = title; 223 for (let displayElement of element.querySelectorAll(".display"))
Thomas Greiner 2017/08/16 17:57:09 According to https://developer.mozilla.org/en-US/d
saroyanm 2017/08/17 11:21:17 well spotted.
saroyanm 2017/08/17 21:24:07 Done.
224 displayElement.textContent = title;
225
218 element.setAttribute("aria-label", title); 226 element.setAttribute("aria-label", title);
219 if (this.details[i].searchable) 227 if (this.details[i].searchable)
220 element.setAttribute("data-search", title.toLowerCase()); 228 element.setAttribute("data-search", title.toLowerCase());
221 let control = element.querySelector(".control[role='checkbox']"); 229 let control = element.querySelector(".control[role='checkbox']");
222 if (control) 230 if (control)
223 { 231 {
224 control.setAttribute("aria-checked", item.disabled == false); 232 control.setAttribute("aria-checked", item.disabled == false);
225 if (item.url == acceptableAdsUrl && this == collections.filterLists) 233 if (isAcceptableAds(item.url) && this == collections.filterLists)
226 control.disabled = true; 234 control.disabled = true;
227 } 235 }
228 236
229 let lastUpdateElement = element.querySelector(".last-update"); 237 let lastUpdateElement = element.querySelector(".last-update");
230 if (lastUpdateElement) 238 if (lastUpdateElement)
231 { 239 {
232 let message = element.querySelector(".message"); 240 let message = element.querySelector(".message");
233 if (item.isDownloading) 241 if (item.isDownloading)
234 { 242 {
235 let text = getMessage("options_filterList_lastDownload_inProgress"); 243 let text = getMessage("options_filterList_lastDownload_inProgress");
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
323 index += (index == focusables.length - 1) ? -1 : 1; 331 index += (index == focusables.length - 1) ? -1 : 1;
324 332
325 let nextElement = focusables[index]; 333 let nextElement = focusables[index];
326 if (!nextElement) 334 if (!nextElement)
327 return false; 335 return false;
328 336
329 nextElement.focus(); 337 nextElement.focus();
330 return true; 338 return true;
331 } 339 }
332 340
333 collections.popular = new Collection([ 341 collections.security = new Collection([
334 { 342 {
335 id: "recommend-list-table" 343 id: "recommend-security-list-table"
336 } 344 }
337 ]); 345 ]);
338 collections.langs = new Collection([ 346 collections.langs = new Collection([
339 { 347 {
340 id: "blocking-languages-table", 348 id: "blocking-languages-table",
341 emptyText: ["options_dialog_language_added_empty"] 349 emptyText: ["options_language_empty"]
342 },
343 {
344 id: "blocking-languages-dialog-table",
345 emptyText: ["options_dialog_language_added_empty"]
346 } 350 }
347 ]); 351 ]);
348 collections.allLangs = new Collection([ 352 collections.allLangs = new Collection([
349 { 353 {
350 id: "all-lang-table", 354 id: "all-lang-table-add",
351 emptyText: ["options_dialog_language_other_empty"], 355 emptyText: ["options_dialog_language_other_empty"]
352 searchable: true
353 }
354 ]);
355 collections.acceptableAds = new Collection([
356 {
357 id: "acceptableads-table"
358 } 356 }
359 ]); 357 ]);
360 collections.custom = new Collection([ 358 collections.custom = new Collection([
361 { 359 {
362 id: "custom-list-table" 360 id: "custom-list-table"
363 } 361 }
364 ]); 362 ]);
365 collections.whitelist = new Collection([ 363 collections.whitelist = new Collection([
366 { 364 {
367 id: "whitelisting-table", 365 id: "whitelisting-table",
368 emptyText: ["options_whitelist_empty_1", "options_whitelist_empty_2"] 366 emptyText: ["options_whitelist_empty_1", "options_whitelist_empty_2"]
369 } 367 }
370 ]); 368 ]);
371 collections.filterLists = new Collection([ 369 collections.filterLists = new Collection([
372 { 370 {
373 id: "all-filter-lists-table", 371 id: "all-filter-lists-table",
374 useOriginalTitle: true 372 useOriginalTitle: true
375 } 373 }
376 ]); 374 ]);
377 375
378 function toggleShowLanguage(subscription) 376 function addSubscription(subscription)
379 { 377 {
380 if (subscription.recommended == "ads") 378 let collection = null;
379 if (subscription.recommended)
381 { 380 {
382 if (subscription.disabled) 381 if (isProtection(subscription.recommended))
383 { 382 {
383 collection = collections.security;
Thomas Greiner 2017/08/16 17:57:10 Detail: The previous comments for this still appli
saroyanm 2017/08/17 21:24:07 Done.
384 }
385 else if (subscription.recommended == "ads")
386 {
387 if (subscription.disabled == false)
388 collection = collections.langs;
389
384 collections.allLangs.addItem(subscription); 390 collections.allLangs.addItem(subscription);
385 collections.langs.removeItem(subscription); 391 }
392 else if (subscription.disabled == false)
393 {
394 collection = collections.custom;
Thomas Greiner 2017/08/16 17:57:10 So we're still putting recommended subscriptions i
saroyanm 2017/08/17 11:21:19 Yes, because according to the subscription.xml "Ma
Thomas Greiner 2017/08/17 12:06:05 If they are in subscriptions.xml but are not suppo
saroyanm 2017/08/17 12:32:08 Is it the decision that we can make ? If so I'm
Thomas Greiner 2017/08/17 12:49:06 We are the ones who added them in the first place
saroyanm 2017/08/17 14:06:18 Thanks for clarifying that, in this case whole log
saroyanm 2017/08/17 21:24:05 Done.
386 } 395 }
387 else 396 else
Thomas Greiner 2017/08/16 17:57:09 This part of the if-statement is redundant because
saroyanm 2017/08/17 11:21:18 agree.
saroyanm 2017/08/17 21:24:05 Done.
388 { 397 {
389 collections.allLangs.removeItem(subscription); 398 subscriptionsMap[subscription.url] = subscription;
390 collections.langs.addItem(subscription); 399 return;
391 } 400 }
392 } 401 }
393 } 402 else if (!isAcceptableAds(subscription.url))
403 {
404 collection = collections.custom;
405 }
394 406
395 function addSubscription(subscription) 407 if (collection)
396 { 408 collection.addItem(subscription);
397 let collection;
398 if (subscription.recommended)
399 {
400 if (subscription.recommended != "ads")
401 collection = collections.popular;
402 else if (subscription.disabled == false)
403 collection = collections.langs;
404 else
405 collection = collections.allLangs;
406 }
407 else if (subscription.url == acceptableAdsUrl)
408 collection = collections.acceptableAds;
409 else
410 collection = collections.custom;
411 409
412 collection.addItem(subscription);
413 subscriptionsMap[subscription.url] = subscription; 410 subscriptionsMap[subscription.url] = subscription;
414 toggleShowLanguage(subscription);
415 updateTooltips(); 411 updateTooltips();
416 } 412 }
417 413
418 function updateSubscription(subscription) 414 function updateSubscription(subscription)
419 { 415 {
420 for (let name in collections) 416 for (let name in collections)
421 collections[name].updateItem(subscription); 417 collections[name].updateItem(subscription);
422 418
423 toggleShowLanguage(subscription); 419 if (subscription.recommended == "ads")
420 {
421 if (subscription.disabled)
422 collections.langs.removeItem(subscription);
423 else
424 collections.langs.addItem(subscription);
425 }
426 else if (!isProtection(subscription.recommended) &&
427 !isAcceptableAds(subscription.url))
428 {
429 if (subscription.disabled == false)
430 {
431 collections.custom.addItem(subscription);
Thomas Greiner 2017/08/16 17:57:09 Again, it seems like we're still putting recommend
saroyanm 2017/08/17 11:21:17 As, same as the comment above, the definition of t
saroyanm 2017/08/17 21:24:05 Done.
432 updateTooltips();
433 }
434 else
435 {
436 collections.custom.removeItem(subscription);
437 }
438 }
424 } 439 }
425 440
426 function updateFilter(filter) 441 function updateFilter(filter)
427 { 442 {
428 let match = filter.text.match(whitelistedDomainRegexp); 443 let match = filter.text.match(whitelistedDomainRegexp);
429 if (match && !filtersMap[filter.text]) 444 if (match && !filtersMap[filter.text])
430 { 445 {
431 filter.title = match[1]; 446 filter.title = match[1];
432 collections.whitelist.addItem(filter); 447 collections.whitelist.addItem(filter);
433 } 448 }
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
554 let dialog = E("dialog-content-predefined"); 569 let dialog = E("dialog-content-predefined");
555 let title = dialog.querySelector("h3").textContent; 570 let title = dialog.querySelector("h3").textContent;
556 let url = dialog.querySelector(".url").textContent; 571 let url = dialog.querySelector(".url").textContent;
557 addEnableSubscription(url, title); 572 addEnableSubscription(url, title);
558 closeDialog(); 573 closeDialog();
559 break; 574 break;
560 } 575 }
561 case "cancel-custom-filters": 576 case "cancel-custom-filters":
562 setCustomFiltersView("read"); 577 setCustomFiltersView("read");
563 break; 578 break;
579 case "change-language-subscription":
580 for (let key in subscriptionsMap)
581 {
582 let subscription = subscriptionsMap[key];
583 let subscriptionType = subscription.recommended;
584 if (subscriptionType == "ads" && subscription.disabled == false)
585 {
586 ext.backgroundPage.sendMessage({
587 type: "subscriptions.remove",
588 url: subscription.url
589 });
590 ext.backgroundPage.sendMessage({
591 type: "subscriptions.add",
592 url: findParentData(element, "access", false)
593 });
594 }
Thomas Greiner 2017/08/16 17:57:10 Detail: Let's exit the loop as soon as we find the
saroyanm 2017/08/17 21:24:06 Done.
595 }
596 break;
564 case "close-dialog": 597 case "close-dialog":
565 closeDialog(); 598 closeDialog();
566 break; 599 break;
567 case "edit-custom-filters": 600 case "edit-custom-filters":
568 setCustomFiltersView("write"); 601 setCustomFiltersView("write");
569 break; 602 break;
570 case "import-subscription": { 603 case "import-subscription": {
571 let url = E("blockingList-textbox").value; 604 let url = E("blockingList-textbox").value;
572 addEnableSubscription(url); 605 addEnableSubscription(url);
573 closeDialog(); 606 closeDialog();
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
605 sendMessageHandleErrors({ 638 sendMessageHandleErrors({
606 type: "filters.importRaw", 639 type: "filters.importRaw",
607 text: E("custom-filters-raw").value, 640 text: E("custom-filters-raw").value,
608 removeExisting: true 641 removeExisting: true
609 }, 642 },
610 () => 643 () =>
611 { 644 {
612 setCustomFiltersView("read"); 645 setCustomFiltersView("read");
613 }); 646 });
614 break; 647 break;
648 case "switch-acceptable-ads":
Thomas Greiner 2017/08/16 17:57:10 It's great that the code has been made more consis
saroyanm 2017/08/17 11:21:18 I think I missed the part of combining them into o
Thomas Greiner 2017/08/17 12:06:05 Your proposal is perfectly fine. :)
saroyanm 2017/08/17 21:24:04 Done.
649 ext.backgroundPage.sendMessage({
650 type: "subscriptions.remove",
651 url: acceptableAdsPrivacyUrl
652 });
653 ext.backgroundPage.sendMessage({
654 type: "subscriptions.add",
655 url: acceptableAdsUrl
656 });
657 break;
658 case "switch-privacy-acceptable-ads":
659 ext.backgroundPage.sendMessage({
660 type: "subscriptions.remove",
661 url: acceptableAdsUrl
662 });
663 ext.backgroundPage.sendMessage({
664 type: "subscriptions.add",
665 url: acceptableAdsPrivacyUrl
666 });
667 break;
668 case "switch-no-acceptable-ads":
669 ext.backgroundPage.sendMessage({
670 type: "subscriptions.remove",
671 url: acceptableAdsPrivacyUrl
672 });
673 ext.backgroundPage.sendMessage({
674 type: "subscriptions.remove",
675 url: acceptableAdsUrl
676 });
677 break;
615 case "switch-tab": 678 case "switch-tab":
616 let tabId = findParentData(element, "tab", false); 679 let tabId = findParentData(element, "tab", false);
617 switchTab(tabId); 680 switchTab(tabId);
618 break; 681 break;
619 case "toggle-disable-subscription": 682 case "toggle-disable-subscription":
620 ext.backgroundPage.sendMessage({ 683 ext.backgroundPage.sendMessage({
621 type: "subscriptions.toggle", 684 type: "subscriptions.toggle",
622 keepInstalled: true, 685 keepInstalled: true,
623 url: findParentData(element, "access", false) 686 url: findParentData(element, "access", false)
624 }); 687 });
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
781 let tabId = tabIds.slice(0, i + 1).join("-"); 844 let tabId = tabIds.slice(0, i + 1).join("-");
782 tabContent = selectTabItem(tabId, tabContent, true); 845 tabContent = selectTabItem(tabId, tabContent, true);
783 if (!tabContent) 846 if (!tabContent)
784 break; 847 break;
785 } 848 }
786 } 849 }
787 850
788 function onDOMLoaded() 851 function onDOMLoaded()
789 { 852 {
790 populateLists(); 853 populateLists();
791 function onFindLanguageKeyUp()
792 {
793 let searchStyle = E("search-style");
794 if (!this.value)
795 searchStyle.innerHTML = "";
796 else
797 {
798 searchStyle.innerHTML = "#all-lang-table li:not([data-search*=\"" +
799 this.value.toLowerCase() + "\"]) { display: none; }";
800 }
801 }
802 854
803 // Initialize navigation sidebar 855 // Initialize navigation sidebar
804 ext.backgroundPage.sendMessage({ 856 ext.backgroundPage.sendMessage({
805 type: "app.get", 857 type: "app.get",
806 what: "addonVersion" 858 what: "addonVersion"
807 }, 859 },
808 (addonVersion) => 860 (addonVersion) =>
809 { 861 {
810 E("abp-version").textContent = addonVersion; 862 E("abp-version").textContent = addonVersion;
811 }); 863 });
812 getDocLink("releases", (link) => 864 getDocLink("releases", (link) =>
813 { 865 {
814 E("link-version").setAttribute("href", link); 866 E("link-version").setAttribute("href", link);
815 }); 867 });
816 868
817 updateShareLink(); 869 updateShareLink();
818 updateTooltips(); 870 updateTooltips();
819 871
820 // Initialize interactive UI elements 872 // Initialize interactive UI elements
821 document.body.addEventListener("click", onClick, false); 873 document.body.addEventListener("click", onClick, false);
822 document.body.addEventListener("keyup", onKeyUp, false); 874 document.body.addEventListener("keyup", onKeyUp, false);
823 let placeholderValue = getMessage("options_dialog_language_find");
824 E("find-language").setAttribute("placeholder", placeholderValue);
825 E("find-language").addEventListener("keyup", onFindLanguageKeyUp, false);
826 let exampleValue = getMessage("options_whitelist_placeholder_example", 875 let exampleValue = getMessage("options_whitelist_placeholder_example",
827 ["www.example.com"]); 876 ["www.example.com"]);
828 E("whitelisting-textbox").setAttribute("placeholder", exampleValue); 877 E("whitelisting-textbox").setAttribute("placeholder", exampleValue);
829 E("whitelisting-textbox").addEventListener("keyup", (e) => 878 E("whitelisting-textbox").addEventListener("keyup", (e) =>
830 { 879 {
831 E("whitelisting-add-button").disabled = !e.target.value; 880 E("whitelisting-add-button").disabled = !e.target.value;
832 }, false); 881 }, false);
833 882
883 getDocLink("acceptable_ads_criteria", (link) =>
884 {
885 setLinks("enable-aa-description", link);
886 });
887
834 // Advanced tab 888 // Advanced tab
835 let customize = document.querySelectorAll("#customize li[data-pref]"); 889 let customize = document.querySelectorAll("#customize li[data-pref]");
836 customize = Array.prototype.map.call(customize, (checkbox) => 890 customize = Array.prototype.map.call(customize, (checkbox) =>
837 { 891 {
838 return checkbox.getAttribute("data-pref"); 892 return checkbox.getAttribute("data-pref");
839 }); 893 });
840 for (let key of customize) 894 for (let key of customize)
841 { 895 {
842 getPref(key, (value) => 896 getPref(key, (value) =>
843 { 897 {
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
962 1016
963 function closeDialog() 1017 function closeDialog()
964 { 1018 {
965 let dialog = E("dialog"); 1019 let dialog = E("dialog");
966 dialog.setAttribute("aria-hidden", true); 1020 dialog.setAttribute("aria-hidden", true);
967 dialog.removeAttribute("aria-labelledby"); 1021 dialog.removeAttribute("aria-labelledby");
968 document.body.removeAttribute("data-dialog"); 1022 document.body.removeAttribute("data-dialog");
969 focusedBeforeDialog.focus(); 1023 focusedBeforeDialog.focus();
970 } 1024 }
971 1025
1026 function setDntNotification(state)
1027 {
1028 if (state)
1029 E("acceptable-ads").classList.add("show-dnt-notification");
1030 else
1031 E("acceptable-ads").classList.remove("show-dnt-notification");
1032 }
1033
1034 function setAcceptableAds(option)
1035 {
1036 let optionsContainer = E("acceptable-ads");
1037 switch (option)
1038 {
1039 case "default":
1040 optionsContainer.querySelector("[value='ads']").checked = true;
1041 break;
1042 case "privacy":
1043 optionsContainer.querySelector("[value='ads,privacy']").checked = true;
1044 break;
1045 case "none":
1046 optionsContainer.querySelector("[value='none']").checked = true;
1047 break;
1048 }
1049 }
1050
1051 function isAcceptableAds(url)
1052 {
1053 return url == acceptableAdsUrl || url == acceptableAdsPrivacyUrl;
1054 }
1055
1056 function isProtection(type)
1057 {
1058 return type == "privacy" || type == "social";
1059 }
1060
972 function populateLists() 1061 function populateLists()
973 { 1062 {
974 subscriptionsMap = Object.create(null); 1063 subscriptionsMap = Object.create(null);
975 filtersMap = Object.create(null); 1064 filtersMap = Object.create(null);
976 1065
977 // Empty collections and lists 1066 // Empty collections and lists
978 for (let property in collections) 1067 for (let property in collections)
979 collections[property].clearAll(); 1068 collections[property].clearAll();
980 1069
981 ext.backgroundPage.sendMessage({ 1070 ext.backgroundPage.sendMessage({
(...skipping 25 matching lines...) Expand all
1007 key: "subscriptions_exceptionsurl" 1096 key: "subscriptions_exceptionsurl"
1008 }, 1097 },
1009 (url) => 1098 (url) =>
1010 { 1099 {
1011 acceptableAdsUrl = url; 1100 acceptableAdsUrl = url;
1012 addSubscription({ 1101 addSubscription({
1013 url: acceptableAdsUrl, 1102 url: acceptableAdsUrl,
1014 disabled: true 1103 disabled: true
1015 }); 1104 });
1016 1105
1017 // Load user subscriptions
1018 ext.backgroundPage.sendMessage({ 1106 ext.backgroundPage.sendMessage({
1019 type: "subscriptions.get", 1107 type: "prefs.get",
1020 downloadable: true 1108 key: "subscriptions_exceptionsurl_privacy"
1021 }, 1109 },
1022 (subscriptions) => 1110 (urlPrivacy) =>
1023 { 1111 {
1024 for (let subscription of subscriptions) 1112 acceptableAdsPrivacyUrl = urlPrivacy;
1025 onSubscriptionMessage("added", subscription); 1113
1114 // Load user subscriptions
1115 ext.backgroundPage.sendMessage({
1116 type: "subscriptions.get",
1117 downloadable: true
1118 },
1119 (subscriptions) =>
1120 {
1121 for (let subscription of subscriptions)
1122 onSubscriptionMessage("added", subscription);
1123 });
1026 }); 1124 });
1027 }); 1125 });
1028 } 1126 }
1029 1127
1030 function addWhitelistedDomain() 1128 function addWhitelistedDomain()
1031 { 1129 {
1032 let domain = E("whitelisting-textbox"); 1130 let domain = E("whitelisting-textbox");
1033 for (let whitelistItem of collections.whitelist.items) 1131 for (let whitelistItem of collections.whitelist.items)
1034 { 1132 {
1035 if (whitelistItem.title == domain.value) 1133 if (whitelistItem.title == domain.value)
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
1123 case "lastDownload": 1221 case "lastDownload":
1124 case "title": 1222 case "title":
1125 updateSubscription(subscription); 1223 updateSubscription(subscription);
1126 break; 1224 break;
1127 case "added": 1225 case "added":
1128 if (subscription.url in subscriptionsMap) 1226 if (subscription.url in subscriptionsMap)
1129 updateSubscription(subscription); 1227 updateSubscription(subscription);
1130 else 1228 else
1131 addSubscription(subscription); 1229 addSubscription(subscription);
1132 1230
1231 if (subscription.url == acceptableAdsUrl)
1232 setAcceptableAds("default");
Thomas Greiner 2017/08/16 17:57:10 We cannot determine the current state based on whi
saroyanm 2017/08/17 11:21:18 I agree. I'll update accordingly.
saroyanm 2017/08/17 21:24:04 Done.
1233
1234 if (subscription.url == acceptableAdsPrivacyUrl)
1235 {
1236 setAcceptableAds("privacy");
1237 if (!navigator.doNotTrack)
1238 setDntNotification(true);
1239 }
1240
1133 collections.filterLists.addItem(subscription); 1241 collections.filterLists.addItem(subscription);
1134 break; 1242 break;
1135 case "removed": 1243 case "removed":
1136 if (subscription.url == acceptableAdsUrl || subscription.recommended) 1244 if (subscription.recommended == "ads" ||
1245 isProtection(subscription.recommended))
1137 { 1246 {
1138 subscription.disabled = true; 1247 subscription.disabled = true;
1139 onSubscriptionMessage("disabled", subscription); 1248 onSubscriptionMessage("disabled", subscription);
1140 } 1249 }
1250 if (isAcceptableAds(subscription.url))
1251 {
1252 setAcceptableAds("none");
1253 if (subscription.url == acceptableAdsPrivacyUrl)
1254 {
1255 setDntNotification(false);
1256 }
1257 }
1141 else 1258 else
1142 { 1259 {
1143 collections.custom.removeItem(subscription); 1260 collections.custom.removeItem(subscription);
Thomas Greiner 2017/08/16 17:57:09 Detail: Recommended subscriptions should not be in
saroyanm 2017/08/17 21:24:06 Done.
1144 delete subscriptionsMap[subscription.url]; 1261 delete subscriptionsMap[subscription.url];
Thomas Greiner 2017/08/16 17:57:10 In `addSubscription()` we're adding Acceptable Ads
saroyanm 2017/08/17 11:21:17 I tried to be consistent with old implementation h
Thomas Greiner 2017/08/17 12:06:06 Sounds good.
saroyanm 2017/08/17 21:24:07 With current implementation is more understandable
Thomas Greiner 2017/08/22 16:08:57 I don't think not removing recommended subscriptio
1145 } 1262 }
1146 collections.filterLists.removeItem(subscription); 1263 collections.filterLists.removeItem(subscription);
1147 break; 1264 break;
1148 } 1265 }
1149 1266
1150 updateShareLink(); 1267 updateShareLink();
1151 } 1268 }
1152 1269
1153 function hidePref(key, value) 1270 function hidePref(key, value)
1154 { 1271 {
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
1225 { 1342 {
1226 // Hide the share tab if a script on the share page would be blocked 1343 // Hide the share tab if a script on the share page would be blocked
1227 E("tab-share").hidden = isAnyBlocked; 1344 E("tab-share").hidden = isAnyBlocked;
1228 } 1345 }
1229 } 1346 }
1230 1347
1231 for (let sharedResource of shareResources) 1348 for (let sharedResource of shareResources)
1232 checkShareResource(sharedResource, onResult); 1349 checkShareResource(sharedResource, onResult);
1233 } 1350 }
1234 1351
1235 function getMessages(id)
1236 {
1237 let messages = [];
1238 for (let i = 1; true; i++)
1239 {
1240 let message = ext.i18n.getMessage(id + "_" + i);
1241 if (!message)
1242 break;
1243
1244 messages.push(message);
1245 }
1246 return messages;
1247 }
1248
1249 function updateTooltips() 1352 function updateTooltips()
1250 { 1353 {
1251 let anchors = document.querySelectorAll(":not(.tooltip) > [data-tooltip]"); 1354 let anchors = document.querySelectorAll(":not(.tooltip) > [data-tooltip]");
1252 for (let anchor of anchors) 1355 for (let anchor of anchors)
1253 { 1356 {
1254 let id = anchor.getAttribute("data-tooltip"); 1357 let id = anchor.getAttribute("data-tooltip");
1255 1358
1256 let wrapper = document.createElement("div"); 1359 let wrapper = document.createElement("div");
1257 wrapper.className = "tooltip"; 1360 wrapper.className = "tooltip";
1258 anchor.parentNode.replaceChild(wrapper, anchor); 1361 anchor.parentNode.replaceChild(wrapper, anchor);
1259 wrapper.appendChild(anchor); 1362 wrapper.appendChild(anchor);
1260 1363
1261 let topTexts = getMessages(id);
1262 let bottomTexts = getMessages(id + "_notes");
1263
1264 // We have to use native tooltips to avoid issues when attaching a tooltip
1265 // to an element in a scrollable list or otherwise it might get cut off
1266 if (anchor.hasAttribute("data-tooltip-native"))
1267 {
1268 let title = topTexts.concat(bottomTexts).join("\n\n");
1269 anchor.setAttribute("title", title);
1270 continue;
1271 }
1272
1273 let tooltip = document.createElement("div"); 1364 let tooltip = document.createElement("div");
1274 tooltip.setAttribute("role", "tooltip"); 1365 tooltip.setAttribute("role", "tooltip");
1275 1366
1276 let flip = anchor.getAttribute("data-tooltip-flip"); 1367 let paragraph = document.createElement("p");
1277 if (flip) 1368 paragraph.textContent = getMessage(id);
1278 tooltip.className = "flip-" + flip; 1369 tooltip.appendChild(paragraph);
1279
1280 let imageSource = anchor.getAttribute("data-tooltip-image");
1281 if (imageSource)
1282 {
1283 let image = document.createElement("img");
1284 image.src = imageSource;
1285 image.alt = "";
1286 tooltip.appendChild(image);
1287 }
1288
1289 for (let topText of topTexts)
1290 {
1291 let paragraph = document.createElement("p");
1292 paragraph.innerHTML = topText;
1293 tooltip.appendChild(paragraph);
1294 }
1295 if (bottomTexts.length > 0)
1296 {
1297 let notes = document.createElement("div");
1298 notes.className = "notes";
1299 for (let bottomText of bottomTexts)
1300 {
1301 let paragraph = document.createElement("p");
1302 paragraph.innerHTML = bottomText;
1303 notes.appendChild(paragraph);
1304 }
1305 tooltip.appendChild(notes);
1306 }
1307 1370
1308 wrapper.appendChild(tooltip); 1371 wrapper.appendChild(tooltip);
1309 } 1372 }
1310 } 1373 }
1311 1374
1312 ext.onMessage.addListener((message) => 1375 ext.onMessage.addListener((message) =>
1313 { 1376 {
1314 switch (message.type) 1377 switch (message.type)
1315 { 1378 {
1316 case "app.respond": 1379 case "app.respond":
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
1355 }); 1418 });
1356 ext.backgroundPage.sendMessage({ 1419 ext.backgroundPage.sendMessage({
1357 type: "subscriptions.listen", 1420 type: "subscriptions.listen",
1358 filter: ["added", "disabled", "homepage", "lastDownload", "removed", 1421 filter: ["added", "disabled", "homepage", "lastDownload", "removed",
1359 "title", "downloadStatus", "downloading"] 1422 "title", "downloadStatus", "downloading"]
1360 }); 1423 });
1361 1424
1362 window.addEventListener("DOMContentLoaded", onDOMLoaded, false); 1425 window.addEventListener("DOMContentLoaded", onDOMLoaded, false);
1363 window.addEventListener("hashchange", onHashChange, false); 1426 window.addEventListener("hashchange", onHashChange, false);
1364 } 1427 }
OLDNEW
« locale/en-US/new-options.json ('K') | « new-options.html ('k') | skin/new-options.css » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld