4 ms·
There's a userscript manager built into your browser: it's called "extensions". No, I'm serious. Yes, extensions come with extra complexity, but that's because
by jfrunyon 6y ago
There's a userscript manager built into your browser: it's called "extensions".
No, I'm serious. Yes, extensions come with extra complexity, but that's because they have things like permissions, so that you don't have to trust Joe Developer as much.
- thiht 6y ago> extensions come with extra complexity Aaand that's where I (figuratively) stopped reading. If I can do something with a user script, I have no incentive for doing it with a full blown extension. I'd even say that the fact extensions are so much harder to write than user scripts is a complete failure from browser vendors. I get that extensions CAN be complex, but they shouldn't HAVE TO be for simple use cases. User scripts are a proof of that.
- vbezhenar 6y agoThey're not so much harder to write. I spent may be an hour to figure it out. You need simple manifest.json where you'll enumerate stylesheets, scripts and URL filter rules and where to inject them. Of course you don't need all of those things, if you're OK with uBlock, don't add URL filter rules. And then you need to write a little bit of code to insert custom JavaScript on the page, because by default it's executed on extension behalf and can't just access any page DOM. Here's example of my manifest.json: { "manifest_version": 2, "name": "My Web", "version": "1.0", "icons": { "16": "icon_16.png", "32": "icon_32.png", "48": "icon_48.png", "128": "icon_128.png" }, "permissions": ["declarativeNetRequest"], "content_scripts": [{ "matches": ["https://www.pornhub.com/*"], "run_at": "document_start", "js": ["pornhub.js"] }, { "matches": ["https://www.youtube.com/*"], "run_at": "document_start", "css": ["youtube.css"], "js": ["youtube.js"] }], "web_accessible_resources": ["pornhub_script.js", "youtube_script.js"], "declarative_net_request": { "rule_resources": [{ "id": "rules", "enabled": true, "path": "rules.json" }] } } I think, everything there is pretty obvious. Here's my youtube.css: .video-ads { display: none; } Here's my pornhub.js which just injects pornhub_script.js: (() => { "use strict"; var script = document.createElement('script'); script.src = chrome.runtime.getURL('pornhub_script.js'); script.onload = function() { this.remove(); }; document.documentElement.appendChild(script); })(); And here's my pornhub_script.js which disabled stopping video when I'm switching tabs: (() => { "use strict"; const originalDocumentAddEventListener = document.addEventListener; document.addEventListener = function (type) { if (type !== "visibilitychange") { return originalDocumentAddEventListener.apply(this, arguments); } }; })(); And some of my rules.json: [{ "id": 1, "priority": 1, "action": {"type": "block"}, "condition": { "urlFilter": "/pagead/" } }, { "id": 101, "priority": 1, "action": {"type": "block"}, "condition": { "urlFilter": "||doubleclick.net/" } }, ... You can just copy this structure and it should work in Chrome (open chrome://extensions/ and click "Load unpacked"). On the plus side: you're not giving up any control over your user scripts to addon authors.
- rakoo 6y agoThe only time I had to hack on a webextension I had to reload it on every change, and do it all again every time I restarted my browser. And I only felt comfortable to hack on this extension because I forked it and wanted to add something on top. As a user who wants to dev for myself, it was a bit too heavy.