Created
July 11, 2024 19:35
-
-
Save embeddinglayer/1d9a1b6ba669387d9f6327dd2693cc23 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function detectTamperMonkey(callback) { | |
| /** | |
| * Detect tampermonkey via stack dumping | |
| */ | |
| const createElem = document.createElement; | |
| document.createElement = function() { | |
| try { | |
| throw new Error(); | |
| } catch (e) { | |
| const stackTrace = e.stack; | |
| if (stackTrace.includes('userscript.html')) { | |
| callback(stackTrace, arguments[0]); | |
| return; | |
| } | |
| } | |
| return createElem.apply(this, arguments); | |
| }; | |
| } | |
| // Usage | |
| /* | |
| detectTamperMonkey((stackTrace, element) => { | |
| console.log('TamperMonkey detected!'); | |
| window.location.href = 'about:blank'; | |
| }); | |
| */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment