OLD | NEW |
1 /* | 1 /* |
2 * This file is part of Adblock Plus <https://adblockplus.org/>, | 2 * This file is part of Adblock Plus <https://adblockplus.org/>, |
3 * Copyright (C) 2006-2017 eyeo GmbH | 3 * Copyright (C) 2006-2017 eyeo GmbH |
4 * | 4 * |
5 * Adblock Plus is free software: you can redistribute it and/or modify | 5 * Adblock Plus is free software: you can redistribute it and/or modify |
6 * it under the terms of the GNU General Public License version 3 as | 6 * it under the terms of the GNU General Public License version 3 as |
7 * published by the Free Software Foundation. | 7 * published by the Free Software Foundation. |
8 * | 8 * |
9 * Adblock Plus is distributed in the hope that it will be useful, | 9 * Adblock Plus is distributed in the hope that it will be useful, |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 * GNU General Public License for more details. | 12 * GNU General Public License for more details. |
13 * | 13 * |
14 * You should have received a copy of the GNU General Public License | 14 * You should have received a copy of the GNU General Public License |
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. | 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
16 */ | 16 */ |
17 | 17 |
18 /* globals checkShareResource, getDocLink, i18nFormatDateTime, openSharePopup, | 18 /* globals checkShareResource, getDocLink, i18nFormatDateTime, openSharePopup, |
19 E */ | 19 E */ |
20 | 20 |
21 "use strict"; | 21 "use strict"; |
22 | 22 |
23 { | 23 { |
24 let subscriptionsMap = Object.create(null); | 24 let subscriptionsMap = Object.create(null); |
25 let filtersMap = Object.create(null); | 25 let filtersMap = Object.create(null); |
26 let collections = Object.create(null); | 26 let collections = Object.create(null); |
27 let acceptableAdsUrl = null; | 27 let acceptableAdsUrl = null; |
28 let isCustomFiltersLoaded = false; | 28 let isCustomFiltersLoaded = false; |
29 let {getMessage} = ext.i18n; | 29 let {getMessage} = ext.i18n; |
| 30 let customFiltersArray = []; |
30 let 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 Loading... |
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 Loading... |
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 lastUpdateLive = function() |
248 timeElement.textContent = dateTime[1]; | 252 { |
| 253 let sinceUpdate = Date.now() - lastUpdate; |
| 254 if (sinceUpdate > fullDayInMs) |
| 255 { |
| 256 let lastUpdateDate = new Date(item.lastDownload * 1000); |
| 257 let monthName = lastUpdateDate.toLocaleString(undefined, |
| 258 {month: "short"}); |
| 259 let day = lastUpdateDate.getDate(); |
| 260 day = day < 10 ? "0" + day : day; |
| 261 lastUpdateElement.textContent = day + " " + monthName + " " + |
| 262 lastUpdateDate.getFullYear(); |
| 263 } |
| 264 else if (sinceUpdate > hourInMs) |
| 265 { |
| 266 let placeholder = [Math.round(sinceUpdate / hourInMs)]; |
| 267 lastUpdateElement.textContent = |
| 268 getMessage("options_filterList_hours", placeholder); |
| 269 } |
| 270 else if (sinceUpdate > minuteInMs) |
| 271 { |
| 272 let placeholder = [Math.round(sinceUpdate / minuteInMs)]; |
| 273 lastUpdateElement.textContent = |
| 274 getMessage("options_filterList_minutes", placeholder); |
| 275 } |
| 276 else |
| 277 { |
| 278 lastUpdateElement.textContent = |
| 279 getMessage("options_filterList_now"); |
| 280 } |
| 281 }; |
| 282 lastUpdateLive(); |
249 element.classList.remove("show-message"); | 283 element.classList.remove("show-message"); |
250 } | 284 } |
251 } | 285 } |
252 | 286 |
253 let websiteElement = element.querySelector(".context-menu .website"); | 287 let websiteElement = element.querySelector(".context-menu .website"); |
254 if (websiteElement) | 288 if (websiteElement) |
255 { | 289 { |
256 if (item.homepage) | 290 if (item.homepage) |
257 websiteElement.setAttribute("href", item.homepage); | 291 websiteElement.setAttribute("href", item.homepage); |
258 else | 292 else |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
333 { | 367 { |
334 id: "custom-list-table" | 368 id: "custom-list-table" |
335 } | 369 } |
336 ]); | 370 ]); |
337 collections.whitelist = new Collection([ | 371 collections.whitelist = new Collection([ |
338 { | 372 { |
339 id: "whitelisting-table", | 373 id: "whitelisting-table", |
340 emptyText: ["options_whitelist_empty_1", "options_whitelist_empty_2"] | 374 emptyText: ["options_whitelist_empty_1", "options_whitelist_empty_2"] |
341 } | 375 } |
342 ]); | 376 ]); |
343 collections.customFilters = new Collection([ | |
344 { | |
345 id: "custom-filters-table", | |
346 emptyText: ["options_customFilters_empty"] | |
347 } | |
348 ]); | |
349 collections.filterLists = new Collection([ | 377 collections.filterLists = new Collection([ |
350 { | 378 { |
351 id: "all-filter-lists-table", | 379 id: "all-filter-lists-table", |
352 useOriginalTitle: true | 380 useOriginalTitle: true |
353 } | 381 } |
354 ]); | 382 ]); |
355 | 383 |
356 function toggleShowLanguage(subscription) | 384 function toggleShowLanguage(subscription) |
357 { | 385 { |
358 if (subscription.recommended == "ads") | 386 if (subscription.recommended == "ads") |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
396 function updateSubscription(subscription) | 424 function updateSubscription(subscription) |
397 { | 425 { |
398 for (let name in collections) | 426 for (let name in collections) |
399 collections[name].updateItem(subscription); | 427 collections[name].updateItem(subscription); |
400 | 428 |
401 toggleShowLanguage(subscription); | 429 toggleShowLanguage(subscription); |
402 } | 430 } |
403 | 431 |
404 function updateFilter(filter) | 432 function updateFilter(filter) |
405 { | 433 { |
406 let match = filter.text.match(/^@@\|\|([^/:]+)\^\$document$/); | 434 let match = filter.text.match(whitelistedDomainRegexp); |
407 if (match && !filtersMap[filter.text]) | 435 if (match && !filtersMap[filter.text]) |
408 { | 436 { |
409 filter.title = match[1]; | 437 filter.title = match[1]; |
410 collections.whitelist.addItem(filter); | 438 collections.whitelist.addItem(filter); |
411 } | 439 } |
412 else | 440 else |
413 collections.customFilters.addItem(filter); | 441 { |
| 442 customFiltersArray.push(filter.text); |
| 443 if (isCustomFiltersLoaded) |
| 444 updateCustomFiltersUi(); |
| 445 } |
414 | 446 |
415 filtersMap[filter.text] = filter; | 447 filtersMap[filter.text] = filter; |
416 } | 448 } |
417 | 449 |
| 450 function removeCustomFilter(text) |
| 451 { |
| 452 let index = customFiltersArray.indexOf(text); |
| 453 if (index >= 0) |
| 454 customFiltersArray.splice(index, 1); |
| 455 |
| 456 updateCustomFiltersUi(); |
| 457 } |
| 458 |
| 459 function updateCustomFiltersUi() |
| 460 { |
| 461 let customFiltersListElement = E("custom-filters-raw"); |
| 462 customFiltersListElement.value = ""; |
| 463 customFiltersListElement.value = customFiltersArray.join("\n"); |
| 464 } |
| 465 |
418 function loadRecommendations() | 466 function loadRecommendations() |
419 { | 467 { |
420 fetch("subscriptions.xml") | 468 fetch("subscriptions.xml") |
421 .then((response) => | 469 .then((response) => |
422 { | 470 { |
423 return response.text(); | 471 return response.text(); |
424 }) | 472 }) |
425 .then((text) => | 473 .then((text) => |
426 { | 474 { |
427 let doc = new DOMParser().parseFromString(text, "application/xml"); | 475 let doc = new DOMParser().parseFromString(text, "application/xml"); |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
492 else | 540 else |
493 location.href = link; | 541 location.href = link; |
494 }); | 542 }); |
495 } | 543 } |
496 | 544 |
497 function switchTab(id) | 545 function switchTab(id) |
498 { | 546 { |
499 location.hash = id; | 547 location.hash = id; |
500 } | 548 } |
501 | 549 |
502 function execAction(action, element) | 550 function execAction(action, element, event) |
503 { | 551 { |
504 switch (action) | 552 switch (action) |
505 { | 553 { |
506 case "add-domain-exception": | 554 case "add-domain-exception": |
507 addWhitelistedDomain(); | 555 addWhitelistedDomain(); |
508 break; | 556 break; |
509 case "add-language-subscription": | 557 case "add-language-subscription": |
510 addEnableSubscription(findParentData(element, "access", false)); | 558 addEnableSubscription(findParentData(element, "access", false)); |
511 break; | 559 break; |
512 case "add-predefined-subscription": { | 560 case "add-predefined-subscription": { |
513 let dialog = E("dialog-content-predefined"); | 561 let dialog = E("dialog-content-predefined"); |
514 let title = dialog.querySelector("h3").textContent; | 562 let title = dialog.querySelector("h3").textContent; |
515 let url = dialog.querySelector(".url").textContent; | 563 let url = dialog.querySelector(".url").textContent; |
516 addEnableSubscription(url, title); | 564 addEnableSubscription(url, title); |
517 closeDialog(); | 565 closeDialog(); |
518 break; | 566 break; |
519 } | 567 } |
520 case "cancel-custom-filters": | 568 case "cancel-custom-filters": |
521 E("custom-filters").classList.remove("mode-edit"); | 569 updateCustomFiltersUi(); |
| 570 setCustomFiltersView("read"); |
522 break; | 571 break; |
523 case "close-dialog": | 572 case "close-dialog": |
524 closeDialog(); | 573 closeDialog(); |
525 break; | 574 break; |
526 case "edit-custom-filters": | 575 case "edit-custom-filters": |
527 editCustomFilters(); | 576 setCustomFiltersView("write"); |
528 break; | 577 break; |
529 case "import-subscription": { | 578 case "import-subscription": { |
530 let url = E("blockingList-textbox").value; | 579 let url = E("blockingList-textbox").value; |
531 addEnableSubscription(url); | 580 addEnableSubscription(url); |
532 closeDialog(); | 581 closeDialog(); |
533 break; | 582 break; |
534 } | 583 } |
535 case "open-context-menu": { | 584 case "open-context-menu": { |
536 let listItem = findParentData(element, "access", true); | 585 let listItem = findParentData(element, "access", true); |
537 if (listItem && !listItem.classList.contains("show-context-menu")) | 586 if (listItem && !listItem.classList.contains("show-context-menu")) |
(...skipping 23 matching lines...) Expand all Loading... |
561 }); | 610 }); |
562 break; | 611 break; |
563 case "save-custom-filters": | 612 case "save-custom-filters": |
564 sendMessageHandleErrors({ | 613 sendMessageHandleErrors({ |
565 type: "filters.importRaw", | 614 type: "filters.importRaw", |
566 text: E("custom-filters-raw").value, | 615 text: E("custom-filters-raw").value, |
567 removeExisting: true | 616 removeExisting: true |
568 }, | 617 }, |
569 () => | 618 () => |
570 { | 619 { |
571 E("custom-filters").classList.remove("mode-edit"); | 620 setCustomFiltersView("read"); |
572 }); | 621 }); |
573 break; | 622 break; |
574 case "switch-tab": | 623 case "switch-tab": |
575 let tabId = findParentData(element, "tab", false); | 624 let tabId = findParentData(element, "tab", false); |
576 switchTab(tabId); | 625 switchTab(tabId); |
577 break; | 626 break; |
578 case "toggle-disable-subscription": | 627 case "toggle-disable-subscription": |
579 ext.backgroundPage.sendMessage({ | 628 ext.backgroundPage.sendMessage({ |
580 type: "subscriptions.toggle", | 629 type: "subscriptions.toggle", |
581 keepInstalled: true, | 630 keepInstalled: true, |
(...skipping 25 matching lines...) Expand all Loading... |
607 break; | 656 break; |
608 case "update-subscription": | 657 case "update-subscription": |
609 ext.backgroundPage.sendMessage({ | 658 ext.backgroundPage.sendMessage({ |
610 type: "subscriptions.update", | 659 type: "subscriptions.update", |
611 url: findParentData(element, "access", false) | 660 url: findParentData(element, "access", false) |
612 }); | 661 }); |
613 break; | 662 break; |
614 } | 663 } |
615 } | 664 } |
616 | 665 |
| 666 function setCustomFiltersView(mode) |
| 667 { |
| 668 let customFilters = E("custom-filters"); |
| 669 let customFiltersListElement = E("custom-filters-raw"); |
| 670 if (mode == "read") |
| 671 { |
| 672 customFiltersListElement.disabled = true; |
| 673 if (!customFiltersListElement.value) |
| 674 { |
| 675 setCustomFiltersView("empty"); |
| 676 return; |
| 677 } |
| 678 } |
| 679 else if (mode == "write") |
| 680 { |
| 681 updateCustomFiltersUi(); |
| 682 customFiltersListElement.disabled = false; |
| 683 } |
| 684 |
| 685 customFilters.dataset.mode = mode; |
| 686 } |
| 687 |
617 function onClick(e) | 688 function onClick(e) |
618 { | 689 { |
619 let context = document.querySelector(".show-context-menu"); | 690 let context = document.querySelector(".show-context-menu"); |
620 if (context) | 691 if (context) |
621 context.classList.remove("show-context-menu"); | 692 context.classList.remove("show-context-menu"); |
622 | 693 |
623 let actions = findParentData(e.target, "action", false); | 694 let actions = findParentData(e.target, "action", false); |
624 if (!actions) | 695 if (!actions) |
625 return; | 696 return; |
626 | 697 |
627 actions = actions.split(","); | 698 actions = actions.split(","); |
628 for (let action of actions) | 699 for (let action of actions) |
629 { | 700 { |
630 execAction(action, e.target); | 701 execAction(action, e.target, e); |
631 } | 702 } |
632 } | 703 } |
633 | 704 |
634 function getKey(e) | 705 function getKey(e) |
635 { | 706 { |
636 // e.keyCode has been deprecated so we attempt to use e.key | 707 // e.keyCode has been deprecated so we attempt to use e.key |
637 if ("key" in e) | 708 if ("key" in e) |
638 return e.key; | 709 return e.key; |
639 return getKey.keys[e.keyCode]; | 710 return getKey.keys[e.keyCode]; |
640 } | 711 } |
(...skipping 26 matching lines...) Expand all Loading... |
667 { | 738 { |
668 if (key == "ArrowLeft" || key == "ArrowUp") | 739 if (key == "ArrowLeft" || key == "ArrowUp") |
669 element = element.previousElementSibling || container.lastElementChild; | 740 element = element.previousElementSibling || container.lastElementChild; |
670 else if (key == "ArrowRight" || key == "ArrowDown") | 741 else if (key == "ArrowRight" || key == "ArrowDown") |
671 element = element.nextElementSibling || container.firstElementChild; | 742 element = element.nextElementSibling || container.firstElementChild; |
672 } | 743 } |
673 | 744 |
674 let actions = container.getAttribute("data-action").split(","); | 745 let actions = container.getAttribute("data-action").split(","); |
675 for (let action of actions) | 746 for (let action of actions) |
676 { | 747 { |
677 execAction(action, element); | 748 execAction(action, element, e); |
678 } | 749 } |
679 } | 750 } |
680 | 751 |
681 function selectTabItem(tabId, container, focus) | 752 function selectTabItem(tabId, container, focus) |
682 { | 753 { |
683 // Show tab content | 754 // Show tab content |
684 document.body.setAttribute("data-tab", tabId); | 755 document.body.setAttribute("data-tab", tabId); |
685 | 756 |
686 // Select tab | 757 // Select tab |
687 let tabList = container.querySelector("[role='tablist']"); | 758 let tabList = container.querySelector("[role='tablist']"); |
688 if (!tabList) | 759 if (!tabList) |
689 return null; | 760 return null; |
690 | 761 |
691 let previousTab = tabList.querySelector("[aria-selected]"); | 762 let previousTab = tabList.querySelector("[aria-selected]"); |
692 previousTab.removeAttribute("aria-selected"); | 763 previousTab.removeAttribute("aria-selected"); |
693 previousTab.setAttribute("tabindex", -1); | 764 previousTab.setAttribute("tabindex", -1); |
694 | 765 |
695 let tab = tabList.querySelector("li[data-tab='" + tabId + "']"); | 766 let tab = tabList.querySelector("li[data-tab='" + tabId + "']"); |
696 tab.setAttribute("aria-selected", true); | 767 tab.setAttribute("aria-selected", true); |
697 tab.setAttribute("tabindex", 0); | 768 tab.setAttribute("tabindex", 0); |
698 | 769 |
699 let tabContentId = tab.getAttribute("aria-controls"); | 770 let tabContentId = tab.getAttribute("aria-controls"); |
700 let tabContent = document.getElementById(tabContentId); | 771 let tabContent = document.getElementById(tabContentId); |
701 | 772 |
702 // Select sub tabs | |
703 if (tab.hasAttribute("data-subtab")) | |
704 selectTabItem(tab.getAttribute("data-subtab"), tabContent, false); | |
705 | |
706 if (tab && focus) | 773 if (tab && focus) |
707 tab.focus(); | 774 tab.focus(); |
708 | 775 |
709 return tabContent; | 776 return tabContent; |
710 } | 777 } |
711 | 778 |
712 function onHashChange() | 779 function onHashChange() |
713 { | 780 { |
714 let hash = location.hash.substr(1); | 781 let hash = location.hash.substr(1); |
715 if (!hash) | 782 if (!hash) |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
767 E("find-language").addEventListener("keyup", onFindLanguageKeyUp, false); | 834 E("find-language").addEventListener("keyup", onFindLanguageKeyUp, false); |
768 let exampleValue = getMessage("options_whitelist_placeholder_example", | 835 let exampleValue = getMessage("options_whitelist_placeholder_example", |
769 ["www.example.com"]); | 836 ["www.example.com"]); |
770 E("whitelisting-textbox").setAttribute("placeholder", exampleValue); | 837 E("whitelisting-textbox").setAttribute("placeholder", exampleValue); |
771 E("whitelisting-textbox").addEventListener("keyup", (e) => | 838 E("whitelisting-textbox").addEventListener("keyup", (e) => |
772 { | 839 { |
773 E("whitelisting-add-button").disabled = !e.target.value; | 840 E("whitelisting-add-button").disabled = !e.target.value; |
774 }, false); | 841 }, false); |
775 | 842 |
776 // Advanced tab | 843 // Advanced tab |
777 let tweaks = document.querySelectorAll("#tweaks li[data-pref]"); | 844 let customize = document.querySelectorAll("#customize li[data-pref]"); |
778 tweaks = Array.prototype.map.call(tweaks, (checkbox) => | 845 customize = Array.prototype.map.call(customize, (checkbox) => |
779 { | 846 { |
780 return checkbox.getAttribute("data-pref"); | 847 return checkbox.getAttribute("data-pref"); |
781 }); | 848 }); |
782 for (let key of tweaks) | 849 for (let key of customize) |
783 { | 850 { |
784 getPref(key, (value) => | 851 getPref(key, (value) => |
785 { | 852 { |
786 onPrefMessage(key, value, true); | 853 onPrefMessage(key, value, true); |
787 }); | 854 }); |
788 } | 855 } |
789 ext.backgroundPage.sendMessage({ | 856 ext.backgroundPage.sendMessage({ |
790 type: "app.get", | 857 type: "app.get", |
791 what: "features" | 858 what: "features" |
792 }, | 859 }, |
793 (features) => | 860 (features) => |
794 { | 861 { |
795 hidePref("show_devtools_panel", !features.devToolsPanel); | 862 hidePref("show_devtools_panel", !features.devToolsPanel); |
796 }); | 863 }); |
797 | 864 |
798 let filterTextbox = document.querySelector("#custom-filters-add input"); | 865 getDocLink("filterdoc", (link) => |
799 placeholderValue = getMessage("options_customFilters_textbox_placeholder"); | |
800 filterTextbox.setAttribute("placeholder", placeholderValue); | |
801 function addCustomFilters() | |
802 { | 866 { |
803 let filterText = filterTextbox.value; | 867 E("link-filters").setAttribute("href", link); |
804 sendMessageHandleErrors({ | 868 }); |
805 type: "filters.add", | 869 |
806 text: filterText | 870 getDocLink("subscriptions", (link) => |
807 }, | |
808 () => | |
809 { | |
810 filterTextbox.value = ""; | |
811 }); | |
812 } | |
813 E("custom-filters-add").addEventListener("submit", (e) => | |
814 { | 871 { |
815 e.preventDefault(); | 872 setLinks("filter-lists-description", link); |
816 addCustomFilters(); | 873 }); |
817 }, false); | 874 |
| 875 E("custom-filters-raw").setAttribute("placeholder", |
| 876 getMessage("options_customFilters_edit_placeholder", ["/ads/track/*"])); |
818 | 877 |
819 // Help tab | 878 // Help tab |
820 getDocLink("faq", (link) => | 879 getDocLink("faq", (link) => |
821 { | 880 { |
822 E("link-faq").setAttribute("href", link); | 881 E("link-faq").setAttribute("href", link); |
823 }); | 882 }); |
824 getDocLink("social_twitter", (link) => | 883 getDocLink("social_twitter", (link) => |
825 { | 884 { |
826 E("link-twitter").setAttribute("href", link); | 885 E("link-twitter").setAttribute("href", link); |
827 }); | 886 }); |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
940 ext.backgroundPage.sendMessage({ | 999 ext.backgroundPage.sendMessage({ |
941 type: "filters.get", | 1000 type: "filters.get", |
942 subscriptionUrl: subscription.url | 1001 subscriptionUrl: subscription.url |
943 }, | 1002 }, |
944 (filters) => | 1003 (filters) => |
945 { | 1004 { |
946 for (let filter of filters) | 1005 for (let filter of filters) |
947 updateFilter(filter); | 1006 updateFilter(filter); |
948 | 1007 |
949 isCustomFiltersLoaded = true; | 1008 isCustomFiltersLoaded = true; |
| 1009 updateCustomFiltersUi(); |
| 1010 setCustomFiltersView("read"); |
950 }); | 1011 }); |
951 } | 1012 } |
952 }); | 1013 }); |
953 loadRecommendations(); | 1014 loadRecommendations(); |
954 ext.backgroundPage.sendMessage({ | 1015 ext.backgroundPage.sendMessage({ |
955 type: "prefs.get", | 1016 type: "prefs.get", |
956 key: "subscriptions_exceptionsurl" | 1017 key: "subscriptions_exceptionsurl" |
957 }, | 1018 }, |
958 (url) => | 1019 (url) => |
959 { | 1020 { |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1044 case "added": | 1105 case "added": |
1045 filter[timestampUI] = Date.now(); | 1106 filter[timestampUI] = Date.now(); |
1046 updateFilter(filter); | 1107 updateFilter(filter); |
1047 updateShareLink(); | 1108 updateShareLink(); |
1048 break; | 1109 break; |
1049 case "loaded": | 1110 case "loaded": |
1050 populateLists(); | 1111 populateLists(); |
1051 break; | 1112 break; |
1052 case "removed": | 1113 case "removed": |
1053 let knownFilter = filtersMap[filter.text]; | 1114 let knownFilter = filtersMap[filter.text]; |
1054 collections.whitelist.removeItem(knownFilter); | 1115 if (whitelistedDomainRegexp.test(knownFilter.text)) |
1055 collections.customFilters.removeItem(knownFilter); | 1116 collections.whitelist.removeItem(knownFilter); |
| 1117 else |
| 1118 removeCustomFilter(filter.text); |
| 1119 |
1056 delete filtersMap[filter.text]; | 1120 delete filtersMap[filter.text]; |
1057 updateShareLink(); | 1121 updateShareLink(); |
1058 break; | 1122 break; |
1059 } | 1123 } |
1060 } | 1124 } |
1061 | 1125 |
1062 function onSubscriptionMessage(action, subscription) | 1126 function onSubscriptionMessage(action, subscription) |
1063 { | 1127 { |
1064 if (subscription.url in subscriptionsMap) | 1128 if (subscription.url in subscriptionsMap) |
1065 { | 1129 { |
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1316 }); | 1380 }); |
1317 ext.backgroundPage.sendMessage({ | 1381 ext.backgroundPage.sendMessage({ |
1318 type: "subscriptions.listen", | 1382 type: "subscriptions.listen", |
1319 filter: ["added", "disabled", "homepage", "lastDownload", "removed", | 1383 filter: ["added", "disabled", "homepage", "lastDownload", "removed", |
1320 "title", "downloadStatus", "downloading"] | 1384 "title", "downloadStatus", "downloading"] |
1321 }); | 1385 }); |
1322 | 1386 |
1323 window.addEventListener("DOMContentLoaded", onDOMLoaded, false); | 1387 window.addEventListener("DOMContentLoaded", onDOMLoaded, false); |
1324 window.addEventListener("hashchange", onHashChange, false); | 1388 window.addEventListener("hashchange", onHashChange, false); |
1325 } | 1389 } |
OLD | NEW |