refactor(RightClickRestorer): simplify setDomain logic

Replace nested if/try/catch with a single ternary expression.
isUnsupportedPage() already handles invalid URLs, so new URL() is safe here.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
雨霖铃
2026-05-29 20:15:54 +08:00
parent 21a6430f0d
commit e97f4cae9a
@@ -39,13 +39,7 @@ export function useRightClickRestorer(): UseRightClickRestorerReturn {
const [tab] = await chrome.tabs.query({ active: true, currentWindow: true }); const [tab] = await chrome.tabs.query({ active: true, currentWindow: true });
const url = tab?.url; const url = tab?.url;
if (url) { setDomain(url ? new URL(url).hostname : '');
try {
setDomain(new URL(url).hostname);
} catch {
setDomain('');
}
}
if (isUnsupportedPage(url)) { if (isUnsupportedPage(url)) {
setIsUnsupported(true); setIsUnsupported(true);