优化script.js:只要有脚本存在,就加载 tampermonkey.script

pull/300/head
王良 2024-04-19 11:49:05 +08:00
parent 262d338502
commit 3db45d4028
1 changed files with 8 additions and 7 deletions

View File

@ -33,12 +33,12 @@ module.exports = {
keys = [keys]
}
try {
// 内置脚本
// 内置脚本列表
const scripts = monkey.get(setting.script.dirAbsolutePath)
let tags = ''
for (const key of keys) {
if (key === 'global') {
if (key === 'global' || key === 'tampermonkey') {
continue
}
@ -51,10 +51,6 @@ module.exports = {
if (script == null) {
continue
}
if (key === 'github') {
// 如果是github油猴脚本需要先加载 `global.script`,避免 `GM_xxx` 方法不存在导致报错。
tags += '\r\n\t' + getScript('global', scripts.global.script)
}
scriptTag = getScript(key, script.script) // 2.DS内置脚本
}
@ -62,7 +58,12 @@ module.exports = {
}
// 如果脚本为空,则不插入
if (tags === '') return
if (tags === '') {
return
}
// 插入油猴脚本浏览器扩展
tags = '\r\n\t' + getScript('tampermonkey', scripts.tampermonkey.script) + tags
res.setHeader('DS-Script-Interceptor', 'true')
log.info('script response intercept: insert script', rOptions.hostname, rOptions.path, ', head:', tags)