From b5d81abfd26ca3402abe114cd229f0ad00fb10f5 Mon Sep 17 00:00:00 2001 From: Xmader Date: Thu, 5 Nov 2020 17:18:43 -0500 Subject: [PATCH] feat: btn anti-detection --- src/anti-detection.ts | 18 +++++++++++++++++- src/btn.ts | 10 +++++++++- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/src/anti-detection.ts b/src/anti-detection.ts index aa8d18d..0d85a9b 100644 --- a/src/anti-detection.ts +++ b/src/anti-detection.ts @@ -5,7 +5,7 @@ * make hooked methods "native" */ export const makeNative = (() => { - const l: Set = new Set() + const l = new Set() hookNative(Function.prototype, 'toString', (_toString) => { return function () { @@ -42,3 +42,19 @@ export function hookNative ( 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) + } +})() diff --git a/src/btn.ts b/src/btn.ts index 9ebbc50..9e19571 100644 --- a/src/btn.ts +++ b/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