fix SubscribeButton switch statement

This commit is contained in:
Collin M. Barrett 2019-08-05 20:25:34 -05:00
parent f31eb1b82c
commit b5f43df6a8

View file

@ -12,46 +12,45 @@ export const SubscribeButton = (props: Props) => props.viewUrl
? <Button {...buildButtonProps(props)}>{props.text || "Subscribe"}</Button>
: 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)}&amp;title=${hrefTitle}`;
let href = `abp:subscribe?location=${hrefLocation}&amp;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
}
}