/r/userscripts

Photograph via snooOG

A place for discussion of all things related to userscripts.

A place for discussion of all things related to userscripts.


RELATED:

/r/userscripts

4,948 Subscribers

1

Is there a userscript or a CSS snippet that can change how Old Reddit interprets numbered lists, so that it doesn't change the first number to "1."?

When someone begins a comment with a number followed by a period, like "52.", Old Reddit interprets this as the beginning of a numbered list, and replaces that number with "1."

I would like to override this, so that I see the original number instead. Would this be possible?

EDIT: I use Reddit Enhancement Suite, so it's fine if a userscript has to hook into that.

30 Comments
2025/01/25
19:11 UTC

6

Local server for Userscripts instead of Chrome extension?

I'd love to be able to use kind of "dotfiles" to configure my userscripts on a new machine, or easily update them from my local folder rather than the clunky in-extension editor

Is there a kind of chrome extension I can use which would connect to a local server (that I could install locally on my laptop, linux box, etc) which would run the page through it before rendering it again, so that I can effectively inject my userscripts outside of Chrome (and therefore have them in a git repo, version them, etc)?

Tried to detail it a bit here: https://bsky.app/profile/maelp.bsky.social/post/3lgkmasnuls2d

4 Comments
2025/01/25
09:29 UTC

0

Anyone use GoDaddy??

I signed up and created a website, but it's hard to navigate. Especially for setting up how your getting paid.

3 Comments
2025/01/24
16:38 UTC

4

Userscript to set sort order of sub-reddits

I have published a userscript to add default sorting to sub-reddit listings.

It implements:

  • default sort order
  • sort order override by sub-reddit
  • sort order override for reddit homepage
  • flexible redirect when landing page (from a bookmark, or when a link is opened in a new tab) has a sort order: noredir/redir/force/ask

It's available here: https://greasyfork.org/scripts/524564-reddit-subs-default-sort

0 Comments
2025/01/24
00:04 UTC

4

Userscript, old.reddit.com hide subreddits by subreddit and title regex filter

This script adds a small block button beside all subreddits and will hide blocked subreddits from feed.

// ==UserScript==
// @name         Optimized Hide Posts with Block, Unblock, and titleRegex
// @namespace    jjenkx
// @version      0.1
// @description  Hides posts on old.reddit.com based on title and subreddit using customizable regex patterns with toggle and block/unblock buttons. Highlights posts unhidden due to title regex matches in light blue.
// @author       ChatGPT 4o
// @match        https://old.reddit.com/*
// @grant        GM.setValue
// @grant        GM.getValue
// @grant        GM.listValues
// ==/UserScript==

(function () {
    'use strict';

    // Hide posts matching regex
    const titleRegex = /\b(trump|gop|elon|musk|maga)\b/i;
    let blockedSubreddits = new Set();
    let filtersEnabled = true; // Default state is enabled
    let hiddenPostCount = 0;
    let debounceTimeout = null;

    // Load blocked subreddits from storage
    const loadBlockedSubreddits = async () => {
        const stored = await GM.getValue('blockedSubreddits', '[]');
        blockedSubreddits = new Set(JSON.parse(stored));
    };

    // Save blocked subreddits to storage
    const saveBlockedSubreddits = async () => {
        await GM.setValue('blockedSubreddits', JSON.stringify([...blockedSubreddits]));
    };

    // Block a subreddit
    const blockSubreddit = async (subreddit) => {
        blockedSubreddits.add(subreddit);
        await saveBlockedSubreddits();
        hidePosts();
    };

    // Unblock a subreddit
    const unblockSubreddit = async (subreddit) => {
        blockedSubreddits.delete(subreddit);
        await saveBlockedSubreddits();
        hidePosts();
    };

    // Update the counter on the button
    const updateButtonCounter = () => {
        const toggleButton = document.querySelector('.toggle-filters-button');
        if (toggleButton) {
            toggleButton.textContent = filtersEnabled
                ? `Disable Filters (${hiddenPostCount})`
                : 'Enable Filters';
        }
    };

    // Add a block or unblock button based on state
    const manageButtons = (post, subredditText, subredditElement) => {
        // Remove any existing buttons
        const existingBlockButton = post.querySelector('.block-subreddit-button');
        const existingUnblockButton = post.querySelector('.unblock-subreddit-button');
        if (existingBlockButton) existingBlockButton.remove();
        if (existingUnblockButton) existingUnblockButton.remove();

        if (blockedSubreddits.has(subredditText)) {
            // Add "Unblock" button for blocked subreddits
            const unblockButton = document.createElement('button');
            unblockButton.textContent = 'Unblock';
            unblockButton.className = 'unblock-subreddit-button';
            unblockButton.style.marginLeft = '3px';
            unblockButton.style.cursor = 'pointer';
            unblockButton.style.fontSize = '5px'; // Smaller font size
            unblockButton.style.padding = '0px 0px'; // Smaller padding

            unblockButton.addEventListener('click', async () => {
                await unblockSubreddit(subredditText);
            });

            subredditElement.parentNode.appendChild(unblockButton);
        } else {
            // Add "Block" button for unblocked subreddits
            const blockButton = document.createElement('button');
            blockButton.textContent = 'Block';
            blockButton.className = 'block-subreddit-button';
            blockButton.style.marginLeft = '3px';
            blockButton.style.cursor = 'pointer';
            blockButton.style.fontSize = '5px'; // Smaller font size
            blockButton.style.padding = '0px 0px'; // Smaller padding

            blockButton.addEventListener('click', async () => {
                await blockSubreddit(subredditText);
            });

            subredditElement.parentNode.appendChild(blockButton);
        }
    };

    // Hide or show posts based on filters
    const hidePosts = () => {
        const postElements = document.querySelectorAll('.thing');
        let count = 0;

        postElements.forEach((post) => {
            const titleElement = post.querySelector('a.title');
            const titleText = titleElement ? titleElement.textContent : '';

            const subredditElement = post.querySelector('a.subreddit');
            const subredditText = subredditElement ? subredditElement.textContent.replace('/r/', '').trim() : '';

            if (filtersEnabled && (titleRegex.test(titleText) || blockedSubreddits.has(subredditText))) {
                post.style.display = 'none';
                post.setAttribute('data-hidden', 'true'); // Mark post as hidden
                count++;
            } else {
                post.style.display = '';
                if (post.getAttribute('data-hidden') === 'true') {
                    post.setAttribute('data-hidden', 'false'); // Mark as revealed
                }

                // Apply correct shading
                if (!filtersEnabled) {
                    if (titleRegex.test(titleText)) {
                        post.style.backgroundColor = '#ff9999'; // Medium bright red for posts matching title regex
                    } else if (blockedSubreddits.has(subredditText)) {
                        post.style.backgroundColor = '#dcdcdc'; // Darker gray for blocked posts
                    } else {
                        post.style.backgroundColor = ''; // Default background for unblocked posts
                    }
                } else {
                    post.style.backgroundColor = ''; // Clear background when filters are enabled
                }

                // Manage buttons
                if (subredditElement) {
                    manageButtons(post, subredditText, subredditElement);
                }
            }
        });

        hiddenPostCount = count;
        updateButtonCounter();
    };

    // Add a toggle button for filters
    const addFilterToggleButton = () => {
        const sortButtons = document.querySelector('.tabmenu');

        if (sortButtons && !document.querySelector('.toggle-filters-button')) {
            const toggleButton = document.createElement('button');
            toggleButton.textContent = `Disable Filters (${hiddenPostCount})`; // Default text
            toggleButton.className = 'toggle-filters-button';
            toggleButton.style.marginLeft = '5px';
            toggleButton.style.cursor = 'pointer';
            toggleButton.style.fontSize = '10px'; // Smaller font size
            toggleButton.style.padding = '0px 1px'; // Smaller padding

            toggleButton.addEventListener('click', () => {
                filtersEnabled = !filtersEnabled;
                hidePosts();
            });

            sortButtons.appendChild(toggleButton);
        }
    };

    // Debounced callback for MutationObserver
    const debouncedHidePosts = () => {
        if (debounceTimeout) {
            clearTimeout(debounceTimeout);
        }
        debounceTimeout = setTimeout(() => {
            hidePosts();
        }, 100); // Adjust delay to balance performance and responsiveness
    };

    // Observe the post container for dynamically loaded content
    const observePostContainer = () => {
        const postContainer = document.querySelector('#siteTable'); // Specific container for posts
        if (postContainer) {
            const observer = new MutationObserver(debouncedHidePosts);
            observer.observe(postContainer, { childList: true, subtree: false });
        }
    };

    // Initialize
    (async () => {
        await loadBlockedSubreddits();
        addFilterToggleButton();
        hidePosts();
        observePostContainer();
    })();
})();
0 Comments
2025/01/15
09:47 UTC

2

Script to increase Google search results quantity

Is there one? It's a simple thing, just needs to append "&num=100" to any Google search result page for in that instance 100 results.

6 Comments
2025/01/14
10:20 UTC

3

Request: adding an approve button next to reddit username

Hey, I am wondering if there's a script that would let me approve users via a single click. The button would appear beside their username, similar to how moderator toolbox works. Right now, approval can be carried out via the toolbox options but it requires more than one click.

2 Comments
2025/01/05
17:22 UTC

1

UserScript for bypassing Reddit sub limit in sidebar?

Yes, I have too much subreddits i'm subscribed to. I mostly use Reddit APP(s) to browse Reddit where I can find my entire list.

The website hoever has a hard limit of amount of subreddit being listed in the sidebar.

Does anyone have a workaround script for this?

8 Comments
2025/01/04
07:08 UTC

5

Userscript for Reddit bug workaround to allow posting on the r/userscript subreddit

As discussed here there appears to be a problem with Reddit posting to this subreddit when using the new Reddit interface.

So I created a userscript to temporarily redirect Reddit's submit page for r/userscripts to the old Reddit interface to work around the bug. Access it here

7 Comments
2025/01/04
01:22 UTC

3

Userscript for Google Sheets to Suppress F1 Key Preventing Help-Popup

I created a userscript to intercept F1 (help) keypress on Google Sheets and replaces default behavior with nothing. Access it here

0 Comments
2025/01/04
01:13 UTC

1

Userscript for Google Sheets to Enable Scandinavian Keyboard On Mac

I created a userscript to fix shift+option+number keys in Google Sheets on Mac while using a Scandinavian keyboard layout, by interception of shift+option+number keys, and replace them with the correct char pasted in. Access it here

0 Comments
2025/01/04
01:05 UTC

3

Userscript for YouTube to add a save playlist hotkey and a save playlist filter

I just created a userscript that adds a convenient hotkey (p) to YouTube, which opens the Save to Playlist dialog on the currently playing video. It also sorts and filters your playlists in a more useful way. It's just the way it should have been from the start.

Access it here

0 Comments
2025/01/04
00:42 UTC

12

Filter stupid, repetitive, meaningless Reddit comments! #thanksforthegoldkindstranger

Do stupid, repetitive, meaningless Reddit comments like these make you want to punch through your laptop screen?

 

  • Thanks for the gold, kind stranger!
  • Take my upvote!
  • Came here to say this.
  • This comment right here, officer.
  • This.
  • This one.
  • This one right here.
  • So much this.
  • Misread instructions now my dick is stuck in the blender
  • Sigh... unzips pants
  • Underrated comment.
  • Beat me to it.
  • F
  • Chat is this real
  • Good sir
  • Am I the only one who...
  • Wow I can't believe my top comment is about...

 

Yet, you still can't shake that debilitating Reddit addiction? I hear you. Install this userscript to automatically remove these (and many more!) from your comments page.

 

Project page: https://codeberg.org/cache_miss/reddit-comment-filter

Raw userscript: https://codeberg.org/cache_miss/reddit-comment-filter/raw/branch/master/reddit-comment-filter.user.js

 

Also: the filter list is far from complete! If you like the idea, please suggest new phrases you think should be filtered. You can comment them here and I'll round them up, or you can make a request on the project page.

3 Comments
2025/01/03
06:09 UTC

2

Kahoot Autoanswer bot free script

heres a link to the script i wrote to autoanswer any text questions on kahoots https://greasyfork.org/en/scripts/521431-kahootgpt

1 Comment
2024/12/23
00:13 UTC

2

Coding help???

Is there a way to alter a website destination on a website that’s entity isn’t mine? So for example on my schools website I want a link to go to something else is that possible? Info I’ve received:

To be direct: when a file (or any data) is sent from a server somewhere, to a browser, there's "header" text data sent along with it. With backend config you can make sure that header includes data that tells the browser "this is a download". Browsers respect this most of the time. So basically idk how to do this and I was wondering if there are people capable of doing such and where I can get the help. Fiverr i don’t think is much help being that they are website specific but idk im not sure

3 Comments
2024/12/22
05:03 UTC

3

Bookmarklet I've been using to switch back and forth between Old and New Reddit won't work anymore with Old Reddit Redirect enabled

Here's the bookmarklet I've been using:

javascript: (function(){ const n="new.reddit.com"; const o="old.reddit.com"; let url=new URL(window.location.href); switch(url.hostname){ case n:url.hostname=o;break; case o:url.hostname=n;break; default:return;} window.location.href=url.href; })();

Something changed with a recent update to Firefox or Reddit itself, because I can't view the New Reddit version of a page when I use this bookmarklet anymore. Sometimes I need to switch to New Reddit in order to read subreddit sidebar rules, since Reddit doesn't sync them between Old and New Reddit.

Has anyone else been having similar problems? Is there anything you'd suggest for fixing this bookmarklet?

EDIT: Turns out new.reddit.com doesn't work anymore, so you have to use sh.reddit.com. Here's my updated bookmarklet:

javascript: (function(){ const n="sh.reddit.com"; const o="old.reddit.com"; let url=new URL(window.location.href); switch(url.hostname){ case n:url.hostname=o;break; case o:url.hostname=n;break; default:return;} window.location.href=url.href; })();

Somehow, this new bookmarklet works for me with Old Reddit Redirect enabled. This is good, because I need ORR to open images properly in a new tab.

9 Comments
2024/12/13
03:25 UTC

5

Grayscale everything on Youtube but the video itself

I found an add-on, Untrap for Youtube that actually does this, but hear me out. It's kinda pointless to have the add-on just to turn on those grayscale options, so even with all options on, and then turning off all other add-on and restarting the browser, it still makes the website run really slow.

I am looking for an extension/add-on that can grayscale mostly everything colorful on the site (channel avatars, banners, thumbnails on videos and playlists, search music panel thumbnails, etc.) but when you actually play the video.

What I find with a lot of these "grayscale add-ons" also is that they grayscale the whole website, which is fine in other cases like Reddit, but not with Youtube for me at least, so if anyone has any recommendations for add-ons that are lightweight and do what it asks for in this post, please let me know!

10 Comments
2024/12/11
16:03 UTC

1

Google Docs live word count

Is it possible to create a userscript to automatically always display the live word count? I was able to use css to force the word count bubble to always appear but I can't get it to show the text with the actual number of words. It seems like the specific element only appears after some script is run when you manually click the checkbox and ok button on the menu screen. I'm not sure if it's possible to even automate this... I've searched for various extensions online and haven't been able to find a solution yet.

https://preview.redd.it/2fviuc2th54e1.png?width=634&format=png&auto=webp&s=d1040795653d19bff5fca472fa7fcc87317fcde0

https://preview.redd.it/80nwnjxuh54e1.png?width=664&format=png&auto=webp&s=0de01a056d53ec421a16cb1e55b9861591f863c6

https://preview.redd.it/bj4p7dq0h54e1.png?width=778&format=png&auto=webp&s=811479dec3b4431d4e8fdd2b1941552676bb6b77

3 Comments
2024/12/01
02:52 UTC

2

Help with userscript to clean up subtitles

I found a userscript on greasyfork that I am trying to change to function on the Amazon Video website. The script was originally for Netflix and I just changed the class name of the subtitles and it worked for Hulu's site, but for some reason I can't get it figured out for Amazon's site. I've tried various different class names, but none seem to work. I'm pretty positive this is the correct element to target. Does anyone have any ideas on why it's not working?

https://preview.redd.it/qqmhmbtqey3e1.png?width=948&format=png&auto=webp&s=91b76b28caa79f9b178e493c1ef4c022c4fae569

// ==UserScript==
// @name        Amazon subtitle cleanup
// @namespace   Violentmonkey Scripts
// @match       https://www.amazon.com/*
// @grant       none
// @version     1.0
// @description Remove all "[inhales]", "[loud noise]" from the subtitles
// @icon        https://upload.wikimedia.org/wikipedia/commons/4/4a/Amazon_icon.svg
// ==/UserScript==

let observed_node = undefined

let kill_song_lyrics = true

const cleanup = (t) => {
  if (kill_song_lyrics && t.includes('♪')) {
    return '' // ignore song lyrics
  } else if (t.includes('[') && t.includes(']')) {
    return t.replace(/(- *)?\[[^\]]+\]/g, '') // (maybe "- ") "[" .. (not "]")+ .. "]"
  } else if (t.includes('(') && t.includes(')')) {
    return t.replace(/(- *)?\([^\)]+\)/g, '') // (maybe "- ") "(" .. (not ")")+ .. ")"
  }

  return t
}

const on_mutated = (changes) => {
  const ts = observed_node.querySelectorAll('atvwebplayersdk-captions-text')
  for (let i = 0; i < ts.length; i++) {

    const t = ts[i].innerHTML
    const nt = cleanup(t)

    if (nt !== t) {
      ts[i].innerHTML = nt
      // console.log({ original: t, filtered: nt })
    }
  }
}

const observer = new MutationObserver(on_mutated)

const reobserve = () => {
  const elems = document.getElementsByClassName('atvwebplayersdk-captions-text')
  if (elems[0] !== undefined) {
    if (observed_node !== elems[0]) {
      observed_node = elems[0]
      console.log({ observed_node })
      observer.observe(observed_node, { childList: true, subtree: true})
    }
  }
  window.setTimeout(reobserve, 100)
}


const run_tests = () => {
  // the tests are lightning fast, so just do run them quickly on every script startup
  const test_cleanup = (source, expected) => {
    console.assert(cleanup(source) === expected, { test_result: false, source, expected, actual: cleanup(source) })
  }
  test_cleanup('normal text', 'normal text')
  test_cleanup('[coughs]', '')
  test_cleanup('[coughs] yeah', ' yeah')
  test_cleanup('-[coughs]', '')
  test_cleanup('- [coughs]', '')
  test_cleanup('- (inhales)', '')
  test_cleanup('some ♪ singing', '')
  console.log('tests ok')
}


console.log('Netflix subtitle filter userscript starting up')
run_tests()
reobserve()

4 Comments
2024/11/30
02:58 UTC

3

Why I can load function on some sites (e.g. reddit) but not others (e.g. github)? Advice on how to fix it?

So I'm trying to create a function in my userscript and make it available to be called on the dev console in Firefox. While attempting to do so on github, I was running into issues with this and since I have done it tons of times in the past on other sites, I had assumed I had mucked something up in my script. But even boiling it down to really basic snippets, I still can't get it to work. Any help?

// ==UserScript==
// @name        reddit-test
// @namespace   Violentmonkey.github-test
// @include     /https:\/\/(old|new|www)?\.?reddit.com(\/r\/userscripts)?\/?$/
// @grant       none
// @version     1.0
// @author      -
// @description add function to page and make it callable from firefox dev console
// ==/UserScript==
let myfunc = function(selector) {
  let elems = document.querySelectorAll(selector);
  return elems;
}
window.myfunc = myfunc;

And then running that on reddit, I get the following in the dev console

myfunc('#header').length
1 

Taking the same thing and making a new script for gitub (e.g. just name and include are changed)

// ==UserScript==
// @name        github-test
// @namespace   Violentmonkey.github-test
// @include     /https:\/\/github.com\/?$/
// @grant       none
// @version     1.0
// @author      -
// @description add function to page and make it callable from firefox dev console
// ==/UserScript==
let myfunc = function(selector) {
  let elems = document.querySelectorAll(selector);
  return elems;
}
window.myfunc = myfunc;

Then running on github homepage, I get the following in dev console (note: script appears on Violent Monkey icon console.log so the @include is ok and console.log statements show up and functions seem to work within the context of the userscript so I can do things like grab element text / update document title / etc but it appears to be blocked from adding the function to the window / showing up in the dev console for some unknown reason).

myfunc('.AppHeader').length
Uncaught ReferenceError: myfunc is not defined
    <anonymous> debugger eval code:1

I notice that the dev console on github has a a lot of errors about Content-Security-Policy and similar even when Violent Monkey is completely disabled. However, I am still able to manually create functions under the window object from dev console (e.g.):

>> window.myfunc = function() { console.log('success'); };
function myfunc()
 
>> myfunc()
success

I would normally assume that this is something related CORS / cross-site scripting but would that even apply for userscripts that are simply operating on the page without loading things from other domains (e.g. not importing libraries from a cdn like jQuery / etc but just plain vanilla JS, entirely self-contained in the userscript)?

I've been searching for about an hour already and I am as stumped as when I started. I used to be moderately ok with javascript once upon a time but haven't kept up with things over the last 5 or so years. Hoping someone who is more current than me can help shed some light and offer advice on how on to make my userscript functions available via the dev console.

edit: obviously, the function above is just a simple example that I am using for testing. The final function that I plan to add will be significantly more complex but want to stomp out this issue before I continue.

edit 2: even stranger, I just retested the github userscript under chromium + VM and it actually works as expected over there (no modification). So I guess I need to test if this is a) due to some other setting/addon, b) some issue with github not liking FF, b) some VM+FF specific bug or limitation... I guess at least I'm not going crazy but would have been nice if it "just worked".

9 Comments
2024/11/25
06:13 UTC

1

[Request] Redirect Gyazo image page directly to file

Is it possible to do a script to redirect Gyazo images directly to file? I'm currently using Redirector to do it, but it doesn't work if the image is jpg or webp, also I have to press f5 for the redirection to work.

2 Comments
2024/11/23
07:16 UTC

1

Need some pointers

I want to write a script that scans links in a page and sends some of them to a url. I can do this myself but I have two questions:

  1. The url will always be foreign to the current url, so, are there cors restrictions for http requests, or can I make http requests to arbitrary urls? Should I use xhr or fetch?

  2. I need to send all links exactly once so I need to store the ones I've sent already. This must survive across browser restarts. Is there some storage, preferably k/v like localstorage that is shared among all websites?

Thanks

7 Comments
2024/11/21
19:39 UTC

3 Comments
2024/11/20
07:55 UTC

2

Request - Automatically shows more Subscriptions in the sidebar

Hi!

Can someone help me create a script that automatically expands "Show more" in the youtube sideba. I found this script but it no longer works. I tried to edit it but unfortunately I'm not good at javascript

YouTube - automatically expand subscription list

Thanks in advance for reading.

6 Comments
2024/11/10
07:58 UTC

2

Request - Override ArtStation Gallery Hover for Multi-image Icon

Recently Artstation has made a bizarre change in making a once persistent icon that shows if a gallery has multiple images to one that shows up on mouse hover.

Example gallery https://www.artstation.com/felixriano

Before Hover

After Hover (note the image preview hover is a extension)

It appears that simply changing a style from display: none to display: block lets the icon appear. But it has been many years since I've worked on this stuff and I am unsure how to apply this.

Example - Display: block;

I am not sure how to target the entire gallery in a way that the icon is persistent despite any new instances of the mouse hovering over a thumbnail. As with just changing the display from none to block is only temporary till you hover over the thumbnail.

2 Comments
2024/11/09
00:42 UTC

Back To Top