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

fix: should now inject interaction buttons properly on post detail page #87

Merged
merged 7 commits into from
Dec 13, 2022
32 changes: 19 additions & 13 deletions src/content_script/mastodonInject.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,20 +129,26 @@ async function injectInteractionButtons() {
async function init() {
injectFollowButton();

const observer = new MutationObserver(() => {
Promise.allSettled([
injectInteractionButtons(),
]);
});
const ogType = document.querySelector("meta[property='og:type']");

const feedElement = await waitForElement(
"#mastodon .item-list[role='feed']",
hueyy marked this conversation as resolved.
Show resolved Hide resolved
false,
TIMEOUT_DURATION
);
observer.observe(feedElement, {
childList: true, subtree: true,
});
if (ogType && ogType.getAttribute("content") === "article"){
hueyy marked this conversation as resolved.
Show resolved Hide resolved
injectInteractionButtons();
} else {
hueyy marked this conversation as resolved.
Show resolved Hide resolved
const observer = new MutationObserver(() => {
Promise.allSettled([
hueyy marked this conversation as resolved.
Show resolved Hide resolved
injectInteractionButtons(),
]);
});

const feedElement = await waitForElement(
"#mastodon .item-list[role='feed']",
false,
TIMEOUT_DURATION
);
observer.observe(feedElement, {
hueyy marked this conversation as resolved.
Show resolved Hide resolved
childList: true, subtree: true,
});
}
}

init();