diff --git a/css/player.css b/css/player.css index 15c79e8..9c7b7fe 100644 --- a/css/player.css +++ b/css/player.css @@ -943,11 +943,39 @@ li { width: 100px; } -.dialog-playlist li h2{ +.dialog-backuplist li h2{ margin-left: 125px; font-size: 17px; } + +.dialog-backuplist { + padding-left: 0px; + text-align: left; +} + +.dialog-backuplist li { + cursor: pointer; + height: 112px; + padding: 6px; +} + +.dialog-backuplist li:hover { + background-color: #555555; +} + +.dialog-backuplist li img { + float: left; + height: 100px; + width: 100px; +} + +.dialog-backuplist li h2{ + margin-top: 10px; + margin-left: 125px; + font-size: 15px; +} + .dialog-merge-playlist { padding-left: 0px; text-align: left; @@ -983,6 +1011,14 @@ li { margin-right: 96px; } +.dialog-newbackup { + text-align: center; +} + +.dialog-newbackup .confirm-button { + margin-right: 12px; +} + .dialog-editplaylist .dialog-footer { position: absolute; bottom: 20px; @@ -1060,6 +1096,10 @@ li { } +.settings-content .btn { + margin-right: 10px; +} + .btn-group button,.btn-pagination,.btn-pagination:focus { background-color: #333333; color: #ffffff; diff --git a/js/app.js b/js/app.js index 65103f0..6f57094 100644 --- a/js/app.js +++ b/js/app.js @@ -252,6 +252,24 @@ $scope.dialog_title = '连接到Github.com'; $scope.dialog_type = 7; } + if (dialog_type == 8) { + $scope.dialog_title = '导出到Github Gist'; + $scope.dialog_type = 8; + gist.listExistBackup().then(function(res){ + $scope.myBackup = res; + }, function(err){ + $scope.myBackup = []; + }); + } + if (dialog_type == 10) { + $scope.dialog_title = '从Github Gist导入'; + $scope.dialog_type = 10; + gist.listExistBackup().then(function(res){ + $scope.myBackup = res; + }, function(err){ + $scope.myBackup = []; + }); + } }; $scope.chooseDialogOption = function(option_id) { @@ -276,12 +294,12 @@ }); }; - $scope.newDialogOption = function() { - $scope.dialog_type = 1; + $scope.newDialogOption = function(option) { + $scope.dialog_type = option; }; - $scope.cancelNewDialog = function() { - $scope.dialog_type = 0; + $scope.cancelNewDialog = function(option) { + $scope.dialog_type = option; }; $scope.createAndAddPlaylist = function() { @@ -501,14 +519,14 @@ var value = data[key]; localStorage.setObject(key, value); } - Notification.success("恢复我的歌单成功"); + Notification.success("成功导入我的歌单"); } }; reader.readAsText(fileObject); } $scope.gistBackupLoading = false; - $scope.backupMySettings2Gist= function(){ + $scope.backupMySettings2Gist= function(gistId, isPublic){ var items = {}; for ( var i = 0; i < localStorage.length; i++ ) { var key = localStorage.key(i); @@ -519,40 +537,40 @@ } var gistFiles = gist.json2gist(items); $scope.gistBackupLoading = true; - gist.backupMySettings2Gist(gistFiles).then(function(){ + gist.backupMySettings2Gist(gistFiles, gistId, isPublic).then(function(){ Notification.clearAll(); - Notification.success("成功导出歌单到Gist"); + Notification.success("成功导出我的歌单到Gist"); $scope.gistBackupLoading = false; },function(err){ Notification.clearAll(); - Notification.warning("导出歌单失败,检查后重试"); + Notification.warning("导出我的歌单失败,检查后重试"); $scope.gistBackupLoading = false; }); - Notification({message: "正在导出歌单到Gist...", delay: null}); + Notification({message: "正在导出我的歌单到Gist...", delay: null}); } $scope.gistRestoreLoading = false; - $scope.importMySettingsFromGist = function(){ + $scope.importMySettingsFromGist = function(gistId){ $scope.gistRestoreLoading = true; - gist.importMySettingsFromGist().then(function(raw){ + gist.importMySettingsFromGist(gistId).then(function(raw){ var data = gist.gist2json(raw); for ( var key in data) { var value = data[key]; localStorage.setObject(key, value); } Notification.clearAll(); - Notification.success("导入歌单成功"); + Notification.success("导入我的歌单成功"); $scope.gistRestoreLoading = false; },function(err){ Notification.clearAll(); if(err==404){ Notification.warning("未找到备份歌单,请先备份"); }else{ - Notification.warning("导入歌单失败,检查后重试"); + Notification.warning("导入我的歌单失败,检查后重试"); } $scope.gistRestoreLoading = false; }) - Notification({message: "正在从Gist导入歌单...", delay: null}); + Notification({message: "正在从Gist导入我的歌单...", delay: null}); } diff --git a/js/github.js b/js/github.js index 69bc30d..944a426 100644 --- a/js/github.js +++ b/js/github.js @@ -21,8 +21,6 @@ function($rootScope) { }, logout: function(){ Github.logout(); - // delete gist id info; - localStorage.removeItem("gistid"); } }; }]); @@ -37,9 +35,11 @@ ngGithub.provider('gist', { function json2gist(jsonObject) { var result = {}; + result['listen1_backup.json'] = {content: JSON.stringify(jsonObject)}; //var markdown = '# My Listen1 Playlists\n'; var playlistIds = jsonObject['playerlists']; + var songsCount = 0; for(var i=0; i

\n' + tableHeader + tableBody +'

'; var filename = 'listen1_'+playlistId + '.md'; result[filename] = {content: content}; + songsCount += playlist.tracks.length; } + var summary = "本歌单由[Listen1](http://listen1.github.io/listen1/)创建, 歌曲数:" + songsCount + ",歌单数:" + playlistIds.length + ",点击查看更多"; + result['listen1_aha_playlist.md'] = {content: summary}; return result; } @@ -65,9 +68,25 @@ ngGithub.provider('gist', { return JSON.parse(jsonString); } - function backup(files) { + function listExistBackup(){ + var deferred = $q.defer(); + var url = apiUrl; + $http({ + method: 'GET', + url: url, + headers:{'Authorization':'token ' + localStorage.getObject("githubOauthAccessKey")}, + }).then(function(res) { + var result = res.data; + result = result.filter(function(backup){return backup.description.startsWith('updated by Listen1')}); + deferred.resolve(result); + }, function(err) { + deferred.reject(err) + }); + return deferred.promise; + } + + function backup(files, gistId, isPublic) { var deferred = $q.defer(); - var gistId = _getGistId(); var method = ''; var url = ''; if (gistId != null) { @@ -83,13 +102,11 @@ ngGithub.provider('gist', { url: url, headers:{'Authorization':'token ' + localStorage.getObject("githubOauthAccessKey")}, data:{ - "description": "updated by Listen1(http://listen1.github.io/listen1/) at " + new Date().toLocaleString(), - "public": false, - "files": files + "description": "updated by Listen1(http://listen1.github.io/listen1/) at " + new Date().toLocaleString(), + "public": isPublic, + "files": files } }).then(function(res) { - var newGistId = res.data.id; - localStorage.setObject("gistid", newGistId); deferred.resolve(); }, function(err) { deferred.reject(err) @@ -97,11 +114,11 @@ ngGithub.provider('gist', { return deferred.promise; } - function restore() { + function restore(gistId) { var deferred = $q.defer(); $http({ method:'GET', - url:apiUrl + '/' + _getGistId(), + url:apiUrl + '/' + gistId, }).then(function(res) { try{ var files = res.data.files @@ -117,6 +134,7 @@ ngGithub.provider('gist', { var gistApi = { "gist2json": gist2json, "json2gist": json2gist, + "listExistBackup": listExistBackup, "backupMySettings2Gist": backup, "importMySettingsFromGist": restore, }; diff --git a/js/github_api.js b/js/github_api.js index 9d70a0f..3ed5974 100644 --- a/js/github_api.js +++ b/js/github_api.js @@ -55,7 +55,7 @@ return '连接中'; } if(this.status == 2) { - return '已连接: ' + this.username; + return this.username + '已登录'; } return '???' }, diff --git a/listen1.html b/listen1.html index 337e408..40fd6c7 100644 --- a/listen1.html +++ b/listen1.html @@ -50,24 +50,24 @@
{{ dialog_title }} ×
- - + + - -
- - - -
+ +
+ + + +
+
+ + + +
+ + +
@@ -279,21 +304,21 @@
豆瓣:
豆瓣:
--> -
歌单导出
+
导出我的歌单

重装插件或清除缓存数据会导致我的歌单数据丢失,强烈建议在这些操作前,备份我的歌单。

- - + +
-
歌单导入
+
导入我的歌单

选择备份文件,恢复我的歌单。注意:恢复我的歌单会覆盖现有的歌单。

- +
连接到 Github.com
@@ -354,7 +379,7 @@ 收藏 编辑 原始链接 - 导入合并 + 导入合并