Alex Balgavy

Just some stuff about me.

Here's my dotfiles repository.

Check out my blog.

My keys: PGP, SSH

My crypto wallets (BTC, XMR)


What links here:

Injecting JS with uBlock Origin

You can inject scripts with uBlock Origin, and change the behavior of the website. For example, Reddit sometimes collapses comments. So we want to uncollapse all except those that were “collapsed for a reason” – they are below the viewer’s score threshold. Only want to expand comments collapsed because of this https://old.reddit.com/r/redditsecurity/comments/b0a8he/detecting_and_mitigating_content_manipulation_on/

First, create a script:

// Scriptlets for uBlock Origin
/// expand-reddit-comments.js
(function() {
    document.addEventListener("DOMContentLoaded", function() {
        console.log("Expanding all comments...");
        let comments = document.querySelectorAll(".thing.collapsed:not(.collapsed-for-reason)");
        comments.forEach(function (el, i) {
            el.classList.remove("collapsed");
            el.classList.add("noncollapsed");
        });
    });
})();

For syntax reference, see here.

Put that script somewhere accessible on the web, I recommend your own website. Mine is at https://alex.balgavy.eu/ubo-scriptlets.js

Enable uBO advanced settings, open advanced settings, set userResourcesLocation to that value:

userResourcesLocation https://alex.balgavy.eu/ubo-scriptlets.js

Go to my filters in uBO, add the following line:

reddit.com##+js(expand-reddit-comments.js)

Now if you save and load reddit, you should see the message in the console, and all comments will be expanded.