Skip to content

Instantly share code, notes, and snippets.

@rebane2001
Last active July 23, 2023 17:23
Show Gist options
  • Save rebane2001/9d3ef70ccb267e12e2b393c85f5bf96b to your computer and use it in GitHub Desktop.
Save rebane2001/9d3ef70ccb267e12e2b393c85f5bf96b to your computer and use it in GitHub Desktop.
Admin Pixel Notification
// ==UserScript==
// @name Admin Pixel Notification
// @namespace rebane
// @match https://garlic-bread.reddit.com/embed*
// @version 1.1
// @author Rebane
// ==/UserScript==
// Hook into the fetch function
const origFetch = window.fetch;
window.fetch = async (...args) => {
if (args?.[0]?.includes("/query") && args?.[1]?.body?.includes("pixelHistory")) {
const result = await origFetch(...args);
try {
const coords = JSON.parse(args[1].body).variables.input.PixelMessageData.coordinate;
const data = await (await result.clone()).json();
const subData = data.data.act.data[0].data;
const userInfo = subData.userInfo;
if (userInfo?.username?.length && !userInfo?.userID?.length) {
const secondsAgo = Math.floor((Date.now() - subData.lastModifiedTimestamp)/1000);
const displaySeconds = secondsAgo % 60;
const displayMinutes = Math.floor(secondsAgo / 60);
const timeString = `${displayMinutes ? displayMinutes + 'm ' : ''}${displaySeconds}s ago`
adminToast(`Admin pixel detected at (${coords.x}, ${coords.y}) by /u/${userInfo.username} (${timeString})`);
}
} catch (e) {
console.error(e);
}
return result;
}
return await origFetch(...args);
}
// Show a toast message and play a sound
function adminToast(message) {
document.querySelectorAll(".adminToast").forEach(e => e.remove());
const toast = document.createElement('div');
toast.classList.add("adminToast");
toast.style.position = "absolute";
toast.style.width = "fit-content";
toast.style.height = "24px";
toast.style.zIndex = "999";
toast.style.backgroundColor = "#FDD";
toast.style.color = "black";
toast.style.top = "16px";
toast.style.left = "16px";
toast.style.padding = "8px"
toast.style.border = "3px solid red";
toast.style.opacity = "0";
toast.style.transition = "opacity 0.5s";
toast.innerText = message;
document.body.appendChild(toast);
const toastLength = 5000;
setTimeout(() => toast.style.opacity = "1", 1);
setTimeout(() => toast.style.opacity = "0", toastLength - 500);
setTimeout(() => toast.remove(), toastLength);
const a = new Audio("https://garlic-bread.reddit.com/media/interactions/highlight.mp3");
a.preservesPitch = false;
a.playbackRate = 0.2;
a.play();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment