Comments 1 - 7 of 7 Search these comments
{
"manifest_version": 3,
"name": "Force Same-Tab Links",
"version": "1.0",
"description": "Opens links in the same tab unless Command is held on Mac.",
"permissions": ["scripting"],
"content_scripts": [
{
"matches": [""],
"js": ["content.js"],
"run_at": "document_start"
}
]
}
document.addEventListener('click', function (event) {
const link = event.target.closest('a[target="_blank"]');
// Only apply if it's a normal left-click on a link with target=_blank
if (
link &&
event.button === 0 && // left mouse button
!event.metaKey && // ⌘ key not held (on Mac)
!event.ctrlKey && // Ctrl key (in case on Linux/Windows)
!event.shiftKey &&
!event.altKey
) {
event.preventDefault();
window.location.href = link.href;
}
}, true);
background.js
chrome.webRequest.onBeforeRequest.addListener(
function (details) {
const url = details.url.toLowerCase();
if (url.includes("goog")) {
console.log("Blocked (network):", url);
return { cancel: true };
}
},
{ urls: [""] },
["blocking"]
);
content.js
const observer = new MutationObserver((mutations) => {
for (const mutation of mutations) {
for (const node of mutation.addedNodes) {
if (node.tagName === 'SCRIPT' && node.src && node.src.includes('goog')) {
console.log('Blocked script injection:', node.src);
node.remove();
}
if (node.tagName === 'IFRAME' && node.src && node.src.includes('goog')) {
console.log('Blocked iframe injection:', node.src);
node.remove();
}
}
}
});
observer.observe(document.documentElement || document.body, {
childList: true,
subtree: true
});
manifest.json
{
"manifest_version": 3,
"name": "Hard Goog Blocker",
"version": "1.1",
"description": "Blocks any script or resource containing 'goog' in its URL.",
"permissions": ["scripting", "webRequest", "webRequestBlocking", ""],
"host_permissions": [""],
"background": {
"service_worker": "background.js"
},
"content_scripts": [
{
"matches": [""],
"js": ["content.js"],
"run_at": "document_start"
}
],
"action": {
"default_title": "Hard Goog Blocker"
}
}
Here are the three which worked best so far:
- Making ^w jump to the search box on Wiktionary, so I don't have to scroll up and click in the box. I use Wiktionary at least 10x/day, so it's useful.
- Making javascript turn on or off for the current page domain via ^j or clicking on the extension in the toolbar.
- Making links open in the current tab instead of opening in a new tab. I actually have patrick.net using the target="_blank" param on links so that they will open in new tabs, but users asked me to do that.
To install any of them:
- Create a directory for the manfest.json and content.js files.
- In that directory, copy the manifest.json and content.js for the extension. I'll post the "Making links open in the current tab" example in the comments below.
- Go to brave://extensions/ (or chrome://extensions if you're on Chrome or Chromium)
- Turn on "Developer mode" in upper right
- Click "Load unpacked" in upper left
- Select the directory you put the code in
That's all. Uninstall is on the same brave://extensions/ page, in case it doesn't work or you don't like it.