Mastodon: don't redirect on logged-in instances

Close #92
This commit is contained in:
Austin Huang 2023-03-18 16:18:48 -04:00
parent 755dbc2909
commit 587625577e
No known key found for this signature in database
GPG key ID: 84C23AA04587A91F

View file

@ -84,6 +84,21 @@ function waitForElement(selector, multiple = false, timeoutDuration = 200000) {
});
}
/**
* Checks whether the user has logged into the instance.
*
* @returns {boolean}
*/
async function checkLoggedIn() {
try {
const initialState = await waitForElement("#initial-state", false);
return JSON.parse(initialState.textContent).meta.access_token != null;
} catch(error) {
// cannot fetch login status
return false;
}
}
/**
* Inject replacement onClick handler for Follow button.
*
@ -137,8 +152,12 @@ async function injectInteractionButtons() {
* @returns {void}
*/
function initInjections() {
injectFollowButton().catch(console.error);
injectInteractionButtons().catch(console.error);
checkLoggedIn().then((r) => {
if (!r) {
injectFollowButton().catch(console.error);
injectInteractionButtons().catch(console.error);
}
});
}
/**