Skip to content

Commit

Permalink
feat: resolve adblock detection alert
Browse files Browse the repository at this point in the history
  • Loading branch information
piquark6046 committed Sep 6, 2023
1 parent 1e5cc15 commit 1bf07fb
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
2 changes: 2 additions & 0 deletions sources/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import {useNetworkInterceptor} from './interceptors/network.js';
import {useEvalInterceptor} from './interceptors/eval.js';
import {baseshower} from './loaders/baseshower.js';
import {shortwave} from './loaders/shortwave.js';
import {tinywave} from './loaders/ztinywave.js';
import {useDisableMethod, useIsSubframe} from './utils.js';

const bootstrap = () => {
useEvalInterceptor();
useNetworkInterceptor();
useDisableMethod(Element.prototype, 'remove');
useDisableMethod(Element.prototype, 'removeChild');
Expand Down
25 changes: 25 additions & 0 deletions sources/src/interceptors/eval.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// eslint-disable-next-line @typescript-eslint/naming-convention
type unsafeWindowType = typeof window & typeof globalThis;
declare const unsafeWindow: unsafeWindowType;
// eslint-disable-next-line no-negated-condition
const win = typeof unsafeWindow !== 'undefined' ? unsafeWindow : window;
/* eslint-disable no-eval */
import {useDebug, useBannedKeywords} from '../utils';

const debug = useDebug('[microShield:evalInterceptors]');

export const useEvalInterceptor = () => {
const evalProxy = new Proxy(eval, {
apply(target: typeof eval, thisArg: undefined | string, argLists: string[] | [string]) {
if ((!argLists.length && typeof thisArg === 'undefined') || (!useBannedKeywords(argLists[0] ?? thisArg))) {
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
return Reflect.apply(target, thisArg, argLists);
}

debug('eval:ban', argLists);
},
});
Object.defineProperty(win, 'eval', {
value: evalProxy,
});
};
2 changes: 2 additions & 0 deletions sources/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,3 +206,5 @@ export const useDocumentReady = async (document: Document) => {
});
});
};

export const useBannedKeywords = (data: string) => data.includes('loader.min.js') && data.includes('as-async') && /try(.|\n)*{(.|\n)*}(.|\n)*catch(.|\n)*{(.|\n)*}/.test(data);

0 comments on commit 1bf07fb

Please sign in to comment.