diff --git a/src/data/operation.json b/src/data/operation.json new file mode 100644 index 0000000..52e6e6e --- /dev/null +++ b/src/data/operation.json @@ -0,0 +1,9 @@ +[ + { "id": "copy", "title": "复制", "icon": "📄" }, + { "id": "view", "title": "查看全部", "icon": "💬" }, + { "id": "open-folder", "title": "打开文件夹", "icon": "📁" }, + { "id": "collect", "title": "收藏", "icon": "⭐" }, + { "id": "remove", "title": "删除", "icon": "❌" }, + { "id": "word-break", "title": "分词", "icon": "💣" }, + { "id": "save-file", "title": "保存", "icon": "💾" } +] diff --git a/src/data/setting.json b/src/data/setting.json new file mode 100644 index 0000000..52d1a7e --- /dev/null +++ b/src/data/setting.json @@ -0,0 +1,22 @@ +{ + "database.path": "", + "database.maxsize": 800, + "database.maxage": 14, + "operation.shown": ["copy", "view", "collect", "remove"], + "operation.custom": [ + { + "id": "custom.1663468392", + "title": "讯飞OCR识别", + "icon": "⚡", + "match": ["image"], + "command": "redirect:讯飞ocr" + }, + { + "id": "custom.1663468466", + "title": "百度搜索", + "icon": "🔍", + "match": ["text"], + "command": "redirect:百度一下" + } + ] +} diff --git a/src/global/initPlugin.js b/src/global/initPlugin.js index a3f49a1..463bd00 100644 --- a/src/global/initPlugin.js +++ b/src/global/initPlugin.js @@ -1,11 +1,14 @@ const { utools, existsSync, readFileSync, writeFileSync, mkdirSync, crypto, listener, clipboard } = window.exports +import setting from './readSetting' export default function initPlugin() { const sep = utools.isWindows() ? '\\' : '/' - const DBPath = `${ - utools.isMacOs() ? utools.getPath('userData') : utools.getPath('home') - }${sep}_utools_clipboard_manager_storage` + const DBPath = + setting.database.path || + `${ + utools.isMacOs() ? utools.getPath('userData') : utools.getPath('home') + }${sep}_utools_clipboard_manager_storage` class DB { constructor(path) { const d = new Date() @@ -26,7 +29,7 @@ export default function initPlugin() { this.dataBase = dataBase // 将超过14天的数据删除 排除掉收藏 const now = new Date().getTime() - const deleteTime = now - '\u0031\u0034' * '\u0032\u0034' * 60 * 60 * 1000 // unicode + const deleteTime = now - setting.database.maxage * 24 * 60 * 60 * 1000 // unicode this.dataBase.data = this.dataBase.data?.filter((item) => item.updateTime > deleteTime) this.updateDataBaseLocal() } catch (err) { @@ -59,7 +62,7 @@ export default function initPlugin() { addItem(cItem) { this.dataBase.data.unshift(cItem) this.updateDataBase() - const exceedCount = this.dataBase.data.length - '\u0038\u0030\u0030' + const exceedCount = this.dataBase.data.length - setting.database.maxsize if (exceedCount > 0) { // 达到条数限制 删除超出部分 for (let i = 0; i < exceedCount; i++) { diff --git a/src/global/readSetting.js b/src/global/readSetting.js new file mode 100644 index 0000000..3718d9a --- /dev/null +++ b/src/global/readSetting.js @@ -0,0 +1,22 @@ +import defaultSetting from '../data/setting.json' + +let setting = utools.dbStorage.getItem('setting') +if (!setting) { + // 将defaultSetting的key点语法转换为对象 + setting = {} + for (const key in defaultSetting) { + const keys = key.split('.') + let obj = setting + for (let i = 0; i < keys.length; i++) { + if (i === keys.length - 1) { + obj[keys[i]] = defaultSetting[key] + } else { + if (!obj[keys[i]]) obj[keys[i]] = {} + obj = obj[keys[i]] + } + } + } + utools.dbStorage.setItem('setting', setting) +} + +export default setting