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 704 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
715 if (callback) | 715 if (callback) |
716 setTimeout(callback, 0); | 716 setTimeout(callback, 0); |
717 }, | 717 }, |
718 remove: function(key, callback) | 718 remove: function(key, callback) |
719 { | 719 { |
720 delete safari.extension.settings[key]; | 720 delete safari.extension.settings[key]; |
721 | 721 |
722 if (callback) | 722 if (callback) |
723 setTimeout(callback, 0); | 723 setTimeout(callback, 0); |
724 }, | 724 }, |
725 onChanged: new ext._EventTarget(), | 725 onChanged: new ext._EventTarget() |
726 | |
727 // Preferences were previously encoded as JSON for compatibility | |
728 // with localStorage, which has been used on Chrome. | |
729 migratePrefs: function(hooks) | |
730 { | |
731 var settings = safari.extension.settings; | |
732 | |
733 for (var key in settings) | |
734 { | |
735 var item = hooks.map(key, settings[key]); | |
736 | |
737 if (item) | |
738 { | |
739 delete settings[key]; | |
740 settings[item.key] = item.value; | |
741 } | |
742 } | |
743 | |
744 hooks.done(); | |
745 }, | |
746 | |
747 // While moving away from the FileSystem API on Chrome the data structure | |
748 // for files on Safari changed as well, in order to keep thing consistent. | |
749 migrateFiles: function(callback) | |
750 { | |
751 var settings = safari.extension.settings; | |
752 | |
753 for (var key in settings) | |
754 { | |
755 var match = key.match(/^(.*)\/lastModified$/) | |
756 | |
757 if (match) | |
758 { | |
759 var filename = match[1]; | |
760 var content = settings[filename]; | |
761 | |
762 if (typeof content == "string") | |
763 { | |
764 settings["file:" + filename] = { | |
765 content: content.split(/[\r\n]+/), | |
766 lastModified: settings[key] | |
767 }; | |
768 | |
769 delete settings[key]; | |
770 delete settings[filename]; | |
771 } | |
772 } | |
773 } | |
774 | |
775 callback(); | |
776 } | |
777 }; | 726 }; |
778 | 727 |
779 safari.extension.settings.addEventListener("change", function(event) | 728 safari.extension.settings.addEventListener("change", function(event) |
780 { | 729 { |
781 var changes = {}; | 730 var changes = {}; |
782 var change = changes[event.key] = {}; | 731 var change = changes[event.key] = {}; |
783 | 732 |
784 if (event.oldValue != null) | 733 if (event.oldValue != null) |
785 change.oldValue = event.oldValue; | 734 change.oldValue = event.oldValue; |
786 if (event.newValue != null) | 735 if (event.newValue != null) |
(...skipping 19 matching lines...) Expand all Loading... |
806 tab.activate(); | 755 tab.activate(); |
807 if (callback) | 756 if (callback) |
808 callback(page); | 757 callback(page); |
809 return; | 758 return; |
810 } | 759 } |
811 } | 760 } |
812 | 761 |
813 ext.pages.open(optionsUrl, callback); | 762 ext.pages.open(optionsUrl, callback); |
814 }; | 763 }; |
815 })(); | 764 })(); |
OLD | NEW |