Created
December 31, 2024 09:23
-
-
Save VenenJean/32449063c61e4bfc195dfc39c5827585 to your computer and use it in GitHub Desktop.
A simple JS script that can be pasted in the Discord web page which will change your status based on the window.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function ChangeStatus(status) { | |
| const jsonData = { | |
| "status": status | |
| }; | |
| fetch("https://discord.com/api/v10/users/@me/settings", { | |
| method: 'PATCH', | |
| headers: { | |
| 'Authorization': "MTEzNDU4NDk3NTc0OTA0MjM1OA.GQW9bM.LA_eT1tz3MSJqLraT755JAyCmPNAGGZv2xLJP4", | |
| 'Content-Type': 'application/json' | |
| }, | |
| body: JSON.stringify(jsonData) | |
| }) | |
| .then(response => { | |
| if (!response.ok) { | |
| throw new Error('Network response was not ok'); | |
| } | |
| return response.json(); | |
| }) | |
| .then(data => { | |
| console.log(data); | |
| }) | |
| .catch(error => { | |
| console.error('There was a problem with the fetch operation:', error); | |
| }); | |
| } | |
| window.addEventListener('focus', function() { | |
| ChangeStatus("online"); | |
| }); | |
| window.addEventListener('blur', function() { | |
| ChangeStatus("idle"); | |
| }); | |
| window.addEventListener('beforeunload', function (e) { | |
| clearInterval(intervalId); | |
| ChangeStatus("invisible"); | |
| }); | |
| window.addEventListener('load', function () { | |
| ChangeStatus('online'); | |
| }); | |
| // ## Little Discord Status Script | |
| // I am really amazed how easy it was to write a status updating script for Discord in JS. | |
| // ||Where I never coded in JS, just speed-ran through w3schools.com/js and never used it since then for a 1(or2?)|| | |
| // Functionality: | |
| // - Opened Discord: | |
| // => App focused: Online | |
| // => Unfocused: Idle | |
| // - Closed Discord: Offline / Invisible |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment