optimize: global.script只有在加载内置github油猴时,才需要加载。

pull/300/head
王良 2024-04-18 10:46:29 +08:00
parent 47666f2e5d
commit 7d45435883
1 changed files with 11 additions and 1 deletions

View File

@ -33,8 +33,10 @@ module.exports = {
keys = [keys]
}
try {
// 内置脚本
const scripts = monkey.get(setting.script.dirAbsolutePath)
let tags = '\r\n\t' + getScript('global', scripts.global.script)
let tags = ''
for (const key of keys) {
if (key === 'global') {
continue
@ -49,11 +51,19 @@ 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内置脚本
}
tags += '\r\n\t' + scriptTag
}
// 如果脚本为空,则不插入
if (tags === '') return
res.setHeader('DS-Script-Interceptor', 'true')
log.info('script response intercept: insert script', rOptions.hostname, rOptions.path, ', head:', tags)
return {