1
0

Making browser extensions


 invite response                
2025 Apr 29, 3:03pm   112 views  7 comments

by Patrick   ➕follow (60)   ignore (3)  

There are a lot of little annoying things about using the web which can be fixed with custom browser extensions. I've asked AI to make me some, and the majority have worked, though not all.

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.

Comments 1 - 7 of 7        Search these comments

1   Patrick   2025 Apr 29, 3:04pm  

Making links open in the current tab.

manifest.json:


{
"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"
}
]
}


content.js:


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);
2   Ingrid   2025 Apr 29, 5:12pm  

OMG it might as well be Latin. I probably would understand that better LOL. Been trying to send a pic from cellphone to computer, which used to go just fine, but not anymore!
3   Patrick   2025 Apr 29, 6:51pm  

@Ingrid You don't actually need to understand that code to get it to work. But I suppose it does look pretty obscure if you're not from Planet Tech.
4   Patrick   2025 May 6, 11:13pm  

Got one working that blocks all cookies on Wikipedia. Happy to share if anyone wants it. Open source, small, easy to verify that it's not malicious.

So now I can surf Wikipedia and it's much harder for them to track what I'm viewing. Nice.
5   zzyzzx   2025 May 7, 7:23am  

I sometimes use AI to generate code snippets as a starting point. It's relatively decent at it yes,
6   Patrick   2025 May 7, 9:38am  

Yes, it's very good for that, and for getting ideas, but not for creating a finished project. Not yet, anyway.
7   Patrick   2025 May 13, 9:11am  

Wow, Google is a like a leech that you can't get off your skin.

I tried mapping Google domains to localhost in /etc/hosts but Google slime like the recapcha spyware still seeps through, maybe because Brave refuses to use my /etc/hosts file.

I tried blocking all Google elements with Brave filtering brave://settings/shields/filters using:

||accounts.google.com^
||apis.google.com^
||clients6.google.com^
||clients.google.com^
||ssl.gstatic.com/accounts^
||googleapis.com^
||*.googleapis.com^
||youtube.com^
||*.youtube.com^
||*.ytimg.com^
||youtu.be^
||*goog*^

But no better.

I tried a regex rule in https://objective-see.org/products/lulu.html firewall: "/goog/:any port"

But no better.

Now I've created a browser extension that finally seems to be slowing the slime:


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"
}
}

Please register to comment:

api   best comments   contact   latest images   memes   one year ago   users   suggestions   gaiste