-
-
Notifications
You must be signed in to change notification settings - Fork 117
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
3 changed files
with
73 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
111 changes: 37 additions & 74 deletions
111
src/FilterLists.Web/ClientApp/components/SubscribeButton.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,90 +1,53 @@ | ||
import * as React from "react"; | ||
|
||
export default class SubscribeButton extends React.Component<any, any> { | ||
|
||
constructor(props: ISubscribeUrlDto) { | ||
export default class SubscribeButton extends React.Component<ISubscribeButtonProps, any> { | ||
constructor(props: ISubscribeButtonProps) { | ||
super(props); | ||
this.state = { | ||
buttonClassName: props.isOriginal ? "btn-primary" : "btn-secondary", | ||
titlePrefix: "" | ||
}; | ||
} | ||
|
||
render() { | ||
return <div className="btn-group-vertical" role="group"> | ||
<button id="btnGroupDropSubscribe" type="button" className="btn btn-primary dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"> | ||
Subscribe | ||
</button> | ||
<div className="dropdown-menu" aria-labelledby="btnGroupDropSubscribe"> | ||
<SubscribeUrl details={this.props.details} /> | ||
<SubscribeUrlMirror details={this.props.details} index={1} /> | ||
<SubscribeUrlMirror details={this.props.details} index={2} /> | ||
</div> | ||
</div>; | ||
} | ||
} | ||
|
||
function SubscribeUrl(props: any) { | ||
return props.details.viewUrl.indexOf("https://") === -1 | ||
? SubscribeUrlNotSecure() | ||
: props.details.viewUrl.indexOf("web.archive.org") === -1 | ||
? SubscribeUrlPrimary() | ||
: SubscribeUrlWayback(); | ||
|
||
function SubscribeUrlPrimary() { | ||
return <a href={`abp:subscribe?location=${encodeURIComponent(props.details.viewUrl)}&title=${encodeURIComponent(props.details.name)}`} | ||
className="btn btn-primary btn-block fl-btn-details-action" | ||
title={`Subscribe to list with browser extension supporting \"abp:\" protocol (e.g. uBlock Origin, AdBlock Plus).`}> | ||
Subscribe | ||
</a>; | ||
componentDidMount() { | ||
if (this.props.url) { | ||
this.setStateWayback(); | ||
this.setStateInsecure(); | ||
} | ||
} | ||
|
||
function SubscribeUrlWayback() { | ||
return <a href={`abp:subscribe?location=${encodeURIComponent(props.details.viewUrl)}&title=${encodeURIComponent(props.details.name)}`} | ||
className="btn btn-secondary btn-block fl-btn-details-action" | ||
title={`Archive.org Mirror (Original Offline) - Subscribe to list with browser extension supporting \"abp:\" protocol (e.g. uBlock Origin, AdBlock Plus).`}> | ||
Subscribe | ||
</a>; | ||
setStateWayback() { | ||
if (this.props.url.indexOf("web.archive.org") !== -1) { | ||
this.setState({ | ||
buttonClassName: "btn-secondary" | ||
}); | ||
} | ||
} | ||
|
||
function SubscribeUrlNotSecure() { | ||
return <a href={`abp:subscribe?location=${encodeURIComponent(props.details.viewUrl)}&title=${encodeURIComponent(props.details.name)}`} | ||
className="btn btn-danger btn-block fl-btn-details-action" | ||
title={`Not Secure - Subscribe to list with browser extension supporting \"abp:\" protocol (e.g. uBlock Origin, AdBlock Plus).`}> | ||
Subscribe | ||
</a>; | ||
setStateInsecure() { | ||
if (this.props.url.indexOf("https://") === -1) { | ||
this.setState({ | ||
buttonClassName: "btn-danger", | ||
titlePrefix: "Not Secure - " | ||
}); | ||
} | ||
} | ||
}; | ||
|
||
function SubscribeUrlMirror(props: any, index: number) { | ||
return index === 1 | ||
? props.details.viewUrlMirror1 | ||
? props.details.viewUrlMirror1.indexOf("https://") === -1 | ||
? SubscribeUrlNotSecure(props.details.viewUrlMirror1) | ||
: SubscribeUrlSecondary(props.details.viewUrlMirror1) | ||
: null | ||
: props.details.viewUrlMirror2 | ||
? props.details.viewUrlMirror2.indexOf("https://") === -1 | ||
? SubscribeUrlNotSecure(props.details.viewUrlMirror2) | ||
: SubscribeUrlSecondary(props.details.viewUrlMirror2) | ||
render() { | ||
const href = `abp:subscribe?location=${encodeURIComponent(this.props.url)}&title=${encodeURIComponent(this.props.name)}`; | ||
const title = `${this.state.titlePrefix}Subscribe to list with a browser extension supporting the \"abp:\" protocol (e.g. uBlock Origin, AdBlock Plus).`; | ||
const className = `btn ${this.state.buttonClassName} btn-block fl-btn-details-action`; | ||
return this.props.url | ||
? <a href={href} title={title} className={className}> | ||
{this.props.text} | ||
</a> | ||
: null; | ||
|
||
function SubscribeUrlSecondary(url: any) { | ||
return <a href={`abp:subscribe?location=${encodeURIComponent(url)}&title=${encodeURIComponent(props.details.name)}`} | ||
className="btn btn-secondary btn-block fl-btn-details-action" | ||
title={`Mirror - Subscribe to list with browser extension supporting \"abp:\" protocol (e.g. uBlock Origin, AdBlock Plus).`}> | ||
Mirror | ||
</a>; | ||
} | ||
} | ||
|
||
function SubscribeUrlNotSecure(url: any) { | ||
return <a href={`abp:subscribe?location=${encodeURIComponent(url)}&title=${encodeURIComponent(props.details.name)}`} | ||
className="btn btn-danger btn-block fl-btn-details-action" | ||
title={`Mirror - Not Secure - Subscribe to list with browser extension supporting \"abp:\" protocol (e.g. uBlock Origin, AdBlock Plus).`}> | ||
Mirror | ||
</a>; | ||
} | ||
}; | ||
|
||
interface ISubscribeUrlDto { | ||
interface ISubscribeButtonProps { | ||
name: string; | ||
viewUrl: string; | ||
viewUrlMirror1: string; | ||
viewUrlMirror2: string; | ||
url: string; | ||
text: string; | ||
isOriginal: boolean; | ||
} |
30 changes: 30 additions & 0 deletions
30
src/FilterLists.Web/ClientApp/components/SubscribeButtonGroup.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import * as React from "react"; | ||
import SubscribeButton from "./SubscribeButton"; | ||
|
||
export default class SubscribeButtonGroup extends React.Component<ISubscribeButtonGroupProps, any> { | ||
constructor(props: ISubscribeButtonGroupProps) { | ||
super(props); | ||
} | ||
|
||
render() { | ||
return this.props.urlMirror1 | ||
? (<div className="btn-group-vertical fl-btn-details-action" role="group"> | ||
<button id="btnGroupDropSubscribe" type="button" className="btn btn-primary dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"> | ||
Subscribe | ||
</button> | ||
<div className="dropdown-menu" aria-labelledby="btnGroupDropSubscribe"> | ||
<SubscribeButton name={this.props.name} url={this.props.url} text="Original" isOriginal={true}/> | ||
<SubscribeButton name={this.props.name} url={this.props.urlMirror1} text="Mirror 1" isOriginal={false}/> | ||
<SubscribeButton name={this.props.name} url={this.props.urlMirror2} text="Mirror 2" isOriginal={false}/> | ||
</div> | ||
</div>) | ||
: <SubscribeButton name={this.props.name} url={this.props.url} text="Subscribe" isOriginal={true}/>; | ||
} | ||
} | ||
|
||
interface ISubscribeButtonGroupProps { | ||
name: string; | ||
url: string; | ||
urlMirror1: string; | ||
urlMirror2: string; | ||
} |