generated from LiteLoaderQQNT/Plugin-Template
-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
06da1db
commit 34caef0
Showing
4 changed files
with
98 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
{ | ||
"debug": false, | ||
"wordSearch": { | ||
"enabled": false, | ||
"searchUrl": "https://www.bing.com/search?q=%search%" | ||
}, | ||
"imageSearch": { | ||
"enabled": false, | ||
"searchUrl": "https://saucenao.com/search.php?url=%search%" | ||
}, | ||
"sidebar": { | ||
"top": [], | ||
"bottom": [] | ||
}, | ||
"imageViewer": { | ||
"quickClose": false | ||
}, | ||
"message": { | ||
"disabledSticker": false, | ||
"disabledHotGIF": false, | ||
"disabledBadge": false, | ||
"disabledSlideMultipleSelection": false, | ||
"convertMiniPrgmArk": false, | ||
"showMsgTime": false, | ||
"autoOpenURL": false, | ||
"switchReplace": false, | ||
"preventMessageRecall": false, | ||
"removeReplyAt": false, | ||
"mergeMessage": false, | ||
"avatarSticky": { | ||
"enabled": false, | ||
"toBottom": false | ||
} | ||
}, | ||
"tail": { | ||
"enabled": false, | ||
"newLine": false, | ||
"content": "" | ||
}, | ||
"textAreaFuncList": [], | ||
"chatAreaFuncList": [], | ||
"background": { | ||
"enabled": false, | ||
"url": "" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
const fs = require("fs"); | ||
const defaultOptions = require("./defaultOptions.json"); | ||
function loadOptions(optionsPath) { | ||
try { | ||
// 判断是否存在配置文件 | ||
if (!fs.existsSync(optionsPath)) { | ||
// 没有传入配置文件地址则直接返回默认配置文件并初始化 | ||
fs.writeFileSync(optionsPath, JSON.stringify(defaultOptions, null, 4)); | ||
return defaultOptions; | ||
} else { | ||
const fileOptions = JSON.parse(fs.readFileSync(optionsPath, "utf-8")); | ||
const options = recursiveAssignment(fileOptions, defaultOptions); | ||
fs.writeFileSync(optionsPath, JSON.stringify(options, null, 4)); | ||
return options; | ||
} | ||
} catch (err) { | ||
console.error("读取配置文件出错", err); | ||
return defaultOptions; | ||
} | ||
} | ||
|
||
function recursiveAssignment(fileOptions, defaultOptions) { | ||
if (!fileOptions) { | ||
return defaultOptions; | ||
} | ||
let obj = {}; | ||
for (const key in defaultOptions) { | ||
if (Object.hasOwnProperty.call(defaultOptions, key)) { | ||
// 如果键值是对象则递归处理 | ||
if (Object.prototype.toString.call(defaultOptions[key]) === "[object Object]") { | ||
obj[key] = recursiveAssignment(fileOptions[key], defaultOptions[key]); | ||
} | ||
// 判断两者同一个键的数据类型是否一致 | ||
else if (Object.prototype.toString.call(fileOptions[key]) === Object.prototype.toString.call(defaultOptions[key])) { | ||
obj[key] = fileOptions[key]; | ||
} else { | ||
obj[key] = defaultOptions[key]; | ||
} | ||
} | ||
} | ||
return obj; | ||
} | ||
|
||
module.exports = loadOptions; |