Skip to content

Commit

Permalink
Merge pull request #7 from ryohidaka/refact/add-constants-ts
Browse files Browse the repository at this point in the history
定数をconstants.tsに定義
  • Loading branch information
AranoYuki1 authored Jul 27, 2023
2 parents 4e1ad52 + 2dd61b0 commit 06caa97
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 10 deletions.
21 changes: 21 additions & 0 deletions src/common/constants.ts
Original file line number Diff line number Diff line change
@@ -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",
];
3 changes: 2 additions & 1 deletion src/content_script/TwitterCrawler.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { DEFAULT_INSTANCE_URL } from '../common/constants';
import { postToMisskey, Image } from './MisskeyAPI'
import { showNotification } from './Notification'
import { Scope } from './ScopeModal';
Expand Down Expand Up @@ -44,7 +45,7 @@ const getToken = async () => {
const getServer = async () => {
return await new Promise<string>((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)
}
Expand Down
15 changes: 9 additions & 6 deletions src/content_script/content_script.tsx
Original file line number Diff line number Diff line change
@@ -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"]'
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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) => {
Expand Down
7 changes: 4 additions & 3 deletions src/popup/Popup.tsx
Original file line number Diff line number Diff line change
@@ -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<string | null>(null)
const [server, setServer] = useState<string | null>("https://misskey.io")
const [server, setServer] = useState<string | null>(DEFAULT_INSTANCE_URL);
const [cw, setCw] = useState<boolean | null>(null)
const [sensitive, setSensitive] = useState<boolean | null>(null)
const [showAccess, setShowAccess] = useState<boolean|null>(null)
Expand Down Expand Up @@ -65,7 +66,7 @@ const Popup = () => {

<TextField
label="Server URL"
placeholder="https://misskey.io"
placeholder={DEFAULT_INSTANCE_URL}
value={server}
variant="outlined"
fullWidth
Expand Down

0 comments on commit 06caa97

Please # to comment.