搜索增加简繁转换器
This commit is contained in:
@@ -50,6 +50,7 @@
|
|||||||
"next-themes": "^0.4.6",
|
"next-themes": "^0.4.6",
|
||||||
"node-fetch": "^2.7.0",
|
"node-fetch": "^2.7.0",
|
||||||
"nprogress": "^0.2.0",
|
"nprogress": "^0.2.0",
|
||||||
|
"opencc-js": "^1.0.5",
|
||||||
"parse-torrent-name": "^0.5.4",
|
"parse-torrent-name": "^0.5.4",
|
||||||
"react": "^18.3.1",
|
"react": "^18.3.1",
|
||||||
"react-dom": "^18.3.1",
|
"react-dom": "^18.3.1",
|
||||||
|
|||||||
Generated
+20
@@ -98,6 +98,9 @@ importers:
|
|||||||
nprogress:
|
nprogress:
|
||||||
specifier: ^0.2.0
|
specifier: ^0.2.0
|
||||||
version: 0.2.0
|
version: 0.2.0
|
||||||
|
opencc-js:
|
||||||
|
specifier: ^1.0.5
|
||||||
|
version: 1.0.5
|
||||||
parse-torrent-name:
|
parse-torrent-name:
|
||||||
specifier: ^0.5.4
|
specifier: ^0.5.4
|
||||||
version: 0.5.4
|
version: 0.5.4
|
||||||
@@ -1235,24 +1238,28 @@ packages:
|
|||||||
engines: {node: '>= 10'}
|
engines: {node: '>= 10'}
|
||||||
cpu: [arm64]
|
cpu: [arm64]
|
||||||
os: [linux]
|
os: [linux]
|
||||||
|
libc: [glibc]
|
||||||
|
|
||||||
'@next/[email protected]':
|
'@next/[email protected]':
|
||||||
resolution: {integrity: sha512-Bm+QulsAItD/x6Ih8wGIMfRJy4G73tu1HJsrccPW6AfqdZd0Sfm5Imhgkgq2+kly065rYMnCOxTBvmvFY1BKfg==}
|
resolution: {integrity: sha512-Bm+QulsAItD/x6Ih8wGIMfRJy4G73tu1HJsrccPW6AfqdZd0Sfm5Imhgkgq2+kly065rYMnCOxTBvmvFY1BKfg==}
|
||||||
engines: {node: '>= 10'}
|
engines: {node: '>= 10'}
|
||||||
cpu: [arm64]
|
cpu: [arm64]
|
||||||
os: [linux]
|
os: [linux]
|
||||||
|
libc: [musl]
|
||||||
|
|
||||||
'@next/[email protected]':
|
'@next/[email protected]':
|
||||||
resolution: {integrity: sha512-FnFn+ZBgsVMbGDsTqo8zsnRzydvsGV8vfiWwUo1LD8FTmPTdV+otGSWKc4LJec0oSexFnCYVO4hX8P8qQKaSlg==}
|
resolution: {integrity: sha512-FnFn+ZBgsVMbGDsTqo8zsnRzydvsGV8vfiWwUo1LD8FTmPTdV+otGSWKc4LJec0oSexFnCYVO4hX8P8qQKaSlg==}
|
||||||
engines: {node: '>= 10'}
|
engines: {node: '>= 10'}
|
||||||
cpu: [x64]
|
cpu: [x64]
|
||||||
os: [linux]
|
os: [linux]
|
||||||
|
libc: [glibc]
|
||||||
|
|
||||||
'@next/[email protected]':
|
'@next/[email protected]':
|
||||||
resolution: {integrity: sha512-345tsIWMzoXaQndUTDv1qypDRiebFxGYx9pYkhwY4hBRaOLt8UGfiWKr9FSSHs25dFIf8ZqIFaPdy5MljdoawA==}
|
resolution: {integrity: sha512-345tsIWMzoXaQndUTDv1qypDRiebFxGYx9pYkhwY4hBRaOLt8UGfiWKr9FSSHs25dFIf8ZqIFaPdy5MljdoawA==}
|
||||||
engines: {node: '>= 10'}
|
engines: {node: '>= 10'}
|
||||||
cpu: [x64]
|
cpu: [x64]
|
||||||
os: [linux]
|
os: [linux]
|
||||||
|
libc: [musl]
|
||||||
|
|
||||||
'@next/[email protected]':
|
'@next/[email protected]':
|
||||||
resolution: {integrity: sha512-nscpt0G6UCTkrT2ppnJnFsYbPDQwmum4GNXYTeoTIdsmMydSKFz9Iny2jpaRupTb+Wl298+Rh82WKzt9LCcqSQ==}
|
resolution: {integrity: sha512-nscpt0G6UCTkrT2ppnJnFsYbPDQwmum4GNXYTeoTIdsmMydSKFz9Iny2jpaRupTb+Wl298+Rh82WKzt9LCcqSQ==}
|
||||||
@@ -1821,41 +1828,49 @@ packages:
|
|||||||
resolution: {integrity: sha512-34gw7PjDGB9JgePJEmhEqBhWvCiiWCuXsL9hYphDF7crW7UgI05gyBAi6MF58uGcMOiOqSJ2ybEeCvHcq0BCmQ==}
|
resolution: {integrity: sha512-34gw7PjDGB9JgePJEmhEqBhWvCiiWCuXsL9hYphDF7crW7UgI05gyBAi6MF58uGcMOiOqSJ2ybEeCvHcq0BCmQ==}
|
||||||
cpu: [arm64]
|
cpu: [arm64]
|
||||||
os: [linux]
|
os: [linux]
|
||||||
|
libc: [glibc]
|
||||||
|
|
||||||
'@unrs/[email protected]':
|
'@unrs/[email protected]':
|
||||||
resolution: {integrity: sha512-RyMIx6Uf53hhOtJDIamSbTskA99sPHS96wxVE/bJtePJJtpdKGXO1wY90oRdXuYOGOTuqjT8ACccMc4K6QmT3w==}
|
resolution: {integrity: sha512-RyMIx6Uf53hhOtJDIamSbTskA99sPHS96wxVE/bJtePJJtpdKGXO1wY90oRdXuYOGOTuqjT8ACccMc4K6QmT3w==}
|
||||||
cpu: [arm64]
|
cpu: [arm64]
|
||||||
os: [linux]
|
os: [linux]
|
||||||
|
libc: [musl]
|
||||||
|
|
||||||
'@unrs/[email protected]':
|
'@unrs/[email protected]':
|
||||||
resolution: {integrity: sha512-D8Vae74A4/a+mZH0FbOkFJL9DSK2R6TFPC9M+jCWYia/q2einCubX10pecpDiTmkJVUH+y8K3BZClycD8nCShA==}
|
resolution: {integrity: sha512-D8Vae74A4/a+mZH0FbOkFJL9DSK2R6TFPC9M+jCWYia/q2einCubX10pecpDiTmkJVUH+y8K3BZClycD8nCShA==}
|
||||||
cpu: [ppc64]
|
cpu: [ppc64]
|
||||||
os: [linux]
|
os: [linux]
|
||||||
|
libc: [glibc]
|
||||||
|
|
||||||
'@unrs/[email protected]':
|
'@unrs/[email protected]':
|
||||||
resolution: {integrity: sha512-frxL4OrzOWVVsOc96+V3aqTIQl1O2TjgExV4EKgRY09AJ9leZpEg8Ak9phadbuX0BA4k8U5qtvMSQQGGmaJqcQ==}
|
resolution: {integrity: sha512-frxL4OrzOWVVsOc96+V3aqTIQl1O2TjgExV4EKgRY09AJ9leZpEg8Ak9phadbuX0BA4k8U5qtvMSQQGGmaJqcQ==}
|
||||||
cpu: [riscv64]
|
cpu: [riscv64]
|
||||||
os: [linux]
|
os: [linux]
|
||||||
|
libc: [glibc]
|
||||||
|
|
||||||
'@unrs/[email protected]':
|
'@unrs/[email protected]':
|
||||||
resolution: {integrity: sha512-mJ5vuDaIZ+l/acv01sHoXfpnyrNKOk/3aDoEdLO/Xtn9HuZlDD6jKxHlkN8ZhWyLJsRBxfv9GYM2utQ1SChKew==}
|
resolution: {integrity: sha512-mJ5vuDaIZ+l/acv01sHoXfpnyrNKOk/3aDoEdLO/Xtn9HuZlDD6jKxHlkN8ZhWyLJsRBxfv9GYM2utQ1SChKew==}
|
||||||
cpu: [riscv64]
|
cpu: [riscv64]
|
||||||
os: [linux]
|
os: [linux]
|
||||||
|
libc: [musl]
|
||||||
|
|
||||||
'@unrs/[email protected]':
|
'@unrs/[email protected]':
|
||||||
resolution: {integrity: sha512-kELo8ebBVtb9sA7rMe1Cph4QHreByhaZ2QEADd9NzIQsYNQpt9UkM9iqr2lhGr5afh885d/cB5QeTXSbZHTYPg==}
|
resolution: {integrity: sha512-kELo8ebBVtb9sA7rMe1Cph4QHreByhaZ2QEADd9NzIQsYNQpt9UkM9iqr2lhGr5afh885d/cB5QeTXSbZHTYPg==}
|
||||||
cpu: [s390x]
|
cpu: [s390x]
|
||||||
os: [linux]
|
os: [linux]
|
||||||
|
libc: [glibc]
|
||||||
|
|
||||||
'@unrs/[email protected]':
|
'@unrs/[email protected]':
|
||||||
resolution: {integrity: sha512-C3ZAHugKgovV5YvAMsxhq0gtXuwESUKc5MhEtjBpLoHPLYM+iuwSj3lflFwK3DPm68660rZ7G8BMcwSro7hD5w==}
|
resolution: {integrity: sha512-C3ZAHugKgovV5YvAMsxhq0gtXuwESUKc5MhEtjBpLoHPLYM+iuwSj3lflFwK3DPm68660rZ7G8BMcwSro7hD5w==}
|
||||||
cpu: [x64]
|
cpu: [x64]
|
||||||
os: [linux]
|
os: [linux]
|
||||||
|
libc: [glibc]
|
||||||
|
|
||||||
'@unrs/[email protected]':
|
'@unrs/[email protected]':
|
||||||
resolution: {integrity: sha512-rV0YSoyhK2nZ4vEswT/QwqzqQXw5I6CjoaYMOX0TqBlWhojUf8P94mvI7nuJTeaCkkds3QE4+zS8Ko+GdXuZtA==}
|
resolution: {integrity: sha512-rV0YSoyhK2nZ4vEswT/QwqzqQXw5I6CjoaYMOX0TqBlWhojUf8P94mvI7nuJTeaCkkds3QE4+zS8Ko+GdXuZtA==}
|
||||||
cpu: [x64]
|
cpu: [x64]
|
||||||
os: [linux]
|
os: [linux]
|
||||||
|
libc: [musl]
|
||||||
|
|
||||||
'@unrs/[email protected]':
|
'@unrs/[email protected]':
|
||||||
resolution: {integrity: sha512-5u4RkfxJm+Ng7IWgkzi3qrFOvLvQYnPBmjmZQ8+szTK/b31fQCnleNl1GgEt7nIsZRIf5PLhPwT0WM+q45x/UQ==}
|
resolution: {integrity: sha512-5u4RkfxJm+Ng7IWgkzi3qrFOvLvQYnPBmjmZQ8+szTK/b31fQCnleNl1GgEt7nIsZRIf5PLhPwT0WM+q45x/UQ==}
|
||||||
@@ -4558,6 +4573,9 @@ packages:
|
|||||||
resolution: {integrity: sha512-kbpaSSGJTWdAY5KPVeMOKXSrPtr8C8C7wodJbcsd51jRnmD+GZu8Y0VoU6Dm5Z4vWr0Ig/1NKuWRKf7j5aaYSg==}
|
resolution: {integrity: sha512-kbpaSSGJTWdAY5KPVeMOKXSrPtr8C8C7wodJbcsd51jRnmD+GZu8Y0VoU6Dm5Z4vWr0Ig/1NKuWRKf7j5aaYSg==}
|
||||||
engines: {node: '>=6'}
|
engines: {node: '>=6'}
|
||||||
|
|
||||||
|
[email protected]:
|
||||||
|
resolution: {integrity: sha512-LD+1SoNnZdlRwtYTjnQdFrSVCAaYpuDqL5CkmOaHOkKoKh7mFxUicLTRVNLU5C+Jmi1vXQ3QL4jWdgSaa4sKjg==}
|
||||||
|
|
||||||
[email protected]:
|
[email protected]:
|
||||||
resolution: {integrity: sha512-tmZDan2LRIRQyhUGvkff68/O0R8UmF+Btmiiz0SmSw2ng3CfPZB9wJlIjHpe/MKUZqyIZkVIXCrwr1tIN+0Dzg==}
|
resolution: {integrity: sha512-tmZDan2LRIRQyhUGvkff68/O0R8UmF+Btmiiz0SmSw2ng3CfPZB9wJlIjHpe/MKUZqyIZkVIXCrwr1tIN+0Dzg==}
|
||||||
|
|
||||||
@@ -11545,6 +11563,8 @@ snapshots:
|
|||||||
dependencies:
|
dependencies:
|
||||||
mimic-fn: 2.1.0
|
mimic-fn: 2.1.0
|
||||||
|
|
||||||
|
[email protected]: {}
|
||||||
|
|
||||||
[email protected]:
|
[email protected]:
|
||||||
dependencies:
|
dependencies:
|
||||||
kind-of: 6.0.3
|
kind-of: 6.0.3
|
||||||
|
|||||||
+86
-8
@@ -36,6 +36,10 @@ function SearchPageClient() {
|
|||||||
const [triggerAcgSearch, setTriggerAcgSearch] = useState(false);
|
const [triggerAcgSearch, setTriggerAcgSearch] = useState(false);
|
||||||
// 用户权限
|
// 用户权限
|
||||||
const [userRole, setUserRole] = useState<'owner' | 'admin' | 'user' | null>(null);
|
const [userRole, setUserRole] = useState<'owner' | 'admin' | 'user' | null>(null);
|
||||||
|
// 繁体转简体转换器
|
||||||
|
const converterRef = useRef<((text: string) => string) | null>(null);
|
||||||
|
// 转换器是否已初始化
|
||||||
|
const [converterReady, setConverterReady] = useState(false);
|
||||||
|
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const searchParams = useSearchParams();
|
const searchParams = useSearchParams();
|
||||||
@@ -538,6 +542,26 @@ function SearchPageClient() {
|
|||||||
const authInfo = getAuthInfoFromBrowserCookie();
|
const authInfo = getAuthInfoFromBrowserCookie();
|
||||||
setUserRole(authInfo?.role || null);
|
setUserRole(authInfo?.role || null);
|
||||||
|
|
||||||
|
// 初始化繁体转简体转换器
|
||||||
|
if (typeof window !== 'undefined') {
|
||||||
|
import('opencc-js').then((module) => {
|
||||||
|
try {
|
||||||
|
const OpenCC = module.default || module;
|
||||||
|
const converter = OpenCC.Converter({ from: 'hk', to: 'cn' });
|
||||||
|
converterRef.current = converter;
|
||||||
|
setConverterReady(true);
|
||||||
|
} catch (error) {
|
||||||
|
console.error('初始化繁体转简体转换器失败:', error);
|
||||||
|
setConverterReady(true); // 即使失败也设置为 true,避免阻塞
|
||||||
|
}
|
||||||
|
}).catch((error) => {
|
||||||
|
console.error('加载 opencc-js 失败:', error);
|
||||||
|
setConverterReady(true); // 即使失败也设置为 true,避免阻塞
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
setConverterReady(true);
|
||||||
|
}
|
||||||
|
|
||||||
// 初始加载搜索历史
|
// 初始加载搜索历史
|
||||||
getSearchHistory().then(setSearchHistory);
|
getSearchHistory().then(setSearchHistory);
|
||||||
|
|
||||||
@@ -600,13 +624,41 @@ function SearchPageClient() {
|
|||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
// 等待转换器初始化完成
|
||||||
|
if (!converterReady) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// 当搜索参数变化时更新搜索状态
|
// 当搜索参数变化时更新搜索状态
|
||||||
const query = searchParams.get('q') || '';
|
let query = searchParams.get('q') || '';
|
||||||
|
|
||||||
|
// 如果开启了繁体转简体,进行转换
|
||||||
|
if (query && typeof window !== 'undefined') {
|
||||||
|
const searchTraditionalToSimplified = localStorage.getItem('searchTraditionalToSimplified');
|
||||||
|
|
||||||
|
if (searchTraditionalToSimplified === 'true' && converterRef.current) {
|
||||||
|
try {
|
||||||
|
const originalQuery = query;
|
||||||
|
query = converterRef.current(query);
|
||||||
|
|
||||||
|
// 如果转换后的文本与原文本不同,更新 URL
|
||||||
|
if (originalQuery !== query) {
|
||||||
|
const trimmedConverted = query.trim();
|
||||||
|
// 使用 replace 而不是 push,避免在历史记录中留下繁体版本
|
||||||
|
router.replace(`/search?q=${encodeURIComponent(trimmedConverted)}${searchParams.get('type') ? `&type=${searchParams.get('type')}` : ''}`);
|
||||||
|
return; // 等待 URL 更新后重新触发此 effect
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error('[URL参数监听] 繁体转简体转换失败:', error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
currentQueryRef.current = query.trim();
|
currentQueryRef.current = query.trim();
|
||||||
|
|
||||||
if (query) {
|
if (query) {
|
||||||
setSearchQuery(query);
|
setSearchQuery(query);
|
||||||
|
|
||||||
const trimmed = query.trim();
|
const trimmed = query.trim();
|
||||||
|
|
||||||
// 检查是否有缓存且不是强制刷新
|
// 检查是否有缓存且不是强制刷新
|
||||||
@@ -799,7 +851,7 @@ function SearchPageClient() {
|
|||||||
setShowResults(false);
|
setShowResults(false);
|
||||||
setShowSuggestions(false);
|
setShowSuggestions(false);
|
||||||
}
|
}
|
||||||
}, [searchParams, forceRefresh]);
|
}, [searchParams, forceRefresh, converterReady]);
|
||||||
|
|
||||||
// 组件卸载时,关闭可能存在的连接
|
// 组件卸载时,关闭可能存在的连接
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -838,9 +890,21 @@ function SearchPageClient() {
|
|||||||
// 搜索表单提交时触发,处理搜索逻辑
|
// 搜索表单提交时触发,处理搜索逻辑
|
||||||
const handleSearch = (e: React.FormEvent) => {
|
const handleSearch = (e: React.FormEvent) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
const trimmed = searchQuery.trim().replace(/\s+/g, ' ');
|
let trimmed = searchQuery.trim().replace(/\s+/g, ' ');
|
||||||
if (!trimmed) return;
|
if (!trimmed) return;
|
||||||
|
|
||||||
|
// 如果开启了繁体转简体,进行转换
|
||||||
|
if (typeof window !== 'undefined') {
|
||||||
|
const searchTraditionalToSimplified = localStorage.getItem('searchTraditionalToSimplified');
|
||||||
|
if (searchTraditionalToSimplified === 'true' && converterRef.current) {
|
||||||
|
try {
|
||||||
|
trimmed = converterRef.current(trimmed);
|
||||||
|
} catch (error) {
|
||||||
|
console.error('繁体转简体转换失败:', error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 回显搜索框
|
// 回显搜索框
|
||||||
setSearchQuery(trimmed);
|
setSearchQuery(trimmed);
|
||||||
setShowResults(true);
|
setShowResults(true);
|
||||||
@@ -863,7 +927,21 @@ function SearchPageClient() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const handleSuggestionSelect = (suggestion: string) => {
|
const handleSuggestionSelect = (suggestion: string) => {
|
||||||
setSearchQuery(suggestion);
|
let processedSuggestion = suggestion;
|
||||||
|
|
||||||
|
// 如果开启了繁体转简体,进行转换
|
||||||
|
if (typeof window !== 'undefined') {
|
||||||
|
const searchTraditionalToSimplified = localStorage.getItem('searchTraditionalToSimplified');
|
||||||
|
if (searchTraditionalToSimplified === 'true' && converterRef.current) {
|
||||||
|
try {
|
||||||
|
processedSuggestion = converterRef.current(suggestion);
|
||||||
|
} catch (error) {
|
||||||
|
console.error('繁体转简体转换失败:', error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
setSearchQuery(processedSuggestion);
|
||||||
setShowSuggestions(false);
|
setShowSuggestions(false);
|
||||||
|
|
||||||
// 自动执行搜索
|
// 自动执行搜索
|
||||||
@@ -872,15 +950,15 @@ function SearchPageClient() {
|
|||||||
// 根据当前选项卡执行不同的搜索
|
// 根据当前选项卡执行不同的搜索
|
||||||
if (activeTab === 'video') {
|
if (activeTab === 'video') {
|
||||||
// 影视搜索
|
// 影视搜索
|
||||||
router.push(`/search?q=${encodeURIComponent(suggestion)}&type=video`);
|
router.push(`/search?q=${encodeURIComponent(processedSuggestion)}&type=video`);
|
||||||
// 其余由 searchParams 变化的 effect 处理
|
// 其余由 searchParams 变化的 effect 处理
|
||||||
} else if (activeTab === 'pansou') {
|
} else if (activeTab === 'pansou') {
|
||||||
// 网盘搜索 - 触发搜索
|
// 网盘搜索 - 触发搜索
|
||||||
router.push(`/search?q=${encodeURIComponent(suggestion)}&type=pansou`);
|
router.push(`/search?q=${encodeURIComponent(processedSuggestion)}&type=pansou`);
|
||||||
setTriggerPansouSearch(prev => !prev);
|
setTriggerPansouSearch(prev => !prev);
|
||||||
} else if (activeTab === 'acg') {
|
} else if (activeTab === 'acg') {
|
||||||
// ACG 磁力搜索 - 触发搜索
|
// ACG 磁力搜索 - 触发搜索
|
||||||
router.push(`/search?q=${encodeURIComponent(suggestion)}&type=acg`);
|
router.push(`/search?q=${encodeURIComponent(processedSuggestion)}&type=acg`);
|
||||||
setTriggerAcgSearch(prev => !prev);
|
setTriggerAcgSearch(prev => !prev);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -106,6 +106,7 @@ export const UserMenu: React.FC = () => {
|
|||||||
const [bufferStrategy, setBufferStrategy] = useState('medium');
|
const [bufferStrategy, setBufferStrategy] = useState('medium');
|
||||||
const [nextEpisodePreCache, setNextEpisodePreCache] = useState(true);
|
const [nextEpisodePreCache, setNextEpisodePreCache] = useState(true);
|
||||||
const [isBufferStrategyDropdownOpen, setIsBufferStrategyDropdownOpen] = useState(false);
|
const [isBufferStrategyDropdownOpen, setIsBufferStrategyDropdownOpen] = useState(false);
|
||||||
|
const [searchTraditionalToSimplified, setSearchTraditionalToSimplified] = useState(false);
|
||||||
|
|
||||||
// 折叠面板状态
|
// 折叠面板状态
|
||||||
const [isDoubanSectionOpen, setIsDoubanSectionOpen] = useState(true);
|
const [isDoubanSectionOpen, setIsDoubanSectionOpen] = useState(true);
|
||||||
@@ -378,6 +379,12 @@ export const UserMenu: React.FC = () => {
|
|||||||
console.error('解析首页模块配置失败:', error);
|
console.error('解析首页模块配置失败:', error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 加载搜索繁体转简体设置
|
||||||
|
const savedSearchTraditionalToSimplified = localStorage.getItem('searchTraditionalToSimplified');
|
||||||
|
if (savedSearchTraditionalToSimplified !== null) {
|
||||||
|
setSearchTraditionalToSimplified(savedSearchTraditionalToSimplified === 'true');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
@@ -641,6 +648,13 @@ export const UserMenu: React.FC = () => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const handleSearchTraditionalToSimplifiedToggle = (value: boolean) => {
|
||||||
|
setSearchTraditionalToSimplified(value);
|
||||||
|
if (typeof window !== 'undefined') {
|
||||||
|
localStorage.setItem('searchTraditionalToSimplified', String(value));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
// 首页模块配置处理函数
|
// 首页模块配置处理函数
|
||||||
const handleHomeModuleToggle = (id: string, enabled: boolean) => {
|
const handleHomeModuleToggle = (id: string, enabled: boolean) => {
|
||||||
const updatedModules = homeModules.map(module =>
|
const updatedModules = homeModules.map(module =>
|
||||||
@@ -732,6 +746,7 @@ export const UserMenu: React.FC = () => {
|
|||||||
setBufferStrategy('medium');
|
setBufferStrategy('medium');
|
||||||
setNextEpisodePreCache(true);
|
setNextEpisodePreCache(true);
|
||||||
setHomeModules(defaultHomeModules);
|
setHomeModules(defaultHomeModules);
|
||||||
|
setSearchTraditionalToSimplified(false);
|
||||||
|
|
||||||
if (typeof window !== 'undefined') {
|
if (typeof window !== 'undefined') {
|
||||||
localStorage.setItem('defaultAggregateSearch', JSON.stringify(true));
|
localStorage.setItem('defaultAggregateSearch', JSON.stringify(true));
|
||||||
@@ -747,6 +762,7 @@ export const UserMenu: React.FC = () => {
|
|||||||
localStorage.setItem('bufferStrategy', 'medium');
|
localStorage.setItem('bufferStrategy', 'medium');
|
||||||
localStorage.setItem('nextEpisodePreCache', 'true');
|
localStorage.setItem('nextEpisodePreCache', 'true');
|
||||||
localStorage.setItem('homeModules', JSON.stringify(defaultHomeModules));
|
localStorage.setItem('homeModules', JSON.stringify(defaultHomeModules));
|
||||||
|
localStorage.setItem('searchTraditionalToSimplified', 'false');
|
||||||
window.dispatchEvent(new CustomEvent('homeModulesUpdated'));
|
window.dispatchEvent(new CustomEvent('homeModulesUpdated'));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -1423,6 +1439,30 @@ export const UserMenu: React.FC = () => {
|
|||||||
</div>
|
</div>
|
||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{/* 搜索繁体转简体 */}
|
||||||
|
<div className='flex items-center justify-between'>
|
||||||
|
<div>
|
||||||
|
<h4 className='text-sm font-medium text-gray-700 dark:text-gray-300'>
|
||||||
|
搜索繁体转简体
|
||||||
|
</h4>
|
||||||
|
<p className='text-xs text-gray-500 dark:text-gray-400 mt-1'>
|
||||||
|
搜索时自动将繁体中文转换为简体中文
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<label className='flex items-center cursor-pointer'>
|
||||||
|
<div className='relative'>
|
||||||
|
<input
|
||||||
|
type='checkbox'
|
||||||
|
className='sr-only peer'
|
||||||
|
checked={searchTraditionalToSimplified}
|
||||||
|
onChange={(e) => handleSearchTraditionalToSimplifiedToggle(e.target.checked)}
|
||||||
|
/>
|
||||||
|
<div className='w-11 h-6 bg-gray-300 rounded-full peer-checked:bg-green-500 transition-colors dark:bg-gray-600'></div>
|
||||||
|
<div className='absolute top-0.5 left-0.5 w-5 h-5 bg-white rounded-full transition-transform peer-checked:translate-x-5'></div>
|
||||||
|
</div>
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Vendored
+8
@@ -0,0 +1,8 @@
|
|||||||
|
declare module 'opencc-js' {
|
||||||
|
interface ConverterOptions {
|
||||||
|
from: string;
|
||||||
|
to: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function Converter(options: ConverterOptions): (text: string) => string;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user