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: rebase Created Aug. 23, 2017, 12:36 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
« no previous file with comments | « new-options.html ('k') | skin/new-options.css » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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-present eyeo GmbH 3 * Copyright (C) 2006-present 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 }
143 } 145 }
144 146
145 for (let control of listItem.querySelectorAll(".control")) 147 for (let control of listItem.querySelectorAll(".control"))
146 { 148 {
147 if (control.hasAttribute("title")) 149 if (control.hasAttribute("title"))
148 { 150 {
149 let titleValue = getMessage(control.getAttribute("title")); 151 let titleValue = getMessage(control.getAttribute("title"));
150 control.setAttribute("title", titleValue); 152 control.setAttribute("title", titleValue);
151 } 153 }
152 } 154 }
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 this._sortItems(); 209 this._sortItems();
208 let access = (item.url || item.text).replace(/'/g, "\\'"); 210 let access = (item.url || item.text).replace(/'/g, "\\'");
209 for (let i = 0; i < this.details.length; i++) 211 for (let i = 0; i < this.details.length; i++)
210 { 212 {
211 let table = E(this.details[i].id); 213 let table = E(this.details[i].id);
212 let element = table.querySelector("[data-access='" + access + "']"); 214 let element = table.querySelector("[data-access='" + access + "']");
213 if (!element) 215 if (!element)
214 continue; 216 continue;
215 217
216 let title = this._getItemTitle(item, i); 218 let title = this._getItemTitle(item, i);
217 element.querySelector(".display").textContent = title; 219 let displays = element.querySelectorAll(".display");
220 for (let j = 0; j < displays.length; j++)
221 displays[j].textContent = title;
222
218 element.setAttribute("aria-label", title); 223 element.setAttribute("aria-label", title);
219 if (this.details[i].searchable) 224 if (this.details[i].searchable)
220 element.setAttribute("data-search", title.toLowerCase()); 225 element.setAttribute("data-search", title.toLowerCase());
221 let control = element.querySelector(".control[role='checkbox']"); 226 let control = element.querySelector(".control[role='checkbox']");
222 if (control) 227 if (control)
223 { 228 {
224 control.setAttribute("aria-checked", item.disabled == false); 229 control.setAttribute("aria-checked", item.disabled == false);
225 if (item.url == acceptableAdsUrl && this == collections.filterLists) 230 if (isAcceptableAds(item.url) && this == collections.filterLists)
226 control.disabled = true; 231 control.disabled = true;
227 } 232 }
228 233
229 let lastUpdateElement = element.querySelector(".last-update"); 234 let lastUpdateElement = element.querySelector(".last-update");
230 if (lastUpdateElement) 235 if (lastUpdateElement)
231 { 236 {
232 let message = element.querySelector(".message"); 237 let message = element.querySelector(".message");
233 if (item.isDownloading) 238 if (item.isDownloading)
234 { 239 {
235 let text = getMessage("options_filterList_lastDownload_inProgress"); 240 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; 328 index += (index == focusables.length - 1) ? -1 : 1;
324 329
325 let nextElement = focusables[index]; 330 let nextElement = focusables[index];
326 if (!nextElement) 331 if (!nextElement)
327 return false; 332 return false;
328 333
329 nextElement.focus(); 334 nextElement.focus();
330 return true; 335 return true;
331 } 336 }
332 337
333 collections.popular = new Collection([ 338 collections.protection = new Collection([
334 { 339 {
335 id: "recommend-list-table" 340 id: "recommend-protection-list-table"
336 } 341 }
337 ]); 342 ]);
338 collections.langs = new Collection([ 343 collections.langs = new Collection([
339 { 344 {
340 id: "blocking-languages-table", 345 id: "blocking-languages-table",
341 emptyText: ["options_dialog_language_added_empty"] 346 emptyText: ["options_language_empty"]
342 },
343 {
344 id: "blocking-languages-dialog-table",
345 emptyText: ["options_dialog_language_added_empty"]
346 } 347 }
347 ]); 348 ]);
348 collections.allLangs = new Collection([ 349 collections.allLangs = new Collection([
349 { 350 {
350 id: "all-lang-table", 351 id: "all-lang-table-add",
351 emptyText: ["options_dialog_language_other_empty"], 352 emptyText: ["options_dialog_language_other_empty"]
352 searchable: true
353 }
354 ]);
355 collections.acceptableAds = new Collection([
356 {
357 id: "acceptableads-table"
358 } 353 }
359 ]); 354 ]);
360 collections.custom = new Collection([ 355 collections.custom = new Collection([
361 { 356 {
362 id: "custom-list-table" 357 id: "custom-list-table"
363 } 358 }
364 ]); 359 ]);
365 collections.whitelist = new Collection([ 360 collections.whitelist = new Collection([
366 { 361 {
367 id: "whitelisting-table", 362 id: "whitelisting-table",
368 emptyText: ["options_whitelist_empty_1", "options_whitelist_empty_2"] 363 emptyText: ["options_whitelist_empty_1", "options_whitelist_empty_2"]
369 } 364 }
370 ]); 365 ]);
371 collections.filterLists = new Collection([ 366 collections.filterLists = new Collection([
372 { 367 {
373 id: "all-filter-lists-table", 368 id: "all-filter-lists-table",
374 useOriginalTitle: true 369 useOriginalTitle: true
375 } 370 }
376 ]); 371 ]);
377 372
378 function toggleShowLanguage(subscription) 373 function addSubscription(subscription)
379 { 374 {
380 if (subscription.recommended == "ads") 375 let collection = null;
376 if (subscription.recommended)
381 { 377 {
382 if (subscription.disabled) 378 if (subscription.recommended == "ads")
383 { 379 {
380 if (subscription.disabled == false)
381 collection = collections.langs;
382
384 collections.allLangs.addItem(subscription); 383 collections.allLangs.addItem(subscription);
385 collections.langs.removeItem(subscription);
386 } 384 }
387 else 385 else
388 { 386 {
389 collections.allLangs.removeItem(subscription); 387 collection = collections.protection;
390 collections.langs.addItem(subscription);
391 } 388 }
392 } 389 }
393 } 390 else if (!isAcceptableAds(subscription.url))
391 {
392 collection = collections.custom;
393 }
394 394
395 function addSubscription(subscription) 395 if (collection)
396 { 396 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 397
412 collection.addItem(subscription);
413 subscriptionsMap[subscription.url] = subscription; 398 subscriptionsMap[subscription.url] = subscription;
414 toggleShowLanguage(subscription);
415 updateTooltips(); 399 updateTooltips();
416 } 400 }
417 401
418 function updateSubscription(subscription) 402 function updateSubscription(subscription)
419 { 403 {
420 for (let name in collections) 404 for (let name in collections)
421 collections[name].updateItem(subscription); 405 collections[name].updateItem(subscription);
422 406
423 toggleShowLanguage(subscription); 407 if (subscription.recommended == "ads")
408 {
409 if (subscription.disabled)
410 collections.langs.removeItem(subscription);
411 else
412 collections.langs.addItem(subscription);
413 }
414 else if (!subscription.recommended && !isAcceptableAds(subscription.url))
415 {
416 if (subscription.disabled == false)
417 {
418 collections.custom.addItem(subscription);
419 updateTooltips();
420 }
421 else
422 {
423 collections.custom.removeItem(subscription);
424 }
425 }
424 } 426 }
425 427
426 function updateFilter(filter) 428 function updateFilter(filter)
427 { 429 {
428 let match = filter.text.match(whitelistedDomainRegexp); 430 let match = filter.text.match(whitelistedDomainRegexp);
429 if (match && !filtersMap[filter.text]) 431 if (match && !filtersMap[filter.text])
430 { 432 {
431 filter.title = match[1]; 433 filter.title = match[1];
432 collections.whitelist.addItem(filter); 434 collections.whitelist.addItem(filter);
433 } 435 }
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
554 let dialog = E("dialog-content-predefined"); 556 let dialog = E("dialog-content-predefined");
555 let title = dialog.querySelector("h3").textContent; 557 let title = dialog.querySelector("h3").textContent;
556 let url = dialog.querySelector(".url").textContent; 558 let url = dialog.querySelector(".url").textContent;
557 addEnableSubscription(url, title); 559 addEnableSubscription(url, title);
558 closeDialog(); 560 closeDialog();
559 break; 561 break;
560 } 562 }
561 case "cancel-custom-filters": 563 case "cancel-custom-filters":
562 setCustomFiltersView("read"); 564 setCustomFiltersView("read");
563 break; 565 break;
566 case "change-language-subscription":
567 for (let key in subscriptionsMap)
568 {
569 let subscription = subscriptionsMap[key];
570 let subscriptionType = subscription.recommended;
571 if (subscriptionType == "ads" && subscription.disabled == false)
572 {
573 ext.backgroundPage.sendMessage({
574 type: "subscriptions.remove",
575 url: subscription.url
576 });
577 ext.backgroundPage.sendMessage({
578 type: "subscriptions.add",
579 url: findParentData(element, "access", false)
580 });
581 break;
582 }
583 }
584 break;
564 case "close-dialog": 585 case "close-dialog":
565 closeDialog(); 586 closeDialog();
566 break; 587 break;
567 case "edit-custom-filters": 588 case "edit-custom-filters":
568 setCustomFiltersView("write"); 589 setCustomFiltersView("write");
569 break; 590 break;
570 case "import-subscription": { 591 case "import-subscription": {
571 let url = E("blockingList-textbox").value; 592 let url = E("blockingList-textbox").value;
572 addEnableSubscription(url); 593 addEnableSubscription(url);
573 closeDialog(); 594 closeDialog();
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
605 sendMessageHandleErrors({ 626 sendMessageHandleErrors({
606 type: "filters.importRaw", 627 type: "filters.importRaw",
607 text: E("custom-filters-raw").value, 628 text: E("custom-filters-raw").value,
608 removeExisting: true 629 removeExisting: true
609 }, 630 },
610 () => 631 () =>
611 { 632 {
612 setCustomFiltersView("read"); 633 setCustomFiltersView("read");
613 }); 634 });
614 break; 635 break;
636 case "switch-acceptable-ads":
637 let {value} = element;
638 ext.backgroundPage.sendMessage({
639 type: value == "privacy" ? "subscriptions.add" :
640 "subscriptions.remove",
641 url: acceptableAdsPrivacyUrl
642 });
643 ext.backgroundPage.sendMessage({
644 type: value == "ads" ? "subscriptions.add" : "subscriptions.remove",
645 url: acceptableAdsUrl
646 });
647 break;
615 case "switch-tab": 648 case "switch-tab":
616 let tabId = findParentData(element, "tab", false); 649 let tabId = findParentData(element, "tab", false);
617 switchTab(tabId); 650 switchTab(tabId);
618 break; 651 break;
619 case "toggle-disable-subscription": 652 case "toggle-disable-subscription":
620 ext.backgroundPage.sendMessage({ 653 ext.backgroundPage.sendMessage({
621 type: "subscriptions.toggle", 654 type: "subscriptions.toggle",
622 keepInstalled: true, 655 keepInstalled: true,
623 url: findParentData(element, "access", false) 656 url: findParentData(element, "access", false)
624 }); 657 });
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
781 let tabId = tabIds.slice(0, i + 1).join("-"); 814 let tabId = tabIds.slice(0, i + 1).join("-");
782 tabContent = selectTabItem(tabId, tabContent, true); 815 tabContent = selectTabItem(tabId, tabContent, true);
783 if (!tabContent) 816 if (!tabContent)
784 break; 817 break;
785 } 818 }
786 } 819 }
787 820
788 function onDOMLoaded() 821 function onDOMLoaded()
789 { 822 {
790 populateLists(); 823 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 824
803 // Initialize navigation sidebar 825 // Initialize navigation sidebar
804 ext.backgroundPage.sendMessage({ 826 ext.backgroundPage.sendMessage({
805 type: "app.get", 827 type: "app.get",
806 what: "addonVersion" 828 what: "addonVersion"
807 }, 829 },
808 (addonVersion) => 830 (addonVersion) =>
809 { 831 {
810 E("abp-version").textContent = addonVersion; 832 E("abp-version").textContent = addonVersion;
811 }); 833 });
812 getDocLink("releases", (link) => 834 getDocLink("releases", (link) =>
813 { 835 {
814 E("link-version").setAttribute("href", link); 836 E("link-version").setAttribute("href", link);
815 }); 837 });
816 838
817 updateShareLink(); 839 updateShareLink();
818 updateTooltips(); 840 updateTooltips();
819 841
820 // Initialize interactive UI elements 842 // Initialize interactive UI elements
821 document.body.addEventListener("click", onClick, false); 843 document.body.addEventListener("click", onClick, false);
822 document.body.addEventListener("keyup", onKeyUp, false); 844 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", 845 let exampleValue = getMessage("options_whitelist_placeholder_example",
827 ["www.example.com"]); 846 ["www.example.com"]);
828 E("whitelisting-textbox").setAttribute("placeholder", exampleValue); 847 E("whitelisting-textbox").setAttribute("placeholder", exampleValue);
829 E("whitelisting-textbox").addEventListener("keyup", (e) => 848 E("whitelisting-textbox").addEventListener("keyup", (e) =>
830 { 849 {
831 E("whitelisting-add-button").disabled = !e.target.value; 850 E("whitelisting-add-button").disabled = !e.target.value;
832 }, false); 851 }, false);
833 852
853 getDocLink("acceptable_ads_criteria", (link) =>
854 {
855 setLinks("enable-aa-description", link);
856 });
857
834 // Advanced tab 858 // Advanced tab
835 let customize = document.querySelectorAll("#customize li[data-pref]"); 859 let customize = document.querySelectorAll("#customize li[data-pref]");
836 customize = Array.prototype.map.call(customize, (checkbox) => 860 customize = Array.prototype.map.call(customize, (checkbox) =>
837 { 861 {
838 return checkbox.getAttribute("data-pref"); 862 return checkbox.getAttribute("data-pref");
839 }); 863 });
840 for (let key of customize) 864 for (let key of customize)
841 { 865 {
842 getPref(key, (value) => 866 getPref(key, (value) =>
843 { 867 {
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
962 986
963 function closeDialog() 987 function closeDialog()
964 { 988 {
965 let dialog = E("dialog"); 989 let dialog = E("dialog");
966 dialog.setAttribute("aria-hidden", true); 990 dialog.setAttribute("aria-hidden", true);
967 dialog.removeAttribute("aria-labelledby"); 991 dialog.removeAttribute("aria-labelledby");
968 document.body.removeAttribute("data-dialog"); 992 document.body.removeAttribute("data-dialog");
969 focusedBeforeDialog.focus(); 993 focusedBeforeDialog.focus();
970 } 994 }
971 995
996 function setAcceptableAds()
997 {
998 let option = "none";
999 document.forms["acceptable-ads"].classList.remove("show-dnt-notification");
1000 if (acceptableAdsUrl in subscriptionsMap)
1001 {
1002 option = "ads";
1003 }
1004 else if (acceptableAdsPrivacyUrl in subscriptionsMap)
1005 {
1006 option = "privacy";
1007
1008 if (!navigator.doNotTrack)
1009 document.forms["acceptable-ads"].classList.add("show-dnt-notification");
1010 }
1011 document.forms["acceptable-ads"]["acceptable-ads"].value = option;
1012 }
1013
1014 function isAcceptableAds(url)
1015 {
1016 return url == acceptableAdsUrl || url == acceptableAdsPrivacyUrl;
1017 }
1018
972 function populateLists() 1019 function populateLists()
973 { 1020 {
974 subscriptionsMap = Object.create(null); 1021 subscriptionsMap = Object.create(null);
975 filtersMap = Object.create(null); 1022 filtersMap = Object.create(null);
976 1023
977 // Empty collections and lists 1024 // Empty collections and lists
978 for (let property in collections) 1025 for (let property in collections)
979 collections[property].clearAll(); 1026 collections[property].clearAll();
980 1027
981 ext.backgroundPage.sendMessage({ 1028 ext.backgroundPage.sendMessage({
(...skipping 25 matching lines...) Expand all
1007 key: "subscriptions_exceptionsurl" 1054 key: "subscriptions_exceptionsurl"
1008 }, 1055 },
1009 (url) => 1056 (url) =>
1010 { 1057 {
1011 acceptableAdsUrl = url; 1058 acceptableAdsUrl = url;
1012 addSubscription({ 1059 addSubscription({
1013 url: acceptableAdsUrl, 1060 url: acceptableAdsUrl,
1014 disabled: true 1061 disabled: true
1015 }); 1062 });
1016 1063
1017 // Load user subscriptions
1018 ext.backgroundPage.sendMessage({ 1064 ext.backgroundPage.sendMessage({
1019 type: "subscriptions.get", 1065 type: "prefs.get",
1020 downloadable: true 1066 key: "subscriptions_exceptionsurl_privacy"
1021 }, 1067 },
1022 (subscriptions) => 1068 (urlPrivacy) =>
1023 { 1069 {
1024 for (let subscription of subscriptions) 1070 acceptableAdsPrivacyUrl = urlPrivacy;
1025 onSubscriptionMessage("added", subscription); 1071
1072 // Load user subscriptions
1073 ext.backgroundPage.sendMessage({
1074 type: "subscriptions.get",
1075 downloadable: true
1076 },
1077 (subscriptions) =>
1078 {
1079 for (let subscription of subscriptions)
1080 onSubscriptionMessage("added", subscription);
1081 });
1026 }); 1082 });
1027 }); 1083 });
1028 } 1084 }
1029 1085
1030 function addWhitelistedDomain() 1086 function addWhitelistedDomain()
1031 { 1087 {
1032 let domain = E("whitelisting-textbox"); 1088 let domain = E("whitelisting-textbox");
1033 for (let whitelistItem of collections.whitelist.items) 1089 for (let whitelistItem of collections.whitelist.items)
1034 { 1090 {
1035 if (whitelistItem.title == domain.value) 1091 if (whitelistItem.title == domain.value)
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
1123 case "lastDownload": 1179 case "lastDownload":
1124 case "title": 1180 case "title":
1125 updateSubscription(subscription); 1181 updateSubscription(subscription);
1126 break; 1182 break;
1127 case "added": 1183 case "added":
1128 if (subscription.url in subscriptionsMap) 1184 if (subscription.url in subscriptionsMap)
1129 updateSubscription(subscription); 1185 updateSubscription(subscription);
1130 else 1186 else
1131 addSubscription(subscription); 1187 addSubscription(subscription);
1132 1188
1189 if (isAcceptableAds(subscription.url))
1190 setAcceptableAds();
1191
1133 collections.filterLists.addItem(subscription); 1192 collections.filterLists.addItem(subscription);
1134 break; 1193 break;
1135 case "removed": 1194 case "removed":
1136 if (subscription.url == acceptableAdsUrl || subscription.recommended) 1195 if (subscription.recommended)
1137 { 1196 {
1138 subscription.disabled = true; 1197 subscription.disabled = true;
1139 onSubscriptionMessage("disabled", subscription); 1198 onSubscriptionMessage("disabled", subscription);
1140 } 1199 }
1141 else 1200 else
1142 { 1201 {
1143 collections.custom.removeItem(subscription);
1144 delete subscriptionsMap[subscription.url]; 1202 delete subscriptionsMap[subscription.url];
1203 if (isAcceptableAds(subscription.url))
1204 {
1205 setAcceptableAds();
1206 }
1207 else
1208 {
1209 collections.custom.removeItem(subscription);
1210 }
1145 } 1211 }
1146 collections.filterLists.removeItem(subscription); 1212 collections.filterLists.removeItem(subscription);
1147 break; 1213 break;
1148 } 1214 }
1149 1215
1150 updateShareLink(); 1216 updateShareLink();
1151 } 1217 }
1152 1218
1153 function hidePref(key, value) 1219 function hidePref(key, value)
1154 { 1220 {
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
1225 { 1291 {
1226 // Hide the share tab if a script on the share page would be blocked 1292 // Hide the share tab if a script on the share page would be blocked
1227 E("tab-share").hidden = isAnyBlocked; 1293 E("tab-share").hidden = isAnyBlocked;
1228 } 1294 }
1229 } 1295 }
1230 1296
1231 for (let sharedResource of shareResources) 1297 for (let sharedResource of shareResources)
1232 checkShareResource(sharedResource, onResult); 1298 checkShareResource(sharedResource, onResult);
1233 } 1299 }
1234 1300
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() 1301 function updateTooltips()
1250 { 1302 {
1251 let anchors = document.querySelectorAll(":not(.tooltip) > [data-tooltip]"); 1303 let anchors = document.querySelectorAll(":not(.tooltip) > [data-tooltip]");
1252 for (let anchor of anchors) 1304 for (let anchor of anchors)
1253 { 1305 {
1254 let id = anchor.getAttribute("data-tooltip"); 1306 let id = anchor.getAttribute("data-tooltip");
1255 1307
1256 let wrapper = document.createElement("div"); 1308 let wrapper = document.createElement("div");
1257 wrapper.className = "tooltip"; 1309 wrapper.className = "tooltip";
1258 anchor.parentNode.replaceChild(wrapper, anchor); 1310 anchor.parentNode.replaceChild(wrapper, anchor);
1259 wrapper.appendChild(anchor); 1311 wrapper.appendChild(anchor);
1260 1312
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"); 1313 let tooltip = document.createElement("div");
1274 tooltip.setAttribute("role", "tooltip"); 1314 tooltip.setAttribute("role", "tooltip");
1275 1315
1276 let flip = anchor.getAttribute("data-tooltip-flip"); 1316 let paragraph = document.createElement("p");
1277 if (flip) 1317 paragraph.textContent = getMessage(id);
1278 tooltip.className = "flip-" + flip; 1318 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 1319
1308 wrapper.appendChild(tooltip); 1320 wrapper.appendChild(tooltip);
1309 } 1321 }
1310 } 1322 }
1311 1323
1312 ext.onMessage.addListener((message) => 1324 ext.onMessage.addListener((message) =>
1313 { 1325 {
1314 switch (message.type) 1326 switch (message.type)
1315 { 1327 {
1316 case "app.respond": 1328 case "app.respond":
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
1355 }); 1367 });
1356 ext.backgroundPage.sendMessage({ 1368 ext.backgroundPage.sendMessage({
1357 type: "subscriptions.listen", 1369 type: "subscriptions.listen",
1358 filter: ["added", "disabled", "homepage", "lastDownload", "removed", 1370 filter: ["added", "disabled", "homepage", "lastDownload", "removed",
1359 "title", "downloadStatus", "downloading"] 1371 "title", "downloadStatus", "downloading"]
1360 }); 1372 });
1361 1373
1362 window.addEventListener("DOMContentLoaded", onDOMLoaded, false); 1374 window.addEventListener("DOMContentLoaded", onDOMLoaded, false);
1363 window.addEventListener("hashchange", onHashChange, false); 1375 window.addEventListener("hashchange", onHashChange, false);
1364 } 1376 }
OLDNEW
« no previous file with comments | « new-options.html ('k') | skin/new-options.css » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld