Created
November 24, 2024 12:30
-
-
Save eshack94/23ed5cc2d5d22881476100624a62fb20 to your computer and use it in GitHub Desktop.
Simple Userscript that ensures Command+Click (or Ctrl+Click) opens links in a new tab on all websites. Can be used with ViolentMonkey or other similar extensions.
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
// ==UserScript== | |
// @name Force Command+Click to Open in New Tab (Mac, Linux, and Windows) | |
// @namespace http://tampermonkey.net/ | |
// @version 1.0 | |
// @description Ensure Command+Click (or Ctrl+Click) opens links in a new tab on all websites. Overrides client-side JS that disables this behavior. | |
// @author Elijah Shackelford <eshack94> | |
// @match *://*/* | |
// @grant none | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
document.addEventListener('click', function(event) { | |
if (event.metaKey || event.ctrlKey) { | |
const target = event.target; | |
const anchor = target.closest('a'); | |
if (anchor && anchor.href) { | |
event.stopImmediatePropagation(); | |
window.open(anchor.href, '_blank'); | |
} | |
} | |
}, true); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment