refactor: webpack global override hook
This commit is contained in:
parent
b53cc0d345
commit
914c770ea4
|
@ -3,6 +3,8 @@
|
||||||
|
|
||||||
import { hookNative } from './anti-detection'
|
import { hookNative } from './anti-detection'
|
||||||
|
|
||||||
|
const CHUNK_PUSH_FN = 'function a(a){'
|
||||||
|
|
||||||
interface Module {
|
interface Module {
|
||||||
(module, exports, __webpack_require__): void;
|
(module, exports, __webpack_require__): void;
|
||||||
}
|
}
|
||||||
|
@ -72,16 +74,20 @@ export const webpackGlobalOverride = (() => {
|
||||||
|
|
||||||
// hook `webpackJsonpmusescore.push` as soon as `webpackJsonpmusescore` is available
|
// hook `webpackJsonpmusescore.push` as soon as `webpackJsonpmusescore` is available
|
||||||
let jsonp
|
let jsonp
|
||||||
|
let hooked = false
|
||||||
Object.defineProperty(window, 'webpackJsonpmusescore', {
|
Object.defineProperty(window, 'webpackJsonpmusescore', {
|
||||||
get () { return jsonp },
|
get () { return jsonp },
|
||||||
set (v: WebpackJson) {
|
set (v: WebpackJson) {
|
||||||
jsonp = v
|
jsonp = v
|
||||||
hookNative(v, 'push', (_fn) => {
|
if (!hooked && v.push.toString().includes(CHUNK_PUSH_FN)) {
|
||||||
return function (pack) {
|
hooked = true
|
||||||
applyOverride(pack)
|
hookNative(v, 'push', (_fn) => {
|
||||||
return _fn.call(this, pack)
|
return function (pack) {
|
||||||
}
|
applyOverride(pack)
|
||||||
})
|
return _fn.call(this, pack)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue