Created
February 16, 2024 23:49
-
-
Save reallytiredofclowns/857bc1a894ff9b78ded13c94b82ad179 to your computer and use it in GitHub Desktop.
Temporary tool for moderators to auto check for disc reports on discuit.net
This file contains 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 discuit-report-notification | |
// @namespace discuit-aw-userscripts | |
// @version 2024-02-13 | |
// @description Moderator notification for disc reports. | |
// @author AuralWanderer | |
// @match https://discuit.net/* | |
// @icon https://www.google.com/s2/favicons?sz=64&domain=discuit.net | |
// @grant none | |
// ==/UserScript== | |
var discsWithReports = []; | |
function toggleVis() { | |
var node = document.getElementById("listPanel"); | |
if (node.style.display == "block") { | |
node.style.display = "none"; | |
} else { | |
node.style.display = "block"; | |
} | |
} | |
function createDiscLink(name) { | |
var node = document.createElement("p"); | |
node.innerHTML = "<a href='https://discuit.net/" + name + "/modtools/reports'>" + name + "</a>"; | |
return node; | |
} | |
function removeHammer() { | |
var node = document.getElementById("modNotification"); | |
if (node) { | |
node.remove(); | |
} | |
node = document.getElementById("listPanel"); | |
if (node) { | |
node.remove(); | |
} | |
} | |
function showHammer() { | |
var notificationNode = document.querySelector(".notifications-button"); | |
var reportIcon = document.getElementById("modNotification"); | |
if (notificationNode != null && reportIcon == null) { | |
reportIcon = document.createElement("div"); | |
reportIcon.innerHTML = "🔨"; | |
reportIcon.id = "modNotification"; | |
notificationNode.parentNode.parentNode.insertBefore(reportIcon, notificationNode.parentNode); | |
reportIcon.addEventListener("click", toggleVis); | |
} | |
var listPanel = document.getElementById("listPanel"); | |
if (listPanel == null) { | |
listPanel = document.createElement("div"); | |
listPanel.id = "listPanel"; | |
listPanel.style.display = "none"; | |
listPanel.style.position = "fixed"; | |
listPanel.style.backgroundColor = "black"; | |
listPanel.style.padding = "10px"; | |
listPanel.style.color = "gray"; | |
listPanel.style.zIndex = 10; | |
listPanel.style.right = "5px"; | |
var body = document.getElementsByTagName("body")[0] | |
body.insertBefore(listPanel, body.firstChild); | |
} | |
listPanel.innerHTML = "<p>There are reports!</p>"; | |
for (var i = 0; i < discsWithReports.length; i++) { | |
listPanel.appendChild(createDiscLink(discsWithReports[i])); | |
} | |
} | |
async function fetchDiscs() { | |
var currDisc, discsWithReports, currId; | |
let response = await fetch("https://discuit.net/api/_user"); | |
let data = await response.json(); | |
let moddingList = await data.moddingList; | |
discsWithReports = []; | |
for (var i = 0; i < moddingList.length; i++) { | |
// community API doesn't actually return report data; use API call from network log: | |
// https://discuit.net/api/communities/17b3658bdffc74c79d928aad/reports?filter=all&page=1&limit=10 | |
response = await fetch("https://discuit.net/api/communities?q=" + moddingList[i].name); | |
data = await response.json(); | |
data = await data[0]; | |
currDisc = data.name; | |
currId = data.id; | |
response = await fetch("https://discuit.net/api/communities/" + currId + "/reports?filter=all&page=1&limit=10"); | |
data = await response.json(); | |
if (data.reports) { | |
discsWithReports.push(currDisc); | |
} | |
} | |
return discsWithReports; | |
} | |
// check for reports every 60 seconds | |
setInterval( | |
async function () { | |
discsWithReports = await fetchDiscs(); | |
if (discsWithReports.length) { | |
showHammer(); | |
} else { | |
removeHammer(); | |
} | |
}, | |
60000 | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment