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 652 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
663 // only when reloading the page or following links, but not when | 663 // only when reloading the page or following links, but not when |
664 // the current page is replaced with a prerendered page. | 664 // the current page is replaced with a prerendered page. |
665 replacePage(pages[event.message.pageId]); | 665 replacePage(pages[event.message.pageId]); |
666 break; | 666 break; |
667 } | 667 } |
668 }); | 668 }); |
669 | 669 |
670 | 670 |
671 /* Storage */ | 671 /* Storage */ |
672 | 672 |
673 ext.storage = safari.extension.settings; | 673 ext.storage = { |
| 674 get: function(keys, callback) |
| 675 { |
| 676 var items = {}; |
| 677 var settings = safari.extension.settings; |
| 678 |
| 679 for (var i = 0; i < keys.length; i++) |
| 680 { |
| 681 var key = keys[i]; |
| 682 if (key in settings) |
| 683 items[key] = settings[key]; |
| 684 } |
| 685 |
| 686 setTimeout(callback, 0, items); |
| 687 }, |
| 688 set: function(key, value, callback) |
| 689 { |
| 690 safari.extension.settings[key] = value; |
| 691 |
| 692 if (callback) |
| 693 setTimeout(callback, 0); |
| 694 }, |
| 695 remove: function(key, callback) |
| 696 { |
| 697 delete safari.extension.settings[key]; |
| 698 |
| 699 if (callback) |
| 700 setTimeout(callback, 0); |
| 701 }, |
| 702 onChanged: new ext._EventTarget(), |
| 703 |
| 704 // Preferences were previously encoded as JSON for compatibility |
| 705 // with localStorage, which has been used on Chrome. |
| 706 migratePrefs: function(mapFunc) |
| 707 { |
| 708 var settings = safari.extension.settings; |
| 709 |
| 710 for (var key in settings) |
| 711 { |
| 712 var item = mapFunc(key, settings[key]); |
| 713 |
| 714 // Only touch settings if the key changed. Otherwise we would keep |
| 715 // migrating "currentVersion" over and over again on every initilization
. |
| 716 if (item && item.key != key) |
| 717 { |
| 718 delete settings[key]; |
| 719 settings[item.key] = item.value; |
| 720 } |
| 721 } |
| 722 } |
| 723 }; |
| 724 |
| 725 safari.extension.settings.addEventListener("change", function(event) |
| 726 { |
| 727 var changes = {}; |
| 728 var change = changes[event.key] = {}; |
| 729 |
| 730 if (event.oldValue != null) |
| 731 change.oldValue = event.oldValue; |
| 732 if (event.newValue != null) |
| 733 change.newValue = event.newValue; |
| 734 |
| 735 ext.storage.onChanged._dispatch(changes); |
| 736 }); |
674 | 737 |
675 | 738 |
676 /* Options */ | 739 /* Options */ |
677 | 740 |
678 ext.showOptions = function(callback) | 741 ext.showOptions = function(callback) |
679 { | 742 { |
680 var optionsUrl = safari.extension.baseURI + "options.html"; | 743 var optionsUrl = safari.extension.baseURI + "options.html"; |
681 | 744 |
682 for (var id in pages) | 745 for (var id in pages) |
683 { | 746 { |
684 var page = pages[id]; | 747 var page = pages[id]; |
685 var tab = page._tab; | 748 var tab = page._tab; |
686 | 749 |
687 if (page.url.href == optionsUrl && tab.browserWindow == safari.application
.activeBrowserWindow) | 750 if (page.url.href == optionsUrl && tab.browserWindow == safari.application
.activeBrowserWindow) |
688 { | 751 { |
689 tab.activate(); | 752 tab.activate(); |
690 if (callback) | 753 if (callback) |
691 callback(page); | 754 callback(page); |
692 return; | 755 return; |
693 } | 756 } |
694 } | 757 } |
695 | 758 |
696 ext.pages.open(optionsUrl, callback); | 759 ext.pages.open(optionsUrl, callback); |
697 }; | 760 }; |
698 })(); | 761 })(); |
OLD | NEW |