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) {
|
function onClickInteract(event) {
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
event.preventDefault();
|
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 getId = () => {
|
||||||
const rawId = articleElement.getAttribute("data-id");
|
const rawId = articleElement.getAttribute("data-id");
|
||||||
return rawId.slice(0, 2) === "f-" ? rawId.slice(2) : rawId;
|
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.
|
* Inject replacement onClick handler for Follow button.
|
||||||
*
|
*
|
||||||
|
@ -137,8 +152,13 @@ async function injectInteractionButtons() {
|
||||||
* @returns {void}
|
* @returns {void}
|
||||||
*/
|
*/
|
||||||
function initInjections() {
|
function initInjections() {
|
||||||
injectFollowButton().catch(console.error);
|
isLoggedIn().then((isLoggedIn) => {
|
||||||
injectInteractionButtons().catch(console.error);
|
if (isLoggedIn) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
injectFollowButton().catch(console.error);
|
||||||
|
injectInteractionButtons().catch(console.error);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue