fix: auth magic hook

This commit is contained in:
Xmader 2020-10-30 14:53:02 -04:00
parent 01f490b60f
commit 7cd9489a64
1 changed files with 12 additions and 1 deletions

View File

@ -24,7 +24,7 @@ let magic: Promise<string> | string = new Promise((resolve) => {
// This script can run before anything on the page, // This script can run before anything on the page,
// so setting this function to be non-configurable and non-writable is no use. // 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) const m = this.match(MAGIC_REG)
if (m) { if (m) {
resolve(m[2]) resolve(m[2])
@ -33,6 +33,17 @@ let magic: Promise<string> | string = new Promise((resolve) => {
} }
return _fn.call(this, i) as number 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<string> => { export const getFileUrl = async (type: FileType, index = 0): Promise<string> => {