mirror of
https://github.com/collinbarrett/FilterLists.git
synced 2026-03-11 09:04:27 +00:00
refactor SubscribeButton
This commit is contained in:
parent
c5dfe682de
commit
a4d77d4b4b
2 changed files with 34 additions and 36 deletions
|
|
@ -42,7 +42,7 @@ export class AllListsTable extends React.Component<{}, State> {
|
|||
dataIndex={nameof<List>("viewUrl")}
|
||||
width={100}
|
||||
fixed="right"
|
||||
render={(text: any, record: List, index: number) => <SubscribeButton key={index} url={text} name={record.name} />}
|
||||
render={(text: string, record: List, index: number) => <SubscribeButton key={index} viewUrl={text} name={record.name} />}
|
||||
/>
|
||||
</Table>
|
||||
);
|
||||
|
|
|
|||
|
|
@ -1,56 +1,54 @@
|
|||
import * as React from "react";
|
||||
import { Button } from 'antd';
|
||||
import { ButtonType } from "antd/lib/button";
|
||||
import { ButtonType, ButtonProps } from "antd/lib/button";
|
||||
|
||||
interface Props {
|
||||
name: string;
|
||||
url: string;
|
||||
viewUrl: string;
|
||||
text?: string;
|
||||
};
|
||||
|
||||
export const SubscribeButton = (props: Props) => {
|
||||
let buttonType: ButtonType;
|
||||
export const SubscribeButton = (props: Props) => props.viewUrl
|
||||
? <Button {...buildButtonProps(props)}>{props.text || "Subscribe"}</Button>
|
||||
: null;
|
||||
|
||||
function buildButtonProps(props: Props): ButtonProps {
|
||||
let type: ButtonType;
|
||||
let titlePrefix: string;
|
||||
|
||||
if (props.url.indexOf(".onion/") > 0) {
|
||||
buttonType = "ghost";
|
||||
if (props.viewUrl.indexOf(".onion/") > 0) {
|
||||
type = "ghost";
|
||||
titlePrefix = "Tor address - ";
|
||||
} else if (props.url.indexOf("http://") === 0) {
|
||||
buttonType = "danger";
|
||||
}
|
||||
else if (props.viewUrl.indexOf("http://") === 0) {
|
||||
type = "danger";
|
||||
titlePrefix = "Not Secure - ";
|
||||
} else {
|
||||
buttonType = "primary";
|
||||
}
|
||||
else {
|
||||
type = "primary";
|
||||
titlePrefix = "";
|
||||
}
|
||||
|
||||
const hrefTitle = `${encodeURIComponent(props.name)}`;
|
||||
let href;
|
||||
if (props.url.indexOf(".tpl") > 0) {
|
||||
href = `javascript:window.external.msAddTrackingProtectionList('${encodeURIComponent(props.url)}', '${hrefTitle}')`;
|
||||
} else if (props.url.indexOf(".lsrules") > 0) {
|
||||
href = `x-littlesnitch:subscribe-rules?url=${encodeURIComponent(props.url)}`;
|
||||
} else if (props.url.indexOf("?hostformat=littlesnitch") > 0) {
|
||||
href = `x-littlesnitch:subscribe-rules?url=${encodeURIComponent(props.url)}`;
|
||||
} else {
|
||||
href = `abp:subscribe?location=${encodeURIComponent(props.url)}&title=${hrefTitle}`;
|
||||
};
|
||||
let href: string;
|
||||
let title: string;
|
||||
|
||||
let title;
|
||||
if (props.url.indexOf(".tpl") > 0) {
|
||||
if (props.viewUrl.indexOf(".tpl") > 0) {
|
||||
href = `javascript:window.external.msAddTrackingProtectionList('${encodeURIComponent(props.viewUrl)}', '${hrefTitle}')`;
|
||||
title = `${titlePrefix}Subscribe to ${props.name} with Internet Explorer's Tracking Protection List feature.`;
|
||||
} else if (props.url.indexOf(".lsrules") > 0) {
|
||||
}
|
||||
else if (props.viewUrl.indexOf(".lsrules") > 0) {
|
||||
href = `x-littlesnitch:subscribe-rules?url=${encodeURIComponent(props.viewUrl)}`;
|
||||
title = `${titlePrefix}Subscribe to ${props.name} with Little Snitch's rule group subscription feature.`;
|
||||
} else if (props.url.indexOf("?hostformat=littlesnitch") > 0) {
|
||||
}
|
||||
else if (props.viewUrl.indexOf("?hostformat=littlesnitch") > 0) {
|
||||
href = `x-littlesnitch:subscribe-rules?url=${encodeURIComponent(props.viewUrl)}`;
|
||||
title = `${titlePrefix}Subscribe to ${props.name} with Little Snitch's rule group subscription feature.`;
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
href = `abp:subscribe?location=${encodeURIComponent(props.viewUrl)}&title=${hrefTitle}`;
|
||||
title = `${titlePrefix}Subscribe to ${props.name} with a browser extension supporting the "abp:" protocol (e.g. uBlock Origin, Adblock Plus).`;
|
||||
};
|
||||
|
||||
return props.url
|
||||
? <Button
|
||||
type={buttonType}
|
||||
href={href}
|
||||
title={title}
|
||||
>{props.text || "Subscribe"}</Button>
|
||||
: null;
|
||||
};
|
||||
}
|
||||
|
||||
return { type, href, title } as ButtonProps
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue