From 7cd9489a641be4d9e5f4f7dcc6394c5ac2b3eb84 Mon Sep 17 00:00:00 2001 From: Xmader Date: Fri, 30 Oct 2020 14:53:02 -0400 Subject: [PATCH] fix: auth magic hook --- src/file.ts | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/file.ts b/src/file.ts index ecb7dd7..2cc6f54 100644 --- a/src/file.ts +++ b/src/file.ts @@ -24,7 +24,7 @@ let magic: Promise | string = new Promise((resolve) => { // This script can run before anything on the page, // so setting this function to be non-configurable and non-writable is no use. - target[method] = function (i) { + const hookFn = function (i: number) { const m = this.match(MAGIC_REG) if (m) { resolve(m[2]) @@ -33,6 +33,17 @@ let magic: Promise | string = new Promise((resolve) => { } return _fn.call(this, i) as number } + target[method] = hookFn + + // make hooked methods "native" + const _toString = Function.prototype['toString'] + Function.prototype.toString = function s () { + if (this === hookFn || this === s) { + // "function () {\n [native code]\n}" + return _toString.call(parseInt) as string + } + return _toString.call(this) as string + } }) export const getFileUrl = async (type: FileType, index = 0): Promise => {