diff --git a/database/db.js b/database/db.js index ba6f39c..ba6b30d 100644 --- a/database/db.js +++ b/database/db.js @@ -324,6 +324,20 @@ db.updateSearchHistory = function(userId, search_history) { }); }; +db.updateQuickUrl = function(userId, quick_url) { + var sql = "UPDATE `users` SET `quick_url`=" + client.escape(quick_url) + " WHERE (`id`='" + userId + "')"; + console.log('updateQuickUrl', sql); + return new Promise(function(resolve, reject) { + client.query(sql, (err, result) => { + if (err) { + reject(err); + } else { + resolve(result.affectedRows); + } + }); + }); +}; + db.register = function(user) { console.log('register'); var sql = "INSERT INTO `users` (`username`, `password`, `email`) VALUES ('" + user.username + "', '" + user.password + "', '" + user.email + "')"; diff --git a/public/scripts/controllers/menus-controller.js b/public/scripts/controllers/menus-controller.js index 1e472a3..09c658d 100644 --- a/public/scripts/controllers/menus-controller.js +++ b/public/scripts/controllers/menus-controller.js @@ -7,6 +7,7 @@ app.controller('menuCtr', ['$scope', '$stateParams', '$state', '$window', '$time $scope.showStyle = null; $scope.searchHistory = []; $scope.historyTypes = dataService.historyTypes; + $scope.quickUrl = { }; // 防止在登陆的情况下,在浏览器里面直接输入url,这时候要更新菜单选项 pubSubService.subscribe('Common.menuActive', $scope, function(event, params) { @@ -16,6 +17,10 @@ app.controller('menuCtr', ['$scope', '$stateParams', '$state', '$window', '$time updateMenuActive(index); }); + pubSubService.subscribe('Settings.quickUrl', $scope, function(event, params) { + $scope.quickUrl = params.quickUrl; + }); + $scope.loginMenus = dataService.loginMenus; // 登陆之后显示的菜单数据。uiSerf:内部跳转链接。 $scope.notLoginMenus = dataService.notLoginMenus; // 未登陆显示的菜单数据 @@ -168,6 +173,8 @@ app.controller('menuCtr', ['$scope', '$stateParams', '$state', '$window', '$time bookmarkService.userInfo({}) .then((user) => { $scope.searchHistory = JSON.parse(user.search_history || '[]'); + $scope.quickUrl = JSON.parse(user.quick_url || '{}'); + $timeout(function() { var showStyle = (user && user.show_style) || 'navigate'; if (showStyle) { @@ -188,17 +195,7 @@ app.controller('menuCtr', ['$scope', '$stateParams', '$state', '$window', '$time $scope.$apply(function() { if (dataService.keyShortcuts()) { var key = event.key.toUpperCase(); - var urls = { - 'B':'https://www.baidu.com/', - 'G':'https://www.google.com.hk/', - 'L':'http://luchenqun.com/', - 'H':'https://github.com/', - 'S':'https://stackoverflow.com/', - 'V':'https://www.v2ex.com/', - 'Q':'http://www.iqiyi.com/', - }; - - var url = urls[key]; + var url = $scope.quickUrl[key]; if (url) { $window.open(url, '_blank'); } diff --git a/public/scripts/controllers/settings-controller.js b/public/scripts/controllers/settings-controller.js index d17351a..ca9df0a 100644 --- a/public/scripts/controllers/settings-controller.js +++ b/public/scripts/controllers/settings-controller.js @@ -10,13 +10,15 @@ app.controller('settingsCtr', ['$scope', '$stateParams', '$filter', '$state', '$ $scope.loadShowStyle = false; $scope.form[($stateParams && $stateParams.formIndex) || 0] = true; $scope.key = ''; + $scope.url = ''; + $scope.quickUrl = {}; $scope.changeForm = function(index) { console.log("changeForm = ", index); $scope.form = $scope.form.map(() => false); $scope.form[index] = true; - if (index <= 1) { + if (index == 0 || index == 1 || index == 4) { $scope.loadShowStyle = true; bookmarkService.userInfo({}) .then((data) => { @@ -25,25 +27,29 @@ app.controller('settingsCtr', ['$scope', '$stateParams', '$filter', '$state', '$ updateShowStyle(($scope.user && $scope.user.show_style) || 'navigate'); $scope.loadShowStyle = false; } + if (index == 4) { + $scope.quickUrl = JSON.parse($scope.user.quick_url || '{}'); + } }) .catch((err) => { console.log(err); toastr.error('获取信息失败。错误信息:' + JSON.stringify(err), "错误"); $scope.loadShowStyle = false; }); - if (index == 1) { - bookmarkService.getTags({}) - .then((data) => { - $scope.tagCnt = data.length; - $scope.bookmarkCnt = 0; - data.forEach((tag) => { - $scope.bookmarkCnt += tag.cnt; - }) + } + + if (index == 1) { + bookmarkService.getTags({}) + .then((data) => { + $scope.tagCnt = data.length; + $scope.bookmarkCnt = 0; + data.forEach((tag) => { + $scope.bookmarkCnt += tag.cnt; }) - .catch((err) => { - console.log('getTags err', err); - }); - } + }) + .catch((err) => { + console.log('getTags err', err); + }); } } @@ -112,12 +118,52 @@ app.controller('settingsCtr', ['$scope', '$stateParams', '$filter', '$state', '$ console.log('key = ', key); if (!((key >= 'A' && key <= 'Z') || (key >= '1' && key <= '9'))) { key = ''; + toastr.warning('快捷键只能是数字1 ~ 9或者字母a ~ z,字母不区分大小写。', "警告"); } $timeout(function() { $scope.key = key; }); } + $scope.addQuickUrl = function(){ + if (!/http(s)?:\/\/([\w-]+\.)+[\w-]+(\/[\w- .\/?%&=]*)?/.test($scope.url)) { + toastr.warning($scope.url + '
检撤到您的书签链接非法,是否忘记加http或者https了?建议直接从打开浏览器地址栏复制出来直接粘贴到输入框。', "警告"); + $scope.url = ''; + return; + } + if (!(($scope.key >= 'A' && $scope.key <= 'Z') || ($scope.key >= 'a' && $scope.key <= 'z') || ($scope.key >= '1' && $scope.key <= '9'))) { + toastr.warning('快捷键只能是数字1 ~ 9或者字母a ~ z,字母不区分大小写。', "警告"); + $scope.key = ''; + return; + } + + if (dataService.forbidQuickKey[$scope.key]) { + toastr.warning('快捷键' + $scope.key + ',已经设置为系统:' + dataService.forbidQuickKey[$scope.key] + '。无法使用该快捷键', "警告"); + $scope.key = ''; + return; + } + + if ($scope.quickUrl[$scope.key]) { + toastr.warning('快捷键:' + $scope.key + ',已经设置为链接为:' + $scope.quickUrl[$scope.key] + '。您可以先删除再添加。', "警告"); + $scope.key = ''; + return; + } + + $scope.key = $scope.key.toUpperCase(); + $scope.quickUrl[$scope.key] = $scope.url; + + console.log(JSON.stringify($scope.quickUrl)); + + saveQuickUrl(); + $scope.url = ''; + $scope.key = ''; + } + + $scope.delUrl = function(key) { + delete $scope.quickUrl[key]; + saveQuickUrl(); + } + function updateShowStyle(showStyle) { setTimeout(function() { if (showStyle) { @@ -155,8 +201,28 @@ app.controller('settingsCtr', ['$scope', '$stateParams', '$filter', '$state', '$ login: true, index: dataService.LoginIndexSettings }); - transition(); + function saveQuickUrl() { + var parmes = { + quickUrl: JSON.stringify($scope.quickUrl), + }; + bookmarkService.updateQuickUrl(parmes) + .then((data) => { + if (data.retCode == 0) { + toastr.success('全局快捷键更新成功', "提示"); + pubSubService.publish('Settings.quickUrl', { + quickUrl: $scope.quickUrl + }); + } else { + toastr.error('全局快捷键更新失败。错误信息:' + data.msg, "错误"); + } + }) + .catch((err) => { + toastr.error('全局快捷键更新失败。错误信息:' + JSON.stringify(err), "错误"); + }); + } + + transition(); function transition() { var className = 'js-segment-settings'; $('.' + className).transition('hide'); diff --git a/public/scripts/services/bookmark-service.js b/public/scripts/services/bookmark-service.js index 5624f2a..e3ffafe 100644 --- a/public/scripts/services/bookmark-service.js +++ b/public/scripts/services/bookmark-service.js @@ -326,6 +326,19 @@ app.factory('bookmarkService', ['$http', '$q', function($http, $q) { }); return def.promise; }, + updateQuickUrl: function(params) { + var def = $q.defer(); + $http.post('/api/updateQuickUrl/', { + params: params + }) + .success(function(data) { + def.resolve(data); + }) + .error(function(data) { + def.reject('updateQuickUrl error'); + }); + return def.promise; + }, getAdvices: function(params) { var def = $q.defer(); $http.get('/api/advices/', { diff --git a/public/scripts/services/data-service.js b/public/scripts/services/data-service.js index 2bdb293..753709f 100644 --- a/public/scripts/services/data-service.js +++ b/public/scripts/services/data-service.js @@ -62,6 +62,12 @@ app.factory('dataService', [function() { }, historyTypes: ['书签', '谷歌', 'Github', '栈溢出', '百度', '备忘录'], showStyles: ['navigate', 'costomTag', 'card', 'table'], + forbidQuickKey:{ + 'A':'在备忘录界面,已用做新增备忘录', + 'R':'在热门收藏界面,已用作随机查看热门收藏', + 'INSERT':'全局页面,已用做添加书签', + 'ESC':'全局页面,已用做退出弹窗', + }, keyShortcuts: function() { // 判断快捷方式是否生效 var ret = true; var menusScope = $('div[ng-controller="menuCtr"]').scope(); diff --git a/public/views/settings.html b/public/views/settings.html index d427e43..6fdb239 100644 --- a/public/views/settings.html +++ b/public/views/settings.html @@ -157,29 +157,22 @@

1、该代码我托管在Github上my-bookmark。该地址有文件夹详细说明以及部署步骤。git地址:git@github.com:luchenqun/my-bookmark.git。如果你需要源码,你尽可随意使用此项目无需通知我。

-

功能说明:可在该页面,设置全局快速打开的链接。快捷键只能是数字1 ~ 9或者字母a ~ z,字母不区分大小写。
注意:在该设置界面,不触发全局的链接打开,否则没法设置了。

+

功能说明:可在该页面,设置全局快速打开的链接。快捷键只能是数字1 ~ 9或者字母a ~ z,字母不区分大小写。

- + - - - + + + - - - - - @@ -187,16 +180,16 @@
-
+
- +
-
+
- +
-
确定
+
确定
diff --git a/routes/api.js b/routes/api.js index 7a8e398..558a42b 100644 --- a/routes/api.js +++ b/routes/api.js @@ -227,6 +227,37 @@ api.post('/updateSearchHistory', function(req, res) { }); }); +api.post('/updateQuickUrl', function(req, res) { + console.log("updateQuickUrl username = ", req.session.username); + if (!req.session.user) { + res.send(401); + return; + } + + var params = req.body.params; + db.getUser(req.session.user.username) + .then((user) => { + if (user) { + return db.updateQuickUrl(req.session.userId, params.quickUrl) + } else { + return Promise.resolve(0) + } + }) + .then((affectedRows) => { + res.json({ + retCode: (affectedRows == 1 ? 0 : 1), + msg: req.session.username + " 更新全局快捷键成功!", + }) + }) + .catch((err) => { + console.log('resetPassword error', err); + res.json({ + retCode: 2, + msg: req.session.username + " 更新全局快捷键失败!: " + JSON.stringify(err), + }) + }); +}); + api.get('/autoLogin', function(req, res) { console.log("autoLogin username = ", req.session.username); var ret = {
快捷键链接网站地址 操作
Ahttp://mybookmark.cn/#/settings
{{key}}{{value}} - -
Bhttps://www.google.com.hk/ - +