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

Delta Between Two Patch Sets: new-options.js

Issue 29375899: Issue 4871 - Start using ESLint for adblockplusui (Closed)
Left Patch Set: Created Feb. 20, 2017, 10:01 a.m.
Right Patch Set: Avoid violating operator-linebreak rule Created March 15, 2017, 4:43 a.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 | « messageResponder.js ('k') | no next file » | 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-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
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, i18n_formatDateTime, 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 {getMessage} = ext.i18n; 28 let {getMessage} = ext.i18n;
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 listItem.setAttribute("role", "section"); 108 listItem.setAttribute("role", "section");
109 109
110 let label = listItem.querySelector(".display"); 110 let label = listItem.querySelector(".display");
111 if (item.recommended && label.hasAttribute("data-tooltip")) 111 if (item.recommended && label.hasAttribute("data-tooltip"))
112 { 112 {
113 let tooltipId = label.getAttribute("data-tooltip"); 113 let tooltipId = label.getAttribute("data-tooltip");
114 tooltipId = tooltipId.replace("%value%", item.recommended); 114 tooltipId = tooltipId.replace("%value%", item.recommended);
115 label.setAttribute("data-tooltip", tooltipId); 115 label.setAttribute("data-tooltip", tooltipId);
116 } 116 }
117 117
118 let controls = listItem.querySelectorAll(".control"); 118 for (let control of listItem.querySelectorAll(".control"))
119 for (let k = 0; k < controls.length; k++) 119 {
120 { 120 if (control.hasAttribute("title"))
121 if (controls[k].hasAttribute("title"))
122 { 121 {
123 let titleValue = getMessage(controls[k].getAttribute("title")); 122 let titleValue = getMessage(control.getAttribute("title"));
124 controls[k].setAttribute("title", titleValue); 123 control.setAttribute("title", titleValue);
125 } 124 }
126 } 125 }
127 126
128 this._setEmpty(table, null); 127 this._setEmpty(table, null);
129 if (table.hasChildNodes()) 128 if (table.hasChildNodes())
130 { 129 {
131 table.insertBefore(listItem, 130 table.insertBefore(listItem,
132 table.childNodes[this.items.indexOf(item)]); 131 table.childNodes[this.items.indexOf(item)]);
133 } 132 }
134 else 133 else
135 table.appendChild(listItem); 134 table.appendChild(listItem);
136 this.updateItem(item); 135 this.updateItem(item);
137 } 136 }
138 return length; 137 return length;
139 }; 138 };
140 139
141 Collection.prototype.removeItem = function(item) 140 Collection.prototype.removeItem = function(item)
142 { 141 {
143 let index = this.items.indexOf(item); 142 let index = this.items.indexOf(item);
144 if (index == -1) 143 if (index == -1)
145 return; 144 return;
146 145
147 this.items.splice(index, 1); 146 this.items.splice(index, 1);
148 let getListElement = this._createElementQuery(item); 147 let getListElement = this._createElementQuery(item);
149 for (let i = 0; i < this.details.length; i++) 148 for (let detail of this.details)
150 { 149 {
151 let table = E(this.details[i].id); 150 let table = E(detail.id);
152 let element = getListElement(table); 151 let element = getListElement(table);
153 152
154 // Element gets removed so make sure to handle focus appropriately 153 // Element gets removed so make sure to handle focus appropriately
155 let control = element.querySelector(".control"); 154 let control = element.querySelector(".control");
156 if (control && control == document.activeElement) 155 if (control && control == document.activeElement)
157 { 156 {
158 if (!focusNextElement(element.parentElement, control)) 157 if (!focusNextElement(element.parentElement, control))
159 { 158 {
160 // Fall back to next focusable element within same tab or dialog 159 // Fall back to next focusable element within same tab or dialog
161 let focusableElement = element.parentElement; 160 let focusableElement = element.parentElement;
162 while (focusableElement) 161 while (focusableElement)
163 { 162 {
164 if (focusableElement.classList.contains("tab-content") || 163 if (focusableElement.classList.contains("tab-content") ||
165 focusableElement.classList.contains("dialog-content")) 164 focusableElement.classList.contains("dialog-content"))
166 break; 165 break;
167 166
168 focusableElement = focusableElement.parentElement; 167 focusableElement = focusableElement.parentElement;
169 } 168 }
170 focusNextElement(focusableElement || document, control); 169 focusNextElement(focusableElement || document, control);
171 } 170 }
172 } 171 }
173 172
174 element.parentElement.removeChild(element); 173 element.parentElement.removeChild(element);
175 if (this.items.length == 0) 174 if (this.items.length == 0)
176 this._setEmpty(table, this.details[i].emptyText); 175 this._setEmpty(table, detail.emptyText);
177 } 176 }
178 }; 177 };
179 178
180 Collection.prototype.updateItem = function(item) 179 Collection.prototype.updateItem = function(item)
181 { 180 {
182 let access = (item.url || item.text).replace(/'/g, "\\'"); 181 let access = (item.url || item.text).replace(/'/g, "\\'");
183 for (let i = 0; i < this.details.length; i++) 182 for (let i = 0; i < this.details.length; i++)
184 { 183 {
185 let table = E(this.details[i].id); 184 let table = E(this.details[i].id);
186 let element = table.querySelector("[data-access='" + access + "']"); 185 let element = table.querySelector("[data-access='" + access + "']");
(...skipping 28 matching lines...) Expand all
215 { 214 {
216 let error = filterErrors.get(item.downloadStatus); 215 let error = filterErrors.get(item.downloadStatus);
217 if (error) 216 if (error)
218 message.textContent = getMessage(error); 217 message.textContent = getMessage(error);
219 else 218 else
220 message.textContent = item.downloadStatus; 219 message.textContent = item.downloadStatus;
221 element.classList.add("show-message"); 220 element.classList.add("show-message");
222 } 221 }
223 else if (item.lastDownload > 0) 222 else if (item.lastDownload > 0)
224 { 223 {
225 let dateTime = i18n_formatDateTime(item.lastDownload * 1000); 224 let dateTime = i18nFormatDateTime(item.lastDownload * 1000);
226 dateElement.textContent = dateTime[0]; 225 dateElement.textContent = dateTime[0];
227 timeElement.textContent = dateTime[1]; 226 timeElement.textContent = dateTime[1];
228 element.classList.remove("show-message"); 227 element.classList.remove("show-message");
229 } 228 }
230 } 229 }
231 230
232 let websiteElement = element.querySelector(".context-menu .website"); 231 let websiteElement = element.querySelector(".context-menu .website");
233 if (websiteElement) 232 if (websiteElement)
234 { 233 {
235 if (item.homepage) 234 if (item.homepage)
236 websiteElement.setAttribute("href", item.homepage); 235 websiteElement.setAttribute("href", item.homepage);
237 else 236 else
238 websiteElement.setAttribute("aria-hidden", true); 237 websiteElement.setAttribute("aria-hidden", true);
239 } 238 }
240 239
241 let sourceElement = element.querySelector(".context-menu .source"); 240 let sourceElement = element.querySelector(".context-menu .source");
242 if (sourceElement) 241 if (sourceElement)
243 sourceElement.setAttribute("href", item.url); 242 sourceElement.setAttribute("href", item.url);
244 } 243 }
245 }; 244 };
246 245
247 Collection.prototype.clearAll = function() 246 Collection.prototype.clearAll = function()
248 { 247 {
249 this.items = []; 248 this.items = [];
250 for (let i = 0; i < this.details.length; i++) 249 for (let detail of this.details)
251 { 250 {
252 let table = E(this.details[i].id); 251 let table = E(detail.id);
253 let element = table.firstChild; 252 let element = table.firstChild;
254 while (element) 253 while (element)
255 { 254 {
256 if (element.tagName == "LI" && !element.classList.contains("static")) 255 if (element.tagName == "LI" && !element.classList.contains("static"))
257 table.removeChild(element); 256 table.removeChild(element);
258 element = element.nextElementSibling; 257 element = element.nextElementSibling;
259 } 258 }
260 259
261 this._setEmpty(table, this.details[i].emptyText); 260 this._setEmpty(table, detail.emptyText);
262 } 261 }
263 }; 262 };
264 263
265 function focusNextElement(container, currentElement) 264 function focusNextElement(container, currentElement)
266 { 265 {
267 let focusables = container.querySelectorAll("a, button, input, .control"); 266 let focusables = container.querySelectorAll("a, button, input, .control");
268 focusables = Array.prototype.slice.call(focusables); 267 focusables = Array.prototype.slice.call(focusables);
269 let index = focusables.indexOf(currentElement); 268 let index = focusables.indexOf(currentElement);
270 index += (index == focusables.length - 1) ? -1 : 1; 269 index += (index == focusables.length - 1) ? -1 : 1;
271 270
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
386 } 385 }
387 else 386 else
388 collections.customFilters.addItem(filter); 387 collections.customFilters.addItem(filter);
389 388
390 filtersMap[filter.text] = filter; 389 filtersMap[filter.text] = filter;
391 } 390 }
392 391
393 function loadRecommendations() 392 function loadRecommendations()
394 { 393 {
395 fetch("subscriptions.xml") 394 fetch("subscriptions.xml")
396 .then(response => 395 .then((response) =>
397 { 396 {
398 return response.text(); 397 return response.text();
399 }) 398 })
400 .then(text => 399 .then((text) =>
401 { 400 {
402 let list = document.getElementById("subscriptionSelector");
403 let doc = new DOMParser().parseFromString(text, "application/xml"); 401 let doc = new DOMParser().parseFromString(text, "application/xml");
404 let elements = doc.documentElement.getElementsByTagName("subscription"); 402 let elements = doc.documentElement.getElementsByTagName("subscription");
405 for (let i = 0; i < elements.length; i++) 403 for (let element of elements)
406 { 404 {
407 let element = elements[i];
408 let type = element.getAttribute("type"); 405 let type = element.getAttribute("type");
409 let subscription = { 406 let subscription = {
410 disabled: true, 407 disabled: true,
411 downloadStatus: null, 408 downloadStatus: null,
412 homepage: null, 409 homepage: null,
413 originalTitle: element.getAttribute("title"), 410 originalTitle: element.getAttribute("title"),
414 recommended: type, 411 recommended: type,
415 url: element.getAttribute("url") 412 url: element.getAttribute("url")
416 }; 413 };
417 414
(...skipping 26 matching lines...) Expand all
444 return element.getAttribute("data-" + dataName); 441 return element.getAttribute("data-" + dataName);
445 } 442 }
446 443
447 element = element.parentElement; 444 element = element.parentElement;
448 } 445 }
449 return null; 446 return null;
450 } 447 }
451 448
452 function sendMessageHandleErrors(message, onSuccess) 449 function sendMessageHandleErrors(message, onSuccess)
453 { 450 {
454 ext.backgroundPage.sendMessage(message, errors => 451 ext.backgroundPage.sendMessage(message, (errors) =>
455 { 452 {
456 if (errors.length > 0) 453 if (errors.length > 0)
457 alert(errors.join("\n")); 454 alert(errors.join("\n"));
458 else if (onSuccess) 455 else if (onSuccess)
459 onSuccess(); 456 onSuccess();
460 }); 457 });
461 } 458 }
462 459
463 function openDocLink(id) 460 function openDocLink(id)
464 { 461 {
465 getDocLink(id, link => 462 getDocLink(id, (link) =>
466 { 463 {
467 if (id == "share-general") 464 if (id == "share-general")
468 openSharePopup(link); 465 openSharePopup(link);
469 else 466 else
470 location.href = link; 467 location.href = link;
471 }); 468 });
472 } 469 }
473 470
474 function switchTab(id) 471 function switchTab(id)
475 { 472 {
476 location.hash = id; 473 location.hash = id;
477 } 474 }
478 475
479 function onClick(e) 476 function onClick(e)
480 { 477 {
481 let context = document.querySelector(".show-context-menu"); 478 let context = document.querySelector(".show-context-menu");
482 if (context) 479 if (context)
483 context.classList.remove("show-context-menu"); 480 context.classList.remove("show-context-menu");
484 481
485 let element = e.target; 482 let element = findParentData(e.target, "action", true);
486 while (element && !element.hasAttribute("data-action")) 483 if (!element)
487 element = element.parentElement; 484 return;
488 485
489 element = findParentData(e.target, "action", true);
490 let actions = element.getAttribute("data-action").split(","); 486 let actions = element.getAttribute("data-action").split(",");
491 for (let i = 0; i < actions.length; i++) 487 for (let action of actions)
492 { 488 {
493 switch (actions[i]) 489 switch (action)
494 { 490 {
495 case "add-domain-exception": 491 case "add-domain-exception":
496 addWhitelistedDomain(); 492 addWhitelistedDomain();
497 break; 493 break;
498 case "add-predefined-subscription": { 494 case "add-predefined-subscription": {
499 let dialog = E("dialog-content-predefined"); 495 let dialog = E("dialog-content-predefined");
500 let title = dialog.querySelector("h3").textContent; 496 let title = dialog.querySelector("h3").textContent;
501 let url = dialog.querySelector(".url").textContent; 497 let url = dialog.querySelector(".url").textContent;
502 addEnableSubscription(url, title); 498 addEnableSubscription(url, title);
503 closeDialog(); 499 closeDialog();
504 break; 500 break;
505 } 501 }
506 case "cancel-custom-filters": 502 case "cancel-custom-filters":
507 E("custom-filters").classList.remove("mode-edit"); 503 E("custom-filters").classList.remove("mode-edit");
508 break; 504 break;
509 case "cancel-domain-exception": 505 case "cancel-domain-exception":
510 E("whitelisting-textbox").value = ""; 506 E("whitelisting-textbox").value = "";
511 document.querySelector("#whitelisting .controls").classList. 507 document.querySelector("#whitelisting .controls").classList
512 remove("mode-edit"); 508 .remove("mode-edit");
513 break; 509 break;
514 case "close-dialog": 510 case "close-dialog":
515 closeDialog(); 511 closeDialog();
516 break; 512 break;
517 case "edit-custom-filters": 513 case "edit-custom-filters":
518 E("custom-filters").classList.add("mode-edit"); 514 E("custom-filters").classList.add("mode-edit");
519 editCustomFilters(); 515 editCustomFilters();
520 break; 516 break;
521 case "edit-domain-exception": 517 case "edit-domain-exception":
522 document.querySelector("#whitelisting .controls").classList. 518 document.querySelector("#whitelisting .controls").classList
523 add("mode-edit"); 519 .add("mode-edit");
524 E("whitelisting-textbox").focus(); 520 E("whitelisting-textbox").focus();
525 break; 521 break;
526 case "import-subscription": { 522 case "import-subscription": {
527 let url = E("blockingList-textbox").value; 523 let url = E("blockingList-textbox").value;
528 addEnableSubscription(url); 524 addEnableSubscription(url);
529 closeDialog(); 525 closeDialog();
530 break; 526 break;
531 } 527 }
532 case "open-dialog": { 528 case "open-dialog": {
533 let dialog = findParentData(element, "dialog", false); 529 let dialog = findParentData(element, "dialog", false);
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
746 searchStyle.innerHTML = "#all-lang-table li:not([data-search*=\"" + 742 searchStyle.innerHTML = "#all-lang-table li:not([data-search*=\"" +
747 this.value.toLowerCase() + "\"]) { display: none; }"; 743 this.value.toLowerCase() + "\"]) { display: none; }";
748 } 744 }
749 } 745 }
750 746
751 // Initialize navigation sidebar 747 // Initialize navigation sidebar
752 ext.backgroundPage.sendMessage({ 748 ext.backgroundPage.sendMessage({
753 type: "app.get", 749 type: "app.get",
754 what: "addonVersion" 750 what: "addonVersion"
755 }, 751 },
756 addonVersion => 752 (addonVersion) =>
757 { 753 {
758 E("abp-version").textContent = addonVersion; 754 E("abp-version").textContent = addonVersion;
759 }); 755 });
760 getDocLink("releases", link => 756 getDocLink("releases", (link) =>
761 { 757 {
762 E("link-version").setAttribute("href", link); 758 E("link-version").setAttribute("href", link);
763 }); 759 });
764 760
765 updateShareLink(); 761 updateShareLink();
766 updateTooltips(); 762 updateTooltips();
767 763
768 // Initialize interactive UI elements 764 // Initialize interactive UI elements
769 document.body.addEventListener("click", onClick, false); 765 document.body.addEventListener("click", onClick, false);
770 document.body.addEventListener("keyup", onKeyUp, false); 766 document.body.addEventListener("keyup", onKeyUp, false);
771 let placeholderValue = getMessage("options_dialog_language_find"); 767 let placeholderValue = getMessage("options_dialog_language_find");
772 E("find-language").setAttribute("placeholder", placeholderValue); 768 E("find-language").setAttribute("placeholder", placeholderValue);
773 E("find-language").addEventListener("keyup", onFindLanguageKeyUp, false); 769 E("find-language").addEventListener("keyup", onFindLanguageKeyUp, false);
774 E("whitelisting-textbox").addEventListener("keypress", e => 770 E("whitelisting-textbox").addEventListener("keypress", (e) =>
775 { 771 {
776 if (getKey(e) == "Enter") 772 if (getKey(e) == "Enter")
777 addWhitelistedDomain(); 773 addWhitelistedDomain();
778 }, false); 774 }, false);
779 775
780 // Advanced tab 776 // Advanced tab
781 let tweaks = document.querySelectorAll("#tweaks li[data-pref]"); 777 let tweaks = document.querySelectorAll("#tweaks li[data-pref]");
782 tweaks = Array.prototype.map.call(tweaks, checkbox => 778 tweaks = Array.prototype.map.call(tweaks, (checkbox) =>
783 { 779 {
784 return checkbox.getAttribute("data-pref"); 780 return checkbox.getAttribute("data-pref");
785 }); 781 });
786 tweaks.forEach(key => 782 for (let key of tweaks)
787 { 783 {
788 getPref(key, value => 784 getPref(key, (value) =>
789 { 785 {
790 onPrefMessage(key, value, true); 786 onPrefMessage(key, value, true);
791 }); 787 });
792 }); 788 }
793 ext.backgroundPage.sendMessage({ 789 ext.backgroundPage.sendMessage({
794 type: "app.get", 790 type: "app.get",
795 what: "features" 791 what: "features"
796 }, 792 },
797 features => 793 (features) =>
798 { 794 {
799 hidePref("show_devtools_panel", !features.devToolsPanel); 795 hidePref("show_devtools_panel", !features.devToolsPanel);
800 }); 796 });
801 797
802 let filterTextbox = document.querySelector("#custom-filters-add input"); 798 let filterTextbox = document.querySelector("#custom-filters-add input");
803 placeholderValue = getMessage("options_customFilters_textbox_placeholder"); 799 placeholderValue = getMessage("options_customFilters_textbox_placeholder");
804 filterTextbox.setAttribute("placeholder", placeholderValue); 800 filterTextbox.setAttribute("placeholder", placeholderValue);
805 function addCustomFilters() 801 function addCustomFilters()
806 { 802 {
807 let filterText = filterTextbox.value; 803 let filterText = filterTextbox.value;
808 sendMessageHandleErrors({ 804 sendMessageHandleErrors({
809 type: "filters.add", 805 type: "filters.add",
810 text: filterText 806 text: filterText
811 }, 807 },
812 () => 808 () =>
813 { 809 {
814 filterTextbox.value = ""; 810 filterTextbox.value = "";
815 }); 811 });
816 } 812 }
817 E("custom-filters-add").addEventListener("submit", e => 813 E("custom-filters-add").addEventListener("submit", (e) =>
818 { 814 {
819 e.preventDefault(); 815 e.preventDefault();
820 addCustomFilters(); 816 addCustomFilters();
821 }, false); 817 }, false);
822 let customFilterEditButtons = document.querySelectorAll( 818
823 "#custom-filters-edit-wrapper button" 819 // Help tab
824 ); 820 getDocLink("faq", (link) =>
821 {
822 E("link-faq").setAttribute("href", link);
823 });
824 getDocLink("social_twitter", (link) =>
825 {
826 E("link-twitter").setAttribute("href", link);
827 });
828 getDocLink("social_facebook", (link) =>
829 {
830 E("link-facebook").setAttribute("href", link);
831 });
832 getDocLink("social_gplus", (link) =>
833 {
834 E("link-gplus").setAttribute("href", link);
835 });
836 getDocLink("social_renren", (link) =>
837 {
838 E("link-renren").setAttribute("href", link);
839 });
840 getDocLink("social_weibo", (link) =>
841 {
842 E("link-weibo").setAttribute("href", link);
843 });
844
845 // Set forum link
846 ext.backgroundPage.sendMessage({
847 type: "app.get",
848 what: "platform"
849 },
850 (platform) =>
851 {
852 ext.backgroundPage.sendMessage({
853 type: "app.get",
854 what: "application"
855 },
856 (application) =>
857 {
858 if (platform == "chromium" && application != "opera")
859 application = "chrome";
860
861 getDocLink(application + "_support", (link) =>
862 {
863 E("link-forum").setAttribute("href", link);
864 });
865 });
866 });
825 867
826 E("dialog").addEventListener("keydown", function(e) 868 E("dialog").addEventListener("keydown", function(e)
827 { 869 {
828 switch (getKey(e)) 870 switch (getKey(e))
829 { 871 {
830 case "Escape": 872 case "Escape":
831 closeDialog(); 873 closeDialog();
832 break; 874 break;
833 case "Tab": 875 case "Tab":
834 if (e.shiftKey) 876 if (e.shiftKey)
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
883 filtersMap = Object.create(null); 925 filtersMap = Object.create(null);
884 926
885 // Empty collections and lists 927 // Empty collections and lists
886 for (let property in collections) 928 for (let property in collections)
887 collections[property].clearAll(); 929 collections[property].clearAll();
888 930
889 ext.backgroundPage.sendMessage({ 931 ext.backgroundPage.sendMessage({
890 type: "subscriptions.get", 932 type: "subscriptions.get",
891 special: true 933 special: true
892 }, 934 },
893 subscriptions => 935 (subscriptions) =>
894 { 936 {
895 // Load filters 937 // Load filters
896 for (let i = 0; i < subscriptions.length; i++) 938 for (let subscription of subscriptions)
897 { 939 {
898 ext.backgroundPage.sendMessage({ 940 ext.backgroundPage.sendMessage({
899 type: "filters.get", 941 type: "filters.get",
900 subscriptionUrl: subscriptions[i].url 942 subscriptionUrl: subscription.url
901 }, 943 },
902 filters => 944 (filters) =>
903 { 945 {
904 for (let filter of filters) 946 for (let filter of filters)
905 updateFilter(filter); 947 updateFilter(filter);
906 }); 948 });
907 } 949 }
908 }); 950 });
909 loadRecommendations(); 951 loadRecommendations();
910 ext.backgroundPage.sendMessage({ 952 ext.backgroundPage.sendMessage({
911 type: "prefs.get", 953 type: "prefs.get",
912 key: "subscriptions_exceptionsurl" 954 key: "subscriptions_exceptionsurl"
913 }, 955 },
914 url => 956 (url) =>
915 { 957 {
916 acceptableAdsUrl = url; 958 acceptableAdsUrl = url;
917 addSubscription({ 959 addSubscription({
918 url: acceptableAdsUrl, 960 url: acceptableAdsUrl,
919 disabled: true 961 disabled: true
920 }); 962 });
921 963
922 // Load user subscriptions 964 // Load user subscriptions
923 ext.backgroundPage.sendMessage({ 965 ext.backgroundPage.sendMessage({
924 type: "subscriptions.get", 966 type: "subscriptions.get",
925 downloadable: true 967 downloadable: true
926 }, 968 },
927 subscriptions => 969 (subscriptions) =>
928 { 970 {
929 for (let i = 0; i < subscriptions.length; i++) 971 for (let subscription of subscriptions)
930 onSubscriptionMessage("added", subscriptions[i]); 972 onSubscriptionMessage("added", subscription);
931 }); 973 });
932 }); 974 });
933 } 975 }
934 976
935 function addWhitelistedDomain() 977 function addWhitelistedDomain()
936 { 978 {
937 let domain = E("whitelisting-textbox"); 979 let domain = E("whitelisting-textbox");
938 if (domain.value) 980 if (domain.value)
939 { 981 {
940 sendMessageHandleErrors({ 982 sendMessageHandleErrors({
941 type: "filters.add", 983 type: "filters.add",
942 text: "@@||" + domain.value.toLowerCase() + "^$document" 984 text: "@@||" + domain.value.toLowerCase() + "^$document"
943 }); 985 });
944 } 986 }
945 987
946 domain.value = ""; 988 domain.value = "";
947 document.querySelector("#whitelisting .controls"). 989 document.querySelector("#whitelisting .controls")
948 classList.remove("mode-edit"); 990 .classList.remove("mode-edit");
949 } 991 }
950 992
951 function editCustomFilters() 993 function editCustomFilters()
952 { 994 {
953 let customFilterItems = collections.customFilters.items;
954 let filterTexts = []; 995 let filterTexts = [];
955 for (let i = 0; i < customFilterItems.length; i++) 996 for (let customFilterItem of collections.customFilters.items)
956 filterTexts.push(customFilterItems[i].text); 997 filterTexts.push(customFilterItem.text);
957 E("custom-filters-raw").value = filterTexts.join("\n"); 998 E("custom-filters-raw").value = filterTexts.join("\n");
958 } 999 }
959 1000
960 function addEnableSubscription(url, title, homepage) 1001 function addEnableSubscription(url, title, homepage)
961 { 1002 {
962 let messageType = null; 1003 let messageType = null;
963 let knownSubscription = subscriptionsMap[url]; 1004 let knownSubscription = subscriptionsMap[url];
964 if (knownSubscription && knownSubscription.disabled == true) 1005 if (knownSubscription && knownSubscription.disabled == true)
965 messageType = "subscriptions.toggle"; 1006 messageType = "subscriptions.toggle";
966 else 1007 else
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
1054 function hidePref(key, value) 1095 function hidePref(key, value)
1055 { 1096 {
1056 let element = document.querySelector("[data-pref='" + key + "']"); 1097 let element = document.querySelector("[data-pref='" + key + "']");
1057 if (element) 1098 if (element)
1058 element.setAttribute("aria-hidden", value); 1099 element.setAttribute("aria-hidden", value);
1059 } 1100 }
1060 1101
1061 function getPref(key, callback) 1102 function getPref(key, callback)
1062 { 1103 {
1063 let checkPref = getPref.checks[key] || getPref.checkNone; 1104 let checkPref = getPref.checks[key] || getPref.checkNone;
1064 checkPref(isActive => 1105 checkPref((isActive) =>
1065 { 1106 {
1066 if (!isActive) 1107 if (!isActive)
1067 { 1108 {
1068 hidePref(key, !isActive); 1109 hidePref(key, !isActive);
1069 return; 1110 return;
1070 } 1111 }
1071 1112
1072 ext.backgroundPage.sendMessage({ 1113 ext.backgroundPage.sendMessage({
1073 type: "prefs.get", 1114 type: "prefs.get",
1074 key 1115 key
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
1122 function onResult(isBlocked) 1163 function onResult(isBlocked)
1123 { 1164 {
1124 isAnyBlocked |= isBlocked; 1165 isAnyBlocked |= isBlocked;
1125 if (!--checksRemaining) 1166 if (!--checksRemaining)
1126 { 1167 {
1127 // Hide the share tab if a script on the share page would be blocked 1168 // Hide the share tab if a script on the share page would be blocked
1128 E("tab-share").hidden = isAnyBlocked; 1169 E("tab-share").hidden = isAnyBlocked;
1129 } 1170 }
1130 } 1171 }
1131 1172
1132 for (let i = 0; i < shareResources.length; i++) 1173 for (let sharedResource of shareResources)
1133 checkShareResource(shareResources[i], onResult); 1174 checkShareResource(sharedResource, onResult);
1134 } 1175 }
1135 1176
1136 function getMessages(id) 1177 function getMessages(id)
1137 { 1178 {
1138 let messages = []; 1179 let messages = [];
1139 for (let i = 1, message = ext.i18n.getMessage(id + "_" + i); message; i++) 1180 for (let i = 1; true; i++)
1181 {
1182 let message = ext.i18n.getMessage(id + "_" + i);
1183 if (!message)
1184 break;
1185
1140 messages.push(message); 1186 messages.push(message);
1187 }
1141 return messages; 1188 return messages;
1142 } 1189 }
1143 1190
1144 function updateTooltips() 1191 function updateTooltips()
1145 { 1192 {
1146 let anchors = document.querySelectorAll(":not(.tooltip) > [data-tooltip]"); 1193 let anchors = document.querySelectorAll(":not(.tooltip) > [data-tooltip]");
1147 for (let i = 0; i < anchors.length; i++) 1194 for (let anchor of anchors)
1148 { 1195 {
1149 let anchor = anchors[i];
1150 let id = anchor.getAttribute("data-tooltip"); 1196 let id = anchor.getAttribute("data-tooltip");
1151 1197
1152 let wrapper = document.createElement("div"); 1198 let wrapper = document.createElement("div");
1153 wrapper.className = "tooltip"; 1199 wrapper.className = "tooltip";
1154 anchor.parentNode.replaceChild(wrapper, anchor); 1200 anchor.parentNode.replaceChild(wrapper, anchor);
1155 wrapper.appendChild(anchor); 1201 wrapper.appendChild(anchor);
1156 1202
1157 let topTexts = getMessages(id); 1203 let topTexts = getMessages(id);
1158 let bottomTexts = getMessages(id + "_notes"); 1204 let bottomTexts = getMessages(id + "_notes");
1159 1205
(...skipping 15 matching lines...) Expand all
1175 1221
1176 let imageSource = anchor.getAttribute("data-tooltip-image"); 1222 let imageSource = anchor.getAttribute("data-tooltip-image");
1177 if (imageSource) 1223 if (imageSource)
1178 { 1224 {
1179 let image = document.createElement("img"); 1225 let image = document.createElement("img");
1180 image.src = imageSource; 1226 image.src = imageSource;
1181 image.alt = ""; 1227 image.alt = "";
1182 tooltip.appendChild(image); 1228 tooltip.appendChild(image);
1183 } 1229 }
1184 1230
1185 for (let j = 0; j < topTexts.length; j++) 1231 for (let topText of topTexts)
1186 { 1232 {
1187 let paragraph = document.createElement("p"); 1233 let paragraph = document.createElement("p");
1188 paragraph.innerHTML = topTexts[j]; 1234 paragraph.innerHTML = topText;
1189 tooltip.appendChild(paragraph); 1235 tooltip.appendChild(paragraph);
1190 } 1236 }
1191 if (bottomTexts.length > 0) 1237 if (bottomTexts.length > 0)
1192 { 1238 {
1193 let notes = document.createElement("div"); 1239 let notes = document.createElement("div");
1194 notes.className = "notes"; 1240 notes.className = "notes";
1195 for (let j = 0; j < bottomTexts.length; j++) 1241 for (let bottomText of bottomTexts)
1196 { 1242 {
1197 let paragraph = document.createElement("p"); 1243 let paragraph = document.createElement("p");
1198 paragraph.innerHTML = bottomTexts[j]; 1244 paragraph.innerHTML = bottomText;
1199 notes.appendChild(paragraph); 1245 notes.appendChild(paragraph);
1200 } 1246 }
1201 tooltip.appendChild(notes); 1247 tooltip.appendChild(notes);
1202 } 1248 }
1203 1249
1204 wrapper.appendChild(tooltip); 1250 wrapper.appendChild(tooltip);
1205 } 1251 }
1206 } 1252 }
1207 1253
1208 ext.onMessage.addListener(message => 1254 ext.onMessage.addListener((message) =>
1209 { 1255 {
1210 switch (message.type) 1256 switch (message.type)
1211 { 1257 {
1212 case "app.respond": 1258 case "app.respond":
1213 switch (message.action) 1259 switch (message.action)
1214 { 1260 {
1215 case "addSubscription": 1261 case "addSubscription":
1216 let subscription = message.args[0]; 1262 let subscription = message.args[0];
1217 let dialog = E("dialog-content-predefined"); 1263 let dialog = E("dialog-content-predefined");
1218 dialog.querySelector("h3").textContent = subscription.title || ""; 1264 dialog.querySelector("h3").textContent = subscription.title || "";
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
1251 }); 1297 });
1252 ext.backgroundPage.sendMessage({ 1298 ext.backgroundPage.sendMessage({
1253 type: "subscriptions.listen", 1299 type: "subscriptions.listen",
1254 filter: ["added", "disabled", "homepage", "lastDownload", "removed", 1300 filter: ["added", "disabled", "homepage", "lastDownload", "removed",
1255 "title", "downloadStatus", "downloading"] 1301 "title", "downloadStatus", "downloading"]
1256 }); 1302 });
1257 1303
1258 window.addEventListener("DOMContentLoaded", onDOMLoaded, false); 1304 window.addEventListener("DOMContentLoaded", onDOMLoaded, false);
1259 window.addEventListener("hashchange", onHashChange, false); 1305 window.addEventListener("hashchange", onHashChange, false);
1260 } 1306 }
LEFTRIGHT

Powered by Google App Engine
This is Rietveld