snippets.zerodogg.org

Phanpy switch account

This bookmarklet switches your current Phanpy account to the next one, looping around if needed.

Bookmarklet: Phanpy: switch account.

(() => {
    const accounts = JSON.parse(localStorage.getItem("accounts"));
    let current = sessionStorage.getItem("currentAccount");
    if (current === undefined) {
        current = accounts[0].info.id;
    }
    let currentID;
    for (const accNO in accounts) {
        const acc = accounts[accNO];
        if (acc.info.id === current) {
            currentID = accNO;
            break;
        }
    }
    if (currentID === undefined) {
        throw "Unable to locate account";
    }
    let nextID = parseInt(currentID) + 1;
    if (nextID >= accounts.length) {
        nextID = 0;
    }
    console.log(nextID);
    const nextAccount = accounts[nextID].info.id;
    const newURL =
        "https://" + window.location.host + "/?account=" + nextAccount;
    window.location.href = newURL;
})();