From 755dbc2909c61bcfc1306051f08e74b17bb86111 Mon Sep 17 00:00:00 2001 From: Austin Huang Date: Sat, 18 Mar 2023 16:17:33 -0400 Subject: [PATCH 1/3] Mastodon: allow interacting on unlisted posts --- src/content_script/mastodonInject.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/content_script/mastodonInject.js b/src/content_script/mastodonInject.js index 6f2dee7..0d05fe0 100644 --- a/src/content_script/mastodonInject.js +++ b/src/content_script/mastodonInject.js @@ -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; From 587625577e2a078bf0ce4bfae9d96abfb99368e2 Mon Sep 17 00:00:00 2001 From: Austin Huang Date: Sat, 18 Mar 2023 16:18:48 -0400 Subject: [PATCH 2/3] Mastodon: don't redirect on logged-in instances Close #92 --- src/content_script/mastodonInject.js | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/src/content_script/mastodonInject.js b/src/content_script/mastodonInject.js index 0d05fe0..594d931 100644 --- a/src/content_script/mastodonInject.js +++ b/src/content_script/mastodonInject.js @@ -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() { + 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,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); + } + }); } /** From bb4ac0c74cde546339fe03483072e18e6100fd9e Mon Sep 17 00:00:00 2001 From: Austin Huang Date: Sun, 19 Mar 2023 10:44:02 -0400 Subject: [PATCH 3/3] Implement #102 suggestions --- src/content_script/mastodonInject.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/content_script/mastodonInject.js b/src/content_script/mastodonInject.js index 594d931..961d069 100644 --- a/src/content_script/mastodonInject.js +++ b/src/content_script/mastodonInject.js @@ -89,7 +89,7 @@ function waitForElement(selector, multiple = false, timeoutDuration = 200000) { * * @returns {boolean} */ -async function checkLoggedIn() { +async function isLoggedIn() { try { const initialState = await waitForElement("#initial-state", false); return JSON.parse(initialState.textContent).meta.access_token != null; @@ -152,11 +152,12 @@ async function injectInteractionButtons() { * @returns {void} */ function initInjections() { - checkLoggedIn().then((r) => { - if (!r) { - injectFollowButton().catch(console.error); - injectInteractionButtons().catch(console.error); + isLoggedIn().then((isLoggedIn) => { + if (isLoggedIn) { + return; } + injectFollowButton().catch(console.error); + injectInteractionButtons().catch(console.error); }); }