您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
Automatically changes your Discord status
当前为
- // ==UserScript==
- // @name Discord Status Animator (Manual edit/Non-UI)
- // @namespace https://github.com/Hakorr/status-animator
- // @run-at document-start
- // @version 1.0
- // @description Automatically changes your Discord status
- // @author HKR
- // @match https://discord.com/*
- // @grant none
- // ==/UserScript==
- (function() {
- //Welcome! Don't be scared by the code, I was too lazy to do an UI for this.
- //All you have to edit is the statusanimation function's code (Around the line 40)
- var name = "Status Animator";
- var version = "V1.0";
- var run = true;
- //A Cookie will be made with this name, feel free to edit it
- var cookie_name = "StatusToken";
- var delete_cookie_after_a_week = true;
- //Your status will be changed to these after you close the Discord tab
- var default_status_text = "";
- var default_status_emoji = "";
- //Animation blocks////////////////
- /*
- 1. status(emoji,text);
- 2. await delay(ms);
- */async function statusanimation() {
- ////////////////////////////////////
- status("👐","This");
- await delay(500);
- status("👀","Is");
- await delay(500);
- status("😶","A");
- await delay(500);
- status("✨","Test");
- await delay(500);
- status("","");
- await delay(2000);
- /////////////////////////////
- if (run) statusanimation(); }
- //Do not edit after this line (If you don't know what you're doing)
- ///////////////////////////////////////////////////////////////////
- //Function to read the saved cookie
- window.getCookie = function(name) {
- var match = document.cookie.match(new RegExp('(^| )' + name + '=([^;]+)'));
- if (match) return match[2];
- }
- //Set the Discord Token as a Cookie for future use of the script
- if(document.cookie.indexOf(cookie_name + "=") == -1) {
- if(confirm("\"" + cookie_name + "\" cookie not found. Refreshing Discord to get it.\n\n- " + name + version)) {
- location.reload();
- var i = document.createElement('iframe');
- document.body.appendChild(i);
- //Get Token from localStorage
- var token = i.contentWindow.localStorage.token
- token = token.slice(1, -1);
- if(delete_cookie_after_a_week) {
- //Save the encrypted Token to a Cookie - The cookie will be deleted after a week
- document.cookie = cookie_name + "=" + token + "; secure=true; max-age=604800; path=/";
- } else {
- document.cookie = cookie_name + "=" + token + "; secure=true; path=/";
- }
- } else { throw new Error("[Not an actually uncaught] User stopped the Status Animator. \n\nNo cookie was found and user decided not to continue."); }
- }
- var status_text = "";
- var status_emoji = "";
- //Function that changes the status variables (Saves up a bit space)
- function status(emoji,text) {
- if(run) {
- status_text = text;
- status_emoji = emoji;
- setstatus();
- }
- }
- //Get Discord Token from saved Cookie
- var token = getCookie(cookie_name);
- //HTTP Request's URL address
- var url = "https://discord.com/api/v9/users/@me/settings";
- //Function that handles the HTTP request for the status change
- function setstatus() {
- //Set up a HTTP request to change the status
- var request = new XMLHttpRequest();
- request.open("PATCH", url);
- request.setRequestHeader("Accept", "*/*" );
- request.setRequestHeader("Content-Type", "application/json");
- request.setRequestHeader("Authorization", token);
- //Send the HTTP request to change the status
- request.send(JSON.stringify({"custom_status":{"text":status_text,"emoji_name":status_emoji}}));
- //If request failed
- request.onreadystatechange = () => {
- if (request.status != 200) {
- run = false;
- throw new Error("[Not an actually uncaught] Failed to update status. \n\nThe HTTP request failed. Most likely because the authorization token is incorrect.");
- }
- };
- }
- //Simple delay function for animation
- function delay(t) {
- return new Promise(function(resolve) {
- setTimeout(resolve, t)
- });
- }
- //Start the animation for the first time
- if (run) statusanimation();
- //Edit (Clear by default) status before exiting
- window.onbeforeunload = function () {
- run = false;
- status_text = default_status_text;
- status_emoji = default_status_emoji;
- setstatus();
- return "";
- };
- })();