Last active
March 12, 2023 20:54
-
-
Save gosoccerboy5/0e44ad090d6c683f0764a998ddf9a8a9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Hide Upvote Count | |
// @description Hides upvote count on posts and comments on Reddit | |
// @match *://*.reddit.com/* | |
// @version 0.0.0.0.1 | |
// @developer gosoccerboy5 | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
let style = document.createElement("style"); | |
style.innerText = "[id^=vote-arrows] div {min-width: 1.9vw;}.Post div div[id^=vote-arrows] div {text-align:center;}"; | |
document.head.append(style); | |
function updateNode(node) { | |
let updoots = node.innerText; | |
let permanent = node.innerText = "Vote"; | |
let isPost = [...node.parentElement.parentElement.parentElement.classList].includes("Post"); | |
node.parentNode.addEventListener("mouseover", function(evt) { | |
if (isPost && (evt.target === this || evt.target === this.children[1])) this.children[1].innerText = updoots; | |
}); | |
node.parentNode.addEventListener("mouseout", function(evt) { | |
if (isPost && (evt.target === this || evt.target === this.children[1])) this.children[1].innerText = permanent; | |
}); | |
node.parentNode.addEventListener("click", function(evt) { | |
permanent = node.innerText = updoots; | |
}); | |
} | |
let mut = new MutationObserver(function(mutationList) { | |
for (let mutation of mutationList) { | |
if (mutation.type === "childList") { | |
mutation.addedNodes.forEach(node => { | |
node.querySelector && node.querySelector("[id*=vote-arrows] > div") && | |
node.querySelectorAll("[id*=vote-arrows] > div").forEach(updateNode); | |
}); | |
} | |
} | |
}); | |
mut.observe(document.body, {subtree: true, childList: true}); | |
window.addEventListener("load", () => document.body.querySelectorAll("[id*=vote-arrows] > div").forEach(updateNode)); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment