Wednesday, 4 March 2020

How to bulk reset your Reddit upvote history

Ever needed to bulk reset your upvote history for a subreddit? Yes, it is a bit of a random topic. However, I found myself in this situation recently and there wasn't a way to do so using Reddit's built in capabilities. A simple piece of Javascript came to the rescue!


Disclaimer: This solution is coupled to the markup of the current Reddit website. So will only be functional until Reddit changes their markup in the future.
Start by navigating your browser to:
https://www.reddit.com/user/dionbeetson/upvoted/
Then open up your developer console (F12). Click on the console tab.

The javascript code

/**
 * Function to clear votes for a specific subreddit
 */
let clearVote = (subReddit) => {
    let clearedCounter = 0;
    let anchorsFound = document.querySelectorAll("a[href$='/r/" + subReddit + "/']");
    for (var i = 0, l = anchorsFound.length; i < l; i++) { let anchor = anchorsFound[i]; let post = anchor.closest('.Post'); let button = post.querySelector("button[data-click-id='upvote']"); button.click(); clearedCounter++;     }     console.log('Cleared ' + clearedCounter + ' upvotes from ' + subReddit);
}; // We need to continually keep scrolling to the bottom to load more history let scrollToBottomCounter = 0; let interval = setInterval(() => {
    if( scrollToBottomCounter > 300 ) {
        clearInterval(interval);
        clearVote('Bitcoin');
    }

    window.scrollTo(0,document.body.scrollHeight);

    scrollToBottomCounter++;
}, 1500);

// Call clear vote for the subreddits you want to clear your upvotes for
// EG: this is the name of the subreddit that you can see within the UI that looks like r/CryptoMarkets/
// However you simply include the subreddit name and not the starting 'r/' and trailing '/'
clearVote('InstantRegret');
clearVote('RoastMe');

// You can call clearVote as many times as you require.

How to run the script

Now, after adding a 'clearVote' function call for each subreddit you want to clear upvotes for you can paste this script into the 'console' within your browser and the script will simulate a user clicking the upvote button for all of your upvote history.
Enjoy :-)

0 comments:

Post a Comment