Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save reallytiredofclowns/c772b49b463f2058a4406a7e4a1fda7f to your computer and use it in GitHub Desktop.
Save reallytiredofclowns/c772b49b463f2058a4406a7e4a1fda7f to your computer and use it in GitHub Desktop.
Userscript to hide view of downvotes on discuit.net
// ==UserScript==
// @name discuit-hide-downvotes
// @namespace discuit-aw-userscripts
// @version 2024-04-11
// @description Hide downvotes on Discuit
// @author AuralWanderer
// @match https://discuit.net/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=discuit.net
// @grant none
// ==/UserScript==
"use strict";
// elements to hide: hover on posts in feed
// post page: green/red bar and its hover; hover on post badge
// comments: downvote element
// user feed: downvote count, post badge hover
function nodeSelect(root, selector, handler) {
// check the node itself for matching the selector
if (root.matches(selector)) {
handler(root);
}
// check the subtree
let subMatches = root.querySelectorAll(selector);
for (let node of subMatches) {
handler(node);
}
}
function handlePostBadge(node) {
const pat = /Upvotes: (\d+) • Downvotes: (\d+)/i;
let matchResult = node.title.match(pat);
node.innerHTML = matchResult[1];
node.title = "Upvotes: " + matchResult[1] + " • Downvotes: 0";
}
function handleVoteBar(node) {
node.querySelector(".votes-bar-down").style.width = "0%";
const pat = /upvoted • (\d+ upvotes?)/i;
let upvotes = node.title.match(pat)[1];
node.title = "100% upvoted • " + upvotes + " • 0 downvotes";
}
function handlePostComment(node) {
node.innerHTML = 0;
}
function handleUserFeedComment(node) {
const pat = /\d+ upvotes?/i;
let upvotes = node.innerHTML.match(pat)[0];
node.innerHTML = upvotes + " • 0 downvotes";
}
function handleMobilePostPercent(node) {
node.innerHTML = "100% Upvoted";
}
function observeDownvotes(mutations) {
for (let mutation of mutations) {
for (let node of mutation.addedNodes) {
if (! (node instanceof HTMLElement)) continue;
nodeSelect(node, "div.post-votes-no", handlePostBadge);
nodeSelect(node, "div.post-card-votes-bar", handleVoteBar);
nodeSelect(node, "div.post-comment-points.is-grayed", handlePostComment);
nodeSelect(node, "div.comment-score", handleUserFeedComment);
nodeSelect(node, "div.post-card-vote-percent", handleMobilePostPercent);
}
}
}
let observerInit = new MutationObserver(observeDownvotes);
observerInit.observe(document.querySelector("body"), {childList: true, subtree: true});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment