diff --git a/src/FilterLists.Web.V2/src/shared/SubscribeButton.tsx b/src/FilterLists.Web.V2/src/shared/SubscribeButton.tsx index 244c1f507..47c6e8f2d 100644 --- a/src/FilterLists.Web.V2/src/shared/SubscribeButton.tsx +++ b/src/FilterLists.Web.V2/src/shared/SubscribeButton.tsx @@ -12,46 +12,45 @@ export const SubscribeButton = (props: Props) => props.viewUrl ? : null; -function buildButtonProps(props: Props): ButtonProps { +const buildButtonProps = (props: Props) => { let type: ButtonType = "primary"; + const hrefLocation = `${encodeURIComponent(props.viewUrl)}`; const hrefTitle = `${encodeURIComponent(props.name)}`; - let href: string = `abp:subscribe?location=${encodeURIComponent(props.viewUrl)}&title=${hrefTitle}`; + let href = `abp:subscribe?location=${hrefLocation}&title=${hrefTitle}`; - let titlePrefix = ""; - let title: string = ""; + const defaultTitle = (prefix?: string) => `${prefix || ""}Subscribe to ${props.name} with a browser extension supporting the "abp:" protocol (e.g. uBlock Origin, Adblock Plus).`; + let title: string; - const contains = (match: string) => props.viewUrl.indexOf(match) > 0; - - switch (contains) { + switch (true) { // HTTP protocols - case contains(".onion/").valueOf: + case props.viewUrl.includes(".onion/"): type = "ghost"; - titlePrefix = "Tor address - "; + title = defaultTitle("Tor address - "); break; - case contains("http://").valueOf: + case props.viewUrl.includes("http://"): type = "danger"; - titlePrefix = "Not Secure - "; + title = defaultTitle("Not Secure - "); break; // Software protocols - case contains(".tpl").valueOf: - href = `javascript:window.external.msAddTrackingProtectionList('${encodeURIComponent(props.viewUrl)}', '${hrefTitle}')`; - title = `${titlePrefix}Subscribe to ${props.name} with Internet Explorer's Tracking Protection List feature.`; + case props.viewUrl.includes(".tpl"): + href = `javascript:window.external.msAddTrackingProtectionList('${hrefLocation}', '${hrefTitle}')`; + title = `Subscribe to ${props.name} with Internet Explorer's Tracking Protection List feature.`; break; - case contains(".lsrules").valueOf: - href = `x-littlesnitch:subscribe-rules?url=${encodeURIComponent(props.viewUrl)}`; - title = `${titlePrefix}Subscribe to ${props.name} with Little Snitch's rule group subscription feature.`; + case props.viewUrl.includes(".lsrules"): + href = `x-littlesnitch:subscribe-rules?url=${hrefLocation}`; + title = `Subscribe to ${props.name} with Little Snitch's rule group subscription feature.`; break; - case contains("?hostformat=littlesnitch").valueOf: - href = `x-littlesnitch:subscribe-rules?url=${encodeURIComponent(props.viewUrl)}`; - title = `${titlePrefix}Subscribe to ${props.name} with Little Snitch's rule group subscription feature.`; + case props.viewUrl.includes("?hostformat=littlesnitch"): + href = `x-littlesnitch:subscribe-rules?url=${hrefLocation}`; + title = `Subscribe to ${props.name} with Little Snitch's rule group subscription feature.`; break; default: - title = `${titlePrefix}Subscribe to ${props.name} with a browser extension supporting the "abp:" protocol (e.g. uBlock Origin, Adblock Plus).`; + title = defaultTitle(); break; } return { type, href, title } as ButtonProps -} \ No newline at end of file +}