diff --git a/src/App.tsx b/src/App.tsx index 333aedd..11960e8 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -15,8 +15,17 @@ import type { SettingsDialogPage, Sentence } from "./types"; export default function App() { const queryOptions = useQueryOptions(); - const { language, voice, inferenceMode, voiceSpeed, hakkaToneMode, setLanguage, setVoice } = queryOptions; - const [sentences, setSentences] = useState([]); + const { language, voice, inferenceMode, voiceSpeed, hakkaToneMode, setLanguage, setVoice, screenshotMode } = queryOptions; + const [sentences, setSentences] = useState( + screenshotMode + ? () => [ + { language: "waitau", voice: "male", inferenceMode: "online", voiceSpeed: 1, syllables: segment("天地玄黃,宇宙洪荒。") }, + { language: "waitau", voice: "female", inferenceMode: "online", voiceSpeed: 1, syllables: segment("日月盈昃,辰宿列張。") }, + { language: "hakka", voice: "male", inferenceMode: "online", voiceSpeed: 1, syllables: segment("天地玄黃,宇宙洪荒。") }, + { language: "hakka", voice: "female", inferenceMode: "online", voiceSpeed: 1, syllables: segment("日月盈昃,辰宿列張。") }, + ] + : [], + ); const textArea = useRef(null); const btnAddSentence = useRef(null); diff --git a/src/hooks.ts b/src/hooks.ts index 015633a..68627ae 100644 --- a/src/hooks.ts +++ b/src/hooks.ts @@ -33,12 +33,15 @@ export function useQueryOptions(): QueryOptions { mode: ALL_INFERENCE_MODES.find(mode => searchParams.has(mode)) || parseOption("mode", ALL_INFERENCE_MODES), speed: +([searchParams.get("speed"), localStorage.getItem("speed")].find((speed): speed is string => !!speed && +speed >= 0.5 && +speed <= 2) || "1"), hakka_tones: parseOption("hakka_tones", ALL_HAKKA_TONE_MODES), + screenshot: searchParams.has("screenshot"), }; }); useEffect(() => { - Object.assign(localStorage, queryOptions); + // eslint-disable-next-line @typescript-eslint/no-unused-vars + const { screenshot, ...rest } = queryOptions; + Object.assign(localStorage, rest); }, [queryOptions]); - const { language, voice, mode: inferenceMode, speed: voiceSpeed, hakka_tones: hakkaToneMode } = queryOptions; + const { language, voice, mode: inferenceMode, speed: voiceSpeed, hakka_tones: hakkaToneMode, screenshot: screenshotMode } = queryOptions; return { language, voice, @@ -50,8 +53,11 @@ export function useQueryOptions(): QueryOptions { setInferenceMode: (inferenceMode: InferenceMode) => setQueryOptions(oldOptions => ({ ...oldOptions, mode: inferenceMode })), setVoiceSpeed: (voiceSpeed: number) => setQueryOptions(oldOptions => ({ ...oldOptions, speed: voiceSpeed })), setHakkaToneMode: (hakkaToneMode: HakkaToneMode) => setQueryOptions(oldOptions => ({ ...oldOptions, hakka_tones: hakkaToneMode })), + screenshotMode, get urlWithQuery() { - return `${location.origin}${location.pathname}?${String(new URLSearchParams(queryOptions as unknown as Record))}`; // This is fine: number is automatically coalesced to string + // eslint-disable-next-line @typescript-eslint/no-unused-vars + const { screenshot, ...rest } = queryOptions; + return `${location.origin}${location.pathname}?${String(new URLSearchParams(rest as unknown as Record))}`; // This is fine: number is automatically coalesced to string }, }; } diff --git a/src/types.ts b/src/types.ts index 9654ae9..38a2843 100644 --- a/src/types.ts +++ b/src/types.ts @@ -140,6 +140,7 @@ export interface QueryOptions { setInferenceMode: Dispatch; setVoiceSpeed: Dispatch; setHakkaToneMode: Dispatch; + screenshotMode: boolean; get urlWithQuery(): string; }