@hyacin@lemmy.ml
in
privacy
·
Mar 03, 2026
Simple external link blocking extension
I don’t know if it’s just me - I go to great lengths to keep my fedi activity separate from my other internet activity, and I get REALLY mad when I’m browsing Lemmy, click something that I assume will take me to a local discussion, and it opens some random external site - often one I’ve never even heard of - and now who knows what that site is doing, trying to do, cookies, etc., trying to link me and my referrer to my other activity (I do all my fedi stuff by VPN too, so it wouldn’t be by IP, but, they have ways) etc. etc.
As I couldn’t find anything already available, I finally got off my butt and just made something to prevent it. These files can be dumped in a local folder, and then under Chrome/Opera/anything-Chromium extensions, you can ‘enable developer options’, and then ‘load unpacked’. It’s SUPER simple, and works, you just need to customize your instance hostname. I thought it might be something at least one other person in this community has thought about and fought with, so I figured I’d share it here!
background.js - empty file, but required
content.js -
// Check if the current page is on lemmy.ml
if (window.location.hostname === 'lemmy.ml') {
document.querySelectorAll('a').forEach(link => {
link.addEventListener('click', (event) => {
const href = link.href;
const currentDomain = window.location.hostname;
// Check if the clicked link is not on the current domain
if (new URL(href).hostname !== currentDomain) {
event.preventDefault(); // Prevent default navigation
const confirmation = confirm("You are about to leave lemmy.ml. Do you want to continue?");
if (confirmation) {
window.open(href, '_blank'); // Open in a new tab
}
}
});
});
}
manifest.json -
{
"manifest_version": 3,
"name": "Block External Links",
"version": "1.0",
"permissions": [
"tabs",
"activeTab"
],
"background": {
"service_worker": "background.js"
},
"content_scripts": [
{
"matches": [""],
"js": ["content.js"]
}
]
}
Hope this is useful to someone!!
View on lemmy.ml