feat: btn anti-detection
This commit is contained in:
parent
c7b6f305e7
commit
b5d81abfd2
2 changed files with 26 additions and 2 deletions
|
@ -5,7 +5,7 @@
|
|||
* make hooked methods "native"
|
||||
*/
|
||||
export const makeNative = (() => {
|
||||
const l: Set<Function> = new Set()
|
||||
const l = new Set<Function>()
|
||||
|
||||
hookNative(Function.prototype, 'toString', (_toString) => {
|
||||
return function () {
|
||||
|
@ -42,3 +42,19 @@ export function hookNative<T extends object, M extends (keyof T)> (
|
|||
makeNative(hookedFn as any)
|
||||
})
|
||||
}
|
||||
|
||||
export const hideFromArrFilter = (() => {
|
||||
const l = new Set()
|
||||
|
||||
hookNative(Array.prototype, 'filter', (_filter) => {
|
||||
return function (...args) {
|
||||
const arr = _filter.apply(this, args)
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
||||
return _filter.call(arr, (e) => !l.has(e))
|
||||
}
|
||||
})
|
||||
|
||||
return (item: any) => {
|
||||
l.add(item)
|
||||
}
|
||||
})()
|
||||
|
|
10
src/btn.ts
10
src/btn.ts
|
@ -1,5 +1,6 @@
|
|||
|
||||
import { loadMscore, WebMscore } from './mscore'
|
||||
import { hideFromArrFilter } from './anti-detection'
|
||||
import i18n from './i18n'
|
||||
|
||||
type BtnElement = HTMLButtonElement
|
||||
|
@ -42,6 +43,10 @@ export class BtnList {
|
|||
|
||||
private antiDetectionText = 'Download'
|
||||
|
||||
private hide (el: HTMLElement) {
|
||||
hideFromArrFilter(el)
|
||||
}
|
||||
|
||||
add (options: BtnOptions): BtnElement {
|
||||
const btn = this.templateBtn.cloneNode(true) as HTMLButtonElement
|
||||
|
||||
|
@ -60,10 +65,13 @@ export class BtnList {
|
|||
get: () => {
|
||||
// first time only
|
||||
const t = this.antiDetectionText
|
||||
this.antiDetectionText = ''
|
||||
this.antiDetectionText = ' '
|
||||
return t
|
||||
},
|
||||
})
|
||||
// hide this button from Array.prototype.filter
|
||||
this.hide(btn)
|
||||
this.hide(textNode)
|
||||
|
||||
const setText = (str: string): void => {
|
||||
textNode.textContent = str
|
||||
|
|
Loading…
Reference in a new issue