diff --git a/js/app.js b/js/app.js index d6822e2..8ece46a 100644 --- a/js/app.js +++ b/js/app.js @@ -366,8 +366,64 @@ }); }; + $scope.backupMySettings = function() { + var items = {}; + for ( var i = 0, len = localStorage.length; i < len; ++i ) { + var key = localStorage.key(i); + var value = localStorage.getObject(key); + items[key] = value; + } + + var result = JSON.stringify(items); + var url = 'data:application/json,' + result; + chrome.downloads.download({ + url: url, + filename: 'listen1_backup.json' + }); + } + + $scope.importMySettings = function(event) { + console.log('start'); + var fileObject = event.target.files[0]; + if (fileObject == null ){ + Notification.warning("请选择备份文件"); + return; + } + var reader = new FileReader(); + reader.onloadend = function(readerEvent) { + if (readerEvent.target.readyState == FileReader.DONE) { + var data_json = readerEvent.target.result; + // parse json + var data = null; + try{ + data = JSON.parse(data_json); + }catch(e){ + } + if(data == null) { + Notification.warning("备份文件格式错误,请重新选择"); + return; + } + for ( var key in data) { + var value = data[key]; + localStorage.setObject(key, value); + } + Notification.success("恢复我的歌单成功"); + } + }; + reader.readAsText(fileObject); + } }]); + app.directive('customOnChange', function() { + return { + restrict: 'A', + link: function (scope, element, attrs) { + var onChangeHandler = scope.$eval(attrs.customOnChange); + element.bind('change', onChangeHandler); + } + }; + }); + app.controller('PlayController', ['$scope', '$timeout','$log', '$anchorScroll', '$location', 'angularPlayer', '$http', '$httpParamSerializerJQLike','$rootScope', 'Notification','loWeb', diff --git a/listen1.html b/listen1.html index d5dee6e..2bbc2a1 100644 --- a/listen1.html +++ b/listen1.html @@ -220,6 +220,20 @@
重装插件或清除缓存数据会导致我的歌单数据丢失,强烈建议在这些操作前,备份我的歌单。
+选择备份文件,恢复我的歌单。注意:恢复我的歌单会覆盖现有的歌单。
+ +Listen 1 (Chrome Extension) 主页: https://github.com/listen1/listen1_chrome_extension
diff --git a/manifest.json b/manifest.json index d262409..c0ec40a 100644 --- a/manifest.json +++ b/manifest.json @@ -15,7 +15,7 @@ }, "manifest_version": 2, "name": "Listen 1", - "permissions": [ "notifications", "unlimitedStorage", "storage", "contextMenus", "tabs", "*://music.163.com/*", "*://*.xiami.com/*", "*://*.qq.com/*", "webRequest", "webRequestBlocking"], + "permissions": [ "notifications", "unlimitedStorage", "downloads", "storage", "contextMenus", "tabs", "*://music.163.com/*", "*://*.xiami.com/*", "*://*.qq.com/*", "webRequest", "webRequestBlocking"], "version": "1.0", "web_accessible_resources": [ "images/*" ] }