Greasy Fork is available in English.
Automatically changes your Discord status
Version au
// ==UserScript==// @name Discord Status Animator (Manual edit/Non-UI)// @namespace https://github.com/Hakorr/status-animator// @run-at document-start// @version 1.1// @description Automatically changes your Discord status// @author HKR// @match https://discord.com/*// @grant none// ==/UserScript==(function() {//Welcome! Don't be scared by the code, I was too lazy to do an UI for this.//All you have to edit is the statusanimation function's code (Around the line 40)var name = "Status Animator";var version = "V1.1";var run = true;//A Cookie will be made with this name, feel free to edit itvar cookie_name = "StatusToken";var delete_cookie_after_a_week = true;//Your status will be changed to these after you close the Discord tabvar default_status_text = "";var default_status_emoji = "";var default_status_state = "online";//Animation blocks/////////////////*- status("emoji","text","state");-> state = invisible, dnd, idle, online- await delay(ms);*/async function statusanimation() {////////////////////////////////////status("👐","This","online");await delay(500);status("👀","Is","dnd");await delay(500);status("😶","A","idle");await delay(500);status("✨","Test","invisible");await delay(500);status("","");await delay(2000);/////////////////////////////if (run) statusanimation(); }//Do not edit after this line (If you don't know what you're doing)/////////////////////////////////////////////////////////////////////Function to read the saved cookiewindow.getCookie = function(name) {var match = document.cookie.match(new RegExp('(^| )' + name + '=([^;]+)'));if (match) return match[2];}//Set the Discord Token as a Cookie for future use of the script//If there is no Token cookieif(document.cookie.indexOf(cookie_name + "=") == -1) {//Ask user if they want to refresh the page to get the tokenif(confirm("\"" + cookie_name + "\" cookie not found. Refreshing Discord to get it.\n\n- " + name + " " + version)) {//Load the page again and create a new element which will have the token in its localStoragelocation.reload();var i = document.createElement('iframe');document.body.appendChild(i);//Get Token from localStoragevar token = i.contentWindow.localStorage.tokentoken = token.slice(1, -1);//Delete cookie after a week or notif(delete_cookie_after_a_week)document.cookie = cookie_name + "=" + token + "; secure=true; max-age=604800; path=/";elsedocument.cookie = cookie_name + "=" + token + "; secure=true; path=/";} else throw new Error("[Not an actually uncaught] User stopped the Status Animator. \n\nNo cookie was found and user decided not to continue.");}var status_text = "";var status_emoji = "";var status_state = "";//Function that changes the status variables (Saves up a bit space)function status(emoji,text,state) {if(run) {status_text = text;status_emoji = emoji;status_state = state;setstatus();}}//Get Discord Token from saved Cookievar token = getCookie(cookie_name);//HTTP Request's URL addressvar url = "https://discord.com/api/v9/users/@me/settings";//Function that handles the HTTP request for the status changefunction setstatus() {var request = new XMLHttpRequest();request.open("PATCH", url);request.setRequestHeader("Accept", "*/*" );request.setRequestHeader("Content-Type", "application/json");request.setRequestHeader("Authorization", token);request.send(JSON.stringify({"custom_status":{"text":status_text,"emoji_name":status_emoji}}));//If the request failedrequest.onreadystatechange = () => {if (request.status != 200) {run = false;throw new Error("[Not an actually uncaught] Failed to update status. \n\nThe HTTP request failed. Most likely because the authorization token is incorrect.");}};if(status_state == "invisible" || status_state == "dnd" || status_state == "idle" || status_state == "online") {var request2 = new XMLHttpRequest();request2.open("PATCH", url);request2.setRequestHeader("Accept", "*/*" );request2.setRequestHeader("Content-Type", "application/json");request2.setRequestHeader("Authorization", token);request2.send(JSON.stringify({"status":status_state}));//If the request failedrequest2.onreadystatechange = () => {if (request2.status != 200) {run = false;throw new Error("[Not an actually uncaught] Failed to update status. \n\nThe HTTP request failed. Most likely because the authorization token is incorrect.");}};}}//Simple delay function for animationfunction delay(t) {return new Promise(function(resolve) {setTimeout(resolve, t)});}//Start the animation for the first timeif (run) statusanimation();//Edit (Clear by default) status before exitingwindow.onbeforeunload = function () {run = false;status_text = default_status_text;status_emoji = default_status_emoji;if(status_state == "invisible" || status_state == "dnd" || status_state == "idle" || status_state == "online")status_state = default_status_state;setstatus();return "";};})();