refactor: webpack global override hook

This commit is contained in:
Xmader 2020-11-09 14:48:57 -05:00
parent b53cc0d345
commit 914c770ea4
No known key found for this signature in database
GPG Key ID: A20B97FB9EB730E4
1 changed files with 12 additions and 6 deletions

View File

@ -3,6 +3,8 @@
import { hookNative } from './anti-detection'
const CHUNK_PUSH_FN = 'function a(a){'
interface Module {
(module, exports, __webpack_require__): void;
}
@ -72,16 +74,20 @@ export const webpackGlobalOverride = (() => {
// hook `webpackJsonpmusescore.push` as soon as `webpackJsonpmusescore` is available
let jsonp
let hooked = false
Object.defineProperty(window, 'webpackJsonpmusescore', {
get () { return jsonp },
set (v: WebpackJson) {
jsonp = v
hookNative(v, 'push', (_fn) => {
return function (pack) {
applyOverride(pack)
return _fn.call(this, pack)
}
})
if (!hooked && v.push.toString().includes(CHUNK_PUSH_FN)) {
hooked = true
hookNative(v, 'push', (_fn) => {
return function (pack) {
applyOverride(pack)
return _fn.call(this, pack)
}
})
}
},
})