Greasy Fork 还支持 简体中文。

Discord Status Animator (Manual edit/Non-UI)

Automatically changes your Discord status

目前為 2021-06-19 提交的版本,檢視 最新版本

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