Merge pull request #102 from austinhuang0131/patch-1
Improve Mastodon support
This commit is contained in:
commit
6750e346cd
1 changed files with 23 additions and 3 deletions
|
@ -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() {
|
||||
isLoggedIn().then((isLoggedIn) => {
|
||||
if (isLoggedIn) {
|
||||
return;
|
||||
}
|
||||
injectFollowButton().catch(console.error);
|
||||
injectInteractionButtons().catch(console.error);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue