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