Discord Status Animator (Manual edit/Non-UI)

Automatically changes your Discord status

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

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