Skip to content

Commit b943361

Browse files
committed
feat: 优化 '仅进行兼容性转换' 参数判断和 '在脚本开头添加代码' 功能
1 parent f2afa69 commit b943361

2 files changed

Lines changed: 18 additions & 8 deletions

File tree

script-converter.beta.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ let url
5656
const evUrlori = queryObject.evalUrlori ?? ''
5757
const evUrlmodi = queryObject.evalUrlmodi ?? ''
5858
const wrap_response = queryObject.wrap_response
59-
const compatibilityOnly = queryObject.compatibilityOnly
59+
const compatibilityOnly = istrue(queryObject.compatibilityOnly)
60+
const isScriptConversion = type.endsWith('-script')
6061

6162
const subconverter = queryObject.subconverter
6263

@@ -361,8 +362,7 @@ global.$done = _scriptSonverterDone
361362
}
362363
if (type === 'qx-script' || compatibilityOnly) {
363364
const content = `${prefix}\n${compatibilityOnly ? body : body.replace(/\$done\(/g, '_scriptSonverterDone(')}`
364-
body = `${prepend || ''}
365-
const _scriptSonverterCompatibilityType = typeof $response !== 'undefined' ? 'response' : typeof $request !== 'undefined' ? 'request' : ''
365+
body = `const _scriptSonverterCompatibilityType = typeof $response !== 'undefined' ? 'response' : typeof $request !== 'undefined' ? 'request' : ''
366366
const _scriptSonverterCompatibilityDone = $done
367367
try {
368368
${content}
@@ -379,7 +379,12 @@ try {
379379
} else {
380380
throw e
381381
}
382-
}`
382+
}`
383+
}
384+
385+
if (prepend && isScriptConversion) {
386+
body = `${prepend}
387+
${body}`
383388
}
384389

385390
status = status ?? 200

script-converter.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ let url
5656
const evUrlori = queryObject.evalUrlori ?? ''
5757
const evUrlmodi = queryObject.evalUrlmodi ?? ''
5858
const wrap_response = queryObject.wrap_response
59-
const compatibilityOnly = queryObject.compatibilityOnly
59+
const compatibilityOnly = istrue(queryObject.compatibilityOnly)
60+
const isScriptConversion = type.endsWith('-script')
6061

6162
const subconverter = queryObject.subconverter
6263

@@ -361,8 +362,7 @@ global.$done = _scriptSonverterDone
361362
}
362363
if (type === 'qx-script' || compatibilityOnly) {
363364
const content = `${prefix}\n${compatibilityOnly ? body : body.replace(/\$done\(/g, '_scriptSonverterDone(')}`
364-
body = `${prepend || ''}
365-
const _scriptSonverterCompatibilityType = typeof $response !== 'undefined' ? 'response' : typeof $request !== 'undefined' ? 'request' : ''
365+
body = `const _scriptSonverterCompatibilityType = typeof $response !== 'undefined' ? 'response' : typeof $request !== 'undefined' ? 'request' : ''
366366
const _scriptSonverterCompatibilityDone = $done
367367
try {
368368
${content}
@@ -379,7 +379,12 @@ try {
379379
} else {
380380
throw e
381381
}
382-
}`
382+
}`
383+
}
384+
385+
if (prepend && isScriptConversion) {
386+
body = `${prepend}
387+
${body}`
383388
}
384389

385390
status = status ?? 200

0 commit comments

Comments
 (0)