diff --git a/src/common/constants.ts b/src/common/constants.ts new file mode 100644 index 0000000..80b9674 --- /dev/null +++ b/src/common/constants.ts @@ -0,0 +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/TwitterCrawler.ts b/src/content_script/TwitterCrawler.ts index 0cf053d..db97622 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, Image } from './MisskeyAPI' import { showNotification } from './Notification' import { Scope } from './ScopeModal'; @@ -44,7 +45,7 @@ const getToken = async () => { const getServer = async () => { return await new Promise((resolve, reject) => { chrome.storage.sync.get(['misskey_server'], (result) => { - let server = result.misskey_server ?? "https://misskey.io"; + let server = result.misskey_server ?? DEFAULT_INSTANCE_URL; if (server.endsWith('/')) { server = server.slice(0, -1) } diff --git a/src/content_script/content_script.tsx b/src/content_script/content_script.tsx index e9515a3..510c20d 100644 --- a/src/content_script/content_script.tsx +++ b/src/content_script/content_script.tsx @@ -1,6 +1,7 @@ import { tweetToMisskey } from './TwitterCrawler'; import { flag_icon } from './Icons' 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"]' @@ -179,10 +180,6 @@ const addMisskeyImageOptionButton = (editButton: HTMLElement, attachmentsImage: } - -// リプライボタンの文字列一覧 -const replyButtonLabels = [ "返信", "Reply", "답글", "回复", "回覆", "Répondre", "Responder", "Antworten", "Rispondi", "Responder", "Responder", "Antwoorden", "Svara", "Svar" ]; - const foundTweetButtonHandler = (tweetButton: HTMLElement) => { if (!tweetButton) return; @@ -215,8 +212,14 @@ const observer = new MutationObserver(mutations => { if (node.nodeType !== Node.ELEMENT_NODE) return; const tweetButton = node.querySelector(buttonSelector); - if (tweetButton) { foundTweetButtonHandler(tweetButton); } - + if (tweetButton) { + // リプライボタンの場合は後続の処理を行わない + const isReplyButton = REPLY_BUTTON_LABELS.indexOf(tweetBox.innerText) !== -1; + if (isReplyButton) return; + foundTweetButtonHandler(tweetButton); + return; + } + const attachmentsImages = document.querySelectorAll(attachmentsImageSelector); if (attachmentsImages) { attachmentsImages.forEach((attachmentsImage: any) => { diff --git a/src/popup/Popup.tsx b/src/popup/Popup.tsx index 6cff077..0b5b221 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 { Container, Typography, AppBar, Toolbar, TextField, 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(null) const [sensitive, setSensitive] = useState(null) const [showAccess, setShowAccess] = useState(null) @@ -65,7 +66,7 @@ const Popup = () => {