Merge pull request #102 from austinhuang0131/patch-1

Improve Mastodon support
This commit is contained in:
rugk 2023-06-20 16:21:12 +02:00 committed by GitHub
commit 6750e346cd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -23,7 +23,7 @@ function onClickFollow(event) {
function onClickInteract(event) {
event.stopPropagation();
event.preventDefault();
const articleElement = event.target.closest(".status.status-public[data-id]");
const articleElement = event.target.closest(".status.status-public[data-id], .status.status-unlisted[data-id]");
const getId = () => {
const rawId = articleElement.getAttribute("data-id");
return rawId.slice(0, 2) === "f-" ? rawId.slice(2) : rawId;
@ -84,6 +84,21 @@ function waitForElement(selector, multiple = false, timeoutDuration = 200000) {
});
}
/**
* Checks whether the user has logged into the instance.
*
* @returns {boolean}
*/
async function isLoggedIn() {
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,13 @@ async function injectInteractionButtons() {
* @returns {void}
*/
function initInjections() {
injectFollowButton().catch(console.error);
injectInteractionButtons().catch(console.error);
isLoggedIn().then((isLoggedIn) => {
if (isLoggedIn) {
return;
}
injectFollowButton().catch(console.error);
injectInteractionButtons().catch(console.error);
});
}
/**