optimize: global.script只有在加载内置github油猴时,才需要加载。
parent
47666f2e5d
commit
7d45435883
|
@ -33,8 +33,10 @@ module.exports = {
|
||||||
keys = [keys]
|
keys = [keys]
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
|
// 内置脚本
|
||||||
const scripts = monkey.get(setting.script.dirAbsolutePath)
|
const scripts = monkey.get(setting.script.dirAbsolutePath)
|
||||||
let tags = '\r\n\t' + getScript('global', scripts.global.script)
|
|
||||||
|
let tags = ''
|
||||||
for (const key of keys) {
|
for (const key of keys) {
|
||||||
if (key === 'global') {
|
if (key === 'global') {
|
||||||
continue
|
continue
|
||||||
|
@ -49,11 +51,19 @@ module.exports = {
|
||||||
if (script == null) {
|
if (script == null) {
|
||||||
continue
|
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内置脚本
|
scriptTag = getScript(key, script.script) // 2.DS内置脚本
|
||||||
}
|
}
|
||||||
|
|
||||||
tags += '\r\n\t' + scriptTag
|
tags += '\r\n\t' + scriptTag
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 如果脚本为空,则不插入
|
||||||
|
if (tags === '') return
|
||||||
|
|
||||||
res.setHeader('DS-Script-Interceptor', 'true')
|
res.setHeader('DS-Script-Interceptor', 'true')
|
||||||
log.info('script response intercept: insert script', rOptions.hostname, rOptions.path, ', head:', tags)
|
log.info('script response intercept: insert script', rOptions.hostname, rOptions.path, ', head:', tags)
|
||||||
return {
|
return {
|
||||||
|
|
Loading…
Reference in New Issue