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

Side by Side Diff: new-options.js

Issue 29445590: Issue 5255 - Advanced tab (HTML, strings and functionality) (Closed)
Patch Set: Fixed nits Created July 14, 2017, 5:43 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
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-2017 eyeo GmbH 3 * Copyright (C) 2006-2017 eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details. 12 * GNU General Public License for more details.
13 * 13 *
14 * You should have received a copy of the GNU General Public License 14 * You should have received a copy of the GNU General Public License
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
16 */ 16 */
17 17
18 /* globals checkShareResource, getDocLink, i18nFormatDateTime, openSharePopup, 18 /* globals checkShareResource, getDocLink, i18nFormatDateTime, openSharePopup,
19 E */ 19 E */
20 20
21 "use strict"; 21 "use strict";
22 22
23 { 23 {
24 let subscriptionsMap = Object.create(null); 24 let subscriptionsMap = Object.create(null);
25 let filtersMap = Object.create(null); 25 let filtersMap = Object.create(null);
26 let collections = Object.create(null); 26 let collections = Object.create(null);
27 let acceptableAdsUrl = null; 27 let acceptableAdsUrl = null;
28 let isCustomFiltersLoaded = false; 28 let isCustomFiltersLoaded = false;
29 let {getMessage} = ext.i18n; 29 let {getMessage} = ext.i18n;
30 let customFilters = [];
30 let filterErrors = new Map([ 31 let filterErrors = new Map([
31 ["synchronize_invalid_url", 32 ["synchronize_invalid_url",
32 "options_filterList_lastDownload_invalidURL"], 33 "options_filterList_lastDownload_invalidURL"],
33 ["synchronize_connection_error", 34 ["synchronize_connection_error",
34 "options_filterList_lastDownload_connectionError"], 35 "options_filterList_lastDownload_connectionError"],
35 ["synchronize_invalid_data", 36 ["synchronize_invalid_data",
36 "options_filterList_lastDownload_invalidData"], 37 "options_filterList_lastDownload_invalidData"],
37 ["synchronize_checksum_mismatch", 38 ["synchronize_checksum_mismatch",
38 "options_filterList_lastDownload_checksumMismatch"] 39 "options_filterList_lastDownload_checksumMismatch"]
39 ]); 40 ]);
40 const timestampUI = Symbol(); 41 const timestampUI = Symbol();
42 const whitelistedDomainRegexp = /^@@\|\|([^/:]+)\^\$document$/;
43 // Period of time in milliseconds
44 const minuteInMs = 60000;
45 const hourInMs = 3600000;
46 const fullDayInMs = 86400000;
41 47
42 function Collection(details) 48 function Collection(details)
43 { 49 {
44 this.details = details; 50 this.details = details;
45 this.items = []; 51 this.items = [];
46 } 52 }
47 53
48 Collection.prototype._setEmpty = function(table, texts) 54 Collection.prototype._setEmpty = function(table, texts)
49 { 55 {
50 let placeholders = table.querySelectorAll(".empty-placeholder"); 56 let placeholders = table.querySelectorAll(".empty-placeholder");
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 118
113 Collection.prototype.addItem = function(item) 119 Collection.prototype.addItem = function(item)
114 { 120 {
115 if (this.items.indexOf(item) >= 0) 121 if (this.items.indexOf(item) >= 0)
116 return; 122 return;
117 123
118 this.items.push(item); 124 this.items.push(item);
119 this._sortItems(); 125 this._sortItems();
120 for (let j = 0; j < this.details.length; j++) 126 for (let j = 0; j < this.details.length; j++)
121 { 127 {
122 let table = E(this.details[j].id); 128 let detail = this.details[j];
129 let table = E(detail.id);
123 let template = table.querySelector("template"); 130 let template = table.querySelector("template");
124 let listItem = document.createElement("li"); 131 let listItem = document.createElement("li");
125 listItem.appendChild(document.importNode(template.content, true)); 132 listItem.appendChild(document.importNode(template.content, true));
126 listItem.setAttribute("aria-label", this._getItemTitle(item, j)); 133 listItem.setAttribute("aria-label", this._getItemTitle(item, j));
127 listItem.setAttribute("data-access", item.url || item.text); 134 listItem.setAttribute("data-access", item.url || item.text);
128 listItem.setAttribute("role", "section"); 135 listItem.setAttribute("role", "section");
129 136
130 let label = listItem.querySelector(".display"); 137 let label = listItem.querySelector(".display");
131 if (item.recommended && label.hasAttribute("data-tooltip")) 138 if (item.recommended && label.hasAttribute("data-tooltip"))
132 { 139 {
133 let tooltipId = label.getAttribute("data-tooltip"); 140 let tooltipId = label.getAttribute("data-tooltip");
134 tooltipId = tooltipId.replace("%value%", item.recommended); 141 tooltipId = tooltipId.replace("%value%", item.recommended);
135 label.setAttribute("data-tooltip", tooltipId); 142 label.setAttribute("data-tooltip", tooltipId);
136 } 143 }
137 144
138 for (let control of listItem.querySelectorAll(".control")) 145 for (let control of listItem.querySelectorAll(".control"))
139 { 146 {
140 if (control.hasAttribute("title")) 147 if (control.hasAttribute("title"))
141 { 148 {
142 let titleValue = getMessage(control.getAttribute("title")); 149 let titleValue = getMessage(control.getAttribute("title"));
143 control.setAttribute("title", titleValue); 150 control.setAttribute("title", titleValue);
144 } 151 }
145 } 152 }
146 153
147 this._setEmpty(table, null); 154 this._setEmpty(table, null);
148 if (table.hasChildNodes()) 155 if (table.children.length > 0)
149 { 156 table.insertBefore(listItem, table.children[this.items.indexOf(item)]);
150 table.insertBefore(listItem,
151 table.childNodes[this.items.indexOf(item)]);
152 }
153 else 157 else
154 table.appendChild(listItem); 158 table.appendChild(listItem);
159
155 this.updateItem(item); 160 this.updateItem(item);
156 } 161 }
157 return length; 162 return length;
158 }; 163 };
159 164
160 Collection.prototype.removeItem = function(item) 165 Collection.prototype.removeItem = function(item)
161 { 166 {
162 let index = this.items.indexOf(item); 167 let index = this.items.indexOf(item);
163 if (index == -1) 168 if (index == -1)
164 return; 169 return;
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
214 if (this.details[i].searchable) 219 if (this.details[i].searchable)
215 element.setAttribute("data-search", title.toLowerCase()); 220 element.setAttribute("data-search", title.toLowerCase());
216 let control = element.querySelector(".control[role='checkbox']"); 221 let control = element.querySelector(".control[role='checkbox']");
217 if (control) 222 if (control)
218 { 223 {
219 control.setAttribute("aria-checked", item.disabled == false); 224 control.setAttribute("aria-checked", item.disabled == false);
220 if (item.url == acceptableAdsUrl && this == collections.filterLists) 225 if (item.url == acceptableAdsUrl && this == collections.filterLists)
221 control.disabled = true; 226 control.disabled = true;
222 } 227 }
223 228
224 let dateElement = element.querySelector(".date"); 229 let lastUpdateElement = element.querySelector(".last-update");
225 let timeElement = element.querySelector(".time"); 230 if (lastUpdateElement)
226 if (dateElement && timeElement)
227 { 231 {
228 let message = element.querySelector(".message"); 232 let message = element.querySelector(".message");
229 if (item.isDownloading) 233 if (item.isDownloading)
230 { 234 {
231 let text = getMessage("options_filterList_lastDownload_inProgress"); 235 let text = getMessage("options_filterList_lastDownload_inProgress");
232 message.textContent = text; 236 message.textContent = text;
233 element.classList.add("show-message"); 237 element.classList.add("show-message");
234 } 238 }
235 else if (item.downloadStatus != "synchronize_ok") 239 else if (item.downloadStatus != "synchronize_ok")
236 { 240 {
237 let error = filterErrors.get(item.downloadStatus); 241 let error = filterErrors.get(item.downloadStatus);
238 if (error) 242 if (error)
239 message.textContent = getMessage(error); 243 message.textContent = getMessage(error);
240 else 244 else
241 message.textContent = item.downloadStatus; 245 message.textContent = item.downloadStatus;
242 element.classList.add("show-message"); 246 element.classList.add("show-message");
243 } 247 }
244 else if (item.lastDownload > 0) 248 else if (item.lastDownload > 0)
245 { 249 {
246 let dateTime = i18nFormatDateTime(item.lastDownload * 1000); 250 let lastUpdate = item.lastDownload * 1000;
247 dateElement.textContent = dateTime[0]; 251 let sinceUpdate = Date.now() - lastUpdate;
248 timeElement.textContent = dateTime[1]; 252 if (sinceUpdate > fullDayInMs)
253 {
254 let lastUpdateDate = new Date(item.lastDownload * 1000);
255 let monthName = lastUpdateDate.toLocaleString(undefined,
256 {month: "short"});
257 let day = lastUpdateDate.getDate();
258 day = day < 10 ? "0" + day : day;
259 lastUpdateElement.textContent = day + " " + monthName + " " +
260 lastUpdateDate.getFullYear();
261 }
262 else if (sinceUpdate > hourInMs)
263 {
264 lastUpdateElement.textContent =
265 getMessage("options_filterList_hours");
266 }
267 else if (sinceUpdate > minuteInMs)
268 {
269 lastUpdateElement.textContent =
270 getMessage("options_filterList_minutes");
271 }
272 else
273 {
274 lastUpdateElement.textContent =
275 getMessage("options_filterList_now");
276 }
249 element.classList.remove("show-message"); 277 element.classList.remove("show-message");
250 } 278 }
251 } 279 }
252 280
253 let websiteElement = element.querySelector(".context-menu .website"); 281 let websiteElement = element.querySelector(".context-menu .website");
254 if (websiteElement) 282 if (websiteElement)
255 { 283 {
256 if (item.homepage) 284 if (item.homepage)
257 websiteElement.setAttribute("href", item.homepage); 285 websiteElement.setAttribute("href", item.homepage);
258 else 286 else
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
333 { 361 {
334 id: "custom-list-table" 362 id: "custom-list-table"
335 } 363 }
336 ]); 364 ]);
337 collections.whitelist = new Collection([ 365 collections.whitelist = new Collection([
338 { 366 {
339 id: "whitelisting-table", 367 id: "whitelisting-table",
340 emptyText: ["options_whitelist_empty_1", "options_whitelist_empty_2"] 368 emptyText: ["options_whitelist_empty_1", "options_whitelist_empty_2"]
341 } 369 }
342 ]); 370 ]);
343 collections.customFilters = new Collection([
344 {
345 id: "custom-filters-table",
346 emptyText: ["options_customFilters_empty"]
347 }
348 ]);
349 collections.filterLists = new Collection([ 371 collections.filterLists = new Collection([
350 { 372 {
351 id: "all-filter-lists-table", 373 id: "all-filter-lists-table",
352 useOriginalTitle: true 374 useOriginalTitle: true
353 } 375 }
354 ]); 376 ]);
355 377
356 function toggleShowLanguage(subscription) 378 function toggleShowLanguage(subscription)
357 { 379 {
358 if (subscription.recommended == "ads") 380 if (subscription.recommended == "ads")
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
396 function updateSubscription(subscription) 418 function updateSubscription(subscription)
397 { 419 {
398 for (let name in collections) 420 for (let name in collections)
399 collections[name].updateItem(subscription); 421 collections[name].updateItem(subscription);
400 422
401 toggleShowLanguage(subscription); 423 toggleShowLanguage(subscription);
402 } 424 }
403 425
404 function updateFilter(filter) 426 function updateFilter(filter)
405 { 427 {
406 let match = filter.text.match(/^@@\|\|([^/:]+)\^\$document$/); 428 let match = filter.text.match(whitelistedDomainRegexp);
407 if (match && !filtersMap[filter.text]) 429 if (match && !filtersMap[filter.text])
408 { 430 {
409 filter.title = match[1]; 431 filter.title = match[1];
410 collections.whitelist.addItem(filter); 432 collections.whitelist.addItem(filter);
411 } 433 }
412 else 434 else
413 collections.customFilters.addItem(filter); 435 {
436 customFilters.push(filter.text);
437 if (isCustomFiltersLoaded)
438 updateCustomFiltersUi();
439 }
414 440
415 filtersMap[filter.text] = filter; 441 filtersMap[filter.text] = filter;
416 } 442 }
417 443
444 function removeCustomFilter(text)
445 {
446 let index = customFilters.indexOf(text);
447 if (index >= 0)
448 customFilters.splice(index, 1);
449
450 updateCustomFiltersUi();
451 }
452
453 function updateCustomFiltersUi()
454 {
455 let customFiltersListElement = E("custom-filters-raw");
456 customFiltersListElement.value = customFilters.join("\n");
457 }
458
418 function loadRecommendations() 459 function loadRecommendations()
419 { 460 {
420 fetch("subscriptions.xml") 461 fetch("subscriptions.xml")
421 .then((response) => 462 .then((response) =>
422 { 463 {
423 return response.text(); 464 return response.text();
424 }) 465 })
425 .then((text) => 466 .then((text) =>
426 { 467 {
427 let doc = new DOMParser().parseFromString(text, "application/xml"); 468 let doc = new DOMParser().parseFromString(text, "application/xml");
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
511 break; 552 break;
512 case "add-predefined-subscription": { 553 case "add-predefined-subscription": {
513 let dialog = E("dialog-content-predefined"); 554 let dialog = E("dialog-content-predefined");
514 let title = dialog.querySelector("h3").textContent; 555 let title = dialog.querySelector("h3").textContent;
515 let url = dialog.querySelector(".url").textContent; 556 let url = dialog.querySelector(".url").textContent;
516 addEnableSubscription(url, title); 557 addEnableSubscription(url, title);
517 closeDialog(); 558 closeDialog();
518 break; 559 break;
519 } 560 }
520 case "cancel-custom-filters": 561 case "cancel-custom-filters":
521 E("custom-filters").classList.remove("mode-edit"); 562 setCustomFiltersView("read");
522 break; 563 break;
523 case "close-dialog": 564 case "close-dialog":
524 closeDialog(); 565 closeDialog();
525 break; 566 break;
526 case "edit-custom-filters": 567 case "edit-custom-filters":
527 editCustomFilters(); 568 setCustomFiltersView("write");
528 break; 569 break;
529 case "import-subscription": { 570 case "import-subscription": {
530 let url = E("blockingList-textbox").value; 571 let url = E("blockingList-textbox").value;
531 addEnableSubscription(url); 572 addEnableSubscription(url);
532 closeDialog(); 573 closeDialog();
533 break; 574 break;
534 } 575 }
535 case "open-context-menu": { 576 case "open-context-menu": {
536 let listItem = findParentData(element, "access", true); 577 let listItem = findParentData(element, "access", true);
537 if (listItem && !listItem.classList.contains("show-context-menu")) 578 if (listItem && !listItem.classList.contains("show-context-menu"))
(...skipping 23 matching lines...) Expand all
561 }); 602 });
562 break; 603 break;
563 case "save-custom-filters": 604 case "save-custom-filters":
564 sendMessageHandleErrors({ 605 sendMessageHandleErrors({
565 type: "filters.importRaw", 606 type: "filters.importRaw",
566 text: E("custom-filters-raw").value, 607 text: E("custom-filters-raw").value,
567 removeExisting: true 608 removeExisting: true
568 }, 609 },
569 () => 610 () =>
570 { 611 {
571 E("custom-filters").classList.remove("mode-edit"); 612 setCustomFiltersView("read");
572 }); 613 });
573 break; 614 break;
574 case "switch-tab": 615 case "switch-tab":
575 let tabId = findParentData(element, "tab", false); 616 let tabId = findParentData(element, "tab", false);
576 switchTab(tabId); 617 switchTab(tabId);
577 break; 618 break;
578 case "toggle-disable-subscription": 619 case "toggle-disable-subscription":
579 ext.backgroundPage.sendMessage({ 620 ext.backgroundPage.sendMessage({
580 type: "subscriptions.toggle", 621 type: "subscriptions.toggle",
581 keepInstalled: true, 622 keepInstalled: true,
(...skipping 25 matching lines...) Expand all
607 break; 648 break;
608 case "update-subscription": 649 case "update-subscription":
609 ext.backgroundPage.sendMessage({ 650 ext.backgroundPage.sendMessage({
610 type: "subscriptions.update", 651 type: "subscriptions.update",
611 url: findParentData(element, "access", false) 652 url: findParentData(element, "access", false)
612 }); 653 });
613 break; 654 break;
614 } 655 }
615 } 656 }
616 657
658 function setCustomFiltersView(mode)
659 {
660 let customFiltersElement = E("custom-filters-raw");
661 updateCustomFiltersUi();
662 if (mode == "read")
663 {
664 customFiltersElement.disabled = true;
665 if (!customFiltersElement.value)
666 {
667 setCustomFiltersView("empty");
668 return;
669 }
670 }
671 else if (mode == "write")
672 {
673 customFiltersElement.disabled = false;
674 }
675
676 E("custom-filters").dataset.mode = mode;
677 }
678
617 function onClick(e) 679 function onClick(e)
618 { 680 {
619 let context = document.querySelector(".show-context-menu"); 681 let context = document.querySelector(".show-context-menu");
620 if (context) 682 if (context)
621 context.classList.remove("show-context-menu"); 683 context.classList.remove("show-context-menu");
622 684
623 let actions = findParentData(e.target, "action", false); 685 let actions = findParentData(e.target, "action", false);
624 if (!actions) 686 if (!actions)
625 return; 687 return;
626 688
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
692 previousTab.removeAttribute("aria-selected"); 754 previousTab.removeAttribute("aria-selected");
693 previousTab.setAttribute("tabindex", -1); 755 previousTab.setAttribute("tabindex", -1);
694 756
695 let tab = tabList.querySelector("li[data-tab='" + tabId + "']"); 757 let tab = tabList.querySelector("li[data-tab='" + tabId + "']");
696 tab.setAttribute("aria-selected", true); 758 tab.setAttribute("aria-selected", true);
697 tab.setAttribute("tabindex", 0); 759 tab.setAttribute("tabindex", 0);
698 760
699 let tabContentId = tab.getAttribute("aria-controls"); 761 let tabContentId = tab.getAttribute("aria-controls");
700 let tabContent = document.getElementById(tabContentId); 762 let tabContent = document.getElementById(tabContentId);
701 763
702 // Select sub tabs
703 if (tab.hasAttribute("data-subtab"))
704 selectTabItem(tab.getAttribute("data-subtab"), tabContent, false);
705
706 if (tab && focus) 764 if (tab && focus)
707 tab.focus(); 765 tab.focus();
708 766
709 return tabContent; 767 return tabContent;
710 } 768 }
711 769
712 function onHashChange() 770 function onHashChange()
713 { 771 {
714 let hash = location.hash.substr(1); 772 let hash = location.hash.substr(1);
715 if (!hash) 773 if (!hash)
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
758 816
759 updateShareLink(); 817 updateShareLink();
760 updateTooltips(); 818 updateTooltips();
761 819
762 // Initialize interactive UI elements 820 // Initialize interactive UI elements
763 document.body.addEventListener("click", onClick, false); 821 document.body.addEventListener("click", onClick, false);
764 document.body.addEventListener("keyup", onKeyUp, false); 822 document.body.addEventListener("keyup", onKeyUp, false);
765 let placeholderValue = getMessage("options_dialog_language_find"); 823 let placeholderValue = getMessage("options_dialog_language_find");
766 E("find-language").setAttribute("placeholder", placeholderValue); 824 E("find-language").setAttribute("placeholder", placeholderValue);
767 E("find-language").addEventListener("keyup", onFindLanguageKeyUp, false); 825 E("find-language").addEventListener("keyup", onFindLanguageKeyUp, false);
768 let exampleValue = getMessage("options_whitelist_placeholder_example", 826 let exampleValue = getMessage("options_whitelist_placeholder_example",
769 ["www.example.com"]); 827 ["www.example.com"]);
770 E("whitelisting-textbox").setAttribute("placeholder", exampleValue); 828 E("whitelisting-textbox").setAttribute("placeholder", exampleValue);
771 E("whitelisting-textbox").addEventListener("keyup", (e) => 829 E("whitelisting-textbox").addEventListener("keyup", (e) =>
772 { 830 {
773 E("whitelisting-add-button").disabled = !e.target.value; 831 E("whitelisting-add-button").disabled = !e.target.value;
774 }, false); 832 }, false);
775 833
776 // Advanced tab 834 // Advanced tab
777 let tweaks = document.querySelectorAll("#tweaks li[data-pref]"); 835 let customize = document.querySelectorAll("#customize li[data-pref]");
778 tweaks = Array.prototype.map.call(tweaks, (checkbox) => 836 customize = Array.prototype.map.call(customize, (checkbox) =>
779 { 837 {
780 return checkbox.getAttribute("data-pref"); 838 return checkbox.getAttribute("data-pref");
781 }); 839 });
782 for (let key of tweaks) 840 for (let key of customize)
783 { 841 {
784 getPref(key, (value) => 842 getPref(key, (value) =>
785 { 843 {
786 onPrefMessage(key, value, true); 844 onPrefMessage(key, value, true);
787 }); 845 });
788 } 846 }
789 ext.backgroundPage.sendMessage({ 847 ext.backgroundPage.sendMessage({
790 type: "app.get", 848 type: "app.get",
791 what: "features" 849 what: "features"
792 }, 850 },
793 (features) => 851 (features) =>
794 { 852 {
795 hidePref("show_devtools_panel", !features.devToolsPanel); 853 hidePref("show_devtools_panel", !features.devToolsPanel);
796 }); 854 });
797 855
798 let filterTextbox = document.querySelector("#custom-filters-add input"); 856 getDocLink("filterdoc", (link) =>
799 placeholderValue = getMessage("options_customFilters_textbox_placeholder");
800 filterTextbox.setAttribute("placeholder", placeholderValue);
801 function addCustomFilters()
802 { 857 {
803 let filterText = filterTextbox.value; 858 E("link-filters").setAttribute("href", link);
804 sendMessageHandleErrors({ 859 });
805 type: "filters.add", 860
806 text: filterText 861 getDocLink("subscriptions", (link) =>
807 },
808 () =>
809 {
810 filterTextbox.value = "";
811 });
812 }
813 E("custom-filters-add").addEventListener("submit", (e) =>
814 { 862 {
815 e.preventDefault(); 863 setLinks("filter-lists-description", link);
816 addCustomFilters(); 864 });
817 }, false); 865
866 E("custom-filters-raw").setAttribute("placeholder",
867 getMessage("options_customFilters_edit_placeholder", ["/ads/track/*"]));
818 868
819 // Help tab 869 // Help tab
820 getDocLink("faq", (link) => 870 getDocLink("faq", (link) =>
821 { 871 {
822 E("link-faq").setAttribute("href", link); 872 E("link-faq").setAttribute("href", link);
823 }); 873 });
824 getDocLink("social_twitter", (link) => 874 getDocLink("social_twitter", (link) =>
825 { 875 {
826 E("link-twitter").setAttribute("href", link); 876 E("link-twitter").setAttribute("href", link);
827 }); 877 });
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
940 ext.backgroundPage.sendMessage({ 990 ext.backgroundPage.sendMessage({
941 type: "filters.get", 991 type: "filters.get",
942 subscriptionUrl: subscription.url 992 subscriptionUrl: subscription.url
943 }, 993 },
944 (filters) => 994 (filters) =>
945 { 995 {
946 for (let filter of filters) 996 for (let filter of filters)
947 updateFilter(filter); 997 updateFilter(filter);
948 998
949 isCustomFiltersLoaded = true; 999 isCustomFiltersLoaded = true;
1000 setCustomFiltersView("read");
950 }); 1001 });
951 } 1002 }
952 }); 1003 });
953 loadRecommendations(); 1004 loadRecommendations();
954 ext.backgroundPage.sendMessage({ 1005 ext.backgroundPage.sendMessage({
955 type: "prefs.get", 1006 type: "prefs.get",
956 key: "subscriptions_exceptionsurl" 1007 key: "subscriptions_exceptionsurl"
957 }, 1008 },
958 (url) => 1009 (url) =>
959 { 1010 {
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
994 sendMessageHandleErrors({ 1045 sendMessageHandleErrors({
995 type: "filters.add", 1046 type: "filters.add",
996 text: "@@||" + domain.value.toLowerCase() + "^$document" 1047 text: "@@||" + domain.value.toLowerCase() + "^$document"
997 }); 1048 });
998 } 1049 }
999 1050
1000 domain.value = ""; 1051 domain.value = "";
1001 E("whitelisting-add-button").disabled = true; 1052 E("whitelisting-add-button").disabled = true;
1002 } 1053 }
1003 1054
1004 function editCustomFilters()
1005 {
1006 if (!isCustomFiltersLoaded)
1007 {
1008 console.error("Custom filters are not loaded");
1009 return;
1010 }
1011
1012 E("custom-filters").classList.add("mode-edit");
1013 let filterTexts = [];
1014 for (let customFilterItem of collections.customFilters.items)
1015 filterTexts.push(customFilterItem.text);
1016 E("custom-filters-raw").value = filterTexts.join("\n");
1017 }
1018
1019 function addEnableSubscription(url, title, homepage) 1055 function addEnableSubscription(url, title, homepage)
1020 { 1056 {
1021 let messageType = null; 1057 let messageType = null;
1022 let knownSubscription = subscriptionsMap[url]; 1058 let knownSubscription = subscriptionsMap[url];
1023 if (knownSubscription && knownSubscription.disabled == true) 1059 if (knownSubscription && knownSubscription.disabled == true)
1024 messageType = "subscriptions.toggle"; 1060 messageType = "subscriptions.toggle";
1025 else 1061 else
1026 messageType = "subscriptions.add"; 1062 messageType = "subscriptions.add";
1027 1063
1028 let message = { 1064 let message = {
(...skipping 15 matching lines...) Expand all
1044 case "added": 1080 case "added":
1045 filter[timestampUI] = Date.now(); 1081 filter[timestampUI] = Date.now();
1046 updateFilter(filter); 1082 updateFilter(filter);
1047 updateShareLink(); 1083 updateShareLink();
1048 break; 1084 break;
1049 case "loaded": 1085 case "loaded":
1050 populateLists(); 1086 populateLists();
1051 break; 1087 break;
1052 case "removed": 1088 case "removed":
1053 let knownFilter = filtersMap[filter.text]; 1089 let knownFilter = filtersMap[filter.text];
1054 collections.whitelist.removeItem(knownFilter); 1090 if (whitelistedDomainRegexp.test(knownFilter.text))
1055 collections.customFilters.removeItem(knownFilter); 1091 collections.whitelist.removeItem(knownFilter);
1092 else
1093 removeCustomFilter(filter.text);
1094
1056 delete filtersMap[filter.text]; 1095 delete filtersMap[filter.text];
1057 updateShareLink(); 1096 updateShareLink();
1058 break; 1097 break;
1059 } 1098 }
1060 } 1099 }
1061 1100
1062 function onSubscriptionMessage(action, subscription) 1101 function onSubscriptionMessage(action, subscription)
1063 { 1102 {
1064 if (subscription.url in subscriptionsMap) 1103 if (subscription.url in subscriptionsMap)
1065 { 1104 {
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after
1316 }); 1355 });
1317 ext.backgroundPage.sendMessage({ 1356 ext.backgroundPage.sendMessage({
1318 type: "subscriptions.listen", 1357 type: "subscriptions.listen",
1319 filter: ["added", "disabled", "homepage", "lastDownload", "removed", 1358 filter: ["added", "disabled", "homepage", "lastDownload", "removed",
1320 "title", "downloadStatus", "downloading"] 1359 "title", "downloadStatus", "downloading"]
1321 }); 1360 });
1322 1361
1323 window.addEventListener("DOMContentLoaded", onDOMLoaded, false); 1362 window.addEventListener("DOMContentLoaded", onDOMLoaded, false);
1324 window.addEventListener("hashchange", onHashChange, false); 1363 window.addEventListener("hashchange", onHashChange, false);
1325 } 1364 }
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