Skip to content

Commit 4d2cf2f

Browse files
committed
[userscript] add bypass-right-click-jacking-while-key-held
Introduce a new userscript that restores the native browser context menu when a modifier key (default: Alt) is held during right-click, bypassing site scripts that hijack the menu. - Add `bypass-right-click-jacking-while-key-held.user.js` - Use capture-phase listener to intercept `contextmenu` events - Suppress site handlers without calling `preventDefault()` - Restore the native browser context menu only while a modifier key is held - Include inline documentation and usage notes - Update README to reference the new script
1 parent 83382c6 commit 4d2cf2f

File tree

3 files changed

+61
-0
lines changed

3 files changed

+61
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ My user scripts to add functionality to various sites around the web (that were
55
## Userscripts
66

77
- [Amazon Prime Gaming Highlighter](./userscripts/amazon-prime-gaming-highlighter/) ([Install](https://github.com/0xdevalias/userscripts/raw/main/userscripts/amazon-prime-gaming-highlighter/amazon-prime-gaming-highlighter.user.js))
8+
- [Bypass Right-Click Jacking (While Key Held)](./userscripts/bypass-right-click-jacking-while-key-held/) ([Install](https://github.com/0xdevalias/userscripts/raw/main/userscripts/bypass-right-click-jacking-while-key-held/bypass-right-click-jacking-while-key-held.user.js))
89
- [ChatGPT Web App Script Update Notifier](./userscripts/chatgpt-web-app-script-update-notifier/) ([Install](https://github.com/0xdevalias/userscripts/raw/main/userscripts/chatgpt-web-app-script-update-notifier/chatgpt-web-app-script-update-notifier.user.js))
910
- [Copy GitHub Repo Summary](./userscripts/copy-github-repo-summary/) ([Install](https://github.com/0xdevalias/userscripts/raw/main/userscripts/copy-github-repo-summary/copy-github-repo-summary.user.js))
1011
- [Freshdesk Make 'Redactor Editor' Resizeable](./userscripts/freshdesk-make-redactor-editor-resizeable/) ([Install](https://github.com/0xdevalias/userscripts/raw/main/userscripts/freshdesk-make-redactor-editor-resizeable/freshdesk-make-redactor-editor-resizeable.user.js))
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Bypass Right-Click Jacking (While Key Held)
2+
3+
```javascript
4+
// ==UserScript==
5+
// @name Bypass Right-Click Jacking (While Key Held)
6+
// @description Bypass right-click jacking to restore the native browser context menu. While holding a modifier key (default: Alt), right-click to temporarily override site scripts that hijack the menu.
7+
// @author Glenn 'devalias' Grant (devalias.net)
8+
// @homepageURL https://github.com/0xdevalias/userscripts
9+
// @supportURL https://github.com/0xdevalias/userscripts/issues
10+
// @downloadURL https://github.com/0xdevalias/userscripts/raw/main/userscripts/bypass-right-click-jacking-while-key-held/bypass-right-click-jacking-while-key-held.user.js
11+
// @updateURL https://github.com/0xdevalias/userscripts/raw/main/userscripts/bypass-right-click-jacking-while-key-held/bypass-right-click-jacking-while-key-held.user.js
12+
// @namespace https://www.devalias.net/
13+
// @version 0.1
14+
// @match *://*/*
15+
// @grant none
16+
// ==/UserScript==
17+
```
18+
19+
- [Install](https://github.com/0xdevalias/userscripts/raw/main/userscripts/bypass-right-click-jacking-while-key-held/bypass-right-click-jacking-while-key-held.user.js)
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// ==UserScript==
2+
// @name Bypass Right-Click Jacking (While Key Held)
3+
// @description Bypass right-click jacking to restore the native browser context menu. While holding a modifier key (default: Alt), right-click to temporarily override site scripts that hijack the menu.
4+
// @author Glenn 'devalias' Grant (devalias.net)
5+
// @homepageURL https://github.com/0xdevalias/userscripts
6+
// @supportURL https://github.com/0xdevalias/userscripts/issues
7+
// @downloadURL https://github.com/0xdevalias/userscripts/raw/main/userscripts/bypass-right-click-jacking-while-key-held/bypass-right-click-jacking-while-key-held.user.js
8+
// @updateURL https://github.com/0xdevalias/userscripts/raw/main/userscripts/bypass-right-click-jacking-while-key-held/bypass-right-click-jacking-while-key-held.user.js
9+
// @namespace https://www.devalias.net/
10+
// @version 0.1
11+
// @match *://*/*
12+
// @grant none
13+
// ==/UserScript==
14+
15+
(function () {
16+
'use strict';
17+
18+
// Change this to e.g. 'Meta', 'Shift', or 'Control' if you prefer
19+
const modifierKeyName = 'Alt';
20+
21+
// Capture-phase listener: intercepts contextmenu events early.
22+
//
23+
// IMPORTANT: we do *not* call preventDefault() here — only stop page handlers,
24+
// so the browser’s native context menu remains free to open when the key is held.
25+
function captureContext(e) {
26+
// Only intervene if the chosen modifier key is being held down at the moment of right-click
27+
if (!e.getModifierState(modifierKeyName)) return;
28+
29+
// Block other listeners bound at the same target and phase
30+
e.stopImmediatePropagation();
31+
32+
// Stop the event from bubbling up to parent elements
33+
e.stopPropagation();
34+
}
35+
36+
// Install listener in capture phase.
37+
// The capture phase runs before bubbling, so we intercept the event
38+
// before site scripts can cancel or hijack it. This ensures our handler
39+
// has priority to allow the native browser menu when the key is held.
40+
document.addEventListener('contextmenu', captureContext, true);
41+
})();

0 commit comments

Comments
 (0)