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 638 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
649 // only when reloading the page or following links, but not when | 649 // only when reloading the page or following links, but not when |
650 // the current page is replaced with a prerendered page. | 650 // the current page is replaced with a prerendered page. |
651 replacePage(pages[event.message.pageId]); | 651 replacePage(pages[event.message.pageId]); |
652 break; | 652 break; |
653 } | 653 } |
654 }); | 654 }); |
655 | 655 |
656 | 656 |
657 /* Storage */ | 657 /* Storage */ |
658 | 658 |
659 ext.storage = safari.extension.settings; | 659 ext.storage = { |
660 get: function(keys, callback) | |
661 { | |
662 var items = {}; | |
663 var settings = safari.extension.settings; | |
664 | |
665 for (var i = 0; i < keys.length; i++) | |
666 { | |
667 var key = keys[i]; | |
668 if (key in settings) | |
669 items[key] = settings[key]; | |
670 } | |
671 | |
672 setTimeout(callback, 0, items); | |
673 }, | |
674 set: function(key, value, callback) | |
675 { | |
676 safari.extension.settings[key] = value; | |
677 | |
678 if (callback) | |
679 setTimeout(callback, 0); | |
680 }, | |
681 remove: function(key, callback) | |
682 { | |
683 delete safari.extension.settings[key]; | |
684 | |
685 if (callback) | |
686 setTimeout(callback, 0); | |
687 }, | |
688 onChanged: new ext._EventTarget(), | |
689 | |
690 // Preferences were previously encoded as JSON for compatibility | |
691 // with localStorage, which has been used on Chrome. | |
692 migratePrefs: function(prefs) | |
693 { | |
694 var settings = safari.extension.settings; | |
695 | |
696 for (var key in settings) | |
697 { | |
698 if (key in prefs) | |
699 { | |
700 try | |
701 { | |
702 settings["pref:" + key] = JSON.parse(settings[key]); | |
kzar
2015/03/09 15:10:29
Nit: Again what about the constant?
Sebastian Noack
2015/03/09 15:21:37
It's not available here, and IMO not worth beeing
| |
703 } | |
704 catch (e) | |
705 { | |
706 } | |
707 | |
708 delete settings[key]; | |
709 } | |
710 } | |
711 } | |
712 }; | |
713 | |
714 safari.extension.settings.addEventListener("change", function(event) | |
715 { | |
716 var changes = {}; | |
717 var change = changes[event.key] = {}; | |
718 | |
719 if (event.oldValue != null) | |
720 change.oldValue = event.oldValue; | |
721 if (event.newValue != null) | |
722 change.newValue = event.newValue; | |
723 | |
724 ext.storage.onChanged._dispatch(changes); | |
725 }); | |
660 | 726 |
661 | 727 |
662 /* Options */ | 728 /* Options */ |
663 | 729 |
664 ext.showOptions = function(callback) | 730 ext.showOptions = function(callback) |
665 { | 731 { |
666 var optionsUrl = safari.extension.baseURI + "options.html"; | 732 var optionsUrl = safari.extension.baseURI + "options.html"; |
667 | 733 |
668 for (var id in pages) | 734 for (var id in pages) |
669 { | 735 { |
670 var page = pages[id]; | 736 var page = pages[id]; |
671 var tab = page._tab; | 737 var tab = page._tab; |
672 | 738 |
673 if (page.url.href == optionsUrl && tab.browserWindow == safari.application .activeBrowserWindow) | 739 if (page.url.href == optionsUrl && tab.browserWindow == safari.application .activeBrowserWindow) |
674 { | 740 { |
675 tab.activate(); | 741 tab.activate(); |
676 if (callback) | 742 if (callback) |
677 callback(page); | 743 callback(page); |
678 return; | 744 return; |
679 } | 745 } |
680 } | 746 } |
681 | 747 |
682 ext.pages.open(optionsUrl, callback); | 748 ext.pages.open(optionsUrl, callback); |
683 }; | 749 }; |
684 })(); | 750 })(); |
OLD | NEW |