Discord Status Animator (Manual edit/Non-UI)

Automatically changes your Discord status

当前为 2021-06-17 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Discord Status Animator (Manual edit/Non-UI)
  3. // @namespace https://github.com/Hakorr/discord-status-animator
  4. // @run-at document-start
  5. // @version 1.7
  6. // @description Automatically changes your Discord status
  7. // @author HKR
  8. // @match https://discord.com/discovery
  9. // @match https://discord.com/discovery/*
  10. // @match https://discord.com/store
  11. // @match https://discord.com/store/*
  12. // @match https://discord.com/channels
  13. // @match https://discord.com/channels/*
  14. // @match https://discord.com/app
  15. // @grant none
  16. // ==/UserScript==
  17.  
  18. //Welcome! Don't be scared by the code, I was too lazy to do an UI for this.
  19. //Visit the Github for more more instructions! github.com/Hakorr/discord-status-animator
  20.  
  21. var name = "Status Animator";
  22. var version = "V1.7";
  23. var run = true;
  24.  
  25. //A Cookie will be made with this name, feel free to edit it
  26. //DO NOT SHARE THIS COOKIE WITH ANYONE AS IT'S YOUR DISCORD TOKEN
  27. var cookie_name = "DoNotShareThisToken";
  28. var delete_cookie_after_a_week = true;
  29.  
  30. //Your status will be changed to these after you close the Discord tab
  31. var default_status_text = "";
  32. var default_status_emoji = "";
  33. var default_status_state = "online";
  34.  
  35. async function statusanimation() {
  36. ////////////////////////////////////
  37. //This is your animation code///////
  38.  
  39. await blink("🥳","I'm using Discord Status Animator!",2000,1);
  40.  
  41. if(await skip(10,"unique")) return;
  42.  
  43. await settext("Get it here! Github.com/Hakorr/discord-status-animator");
  44. await wait(5000);
  45.  
  46. //Your animation code ends here/////
  47. ////////////////////////////////////
  48. }
  49.  
  50. /////////////////////////////////////
  51. /* ANIMATION BLOCKS /////////////////
  52. Timeouts are in milliseconds! You can type "random" on the emoji section to randomize it!
  53. - await wait(ms);
  54.  
  55. - await blank();
  56.  
  57. - await setstate("state");
  58. -> states = invisible, dnd, idle, online
  59. - await setemoji("emoji");
  60.  
  61. - await settext("text");
  62.  
  63. - await status(emoji,text,state);
  64. -> states = invisible, dnd, idle, online
  65. - await typewriter("emoji","text",timeout,reversed);
  66.  
  67. - await glitch("emoji","text",times,timeout);
  68.  
  69. - await glitchtype("emoji","text",timeout,glitch_rate,reversed);
  70.  
  71. - await sentence("emoji","text",timeout);
  72.  
  73. - await blink("emoji","text",timeout,times);
  74.  
  75. - await count("emoji","prefix",count_to,"suffix",timeout,reversed);
  76.  
  77. - if(await skip(1,"unique")) return;
  78. -> The unique string can be anything. If you use two skips, remember to make each one different.
  79. //Do not edit after this line (If you don't know what you're doing)
  80. /*///////////////////////////////////////////////////////////////*/
  81. ///////////////////////////////////////////////////////////////////
  82.  
  83. //Return a random emoji
  84. function random_emoji() {
  85.  
  86. var emojis = [
  87. '😄','😃','😀','😊','😉','😍','😘','😚','😗','😙','😜','😝','😛','😳','😁','😔','😌','😒','😞','😣','😢','😂','😭','😪','😥','😰','😅','😓','😩','😫','😨','😱','😠','😡','😤','😖','😆','😋','😷','😎','😴','😵','😲','😟','😦','😧','😈','👿','😮','😬','😐','😕','😯','😶','😇','😏','😑','👲','👳','👮','👷','💂','👶','👦','👧','👨','👩','👴','👵','👱','👼','👸','😺','😸','😻','😽','😼','🙀','😿','😹','😾','👹','👺','🙈','🙉','🙊','💀','👽','💩','🔥','✨','🌟','💫','💥','💢','💦','💧','💤','💨','👂','👀','👃','👅','👄','👍','👎','👌','👊','✊','✌','👋','✋','👐','👆','👇','👉','👈','🙌','🙏','☝','👏','💪','🚶','🏃','💃','👫','👪','👬','👭','💏','💑','👯','🙆','🙅','💁','🙋','💆','💇','💅','👰','🙎','🙍','🙇','🎩','👑','👒','👟','👞','👡','👠','👢','👕','👔','👚','👗','🎽','👖','👘','👙','💼','👜','👝','👛','👓','🎀','🌂','💄','💛','💙','💜','💚','❤','💔','💗','💓','💕','💖','💞','💘','💌','💋','💍','💎','👤','👥','💬','👣','💭','🐶','🐺','🐱','🐭','🐹','🐰','🐸','🐯','🐨','🐻','🐷','🐽','🐮','🐗','🐵','🐒','🐴','🐑','🐘','🐼','🐧','🐦','🐤','🐥','🐣','🐔','🐍','🐢','🐛','🐝','🐜','🐞','🐌','🐙','🐚','🐠','🐟','🐬','🐳','🐋','🐄','🐏','🐀','🐃','🐅','🐇','🐉','🐎','🐐','🐓','🐕','🐖','🐁','🐂','🐲','🐡','🐊','🐫','🐪','🐆','🐈','🐩','🐾','💐','🌸','🌷','🍀','🌹','🌻','🌺','🍁','🍃','🍂','🌿','🌾','🍄','🌵','🌴','🌲','🌳','🌰','🌱','🌼','🌐','🌞','🌝','🌚','🌑','🌒','🌓','🌔','🌕','🌖','🌗','🌘','🌜','🌛','🌙','🌍','🌎','🌏','🌋','🌌','🌠','⭐','☀','⛅','☁','⚡','☔','❄','⛄','🌀','🌁','🌈','🌊','🎍','💝','🎎','🎒','🎓','🎏','🎆','🎇','🎐','🎑','🎃','👻','🎅','🎄','🎁','🎋','🎉','🎊','🎈','🎌','🔮','🎥','📷','📹','📼','💿','📀','💽','💾','💻','📱','☎','📞','📟','📠','📡','📺','📻','🔊','🔉','🔈','🔇','🔔','🔕','📢','📣','⏳','⌛','⏰','⌚','🔓','🔒','🔏','🔐','🔑','🔎','💡','🔦','🔆','🔅','🔌','🔋','🔍','🛁','🛀','🚿','🚽','🔧','🔩','🔨','🚪','🚬','💣','🔫','🔪','💊','💉','💰','💴','💵','💷','💶','💳','💸','📲','📧','📥','📤','✉','📩','📨','📯','📫','📪','📬','📭','📮','📦','📝','📄','📃','📑','📊','📈','📉','📜','📋','📅','📆','📇','📁','📂','✂','📌','📎','✒','✏','📏','📐','📕','📗','📘','📙','📓','📔','📒','📚','📖','🔖','📛','🔬','🔭','📰','🎨','🎬','🎤','🎧','🎼','🎵','🎶','🎹','🎻','🎺','🎷','🎸','👾','🎮','🃏','🎴','🀄','🎲','🎯','🏈','🏀','⚽','⚾','🎾','🎱','🏉','🎳','⛳','🚵','🚴','🏁','🏇','🏆','🎿','🏂','🏊','🏄','🎣','☕','🍵','🍶','🍼','🍺','🍻','🍸','🍹','🍷','🍴','🍕','🍔','🍟','🍗','🍖','🍝','🍛','🍤','🍱','🍣','🍥','🍙','🍘','🍚','🍜','🍲','🍢','🍡','🍳','🍞','🍩','🍮','🍦','🍨','🍧','🎂','🍰','🍪','🍫','🍬','🍭','🍯','🍎','🍏','🍊','🍋','🍒','🍇','🍉','🍓','🍑','🍈','🍌','🍐','🍍','🍠','🍆','🍅','🌽','🏠','🏡','🏫','🏢','🏣','🏥','🏦','🏪','🏩','🏨','💒','⛪','🏬','🏤','🌇','🌆','🏯','🏰','⛺','🏭','🗼','🗾','🗻','🌄','🌅','🌃','🗽','🌉','🎠','🎡','⛲','🎢','🚢','⛵','🚤','🚣','⚓','🚀','✈','💺','🚁','🚂','🚊','🚉','🚞','🚆','🚄','🚅','🚈','🚇','🚝','🚋','🚃','🚎','🚌','🚍','🚙','🚘','🚗','🚕','🚖','🚛','🚚','🚨','🚓','🚔','🚒','🚑','🚐','🚲','🚡','🚟','🚠','🚜','💈','🚏','🎫','🚦','🚥','⚠','🚧','🔰','⛽','🏮','🎰','♨','🗿','🎪','🎭','📍','🚩','⬆','⬇','⬅','➡','🔠','🔡','🔤','↗','↖','↘','↙','↔','↕','🔄','◀','▶','🔼','🔽','↩','↪','ℹ','⏪','⏩','⏫','⏬','⤵','⤴','🆗','🔀','🔁','🔂','🆕','🆙','🆒','🆓','🆖','📶','🎦','🈁','🈯','🈳','🈵','🈴','🈲','🉐','🈹','🈺','🈶','🈚','🚻','🚹','🚺','🚼','🚾','🚰','🚮','🅿','♿','🚭','🈷','🈸','🈂','Ⓜ','🛂','🛄','🛅','🛃','🉑','㊙','㊗','🆑','🆘','🆔','🚫','🔞','📵','🚯','🚱','🚳','🚷','🚸','⛔','✳','❇','❎','✅','✴','💟','🆚','📳','📴','🅰','🅱','🆎','🅾','💠','➿','♻','♈','♉','♊','♋','♌','♍','♎','♏','♐','♑','♒','♓','⛎','🔯','🏧','💹','💲','💱','©','®','™','〽','〰','🔝','🔚','🔙','🔛','🔜','❌','⭕','❗','❓','❕','❔','🔃','🕛','🕧','🕐','🕜','🕑','🕝','🕒','🕞','🕓','🕟','🕔','🕠','🕕','🕖','🕗','🕘','🕙','🕚','🕡','🕢','🕣','🕤','🕥','🕦','✖','➕','➖','➗','♠','♥','♣','♦','💮','💯','✔','☑','🔘','🔗','➰','🔱','🔲','🔳','◼','◻','◾','◽','▪','▫','🔺','⬜','⬛','⚫','⚪','🔴','🔵','🔻','🔶','🔷','🔸','🔹'
  88. ];
  89.  
  90. return emojis[Math.floor(Math.random() * emojis.length)];
  91. }
  92.  
  93. //Part of user activity function
  94. var is_active = false;
  95. window.onfocus = function() { is_active = true; };
  96. window.onblur = function() { is_active = false; }
  97.  
  98. //Is user on the Discord tab - Return true or false
  99. function activity(positive,negative) {
  100. var return_value = "";
  101. if(is_active) return_value = positive;
  102. else return_value = negative;
  103. return return_value;
  104. }
  105.  
  106. //Output XX/XX/XX @ XX:XX:XX
  107. function getDateTime() {
  108. var currentdate = new Date();
  109.  
  110. if(currentdate.getMinutes() > 9) var fixed_minutes = currentdate.getMinutes();
  111. else var fixed_minutes = "0" + currentdate.getMinutes();
  112. if(currentdate.getSeconds() > 9) var fixed_seconds = currentdate.getSeconds();
  113. else var fixed_seconds = "0" + currentdate.getSeconds();
  114.  
  115. var datetime = currentdate.getDate() + "/" + (currentdate.getMonth()+1) + "/" + currentdate.getFullYear() + " @ " + currentdate.getHours() + ":" + fixed_minutes + ":" + fixed_seconds;
  116.  
  117. return datetime;
  118. }
  119.  
  120. //Output: XX:XX:XX
  121. function getExactTime() {
  122. var currentdate = new Date();
  123.  
  124. if(currentdate.getMinutes() > 9) var fixed_minutes = currentdate.getMinutes();
  125. else var fixed_minutes = "0" + currentdate.getMinutes();
  126. if(currentdate.getSeconds() > 9) var fixed_seconds = currentdate.getSeconds();
  127. else var fixed_seconds = "0" + currentdate.getSeconds();
  128.  
  129. var datetime = currentdate.getHours() + ":" + fixed_minutes + ":" + fixed_seconds;
  130.  
  131. return datetime;
  132. }
  133.  
  134. //Output: XX:XX
  135. function getTime() {
  136. var currentdate = new Date();
  137.  
  138. if(currentdate.getMinutes() > 9) var fixed_minutes = currentdate.getMinutes();
  139. else var fixed_minutes = "0" + currentdate.getMinutes();
  140.  
  141. var datetime = currentdate.getHours() + ":" + fixed_minutes;
  142.  
  143. return datetime;
  144. }
  145.  
  146. //Simple wait function for animation
  147. function wait(t) {
  148. return new Promise(function(resolve) {
  149. setTimeout(resolve, t)
  150. });
  151. }
  152.  
  153. //Typewriter effect
  154. async function typewriter(emoji,text,timeout,reversed) {
  155. //Repeat for each letter
  156. for(var i = 1; i <= text.length; i++) {
  157. //Cut the text
  158. if(!reversed) var substring_text = text.substring(0,i);
  159. else var substring_text = text.substring(0,text.length - i);
  160. //Set the status to the cutted text
  161. if(emoji != "random") await status(emoji,substring_text);
  162. else await status(random_emoji(),substring_text);
  163. //Wait a selected amount of time until writing the next letter
  164. await wait(timeout);
  165. }
  166.  
  167. return;
  168. }
  169.  
  170. //Glitch effect
  171. async function glitch(emoji,text,times,timeout) {
  172. //Repeat for each letter
  173. for(var i = 1; i < times; i++) {
  174. //Shuffle the text
  175. var glitch_text = shuffle(text)
  176. //Set the status to the cutted text
  177. if(emoji != "random") await status(emoji,glitch_text);
  178. else await status(random_emoji(),glitch_text);
  179. //Wait a selected amount of time until writing the next letter
  180. await wait(timeout);
  181. }
  182.  
  183. return;
  184. }
  185.  
  186. //Glitchtype effect
  187. async function glitchtype(emoji,text,timeout,glitch_rate,reversed) {
  188. //Repeat for each letter
  189. for(var i = 1; i <= text.length; i++) {
  190. //Cut the text
  191. if(!reversed) var substring_text = text.substring(0,i);
  192. else var substring_text = text.substring(0,text.length - i);
  193. //Glitch rest of the text
  194. if(!reversed) var glitch_text = shuffle(text.substring(i));
  195. else var glitch_text = shuffle(text.substring(text.length - i));
  196. //Set the status to the cutted text + glitched text
  197. if(emoji != "random") await status(emoji,substring_text + glitch_text);
  198. else await status(random_emoji(),substring_text + glitch_text);
  199. //Wait a selected amount of time until writing the next letter
  200. await wait(timeout);
  201. for(var a = 0; a < glitch_rate; a++) {
  202. //Glitch rest of the text
  203. if(!reversed) var glitch_text = shuffle(text.substring(i));
  204. else var glitch_text = shuffle(text.substring(text.length - i));
  205. //Set the status to the cutted text + glitched text
  206. await status(emoji,substring_text + glitch_text);
  207. //Wait a selected amount of time until writing the next glitched characterset at the end of the string
  208. await wait(timeout/2);
  209. }
  210. }
  211. return;
  212. }
  213.  
  214. //Sentence effect
  215. async function sentence(emoji,text,timeout) {
  216. //Split sentence into words
  217. var words = text.split(" ");
  218.  
  219. //Repeat for each word
  220. for(var i = 0; i < words.length; i++) {
  221. //Set status to array's word
  222. if(emoji != "random") await status(emoji,words[i]);
  223. else await status(random_emoji(),words[i]);
  224. //Wait a selected amount of time until writing the next letter
  225. await wait(timeout);
  226. }
  227. return;
  228. }
  229.  
  230. //Blink effect
  231. async function blink(emoji,text,timeout,times) {
  232. for(var i = 0; i < times; i++) {
  233. if(emoji != "random") await status(emoji,text);
  234. else await status(random_emoji(),text);
  235. await wait(timeout);
  236. await blank();
  237. await wait(timeout);
  238. }
  239.  
  240. return;
  241. }
  242.  
  243. //Clear the status
  244. async function blank() {
  245. //Could just send blank status as {"custom_status":null}, but that behaves weirdly.
  246. await status("","");
  247.  
  248. return;
  249. }
  250.  
  251.  
  252. //Part of the skip function - stackoverflow.com/a/8630472
  253. var store = (function() {
  254. var map = {};
  255.  
  256. return {
  257. set: function ( name, value ) {
  258. map[ name ] = value;
  259. },
  260. get: function ( name ) {
  261. return map[ name ];
  262. }
  263. };
  264. })();
  265.  
  266. //Skip the end of the animation
  267. async function skip(amount,uniquetext) {
  268. var uniqueID = amount + "_" + uniquetext;
  269.  
  270. var set = store.set;
  271. var get = store.get;
  272. var currentamount = get(uniqueID);
  273.  
  274. //Check if there's a variable already
  275. if(currentamount >= 0) {
  276. //If to continue
  277. if(currentamount == amount) {
  278. //Reset the variable
  279. set(uniqueID,0);
  280. //Update the currentamount variable
  281. currentamount = get(uniqueID);
  282. //console.log("id: " + uniqueID + "\n\n value: " + get(uniqueID) + " | result: false\n\n");
  283. return false;
  284. }
  285. //Skip
  286. else {
  287. //Add one to the variable
  288. set(uniqueID,get(uniqueID) + 1);
  289. //Update the currentamount variable
  290. currentamount = get(uniqueID);
  291. //console.log("id: " + uniqueID + "\n\n value: " + get(uniqueID) + " | result: true\n\n");
  292. return true;
  293. }
  294. //If there was no variable made already
  295. } else {
  296. //Make the variable
  297. set(uniqueID,0);
  298. //Add one to it
  299. set(uniqueID,get(uniqueID) + 1);
  300. //Update the currentamount variable
  301. currentamount = get(uniqueID);
  302. //console.log("(FIRST TIME) " + "id: " + uniqueID + "\n\n value: " + get(uniqueID) + " | result: true\n\n");
  303. return true;
  304. }
  305. }
  306.  
  307. //Count effect
  308. async function count(emoji,prefix,count_to,suffix,timeout,reversed) {
  309. for(var i = 0; i < count_to; i++) {
  310. if(!reversed) {
  311. var recalculated_count = i + 1;
  312. var final_string = prefix + recalculated_count + suffix;
  313. }
  314. else {
  315. var recalculated_count = count_to - i;
  316. var final_string = prefix + recalculated_count + suffix;
  317. }
  318. if(emoji != "random") await status(emoji,final_string);
  319. else await status(random_emoji(),final_string);
  320. await wait(timeout);
  321. }
  322. return;
  323. }
  324.  
  325. //Generate random number between min and max
  326. function random_number(min,max) {
  327. return Math.floor(Math.random() * (max - min + 1)) + min;
  328. }
  329.  
  330. //codespeedy.com/shuffle-characters-of-a-string-in-javascript/
  331. function getRandomInt(n) {
  332. return Math.floor(Math.random() * n);
  333. }
  334.  
  335. //codespeedy.com/shuffle-characters-of-a-string-in-javascript/
  336. function shuffle(s) {
  337. var arr = s.split(''); // Convert String to array
  338. var n = arr.length; // Length of the array
  339.  
  340. for(var i=0 ; i<n-1 ; ++i) {
  341. var j = getRandomInt(n); // Get random of [0, n-1]
  342.  
  343. var temp = arr[i]; // Swap arr[i] and arr[j]
  344. arr[i] = arr[j];
  345. arr[j] = temp;
  346. }
  347.  
  348. s = arr.join(''); // Convert Array to string
  349. return s; // Return shuffled string
  350. }
  351.  
  352. //Function to read the saved cookie
  353. window.getCookie = function(name) {
  354. var match = document.cookie.match(new RegExp('(^| )' + name + '=([^;]+)'));
  355. if (match) return match[2];
  356. }
  357.  
  358. //Set the Discord Token as a Cookie for future use of the script
  359. //If there is no Token cookie
  360. if(document.cookie.indexOf(cookie_name + "=") == -1) {
  361. //Ask user if they want to refresh the page to get the token
  362. if(confirm("\"" + cookie_name + "\" cookie not found. Refreshing Discord to get it.\n\n- " + name + " " + version)) {
  363. //Load the page again and create a new element which will have the token in its localStorage
  364. location.reload();
  365. var i = document.createElement('iframe');
  366. document.body.appendChild(i);
  367. //Get Token from localStorage
  368. var token = i.contentWindow.localStorage.token
  369. token = token.slice(1, -1);
  370. //Delete cookie after a week or not
  371. if(delete_cookie_after_a_week)
  372. document.cookie = cookie_name + "=" + token + "; secure=true; max-age=604800; path=/";
  373. else
  374. document.cookie = cookie_name + "=" + token + "; secure=true; path=/";
  375.  
  376. } else throw new Error("[Not an actually uncaught] User stopped the Status Animator. \n\nNo cookie was found and user decided not to continue.");
  377. }
  378.  
  379. var status_text = "";
  380. var status_emoji = "";
  381. var status_state = "";
  382. //Function that changes the status variables (Saves up a bit space)
  383. async function status(emoji,text,state) {
  384. if(run) {
  385. status_text = text;
  386. status_emoji = emoji;
  387. status_state = state;
  388. await setstatus();
  389. return;
  390. }
  391. }
  392.  
  393. //Get Discord Token from saved Cookie
  394. var token = getCookie(cookie_name);
  395.  
  396. //HTTP Request's URL address
  397. var url = "https://discord.com/api/v9/users/@me/settings";
  398.  
  399. //Function that handles the HTTP request for the status change
  400. async function setstatus() {
  401.  
  402. var request = new XMLHttpRequest();
  403. request.open("PATCH", url);
  404. request.setRequestHeader("Accept", "*/*" );
  405. request.setRequestHeader("Content-Type", "application/json");
  406. request.setRequestHeader("Authorization", token);
  407. request.send(JSON.stringify({"custom_status":{"text":status_text,"emoji_name":status_emoji}}));
  408.  
  409. //If the request failed
  410. request.onreadystatechange = () => {
  411. if (request.status != 200) {
  412. run = false;
  413. throw new Error("[Not an actually uncaught] Failed to update status. \n\nThe HTTP request failed. Most likely because the authorization token is incorrect.");
  414. }
  415. };
  416.  
  417. if(status_state == "invisible" || status_state == "dnd" || status_state == "idle" || status_state == "online") {
  418. var request2 = new XMLHttpRequest();
  419. request2.open("PATCH", url);
  420. request2.setRequestHeader("Accept", "*/*" );
  421. request2.setRequestHeader("Content-Type", "application/json");
  422. request2.setRequestHeader("Authorization", token);
  423. request2.send(JSON.stringify({"status":status_state}));
  424. //If the request failed
  425. request2.onreadystatechange = () => {
  426. if (request2.status != 200) {
  427. run = false;
  428. throw new Error("[Not an actually uncaught] Failed to update status. \n\nThe HTTP request failed. Most likely because the authorization token is incorrect.");
  429. }
  430. };
  431. }
  432.  
  433. return;
  434. }
  435.  
  436. async function setstate(text) {
  437. if(run) {
  438. status_state = text;
  439. if(status_state == "invisible" || status_state == "dnd" || status_state == "idle" || status_state == "online") {
  440. var request = new XMLHttpRequest();
  441. request.open("PATCH", url);
  442. request.setRequestHeader("Accept", "*/*" );
  443. request.setRequestHeader("Content-Type", "application/json");
  444. request.setRequestHeader("Authorization", token);
  445. request.send(JSON.stringify({"status":status_state}));
  446. //If the request failed
  447. request.onreadystatechange = () => {
  448. if (request.status != 200) {
  449. run = false;
  450. throw new Error("[Not an actually uncaught] Failed to update state. \n\nThe HTTP request failed. Most likely because the authorization token is incorrect.");
  451. }
  452. };
  453. }
  454.  
  455. return;
  456. }
  457. }
  458.  
  459. async function setemoji(emoji) {
  460. if(run) {
  461. status_emoji = emoji;
  462. var request = new XMLHttpRequest();
  463. request.open("PATCH", url);
  464. request.setRequestHeader("Accept", "*/*" );
  465. request.setRequestHeader("Content-Type", "application/json");
  466. request.setRequestHeader("Authorization", token);
  467. request.send(JSON.stringify({"custom_status":{"emoji_name":status_emoji}}));
  468.  
  469. //If the request failed
  470. request.onreadystatechange = () => {
  471. if (request.status != 200) {
  472. run = false;
  473. throw new Error("[Not an actually uncaught] Failed to update emoji. \n\nThe HTTP request failed. Most likely because the authorization token is incorrect.");
  474. }
  475. };
  476.  
  477. return;
  478. }
  479. }
  480.  
  481. async function settext(text) {
  482. if(run) {
  483. status_text = text;
  484. var request = new XMLHttpRequest();
  485. request.open("PATCH", url);
  486. request.setRequestHeader("Accept", "*/*" );
  487. request.setRequestHeader("Content-Type", "application/json");
  488. request.setRequestHeader("Authorization", token);
  489. request.send(JSON.stringify({"custom_status":{"text":status_text}}));
  490.  
  491. //If the request failed
  492. request.onreadystatechange = () => {
  493. if (request.status != 200) {
  494. run = false;
  495. throw new Error("[Not an actually uncaught] Failed to update text. \n\nThe HTTP request failed. Most likely because the authorization token is incorrect.");
  496. }
  497. };
  498.  
  499. return;
  500. }
  501. }
  502.  
  503. //Loops the animation
  504. async function animation_loop() {
  505. while(run) {
  506. await statusanimation();
  507. }
  508. }
  509.  
  510. //Start the animation loop
  511. animation_loop();
  512.  
  513. //Edit/Clear status before exiting
  514. window.onbeforeunload = function () {
  515. run = false;
  516.  
  517. status_text = default_status_text;
  518. status_emoji = default_status_emoji;
  519.  
  520. if(status_state == "invisible" || status_state == "dnd" || status_state == "idle" || status_state == "online")
  521. status_state = default_status_state;
  522.  
  523. setstatus();
  524.  
  525. return "";
  526. };