| Left: | ||
| Right: |
| 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-2015 Eyeo GmbH | 3 * Copyright (C) 2006-2015 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 |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 29 this.details = details; | 29 this.details = details; |
| 30 this.items = []; | 30 this.items = []; |
| 31 } | 31 } |
| 32 | 32 |
| 33 Collection.prototype.addItems = function() | 33 Collection.prototype.addItems = function() |
| 34 { | 34 { |
| 35 var length = Array.prototype.push.apply(this.items, arguments); | 35 var length = Array.prototype.push.apply(this.items, arguments); |
| 36 if (length == 0) | 36 if (length == 0) |
| 37 return; | 37 return; |
| 38 | 38 |
| 39 this.items.sort(function(a, b) | 39 this.items.sort(function(a, b) |
|
Thomas Greiner
2015/06/30 09:23:29
You need to first filter out all empty lines befor
saroyanm
2015/07/08 18:25:42
I do wander why we even need to submit the empty s
Thomas Greiner
2015/07/09 11:07:54
Yep, the earlier we can filter those out the bette
saroyanm
2015/07/09 16:31:39
Done.
| |
| 40 { | 40 { |
| 41 var aValue = (a.title || a.url || a.text).toLowerCase(); | 41 var aValue = (a.title || a.text || a.url).toLowerCase(); |
| 42 var bValue = (b.title || b.url || a.text).toLowerCase(); | 42 var bValue = (b.title || b.text || a.url).toLowerCase(); |
|
Thomas Greiner
2015/06/30 09:23:27
Be careful: It's `b.url`, not `a.url`
saroyanm
2015/07/08 18:25:41
Done.
| |
| 43 return aValue.localeCompare(bValue); | 43 return aValue.localeCompare(bValue); |
| 44 }); | 44 }); |
| 45 | 45 |
| 46 for (var j = 0; j < this.details.length; j++) | 46 for (var j = 0; j < this.details.length; j++) |
| 47 { | 47 { |
| 48 var table = E(this.details[j].id); | 48 var table = E(this.details[j].id); |
| 49 var template = table.querySelector("template"); | 49 var template = table.querySelector("template"); |
| 50 for (var i = 0; i < arguments.length; i++) | 50 for (var i = 0; i < arguments.length; i++) |
| 51 { | 51 { |
| 52 var item = arguments[i]; | 52 var item = arguments[i]; |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 163 onClick: onToggleSubscriptionClick | 163 onClick: onToggleSubscriptionClick |
| 164 } | 164 } |
| 165 ]); | 165 ]); |
| 166 collections.whitelist = new Collection( | 166 collections.whitelist = new Collection( |
| 167 [ | 167 [ |
| 168 { | 168 { |
| 169 id: "whitelisting-table", | 169 id: "whitelisting-table", |
| 170 onClick: onRemoveFilterClick | 170 onClick: onRemoveFilterClick |
| 171 } | 171 } |
| 172 ]); | 172 ]); |
| 173 collections.customFilters = new Collection( | |
| 174 [ | |
| 175 { | |
| 176 id: "custom-filters-table" | |
| 177 } | |
| 178 ]); | |
| 173 | 179 |
| 174 function updateSubscription(subscription) | 180 function updateSubscription(subscription) |
| 175 { | 181 { |
| 176 var subscriptionUrl = subscription.url; | 182 var subscriptionUrl = subscription.url; |
| 177 var knownSubscription = subscriptionsMap[subscriptionUrl]; | 183 var knownSubscription = subscriptionsMap[subscriptionUrl]; |
| 178 if (knownSubscription) | 184 if (knownSubscription) |
| 179 knownSubscription.disabled = subscription.disabled; | 185 knownSubscription.disabled = subscription.disabled; |
| 180 else | 186 else |
| 181 { | 187 { |
| 182 getAcceptableAdsURL(function(acceptableAdsUrl) | 188 getAcceptableAdsURL(function(acceptableAdsUrl) |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 259 } | 265 } |
| 260 } | 266 } |
| 261 | 267 |
| 262 function updateFilter(filter) | 268 function updateFilter(filter) |
| 263 { | 269 { |
| 264 var match = filter.text.match(/^@@\|\|([^\/:]+)\^\$document$/); | 270 var match = filter.text.match(/^@@\|\|([^\/:]+)\^\$document$/); |
| 265 if (match && !filtersMap[filter.text]) | 271 if (match && !filtersMap[filter.text]) |
| 266 { | 272 { |
| 267 filter.title = match[1]; | 273 filter.title = match[1]; |
| 268 collections.whitelist.addItems(filter); | 274 collections.whitelist.addItems(filter); |
| 269 filtersMap[filter.text] = filter | 275 filtersMap[filter.text] = filter; |
| 270 } | 276 } |
| 271 else | 277 else |
| 272 { | 278 { |
| 273 // TODO: add `filters[i].text` to list of custom filters | 279 // TODO: add `filters[i].text` to list of custom filters |
|
Thomas Greiner
2015/06/30 09:23:28
Remove this comment
saroyanm
2015/07/08 18:25:42
Done.
| |
| 280 collections.customFilters.addItems(filter); | |
| 281 filtersMap[filter.text] = filter; | |
|
Thomas Greiner
2015/06/30 09:23:28
This line is shared across both branches of the if
saroyanm
2015/07/08 18:25:41
Done.
| |
| 274 } | 282 } |
| 275 } | 283 } |
| 276 | 284 |
| 277 function loadRecommendations() | 285 function loadRecommendations() |
| 278 { | 286 { |
| 279 var request = new XMLHttpRequest(); | 287 var request = new XMLHttpRequest(); |
| 280 request.open("GET", "subscriptions.xml", false); | 288 request.open("GET", "subscriptions.xml", false); |
| 281 request.addEventListener("load", function() | 289 request.addEventListener("load", function() |
| 282 { | 290 { |
| 283 var list = document.getElementById("subscriptionSelector"); | 291 var list = document.getElementById("subscriptionSelector"); |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 339 | 347 |
| 340 function onFindLanguageKeyUp() | 348 function onFindLanguageKeyUp() |
| 341 { | 349 { |
| 342 var searchStyle = E("search-style"); | 350 var searchStyle = E("search-style"); |
| 343 if (!this.value) | 351 if (!this.value) |
| 344 searchStyle.innerHTML = ""; | 352 searchStyle.innerHTML = ""; |
| 345 else | 353 else |
| 346 searchStyle.innerHTML = "#all-lang-table li:not([data-search*=\"" + this .value.toLowerCase() + "\"]) { display: none; }"; | 354 searchStyle.innerHTML = "#all-lang-table li:not([data-search*=\"" + this .value.toLowerCase() + "\"]) { display: none; }"; |
| 347 } | 355 } |
| 348 | 356 |
| 357 function isEnterPressed(e) | |
| 358 { | |
| 359 // e.keyCode has been deprecated so we attempt to use e.key | |
| 360 // keyCode "13" corresponds to "Enter" | |
| 361 if ((e.key && e.key == "Enter") || (!e.key && e.keyCode == 13)) | |
| 362 return true; | |
| 363 return false; | |
|
Thomas Greiner
2015/06/30 09:23:28
Detail: You could reduce that to one line:
return
saroyanm
2015/07/08 18:25:41
Done. Please note that this function most probably
| |
| 364 } | |
| 365 | |
| 349 // Update version number in navigation sidebar | 366 // Update version number in navigation sidebar |
| 350 ext.backgroundPage.sendMessage( | 367 ext.backgroundPage.sendMessage( |
| 351 { | 368 { |
| 352 method: "app.get", | 369 method: "app.get", |
| 353 what: "addonVersion" | 370 what: "addonVersion" |
| 354 }, | 371 }, |
| 355 function(addonVersion) | 372 function(addonVersion) |
| 356 { | 373 { |
| 357 E("abp-version").textContent = addonVersion; | 374 E("abp-version").textContent = addonVersion; |
| 358 }); | 375 }); |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 377 { | 394 { |
| 378 var id = e.target.id; | 395 var id = e.target.id; |
| 379 if (id == "whitelisting-add-icon" || id == "whitelisting-enter-icon") | 396 if (id == "whitelisting-add-icon" || id == "whitelisting-enter-icon") |
| 380 addWhitelistedDomain(); | 397 addWhitelistedDomain(); |
| 381 else if (id == "whitelisting-cancel-button") | 398 else if (id == "whitelisting-cancel-button") |
| 382 E("whitelisting-textbox").value = ""; | 399 E("whitelisting-textbox").value = ""; |
| 383 }, false); | 400 }, false); |
| 384 E("whitelisting-add-button").addEventListener("click", addWhitelistedDomain, false); | 401 E("whitelisting-add-button").addEventListener("click", addWhitelistedDomain, false); |
| 385 E("whitelisting-textbox").addEventListener("keypress", function(e) | 402 E("whitelisting-textbox").addEventListener("keypress", function(e) |
| 386 { | 403 { |
| 387 // e.keyCode has been deprecated so we attempt to use e.key | 404 if (isEnterPressed(e)) |
| 388 // keyCode "13" corresponds to "Enter" | |
| 389 if ((e.key && e.key == "Enter") || (!e.key && e.keyCode == 13)) | |
| 390 addWhitelistedDomain(); | 405 addWhitelistedDomain(); |
| 391 }, false); | 406 }, false); |
| 392 E("import-blockingList-button").addEventListener("click", function() | 407 E("import-blockingList-button").addEventListener("click", function() |
| 393 { | 408 { |
| 394 var url = E("blockingList-textbox").value; | 409 var url = E("blockingList-textbox").value; |
| 395 addEnableSubscription(url); | 410 addEnableSubscription(url); |
| 396 delete document.body.dataset.dialog; | 411 delete document.body.dataset.dialog; |
| 397 }, false); | 412 }, false); |
| 413 | |
| 414 // Advanced tab | |
| 415 E("custom-filters-add-textbox").setAttribute("placeholder", ext.i18n.getMess age("options_customFilters_textbox_placeholder")); | |
|
Thomas Greiner
2015/06/30 09:23:28
Split this up into two lines to avoid exceeding th
saroyanm
2015/07/08 18:25:41
Done.
| |
| 416 function addCustomFilter() | |
|
Thomas Greiner
2015/06/30 09:23:28
"addCustomFilters" please
saroyanm
2015/07/08 18:25:41
Done.
| |
| 417 { | |
| 418 var filterTextbox = E("custom-filters-add-textbox"); | |
| 419 ext.backgroundPage.sendMessage( | |
| 420 { | |
| 421 type: "parse.filter", | |
| 422 text: filterTextbox.value | |
| 423 }, | |
| 424 function(result) | |
| 425 { | |
| 426 if (result.error) | |
| 427 { | |
| 428 alert(result.error); | |
| 429 return; | |
| 430 } | |
| 431 if (result.filter) | |
| 432 addFilter(result.filter.text); | |
| 433 | |
| 434 filterTextbox.value = ""; | |
| 435 }); | |
| 436 } | |
| 437 E("custom-filters-add-btn").addEventListener("click", addCustomFilter, false ); | |
| 438 E("custom-filters-add-textbox").addEventListener("keypress", function(e) | |
| 439 { | |
| 440 if (isEnterPressed(e)) | |
| 441 addCustomFilter(); | |
| 442 }, false); | |
| 443 var customFilterEditButtons = document.querySelectorAll("#custom-filters-edi t-wrapper button"); | |
|
Thomas Greiner
2015/06/30 09:23:28
Please avoid setting event listeners individually
saroyanm
2015/07/08 18:25:40
Done.
| |
| 444 for (var i = 0; i < customFilterEditButtons.length; i++) | |
| 445 { | |
| 446 customFilterEditButtons[i].addEventListener("click", function(e) | |
| 447 { | |
| 448 E("custom-filters").dataset.view = e.currentTarget.dataset.show; | |
|
Thomas Greiner
2015/06/30 09:23:28
This can be achieved more performantly by toggling
saroyanm
2015/07/08 18:25:41
Done.
| |
| 449 var id = e.currentTarget.id; | |
| 450 if (id == "custom-filters-edit-btn") | |
| 451 editCustomFilters(); | |
| 452 else if (id == "custom-filters-save-btn") | |
| 453 { | |
| 454 ext.backgroundPage.sendMessage( | |
| 455 { | |
| 456 type: "filters.importRaw", | |
| 457 text: E("custom-filters-textarea").value | |
| 458 }); | |
| 459 } | |
| 460 }, false); | |
| 461 } | |
| 398 } | 462 } |
| 399 | 463 |
| 400 function openDialog(name) | 464 function openDialog(name) |
| 401 { | 465 { |
| 402 document.body.dataset.dialog = name; | 466 document.body.dataset.dialog = name; |
| 403 } | 467 } |
| 404 | 468 |
| 405 function populateLists() | 469 function populateLists() |
| 406 { | 470 { |
| 407 subscriptionsMap = Object.create(null); | 471 subscriptionsMap = Object.create(null); |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 467 type: "filters.add", | 531 type: "filters.add", |
| 468 text: "@@||" + domain.value.toLowerCase() + "^$document" | 532 text: "@@||" + domain.value.toLowerCase() + "^$document" |
| 469 }); | 533 }); |
| 470 } | 534 } |
| 471 | 535 |
| 472 domain.value = ""; | 536 domain.value = ""; |
| 473 } | 537 } |
| 474 | 538 |
| 475 function editCustomFilters() | 539 function editCustomFilters() |
| 476 { | 540 { |
| 477 //TODO: NYI | 541 var customFilterItems = collections.customFilters.items; |
| 542 var text = ""; | |
| 543 for (var i = 0; i < customFilterItems.length; i++) | |
| 544 text += customFilterItems[i].text + "\n"; | |
| 545 E("custom-filters-textarea").value = text; | |
|
Thomas Greiner
2015/06/30 09:23:28
This loop is potentially creating a lot of strings
saroyanm
2015/07/08 18:25:41
Done.
| |
| 478 } | 546 } |
| 479 | 547 |
| 480 function getAcceptableAdsURL(callback) | 548 function getAcceptableAdsURL(callback) |
| 481 { | 549 { |
| 482 ext.backgroundPage.sendMessage( | 550 ext.backgroundPage.sendMessage( |
| 483 { | 551 { |
| 484 type: "prefs.get", | 552 type: "prefs.get", |
| 485 key: "subscriptions_exceptionsurl" | 553 key: "subscriptions_exceptionsurl" |
| 486 }, | 554 }, |
| 487 function(value) | 555 function(value) |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 526 | 594 |
| 527 function removeFilter(filter) | 595 function removeFilter(filter) |
| 528 { | 596 { |
| 529 ext.backgroundPage.sendMessage( | 597 ext.backgroundPage.sendMessage( |
| 530 { | 598 { |
| 531 type: "filters.remove", | 599 type: "filters.remove", |
| 532 text: filter | 600 text: filter |
| 533 }); | 601 }); |
| 534 } | 602 } |
| 535 | 603 |
| 604 function addFilter(filter) | |
|
Thomas Greiner
2015/06/30 09:23:29
There's no need to create a function for that beca
saroyanm
2015/07/08 18:25:41
Done.
Please note that we still have similar metho
Thomas Greiner
2015/07/09 11:07:54
Good point, feel free to include that in this revi
saroyanm
2015/07/09 16:31:39
Done.
| |
| 605 { | |
| 606 ext.backgroundPage.sendMessage( | |
| 607 { | |
| 608 type: "filters.add", | |
| 609 text: filter | |
| 610 }); | |
| 611 } | |
| 612 | |
| 536 function onFilterMessage(action, filter) | 613 function onFilterMessage(action, filter) |
| 537 { | 614 { |
| 538 switch (action) | 615 switch (action) |
| 539 { | 616 { |
| 540 case "added": | 617 case "added": |
| 541 updateFilter(filter); | 618 updateFilter(filter); |
| 542 updateShareLink(); | 619 updateShareLink(); |
| 543 break; | 620 break; |
| 544 case "loaded": | 621 case "loaded": |
| 545 populateLists(); | 622 populateLists(); |
| 546 break; | 623 break; |
| 547 case "removed": | 624 case "removed": |
| 548 var knownFilter = filtersMap[filter.text]; | 625 var knownFilter = filtersMap[filter.text]; |
| 549 collections.whitelist.removeItem(knownFilter); | 626 collections.whitelist.removeItem(knownFilter); |
| 627 collections.customFilters.removeItem(knownFilter); | |
|
Thomas Greiner
2015/06/30 09:23:28
Note that when I click on "edit view" and right af
saroyanm
2015/07/08 18:25:41
The problem is that in "filters.importRaw" we were
| |
| 550 delete filtersMap[filter.text]; | 628 delete filtersMap[filter.text]; |
| 551 updateShareLink(); | 629 updateShareLink(); |
| 552 break; | 630 break; |
| 553 } | 631 } |
| 554 } | 632 } |
| 555 | 633 |
| 556 function onSubscriptionMessage(action, subscription) | 634 function onSubscriptionMessage(action, subscription) |
| 557 { | 635 { |
| 558 switch (action) | 636 switch (action) |
| 559 { | 637 { |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 648 filter: ["added", "loaded", "removed"] | 726 filter: ["added", "loaded", "removed"] |
| 649 }); | 727 }); |
| 650 ext.backgroundPage.sendMessage( | 728 ext.backgroundPage.sendMessage( |
| 651 { | 729 { |
| 652 type: "subscriptions.listen", | 730 type: "subscriptions.listen", |
| 653 filter: ["added", "disabled", "homepage", "removed", "title"] | 731 filter: ["added", "disabled", "homepage", "removed", "title"] |
| 654 }); | 732 }); |
| 655 | 733 |
| 656 window.addEventListener("DOMContentLoaded", onDOMLoaded, false); | 734 window.addEventListener("DOMContentLoaded", onDOMLoaded, false); |
| 657 })(); | 735 })(); |
| OLD | NEW |