Reddit "Vote" Replacer

Replace the word "Vote" with "circle" in the vote counts on reddit.com

La data de 14-12-2023. Vezi ultima versiune.

// ==UserScript==
// @name         Reddit "Vote" Replacer
// @namespace    https://github.com/GitEin11
// @version      1.0
// @description  Replace the word "Vote" with "circle" in the vote counts on reddit.com
// @author       You
// @match        https://www.reddit.com/*
// @grant        none
// @license MIT 
// @run-at       document-idle
// ==/UserScript==

// Define a function that replaces the word "Vote" with "dot" in the vote counts
function replaceVoteWithDot() {
    // Select all elements that have the id starting with "vote-arrows" and ending with "> div:nth-child(2)"
    var voteElements = document.querySelectorAll('[id^="vote-arrows-"] > div:nth-child(2)');
    // Loop through each element and check its inner HTML
    for (var i = 0; i < voteElements.length; i++) {
        // If the inner HTML is "Vote", replace it with "dot"
        if (voteElements[i].innerHTML == "Vote") {
            voteElements[i].innerHTML = "〇";
        }
    }
}


// Define a counter variable
var counter = 0;
// Define an interval variable (in milliseconds)
var interval = 3000;
// Define a function that runs the script and increments the counter
function runScript() {
    // Replace the word "Vote" with "dot" in the vote arrows
    replaceVoteWithDot();
    // Increment the counter
    counter++;
    if (counter == 0) {
        // Clear the interval to stop the execution
        clearInterval(timer);
    }
}
// Set an interval to run the function repeatedly with the interval
var timer = setInterval(runScript, interval);


// Define a function that creates and returns a mutation observer
function createMutationObserver() {
    // Create a new mutation observer object
    var observer = new MutationObserver(function(mutations) {
        // Loop through each mutation record
        for (var j = 0; j < mutations.length; j++) {
            // Check if the mutation added new nodes to the DOM
            if (mutations[j].addedNodes.length > 0) {
                // Run the replaceVoteWithDot function on the new nodes
                replaceVoteWithDot();
            }
        }
    });
    // Return the observer object
    return observer;
}

// Create a mutation observer
var observer = createMutationObserver();
// Select the element that contains the page content
var contentElement = document.getElementById('siteTable');
// Check if the element exists
if (contentElement) {
    // Start observing the element for changes in its child nodes
    observer.observe(contentElement, {childList: true});
}