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

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址