diff --git a/README.md b/README.md index 6dbabc5..f50b649 100644 --- a/README.md +++ b/README.md @@ -11,6 +11,8 @@ - 修复uTools更新后进入插件空白的BUG - 添加Linux支持 - 修复导入BUG +- +- 添加全部导出和全部删除的功能 ## 功能 diff --git a/assets/options.css b/assets/options.css index 18bd98d..864c79d 100644 --- a/assets/options.css +++ b/assets/options.css @@ -183,11 +183,28 @@ cursor: pointer; } +#options .footBtn.danger{ + float: left; + /* right: 5px; + bottom: 2px; */ + border-radius: 4px; + background: #df3f54; + color: white; + padding: 2px 5px; + margin: 0px 5px; + cursor: pointer; +} + #options .footBtn:hover { background: #068506; transition: 0.5s; } +#options .footBtn.danger:hover { + background: #b32033; + transition: 0.5s; +} + #options .foot { position: fixed; height: 30px; diff --git a/assets/options.js b/assets/options.js index 6aa263c..6ad5623 100644 --- a/assets/options.js +++ b/assets/options.js @@ -22,16 +22,56 @@ importCommand = () => { var options = { filters: [{ name: 'json', extensions: ['json'] }, ] } - let file = window.openFolder(options)[0]; + var file = window.openFolder(options)[0]; + var customFts = getCustomFts(); $.get(file, data => { - var pushData = JSON.parse(data), - code = basename(file, '.json'), - customFts = getCustomFts(); - if (code in customFts) { - window.messageBox({ type: 'error', icon: window.logo, message: "命令名称重复, 请先修改文件名再导入!", buttons: ['朕知道了'] }) + try { + var pushData = JSON.parse(data); + } catch (error) { + window.messageBox({ type: 'error', icon: window.logo, message: "格式错误!", buttons: ['朕知道了'] }) + return + } + if (typeof(pushData.features)=='object') { + var code = basename(file, '.json'); + if (code in customFts) { + window.messageBox({ type: 'error', icon: window.logo, message: "命令名称重复, 请先修改文件名再导入!", buttons: ['朕知道了'] }) + } else { + putCustomFts(code, pushData); + showOptions(); + } } else { - putCustomFts(code, pushData); - showOptions(); + if (typeof (Object.values(pushData)[0].features) == 'object') { + for (var code of Object.keys(pushData)){ + if (!(code in customFts)) { + putCustomFts(code, pushData[code]); + } + } + showOptions(); + } else { + window.messageBox({ type: 'error', icon: window.logo, message: "格式错误!", buttons: ['朕知道了'] }) + } + } + }) +} + +exportAll = () => { + json = utools.db.get('customFts').data, + options = { + title: '选择保存位置', + defaultPath: 'quickCommand', + filters: [ + { name: 'json', extensions: ['json'] }, + ] + }; +window.saveFile(options, JSON.stringify(json)); +} + + +clearAll = () => { + window.messageBox({ type: 'question', icon: window.logo, message: "将会清空所有命令,请确认!", buttons: ['手抖...', '确定!'] }, index => { + if (index) { + utools.db.remove('customFts') + showOptions(); } }) } @@ -130,7 +170,9 @@ showOptions = () => { featureList += `