This commit is contained in:
IndieKKY
2024-10-05 20:03:02 +08:00
parent b283695b02
commit d52231227e
33 changed files with 44 additions and 51 deletions

View File

@@ -3,7 +3,7 @@ import 'tippy.js/dist/tippy.css'
import {useAppDispatch, useAppSelector} from './hooks/redux' import {useAppDispatch, useAppSelector} from './hooks/redux'
import {setEnvData, setEnvReady, setTempData, setTempReady} from './redux/envReducer' import {setEnvData, setEnvReady, setTempData, setTempReady} from './redux/envReducer'
import {cloneDeep} from 'lodash-es' import {cloneDeep} from 'lodash-es'
import {STORAGE_ENV, STORAGE_TEMP} from './const' import {STORAGE_ENV, STORAGE_TEMP} from './consts/const'
import OptionsPage from './pages/OptionsPage' import OptionsPage from './pages/OptionsPage'
import {handleJson} from '@kky002/kky-util' import {handleJson} from '@kky002/kky-util'
import {useLocalStorage} from '@kky002/kky-hooks' import {useLocalStorage} from '@kky002/kky-hooks'

View File

@@ -8,6 +8,7 @@ export const EventBusContext = React.createContext<any>(null)
const map: { [key: string]: string } = { const map: { [key: string]: string } = {
'/options.html': 'options', '/options.html': 'options',
'/sidepanel.html': 'app',
// '/close': 'close', // '/close': 'close',
} }

View File

@@ -1,6 +1,6 @@
import {v4} from 'uuid' import {v4} from 'uuid'
import {handleTask, initTaskService, tasksMap} from './taskService' import {handleTask, initTaskService, tasksMap} from './taskService'
import {MESSAGE_TARGET_INJECT, MESSAGE_TO_EXTENSION_ADD_TASK, MESSAGE_TO_EXTENSION_GET_TASK, MESSAGE_TO_EXTENSION_SHOW_FLAG, MESSAGE_TO_INJECT_TOGGLE_DISPLAY, STORAGE_ENV} from '@/const' import {MESSAGE_TARGET_INJECT, MESSAGE_TO_EXTENSION_ADD_TASK, MESSAGE_TO_EXTENSION_GET_TASK, MESSAGE_TO_EXTENSION_SHOW_FLAG, MESSAGE_TO_INJECT_TOGGLE_DISPLAY, STORAGE_ENV} from '@/consts/const'
import ExtensionMessage from '@/messaging/ExtensionMessage' import ExtensionMessage from '@/messaging/ExtensionMessage'
const setBadgeOk = async (tabId: number, ok: boolean) => { const setBadgeOk = async (tabId: number, ok: boolean) => {

View File

@@ -1,4 +1,4 @@
import {DEFAULT_SERVER_URL_OPENAI} from '../const' import {DEFAULT_SERVER_URL_OPENAI} from '../consts/const'
const getServerUrl = (serverUrl?: string) => { const getServerUrl = (serverUrl?: string) => {
if (!serverUrl) { if (!serverUrl) {

View File

@@ -1,4 +1,4 @@
import {TASK_EXPIRE_TIME} from '../const' import {TASK_EXPIRE_TIME} from '../consts/const'
import {handleChatCompleteTask, handleGeminiChatCompleteTask} from './openaiService' import {handleChatCompleteTask, handleGeminiChatCompleteTask} from './openaiService'
export const tasksMap = new Map<string, Task>() export const tasksMap = new Map<string, Task>()

View File

@@ -30,7 +30,7 @@ import {
SEARCH_BAR_HEIGHT, SEARCH_BAR_HEIGHT,
SUMMARIZE_ALL_THRESHOLD, SUMMARIZE_ALL_THRESHOLD,
TITLE_HEIGHT TITLE_HEIGHT
} from '../const' } from '../consts/const'
import {FaClipboardList} from 'react-icons/fa' import {FaClipboardList} from 'react-icons/fa'
import useTranslate from '../hooks/useTranslate' import useTranslate from '../hooks/useTranslate'
import {openUrl} from '@kky002/kky-util' import {openUrl} from '@kky002/kky-util'

View File

@@ -1,6 +1,6 @@
import React, {useMemo} from 'react' import React, {useMemo} from 'react'
import {useAppSelector} from '../hooks/redux' import {useAppSelector} from '../hooks/redux'
import {getDisplay, getTransText} from '../util/biz_util' import {getDisplay, getTransText} from '../utils/biz_util'
import classNames from 'classnames' import classNames from 'classnames'
const CompactSegmentItem = (props: { const CompactSegmentItem = (props: {

View File

@@ -5,7 +5,7 @@ import {find, remove} from 'lodash-es'
import {setCurFetched, setCurInfo, setData, setInfos, setUploadedTranscript} from '../redux/envReducer' import {setCurFetched, setCurInfo, setData, setInfos, setUploadedTranscript} from '../redux/envReducer'
import MoreBtn from './MoreBtn' import MoreBtn from './MoreBtn'
import classNames from 'classnames' import classNames from 'classnames'
import {parseTranscript} from '../util/biz_util' import {parseTranscript} from '../utils/biz_util'
const Header = (props: { const Header = (props: {
foldCallback: () => void foldCallback: () => void

View File

@@ -13,11 +13,11 @@ import {Placement} from '@popperjs/core/lib/enums'
import {useAppDispatch, useAppSelector} from '../hooks/redux' import {useAppDispatch, useAppSelector} from '../hooks/redux'
import {setEnvData, setTempData} from '../redux/envReducer' import {setEnvData, setTempData} from '../redux/envReducer'
import {EventBusContext} from '../Router' import {EventBusContext} from '../Router'
import {EVENT_EXPAND, MESSAGE_TO_INJECT_DOWNLOAD_AUDIO} from '../const' import {EVENT_EXPAND, MESSAGE_TO_INJECT_DOWNLOAD_AUDIO} from '../consts/const'
import {formatSrtTime, formatTime, formatVttTime} from '../util/util' import {formatSrtTime, formatTime, formatVttTime} from '../utils/util'
import {downloadText, openUrl} from '@kky002/kky-util' import {downloadText, openUrl} from '@kky002/kky-util'
import toast from 'react-hot-toast' import toast from 'react-hot-toast'
import {getSummarize} from '../util/biz_util' import {getSummarize} from '../utils/biz_util'
import useMessage from '../messaging/useMessage' import useMessage from '../messaging/useMessage'
interface Props { interface Props {
placement: Placement placement: Placement

View File

@@ -1,7 +1,7 @@
import React, {useMemo} from 'react' import React, {useMemo} from 'react'
import {formatTime} from '../util/util' import {formatTime} from '../utils/util'
import {useAppSelector} from '../hooks/redux' import {useAppSelector} from '../hooks/redux'
import {getDisplay, getTransText} from '../util/biz_util' import {getDisplay, getTransText} from '../utils/biz_util'
import classNames from 'classnames' import classNames from 'classnames'
const NormalSegmentItem = (props: { const NormalSegmentItem = (props: {

View File

@@ -4,7 +4,7 @@ import { IoMdClose } from 'react-icons/io';
import { setTempData } from '../redux/envReducer'; import { setTempData } from '../redux/envReducer';
import { useAppDispatch, useAppSelector } from '../hooks/redux'; import { useAppDispatch, useAppSelector } from '../hooks/redux';
import { openUrl } from '@kky002/kky-util'; import { openUrl } from '@kky002/kky-util';
import { isEdgeBrowser } from '../util/util'; import { isEdgeBrowser } from '../utils/util';
const RateExtension: React.FC = () => { const RateExtension: React.FC = () => {
const dispatch = useAppDispatch() const dispatch = useAppDispatch()

View File

@@ -3,14 +3,14 @@ import {useAppDispatch, useAppSelector} from '../hooks/redux'
import {setFloatKeyPointsSegIdx, setSegmentFold, setTempData} from '../redux/envReducer' import {setFloatKeyPointsSegIdx, setSegmentFold, setTempData} from '../redux/envReducer'
import classNames from 'classnames' import classNames from 'classnames'
import {FaClipboardList} from 'react-icons/fa' import {FaClipboardList} from 'react-icons/fa'
import {PAGE_MAIN, PAGE_SETTINGS, SUMMARIZE_THRESHOLD, SUMMARIZE_TYPES} from '../const' import {PAGE_MAIN, PAGE_SETTINGS, SUMMARIZE_THRESHOLD, SUMMARIZE_TYPES} from '../consts/const'
import useTranslate from '../hooks/useTranslate' import useTranslate from '../hooks/useTranslate'
import {BsDashSquare, BsPlusSquare, CgFileDocument, FaQuestion, GrOverview, RiFileCopy2Line} from 'react-icons/all' import {BsDashSquare, BsPlusSquare, CgFileDocument, FaQuestion, GrOverview, RiFileCopy2Line} from 'react-icons/all'
import toast from 'react-hot-toast' import toast from 'react-hot-toast'
import {getLastTime, getSummaryStr, isSummaryEmpty, parseStrTimeToSeconds} from '../util/biz_util' import {getLastTime, getSummaryStr, isSummaryEmpty, parseStrTimeToSeconds} from '../utils/biz_util'
import {useInViewport} from 'ahooks' import {useInViewport} from 'ahooks'
import SegmentItem from './SegmentItem' import SegmentItem from './SegmentItem'
import {stopPopFunc} from '../util/util' import {stopPopFunc} from '../utils/util'
import useSubtitle from '../hooks/useSubtitle' import useSubtitle from '../hooks/useSubtitle'
const SummarizeItemOverview = (props: { const SummarizeItemOverview = (props: {

View File

@@ -1,7 +1,7 @@
import { setCurFetched, setCurInfo, setData, setInfos, setTitle, setUrl } from '@/redux/envReducer' import { setCurFetched, setCurInfo, setData, setInfos, setTitle, setUrl } from '@/redux/envReducer'
import { useMemo } from 'react' import { useMemo } from 'react'
import { useAppDispatch } from './redux' import { useAppDispatch } from './redux'
import { MESSAGE_TO_APP_SET_INFOS, MESSAGE_TO_APP_SET_VIDEO_INFO } from '@/const' import { MESSAGE_TO_APP_SET_INFOS, MESSAGE_TO_APP_SET_VIDEO_INFO } from '@/consts/const'
import useMessageService from '@/messaging/useMessageService' import useMessageService from '@/messaging/useMessageService'
const useMessagingService = () => { const useMessagingService = () => {

View File

@@ -1,7 +1,7 @@
import {useAppDispatch, useAppSelector} from './redux' import {useAppDispatch, useAppSelector} from './redux'
import {useEffect, useMemo} from 'react' import {useEffect, useMemo} from 'react'
import {setSearchResult, setSearchText, } from '../redux/envReducer' import {setSearchResult, setSearchText, } from '../redux/envReducer'
import {Search} from '../util/search' import {Search} from '../utils/search'
interface Document { interface Document {
idx: number idx: number

View File

@@ -1,7 +1,7 @@
import {useAppDispatch, useAppSelector} from './redux' import {useAppDispatch, useAppSelector} from './redux'
import React, {useCallback} from 'react' import React, {useCallback} from 'react'
import {setNeedScroll, setReviewAction, setTempData} from '../redux/envReducer' import {setNeedScroll, setReviewAction, setTempData} from '../redux/envReducer'
import {MESSAGE_TO_INJECT_MOVE} from '../const' import {MESSAGE_TO_INJECT_MOVE} from '../consts/const'
import useMessage from '../messaging/useMessage' import useMessage from '../messaging/useMessage'
const useSubtitle = () => { const useSubtitle = () => {
const dispatch = useAppDispatch() const dispatch = useAppDispatch()

View File

@@ -16,10 +16,10 @@ import {
setTempData, setTempData,
} from '../redux/envReducer' } from '../redux/envReducer'
import {EventBusContext} from '../Router' import {EventBusContext} from '../Router'
import {EVENT_EXPAND, GEMINI_TOKENS, TOTAL_HEIGHT_MAX, TOTAL_HEIGHT_MIN, WORDS_MIN, WORDS_RATE, MESSAGE_TO_INJECT_GET_VIDEO_STATUS, MESSAGE_TO_INJECT_GET_VIDEO_ELEMENT_INFO, MESSAGE_TO_INJECT_REFRESH_VIDEO_INFO, MESSAGE_TO_INJECT_HIDE_TRANS, MESSAGE_TO_INJECT_UPDATETRANSRESULT, TOTAL_HEIGHT_DEF} from '../const' import {EVENT_EXPAND, GEMINI_TOKENS, TOTAL_HEIGHT_MAX, TOTAL_HEIGHT_MIN, WORDS_MIN, WORDS_RATE, MESSAGE_TO_INJECT_GET_VIDEO_STATUS, MESSAGE_TO_INJECT_GET_VIDEO_ELEMENT_INFO, MESSAGE_TO_INJECT_REFRESH_VIDEO_INFO, MESSAGE_TO_INJECT_HIDE_TRANS, MESSAGE_TO_INJECT_UPDATETRANSRESULT, TOTAL_HEIGHT_DEF} from '../consts/const'
import {useAsyncEffect, useInterval} from 'ahooks' import {useAsyncEffect, useInterval} from 'ahooks'
import {getModelMaxTokens, getWholeText} from '../util/biz_util' import {getModelMaxTokens, getWholeText} from '../utils/biz_util'
import {MESSAGE_TO_INJECT_GET_SUBTITLE} from '../const' import {MESSAGE_TO_INJECT_GET_SUBTITLE} from '../consts/const'
import useMessage from '../messaging/useMessage' import useMessage from '../messaging/useMessage'
import { injectWaiter } from '@/messaging/useMessageService' import { injectWaiter } from '@/messaging/useMessageService'

View File

@@ -26,11 +26,11 @@ import {
SUMMARIZE_TYPES, SUMMARIZE_TYPES,
TRANSLATE_COOLDOWN, TRANSLATE_COOLDOWN,
TRANSLATE_FETCH_DEFAULT, TRANSLATE_FETCH_DEFAULT,
} from '../const' } from '../consts/const'
import toast from 'react-hot-toast' import toast from 'react-hot-toast'
import {useMemoizedFn} from 'ahooks/es' import {useMemoizedFn} from 'ahooks/es'
import {extractJsonArray, extractJsonObject, getModel} from '../util/biz_util' import {extractJsonArray, extractJsonObject, getModel} from '../utils/biz_util'
import {formatTime} from '../util/util' import {formatTime} from '../utils/util'
import useMessage from '@/messaging/useMessage' import useMessage from '@/messaging/useMessage'
const useTranslate = () => { const useTranslate = () => {
const dispatch = useAppDispatch() const dispatch = useAppDispatch()

View File

@@ -1,5 +1,5 @@
import { TOTAL_HEIGHT_DEF, HEADER_HEIGHT, TOTAL_HEIGHT_MIN, TOTAL_HEIGHT_MAX, IFRAME_ID, MESSAGE_TO_INJECT_DOWNLOAD_AUDIO, MESSAGE_TARGET_INJECT, MESSAGE_TO_APP_SET_INFOS, MESSAGE_TO_INJECT_TOGGLE_DISPLAY, STORAGE_ENV, MESSAGE_TO_EXTENSION_SHOW_FLAG } from '@/const' import { TOTAL_HEIGHT_DEF, HEADER_HEIGHT, TOTAL_HEIGHT_MIN, TOTAL_HEIGHT_MAX, IFRAME_ID, MESSAGE_TO_INJECT_DOWNLOAD_AUDIO, MESSAGE_TARGET_INJECT, MESSAGE_TO_APP_SET_INFOS, MESSAGE_TO_INJECT_TOGGLE_DISPLAY, STORAGE_ENV, MESSAGE_TO_EXTENSION_SHOW_FLAG } from '@/consts/const'
import { MESSAGE_TO_INJECT_FOLD, MESSAGE_TO_INJECT_MOVE, MESSAGE_TO_APP_SET_VIDEO_INFO, MESSAGE_TO_INJECT_GET_SUBTITLE, MESSAGE_TO_INJECT_GET_VIDEO_STATUS, MESSAGE_TO_INJECT_GET_VIDEO_ELEMENT_INFO, MESSAGE_TO_INJECT_UPDATETRANSRESULT, MESSAGE_TO_INJECT_PLAY, MESSAGE_TO_INJECT_HIDE_TRANS, MESSAGE_TO_INJECT_REFRESH_VIDEO_INFO } from '@/const' import { MESSAGE_TO_INJECT_FOLD, MESSAGE_TO_INJECT_MOVE, MESSAGE_TO_APP_SET_VIDEO_INFO, MESSAGE_TO_INJECT_GET_SUBTITLE, MESSAGE_TO_INJECT_GET_VIDEO_STATUS, MESSAGE_TO_INJECT_GET_VIDEO_ELEMENT_INFO, MESSAGE_TO_INJECT_UPDATETRANSRESULT, MESSAGE_TO_INJECT_PLAY, MESSAGE_TO_INJECT_HIDE_TRANS, MESSAGE_TO_INJECT_REFRESH_VIDEO_INFO } from '@/consts/const'
import InjectMessage from '@/messaging/InjectMessage' import InjectMessage from '@/messaging/InjectMessage'
const debug = (...args: any[]) => { const debug = (...args: any[]) => {

View File

@@ -4,7 +4,7 @@ import './index.less'
import store from './store' import store from './store'
import {Provider} from 'react-redux' import {Provider} from 'react-redux'
import Router from './Router' import Router from './Router'
import {APP_DOM_ID} from './const' import {APP_DOM_ID} from './consts/const'
const body = document.querySelector('body') const body = document.querySelector('body')
const app = document.createElement('div') const app = document.createElement('div')

View File

@@ -1,4 +1,4 @@
import { MESSAGE_TARGET_EXTENSION, MESSAGE_TARGET_INJECT, MESSAGE_TO_EXTENSION_ROUTE_MSG } from '@/const' import { MESSAGE_TARGET_EXTENSION, MESSAGE_TO_EXTENSION_ROUTE_MSG } from '@/consts/const'
import PortMessageHandler from './PortMessageHandler' import PortMessageHandler from './PortMessageHandler'
export type PortContext = { export type PortContext = {

View File

@@ -1,5 +1,4 @@
import { MESSAGE_TARGET_APP, MESSAGE_TARGET_EXTENSION, MESSAGE_TARGET_INJECT, MESSAGE_TO_EXTENSION_ROUTE_MSG } from '@/const' import { MESSAGE_TARGET_APP, MESSAGE_TARGET_EXTENSION, MESSAGE_TARGET_INJECT, MESSAGE_TO_EXTENSION_ROUTE_MSG } from '@/consts/const'
import { PostMessagePayload, PostMessageResponse, startListening } from 'postmessage-promise'
import PortMessageHandler from './PortMessageHandler' import PortMessageHandler from './PortMessageHandler'
class InjectMessage { class InjectMessage {

View File

@@ -1,4 +1,4 @@
import { MESSAGE_TARGET_EXTENSION, MESSAGE_TARGET_INJECT, MESSAGE_TO_EXTENSION_ROUTE_MSG } from '@/const' import { MESSAGE_TARGET_EXTENSION, MESSAGE_TARGET_INJECT, MESSAGE_TO_EXTENSION_ROUTE_MSG } from '@/consts/const'
import { injectWaiter } from './useMessageService' import { injectWaiter } from './useMessageService'
import { useCallback } from 'react' import { useCallback } from 'react'
import PortMessageHandler from './PortMessageHandler' import PortMessageHandler from './PortMessageHandler'

View File

@@ -1,10 +1,7 @@
import { useCallback, useEffect, useMemo } from 'react' import { useCallback, useMemo } from 'react'
import { import {
MESSAGE_TARGET_APP, MESSAGE_TARGET_APP,
MESSAGE_TARGET_EXTENSION, } from '@/consts/const'
MESSAGE_TARGET_INJECT,
} from '@/const'
import { callServer, PostMessagePayload, PostMessageResponse } from 'postmessage-promise'
import { Waiter } from '@kky002/kky-util' import { Waiter } from '@kky002/kky-util'
import PortMessageHandler from './PortMessageHandler' import PortMessageHandler from './PortMessageHandler'

View File

@@ -1,19 +1,15 @@
import React, {useCallback, useContext, useEffect, useMemo} from 'react' import React, {useCallback, useContext, useEffect} from 'react'
import {useAppDispatch, useAppSelector} from '../hooks/redux' import {useAppDispatch, useAppSelector} from '../hooks/redux'
import {setEnvData, setEnvReady, setFold, setTempData, setTempReady} from '../redux/envReducer' import Header from '../components/Header'
import Header from '../biz/Header' import Body from '../components/Body'
import Body from '../biz/Body'
import useSubtitleService from '../hooks/useSubtitleService' import useSubtitleService from '../hooks/useSubtitleService'
import {cloneDeep} from 'lodash-es' import {EVENT_EXPAND, MESSAGE_TO_INJECT_FOLD} from '../consts/const'
import {EVENT_EXPAND, MESSAGE_TO_INJECT_FOLD, PAGE_MAIN, PAGE_SETTINGS, STORAGE_ENV, STORAGE_TEMP} from '../const'
import {EventBusContext} from '../Router' import {EventBusContext} from '../Router'
import useTranslateService from '../hooks/useTranslateService' import useTranslateService from '../hooks/useTranslateService'
import {handleJson} from '@kky002/kky-util' import {setTheme} from '../utils/biz_util'
import {useLocalStorage} from '@kky002/kky-hooks'
import {Toaster} from 'react-hot-toast'
import {setTheme} from '../util/biz_util'
import useSearchService from '../hooks/useSearchService' import useSearchService from '../hooks/useSearchService'
import useMessage from '../messaging/useMessage' import useMessage from '../messaging/useMessage'
import {setFold} from '../redux/envReducer'
function App() { function App() {
const dispatch = useAppDispatch() const dispatch = useAppDispatch()

View File

@@ -1,4 +1,4 @@
import React, {PropsWithChildren, useCallback, useEffect, useMemo, useState} from 'react' import React, {PropsWithChildren, useCallback, useMemo, useState} from 'react'
import {setEnvData, setTempData} from '../redux/envReducer' import {setEnvData, setTempData} from '../redux/envReducer'
import {useAppDispatch, useAppSelector} from '../hooks/redux' import {useAppDispatch, useAppSelector} from '../hooks/redux'
import { import {
@@ -22,7 +22,7 @@ import {
TRANSLATE_FETCH_MIN, TRANSLATE_FETCH_MIN,
TRANSLATE_FETCH_STEP, TRANSLATE_FETCH_STEP,
WORDS_RATE, WORDS_RATE,
} from '../const' } from '../consts/const'
import {IoWarning} from 'react-icons/all' import {IoWarning} from 'react-icons/all'
import classNames from 'classnames' import classNames from 'classnames'
import toast from 'react-hot-toast' import toast from 'react-hot-toast'

View File

@@ -1,6 +1,6 @@
import {createSlice, PayloadAction} from '@reduxjs/toolkit' import {createSlice, PayloadAction} from '@reduxjs/toolkit'
import {find, findIndex} from 'lodash-es' import {find, findIndex} from 'lodash-es'
import {DEFAULT_SERVER_URL_OPENAI, TOTAL_HEIGHT_DEF} from '../const' import {DEFAULT_SERVER_URL_OPENAI, TOTAL_HEIGHT_DEF} from '../consts/const'
interface EnvState { interface EnvState {
envData: EnvData envData: EnvData

View File

@@ -1,4 +1,4 @@
import {APP_DOM_ID, CUSTOM_MODEL_TOKENS, MODEL_DEFAULT, MODEL_MAP, SUMMARIZE_TYPES} from '../const' import {APP_DOM_ID, CUSTOM_MODEL_TOKENS, MODEL_DEFAULT, MODEL_MAP, SUMMARIZE_TYPES} from '../consts/const'
import {isDarkMode} from '@kky002/kky-util' import {isDarkMode} from '@kky002/kky-util'
import toast from 'react-hot-toast' import toast from 'react-hot-toast'
import {findIndex} from 'lodash-es' import {findIndex} from 'lodash-es'