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 20 matching lines...) Expand all Loading... | |
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) |
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 || b.url).toLowerCase(); |
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 | |
270 } | 275 } |
271 else | 276 else |
272 { | 277 collections.customFilters.addItems(filter); |
273 // TODO: add `filters[i].text` to list of custom filters | 278 |
274 } | 279 filtersMap[filter.text] = filter; |
275 } | 280 } |
276 | 281 |
277 function loadRecommendations() | 282 function loadRecommendations() |
278 { | 283 { |
279 var request = new XMLHttpRequest(); | 284 var request = new XMLHttpRequest(); |
280 request.open("GET", "subscriptions.xml", false); | 285 request.open("GET", "subscriptions.xml", false); |
281 request.addEventListener("load", function() | 286 request.addEventListener("load", function() |
282 { | 287 { |
283 var list = document.getElementById("subscriptionSelector"); | 288 var list = document.getElementById("subscriptionSelector"); |
284 var docElem = request.responseXML.documentElement; | 289 var docElem = request.responseXML.documentElement; |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
338 | 343 |
339 function onFindLanguageKeyUp() | 344 function onFindLanguageKeyUp() |
340 { | 345 { |
341 var searchStyle = E("search-style"); | 346 var searchStyle = E("search-style"); |
342 if (!this.value) | 347 if (!this.value) |
343 searchStyle.innerHTML = ""; | 348 searchStyle.innerHTML = ""; |
344 else | 349 else |
345 searchStyle.innerHTML = "#all-lang-table li:not([data-search*=\"" + this .value.toLowerCase() + "\"]) { display: none; }"; | 350 searchStyle.innerHTML = "#all-lang-table li:not([data-search*=\"" + this .value.toLowerCase() + "\"]) { display: none; }"; |
346 } | 351 } |
347 | 352 |
353 function isEnterPressed(e) | |
354 { | |
355 // e.keyCode has been deprecated so we attempt to use e.key | |
356 // keyCode "13" corresponds to "Enter" | |
357 return (e.key && e.key == "Enter") || (!e.key && e.keyCode == 13); | |
Sebastian Noack
2015/07/09 12:12:15
Please don't duplicate the check for presence of e
saroyanm
2015/07/09 16:31:42
Done.
| |
358 } | |
359 | |
348 // Initialize navigation sidebar | 360 // Initialize navigation sidebar |
349 ext.backgroundPage.sendMessage( | 361 ext.backgroundPage.sendMessage( |
350 { | 362 { |
351 type: "app.get", | 363 type: "app.get", |
352 what: "addonVersion" | 364 what: "addonVersion" |
353 }, | 365 }, |
354 function(addonVersion) | 366 function(addonVersion) |
355 { | 367 { |
356 E("abp-version").textContent = addonVersion; | 368 E("abp-version").textContent = addonVersion; |
357 }); | 369 }); |
(...skipping 30 matching lines...) Expand all Loading... | |
388 { | 400 { |
389 var id = e.target.id; | 401 var id = e.target.id; |
390 if (id == "whitelisting-add-icon" || id == "whitelisting-enter-icon") | 402 if (id == "whitelisting-add-icon" || id == "whitelisting-enter-icon") |
391 addWhitelistedDomain(); | 403 addWhitelistedDomain(); |
392 else if (id == "whitelisting-cancel-button") | 404 else if (id == "whitelisting-cancel-button") |
393 E("whitelisting-textbox").value = ""; | 405 E("whitelisting-textbox").value = ""; |
394 }, false); | 406 }, false); |
395 E("whitelisting-add-button").addEventListener("click", addWhitelistedDomain, false); | 407 E("whitelisting-add-button").addEventListener("click", addWhitelistedDomain, false); |
396 E("whitelisting-textbox").addEventListener("keypress", function(e) | 408 E("whitelisting-textbox").addEventListener("keypress", function(e) |
397 { | 409 { |
398 // e.keyCode has been deprecated so we attempt to use e.key | 410 if (isEnterPressed(e)) |
399 // keyCode "13" corresponds to "Enter" | |
400 if ((e.key && e.key == "Enter") || (!e.key && e.keyCode == 13)) | |
401 addWhitelistedDomain(); | 411 addWhitelistedDomain(); |
402 }, false); | 412 }, false); |
403 E("import-blockingList-button").addEventListener("click", function() | 413 E("import-blockingList-button").addEventListener("click", function() |
404 { | 414 { |
405 var url = E("blockingList-textbox").value; | 415 var url = E("blockingList-textbox").value; |
406 addEnableSubscription(url); | 416 addEnableSubscription(url); |
407 delete document.body.dataset.dialog; | 417 delete document.body.dataset.dialog; |
Sebastian Noack
2015/07/09 12:12:15
I wasn't involved in the initial review, but just
saroyanm
2015/07/09 16:31:41
According to MDN dataset is supported since Safari
Sebastian Noack
2015/07/10 07:31:00
See https://codereview.adblockplus.org/29321417/di
saroyanm
2015/07/13 14:05:34
Yes Its should be fixed with the #2357
| |
408 }, false); | 418 }, false); |
419 | |
420 // Advanced tab | |
421 var filterTextbox = document.querySelector("#custom-filter-add input"); | |
422 placeholderValue = ext.i18n.getMessage("options_customFilters_textbox_placeh older"); | |
423 filterTextbox.setAttribute("placeholder", placeholderValue); | |
424 function addCustomFilters() | |
425 { | |
426 ext.backgroundPage.sendMessage( | |
427 { | |
428 type: "filter.parse", | |
429 text: filterTextbox.value | |
430 }, | |
431 function(result) | |
432 { | |
433 if (result.error) | |
434 { | |
435 alert(result.error); | |
436 return; | |
437 } | |
438 if (result.filter) | |
439 { | |
440 ext.backgroundPage.sendMessage( | |
441 { | |
442 type: "filters.add", | |
443 text: result.filter.text | |
444 }); | |
445 } | |
446 | |
447 filterTextbox.value = ""; | |
448 }); | |
449 } | |
450 E("custom-filter-add").addEventListener("submit", function(e) | |
451 { | |
452 e.preventDefault(); | |
453 addCustomFilters(); | |
454 }, false); | |
455 var customFilterEditButtons = document.querySelectorAll("#custom-filters-edi t-wrapper button"); | |
456 E("custom-filters-edit-wrapper").addEventListener("click", function(e) | |
457 { | |
458 var target = null; | |
459 if (e.target.tagName == "BUTTON") | |
Thomas Greiner
2015/07/09 11:07:56
Use `e.target.localName == "button"` instead becau
saroyanm
2015/07/09 16:31:42
Done.
| |
460 target = e.target; | |
461 else if (e.target.parentElement.tagName == "BUTTON") | |
462 target = e.target.parentElement; | |
463 else | |
464 return; | |
Thomas Greiner
2015/07/09 11:07:56
The most flexible way to achieve this is to go up
saroyanm
2015/07/09 16:31:42
Should we keep it as it is now and add merge it in
Thomas Greiner
2015/07/10 12:38:53
Yes, either in #2357 or a later review.
| |
465 | |
466 var id = target.id; | |
467 E("custom-filters").classList.toggle("mode-edit"); | |
Sebastian Noack
2015/07/09 12:12:15
classList.toggle() isn't supported in older Safari
saroyanm
2015/07/09 16:31:42
According to MDN it's supported from 5.1, but webk
Sebastian Noack
2015/07/10 07:31:00
It might be that I confused this with the second p
| |
468 if (id == "custom-filters-edit-btn") | |
469 editCustomFilters(); | |
470 else if (id == "custom-filters-save-btn") | |
471 { | |
472 ext.backgroundPage.sendMessage( | |
473 { | |
474 type: "filters.importRaw", | |
475 text: E("custom-filters-raw").value | |
476 }); | |
477 } | |
478 }, false); | |
409 } | 479 } |
410 | 480 |
411 function openDialog(name) | 481 function openDialog(name) |
412 { | 482 { |
413 document.body.dataset.dialog = name; | 483 document.body.dataset.dialog = name; |
414 } | 484 } |
415 | 485 |
416 function populateLists() | 486 function populateLists() |
417 { | 487 { |
418 subscriptionsMap = Object.create(null); | 488 subscriptionsMap = Object.create(null); |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
478 type: "filters.add", | 548 type: "filters.add", |
479 text: "@@||" + domain.value.toLowerCase() + "^$document" | 549 text: "@@||" + domain.value.toLowerCase() + "^$document" |
480 }); | 550 }); |
481 } | 551 } |
482 | 552 |
483 domain.value = ""; | 553 domain.value = ""; |
484 } | 554 } |
485 | 555 |
486 function editCustomFilters() | 556 function editCustomFilters() |
487 { | 557 { |
488 //TODO: NYI | 558 var customFilterItems = collections.customFilters.items; |
559 var filterTexts = []; | |
560 for (var i = 0; i < customFilterItems.length; i++) | |
561 filterTexts.push(customFilterItems[i].text); | |
562 E("custom-filters-raw").value = filterTexts.join("\n"); | |
489 } | 563 } |
490 | 564 |
491 function getAcceptableAdsURL(callback) | 565 function getAcceptableAdsURL(callback) |
492 { | 566 { |
493 ext.backgroundPage.sendMessage( | 567 ext.backgroundPage.sendMessage( |
494 { | 568 { |
495 type: "prefs.get", | 569 type: "prefs.get", |
496 key: "subscriptions_exceptionsurl" | 570 key: "subscriptions_exceptionsurl" |
497 }, | 571 }, |
498 function(value) | 572 function(value) |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
551 case "added": | 625 case "added": |
552 updateFilter(filter); | 626 updateFilter(filter); |
553 updateShareLink(); | 627 updateShareLink(); |
554 break; | 628 break; |
555 case "loaded": | 629 case "loaded": |
556 populateLists(); | 630 populateLists(); |
557 break; | 631 break; |
558 case "removed": | 632 case "removed": |
559 var knownFilter = filtersMap[filter.text]; | 633 var knownFilter = filtersMap[filter.text]; |
560 collections.whitelist.removeItem(knownFilter); | 634 collections.whitelist.removeItem(knownFilter); |
635 collections.customFilters.removeItem(knownFilter); | |
561 delete filtersMap[filter.text]; | 636 delete filtersMap[filter.text]; |
562 updateShareLink(); | 637 updateShareLink(); |
563 break; | 638 break; |
564 } | 639 } |
565 } | 640 } |
566 | 641 |
567 function onSubscriptionMessage(action, subscription) | 642 function onSubscriptionMessage(action, subscription) |
568 { | 643 { |
569 switch (action) | 644 switch (action) |
570 { | 645 { |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
669 filter: ["added", "loaded", "removed"] | 744 filter: ["added", "loaded", "removed"] |
670 }); | 745 }); |
671 ext.backgroundPage.sendMessage( | 746 ext.backgroundPage.sendMessage( |
672 { | 747 { |
673 type: "subscriptions.listen", | 748 type: "subscriptions.listen", |
674 filter: ["added", "disabled", "homepage", "removed", "title"] | 749 filter: ["added", "disabled", "homepage", "removed", "title"] |
675 }); | 750 }); |
676 | 751 |
677 window.addEventListener("DOMContentLoaded", onDOMLoaded, false); | 752 window.addEventListener("DOMContentLoaded", onDOMLoaded, false); |
678 })(); | 753 })(); |
OLD | NEW |