From a594e53d716df51ceb116bb76d8f6d19e9d00d12 Mon Sep 17 00:00:00 2001 From: Huey Date: Tue, 22 Nov 2022 10:34:23 +0800 Subject: [PATCH] address comments --- .eslintrc | 3 ++ src/background/modules/AutoRemoteFollow.js | 2 +- src/content_script/mastodonInject.js | 33 +++++++++++----------- 3 files changed, 20 insertions(+), 18 deletions(-) diff --git a/.eslintrc b/.eslintrc index a8d62a3..fb88267 100644 --- a/.eslintrc +++ b/.eslintrc @@ -24,6 +24,9 @@ "allowTemplateLiterals": false }], "brace-style": 2, + "keyword-spacing": ["error", { + "after": true + }], // just to make sure (are defaults) "indent": ["error", 4], diff --git a/src/background/modules/AutoRemoteFollow.js b/src/background/modules/AutoRemoteFollow.js index 1cd8e7b..efba3bf 100644 --- a/src/background/modules/AutoRemoteFollow.js +++ b/src/background/modules/AutoRemoteFollow.js @@ -154,7 +154,7 @@ function getInteractionType(url) { async function onTabUpdate(tabId, changeInfo) { const ownMastodon = await AddonSettings.get("ownMastodon"); const currentURL = new URL(changeInfo.url); - if(ownMastodon.server !== currentURL.hostname){ + if (ownMastodon.server !== currentURL.hostname){ browser.tabs.executeScript({ file: "/content_script/mastodonInject.js" }); diff --git a/src/content_script/mastodonInject.js b/src/content_script/mastodonInject.js index 98cbb88..6ec9629 100644 --- a/src/content_script/mastodonInject.js +++ b/src/content_script/mastodonInject.js @@ -39,7 +39,7 @@ function onClickInteract(event) { * Wait for element to appear. * * @param {string} selector - * @param {boolean} multiple + * @param {boolean} [multiple=false] * @param {number} timeoutDuration * @see {@link https://github.com/storybookjs/test-runner/blob/6d41927154e8dd1e4c9e7493122e24e2739a7a0f/src/setup-page.ts#L134} * from which this was adapted @@ -59,14 +59,14 @@ function waitForElement(selector, multiple = false, timeoutDuration) { }, timeoutDuration); const element = getElement(); - if(isElementFound(element)){ + if (isElementFound(element)){ window.clearTimeout(timeout); return resolve(element); } const observer = new MutationObserver(() => { const element = getElement(); - if(isElementFound(element)){ + if (isElementFound(element)){ window.clearTimeout(timeout); resolve(element); observer.disconnect(); @@ -103,23 +103,22 @@ async function injectFollowButton() { */ async function injectInteractionButtons() { const INJECTED_REPLY_CLASS = "mastodon-simplified-federation-injected-interaction"; - try { - const replyButtons = await waitForElement( - ".item-list[role='feed'] article[data-id] .status__action-bar button," + - ".detailed-status__wrapper .detailed-status__action-bar button", - true, - TIMEOUT_DURATION, - ); - replyButtons.forEach((button) => { - if(!button.classList.contains(INJECTED_REPLY_CLASS)){ + const replyButtons = await waitForElement( + ".item-list[role='feed'] article[data-id] .status__action-bar button," + + ".detailed-status__wrapper .detailed-status__action-bar button", + true, + TIMEOUT_DURATION, + ); + replyButtons.forEach((button) => { + try { + if (!button.classList.contains(INJECTED_REPLY_CLASS)){ button.addEventListener("click", onClickInteract); button.classList.add(INJECTED_REPLY_CLASS); } - }); - } catch (error) { - // Interaction buttons failed to appear - console.log(error); - } + } catch (error) { + // Interaction buttons failed to appear + } + }); } /**