From 914c770ea46489f8dc14fc8ffac05002f72aa070 Mon Sep 17 00:00:00 2001 From: Xmader Date: Mon, 9 Nov 2020 14:48:57 -0500 Subject: [PATCH] refactor: webpack global override hook --- src/webpack-hook.ts | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/webpack-hook.ts b/src/webpack-hook.ts index b7a2e4a..c55af3b 100644 --- a/src/webpack-hook.ts +++ b/src/webpack-hook.ts @@ -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) + } + }) + } }, })