Skip to content

Commit

Permalink
refactor: check for online features first
Browse files Browse the repository at this point in the history
  • Loading branch information
cachho committed Aug 20, 2023
1 parent fb9db34 commit 7f48af8
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions src/lib/handleShortenedLink.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ export async function handleShortenedLink(
link: HTMLAnchorElement,
settings: Settings
): Promise<URL | null> {
if (!settings.onlineFeatures) {
return null;
}
if (
(link.hostname === 'pandabuy.page.link' ||
link.hostname === 'pandabuy.allapp.link') &&
settings.onlineFeatures
link.hostname === 'pandabuy.page.link' ||
link.hostname === 'pandabuy.allapp.link'
) {
const url = `https://api.reparchive.com/convert/pandabuy?url=${encodeURIComponent(
link.href
Expand All @@ -17,21 +19,29 @@ export async function handleShortenedLink(
if (response && response.data) {
return new URL(response.data.url);
}
} else if (link.hostname === 'qr.1688.com' && settings.onlineFeatures) {
} else if (link.hostname === 'weidian.info') {
const url = `https://api.reparchive.com/convert/hagobuy/${link.pathname.slice(
1
)}`;
const response: ApiResponse<{ url: string }> = await fetchData(url);
if (response && response.data) {
return new URL(response.data.url);
}
} else if (link.hostname === 'qr.1688.com') {
const url = `https://api.reparchive.com/convert/1688/${link.pathname.slice(
3
)}`;
const response: ApiResponse<{ url: string }> = await fetchData(url);
if (response && response.data) {
return new URL(response.data.url);
}
} else if (link.hostname === 'k.youshop10.com' && settings.onlineFeatures) {
} else if (link.hostname === 'k.youshop10.com') {
const url = `https://api.reparchive.com/convert/kyoushop${link.pathname}`;
const response: ApiResponse<{ url: string }> = await fetchData(url);
if (response && response.data) {
return new URL(response.data.url);
}
} else if (link.hostname === 'm.tb.cn' && settings.onlineFeatures) {
} else if (link.hostname === 'm.tb.cn') {
const url = `https://api.reparchive.com/convert/taobao${link.pathname}`;
const response: ApiResponse<{ url: string }> = await fetchData(url);
if (response && response.data) {
Expand Down

0 comments on commit 7f48af8

Please sign in to comment.