Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve Mastodon support #102

Merged
merged 3 commits into from
Jun 20, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions src/content_script/mastodonInject.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
austinhuang0131 marked this conversation as resolved.
Show resolved Hide resolved
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.
*
Expand Down Expand Up @@ -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);
}
});
austinhuang0131 marked this conversation as resolved.
Show resolved Hide resolved
}

/**
Expand Down