mirror of
https://github.com/collinbarrett/FilterLists.git
synced 2026-03-11 09:04:27 +00:00
fix SubscribeButton switch statement
This commit is contained in:
parent
f31eb1b82c
commit
b5f43df6a8
1 changed files with 21 additions and 22 deletions
|
|
@ -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)}&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
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue