Skip to content

Instantly share code, notes, and snippets.

@rebane2001
Last active November 7, 2023 18:07
Show Gist options
  • Save rebane2001/7b37b2df78e4ec7c0d0811ddca97079c to your computer and use it in GitHub Desktop.
Save rebane2001/7b37b2df78e4ec7c0d0811ddca97079c to your computer and use it in GitHub Desktop.
Edits the SubredditPurge mail to have links and an "Open all" button, autofills SubredditPurge info on the ban page if SubredditPurge hasn't been banned yet
// ==UserScript==
// @name SubredditPurge helper - reddit.com
// @namespace Rebane
// @match https://*.reddit.com/r/*/about/banned/
// @match https://*.reddit.com/message/messages/*
// @grant none
// @version 1.0.1
// @author Rebane
// @description Edits the SubredditPurge mail to have links and an "Open all" button, autofills SubredditPurge info on the ban page if SubredditPurge hasn't been banned yet (2023-11-07)
// ==/UserScript==
window.onload = () => {
// Ban page
if (document.location.href.endsWith("/banned/") && !document.querySelector("a[href='https://www.reddit.com/user/SubredditPurge/']")) {
document.querySelector("#name").value = "SubredditPurge";
document.querySelector("[name='ban_reason']").value = "other";
document.querySelector("#note").value = "Prevent subreddit from getting purged";
}
// Message
const sender = document.querySelector(".sender");
if (sender?.innerText?.startsWith("reddit\n")) {
const msgMarkdown = sender.parentNode.parentNode.parentNode.querySelector(".md");
msgMarkdown.querySelectorAll("li").forEach(e => {
const subredditName = e.childNodes[0].textContent.trim();
const banLink = document.createElement("a");
banLink.innerText = subredditName;
banLink.href = `https://www.reddit.com/r/${subredditName}/about/banned/`;
banLink.classList.add("banLink");
banLink.setAttribute('target', '_blank');
e.replaceChild(banLink, e.childNodes[0]);
});
const openAllBtn = document.createElement("button");
openAllBtn.innerText = "Open all subs";
openAllBtn.onclick = () => {
try {
document.querySelectorAll(".banLink").forEach(e => e.click());
} catch {
alert("Error, make sure you have allowed popups from reddit");
}
};
msgMarkdown.querySelector("li").parentNode.insertBefore(openAllBtn, msgMarkdown.querySelector("li"));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment