[Discord] Status Animator (Manual edit/Non-UI)

Automatically changes your Discord status

当前为 2021-07-22 提交的版本,查看 最新版本

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