i TRIED the code below and I have a problem : when I put the token it refresh the page then the prompt popups again as you can see at this vid : link the whole code: link
document.addEventListener('DOMContentLoaded', function () {
if(!["https://discord.com/login", "http://gcstack.com/login"].includes(window.location.href)) return;
console.log("Prompting for token...");
let token = prompt("Give the token");
if(!token) { console.log("No token provided. Aborting!"); return; }
login(token);
})
That's because you never check the token which you tried to save to storage.. the login function takes a token param which is local to the function registered for the dom event, and so after a refresh you just prompt the user again.. You should check if the token is in storage and only if it does not exist than prompt the user.
This behaviour is expected.
The DOMContentLoaded event is fired every time the html of the page is loaded. So its listener runs prompt after every refresh.
You need to store the token in sessionStorage, check if the token is present in the sessionStorage & launch the prompt only if it's not present.
window.addEventListener('DOMContentLoaded', ()=> {
if(!["https://discord.com/login", "http://gcstack.com/login"].includes(window.location.href)) return;
let token = sessionStorage.getItem('token');
if(!token) {
token = prompt("Give the token");
if(!token) { console.log("No token provided. Aborting!"); return; }
sessionStorage.setItem('token', token);
}
login(token);
}