From f1109cf608214385425887e2860fe9141fc24f3c Mon Sep 17 00:00:00 2001 From: ryohidaka <39184410+ryohidaka@users.noreply.github.com> Date: Thu, 27 Jul 2023 12:53:23 +0900 Subject: [PATCH 1/4] add: constants.ts --- src/common/constants.ts | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 src/common/constants.ts diff --git a/src/common/constants.ts b/src/common/constants.ts new file mode 100644 index 0000000..e69de29 From e20427c1fea42854c4d945aec7105b6b0ea19620 Mon Sep 17 00:00:00 2001 From: ryohidaka <39184410+ryohidaka@users.noreply.github.com> Date: Thu, 27 Jul 2023 12:56:15 +0900 Subject: [PATCH 2/4] refact: Define Misskey.io URL in constant.ts . --- src/common/constants.ts | 1 + src/content_script/TwitterCrawler.ts | 3 ++- src/popup/Popup.tsx | 5 +++-- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/common/constants.ts b/src/common/constants.ts index e69de29..55d1e29 100644 --- a/src/common/constants.ts +++ b/src/common/constants.ts @@ -0,0 +1 @@ +export const DEFAULT_INSTANCE_URL = "https://misskey.io"; diff --git a/src/content_script/TwitterCrawler.ts b/src/content_script/TwitterCrawler.ts index cdf229a..69b8771 100644 --- a/src/content_script/TwitterCrawler.ts +++ b/src/content_script/TwitterCrawler.ts @@ -1,3 +1,4 @@ +import { DEFAULT_INSTANCE_URL } from '../common/constants'; import { postToMisskey } from './MisskeyAPI' import { showNotification } from './Notification' import { Scope } from './ScopeModal'; @@ -45,7 +46,7 @@ export const tweetToMisskey = async () => { let server = await new Promise((resolve, reject) => { chrome.storage.sync.get(['misskey_server'], (result) => { - resolve(result.misskey_server ?? "https://misskey.io") + resolve(result.misskey_server ?? DEFAULT_INSTANCE_URL); }) }) diff --git a/src/popup/Popup.tsx b/src/popup/Popup.tsx index 4ab9e9e..98d49cc 100644 --- a/src/popup/Popup.tsx +++ b/src/popup/Popup.tsx @@ -1,10 +1,11 @@ import React, { useEffect, useState } from "react" import ReactDOM from "react-dom" import { Container, Typography, AppBar, Toolbar, TextField, Link, FormControlLabel, Checkbox } from "@mui/material" +import { DEFAULT_INSTANCE_URL } from "../common/constants"; const Popup = () => { const [token, setToken] = useState(null) - const [server, setServer] = useState("https://misskey.io") + const [server, setServer] = useState(DEFAULT_INSTANCE_URL); const [cw, setCw] = useState(false) useEffect(() => { @@ -64,7 +65,7 @@ const Popup = () => { Date: Thu, 27 Jul 2023 12:59:31 +0900 Subject: [PATCH 3/4] refact: Define ReplyButtonLabels in constant.ts . --- src/common/constants.ts | 20 ++++++++++++++++++++ src/content_script/content_script.tsx | 7 ++----- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/src/common/constants.ts b/src/common/constants.ts index 55d1e29..80b9674 100644 --- a/src/common/constants.ts +++ b/src/common/constants.ts @@ -1 +1,21 @@ export const DEFAULT_INSTANCE_URL = "https://misskey.io"; + +/** + * リプライボタンの文字列一覧 + */ +export const REPLY_BUTTON_LABELS = [ + "返信", + "Reply", + "답글", + "回复", + "回覆", + "Répondre", + "Responder", + "Antworten", + "Rispondi", + "Responder", + "Responder", + "Antwoorden", + "Svara", + "Svar", +]; diff --git a/src/content_script/content_script.tsx b/src/content_script/content_script.tsx index 132bb50..81ff70a 100644 --- a/src/content_script/content_script.tsx +++ b/src/content_script/content_script.tsx @@ -1,5 +1,6 @@ import { tweetToMisskey } from './TwitterCrawler'; import { isShowingScopeModal, showScopeModal, closeScopeModal, updateScopeButton } from './ScopeModal'; +import { REPLY_BUTTON_LABELS } from '../common/constants'; const gifButtonSelector = 'div[data-testid="gifSearchButton"]' const buttonSelector = 'div[data-testid="tweetButton"], div[data-testid="tweetButtonInline"]' @@ -90,10 +91,6 @@ const addMisskeyPostButton = (tweetBox: Node) => { iconsBlock.appendChild(createScopeButton()) } - -// リプライボタンの文字列一覧 -const replyButtonLabels = [ "返信", "Reply", "답글", "回复", "回覆", "Répondre", "Responder", "Antworten", "Rispondi", "Responder", "Responder", "Antwoorden", "Svara", "Svar" ]; - const observer = new MutationObserver(mutations => { mutations.forEach(mutation => { if (mutation.type !== 'childList') return; @@ -103,7 +100,7 @@ const observer = new MutationObserver(mutations => { if (!tweetBox) return; // リプライボタンの場合は後続の処理を行わない - const isReplyButton = replyButtonLabels.indexOf(tweetBox.innerText) !== -1; + const isReplyButton = REPLY_BUTTON_LABELS.indexOf(tweetBox.innerText) !== -1; if (isReplyButton) return; addMisskeyPostButton(tweetBox); From ce6a6ceca93873cdcf1565f09fcf254d395fa654 Mon Sep 17 00:00:00 2001 From: ryohidaka <39184410+ryohidaka@users.noreply.github.com> Date: Thu, 27 Jul 2023 13:00:07 +0900 Subject: [PATCH 4/4] fix: Remove unused import. * https://github.com/AranoYuki1/Misstter/commit/e0ec7c3f9502aad41d9921dcfcea93dfc2d840ec --- src/popup/Popup.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/popup/Popup.tsx b/src/popup/Popup.tsx index 98d49cc..63dd069 100644 --- a/src/popup/Popup.tsx +++ b/src/popup/Popup.tsx @@ -1,6 +1,6 @@ import React, { useEffect, useState } from "react" import ReactDOM from "react-dom" -import { Container, Typography, AppBar, Toolbar, TextField, Link, FormControlLabel, Checkbox } from "@mui/material" +import { Container, Typography, AppBar, Toolbar, TextField, FormControlLabel, Checkbox } from "@mui/material" import { DEFAULT_INSTANCE_URL } from "../common/constants"; const Popup = () => {