Merge pull request #131 from DeepDoge/master

Added option for where to show the buttons
This commit is contained in:
kodxana 2022-08-08 00:00:17 +02:00 committed by GitHub
commit e0d514916e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 88 additions and 31 deletions

View file

@ -12,7 +12,7 @@ const targetPlatforms = getTargetPlatfromSettingsEntiries()
const ytUrlResolverOptions = getYtUrlResolversSettingsEntiries() const ytUrlResolverOptions = getYtUrlResolversSettingsEntiries()
function WatchOnLbryPopup(params: { profile: Awaited<ReturnType<typeof getProfile>> | null }) { function WatchOnLbryPopup(params: { profile: Awaited<ReturnType<typeof getProfile>> | null }) {
const { redirect, targetPlatform, urlResolver, privateKey, publicKey } = useExtensionSettings() const { redirect, targetPlatform, urlResolver, videoSubButton, channelSubButton, videoPlayerButton, privateKey, publicKey } = useExtensionSettings()
let [loading, updateLoading] = useState(() => false) let [loading, updateLoading] = useState(() => false)
let [route, updateRoute] = useState<string | null>(() => null) let [route, updateRoute] = useState<string | null>(() => null)
@ -100,7 +100,7 @@ function WatchOnLbryPopup(params: { profile: Awaited<ReturnType<typeof getProfil
<label>Purge your profile and data!</label> <label>Purge your profile and data!</label>
<p>Purge your profile data online and offline.</p> <p>Purge your profile data online and offline.</p>
<div className='options'> <div className='options'>
<div className="purge-aaaaaaa"> <div className="center">
<span className='filled'>(°° </span> <span className='filled'>(°° </span>
</div> </div>
<a onClick={() => loads(purgeProfile(dialogManager)).then(() => renderPopup())} className={`button`}> <a onClick={() => loads(purgeProfile(dialogManager)).then(() => renderPopup())} className={`button`}>
@ -140,7 +140,7 @@ function WatchOnLbryPopup(params: { profile: Awaited<ReturnType<typeof getProfil
: :
<main> <main>
<section> <section>
<label>Pick a mode:</label> <label>Pick a mode</label>
<div className='options'> <div className='options'>
<a onClick={() => setExtensionSetting('redirect', true)} className={`button ${redirect ? 'active' : ''}`}> <a onClick={() => setExtensionSetting('redirect', true)} className={`button ${redirect ? 'active' : ''}`}>
Redirect Redirect
@ -150,6 +150,38 @@ function WatchOnLbryPopup(params: { profile: Awaited<ReturnType<typeof getProfil
</a> </a>
</div> </div>
</section> </section>
{
!redirect &&
<section>
<label>Show button at:</label>
<b className='filled'>Video</b>
<div className='options'>
<div className="left">
<span>Subscribe Button:</span>
</div>
<a onClick={() => setExtensionSetting('videoSubButton', !videoSubButton)} className={`button ${videoSubButton ? 'active' : ''}`}>
{videoSubButton ? 'Active' : 'Deactive'}
</a>
</div>
<div className='options'>
<div className="left">
<span>Video Player:</span>
</div>
<a onClick={() => setExtensionSetting('videoPlayerButton', !videoPlayerButton)} className={`button ${videoPlayerButton ? 'active' : ''}`}>
{videoPlayerButton ? 'Active' : 'Deactive'}
</a>
</div>
<b className='filled'>Channel</b>
<div className='options'>
<div className="left">
<span>Subscribe Button:</span>
</div>
<a onClick={() => setExtensionSetting('channelSubButton', !channelSubButton)} className={`button ${channelSubButton ? 'active' : ''}`}>
{channelSubButton ? 'Active' : 'Deactive'}
</a>
</div>
</section>
}
<section> <section>
<label>Which platform you would like to redirect?</label> <label>Which platform you would like to redirect?</label>
<div className='options'> <div className='options'>

View file

@ -27,8 +27,14 @@ section>label {
text-align: center; text-align: center;
} }
section>.options { section>b {
padding: 0 1.5em; display: block;
width: 100%;
text-align: left;
}
section>* {
padding: 0 1rem;
} }
#popup { #popup {
@ -38,7 +44,14 @@ section>.options {
margin: auto; margin: auto;
} }
.purge-aaaaaaa { .center {
display: grid; display: grid;
justify-items: center; place-items: center;
}
.left {
display: grid;
justify-items: start;
align-items: center;
text-align: left;
} }

View file

@ -29,10 +29,10 @@ import { getExtensionSettingsAsync, getSourcePlatfromSettingsFromHostname, getTa
}) })
const buttonMountPoint = document.createElement('div') const buttonMountPoint = document.createElement('div')
buttonMountPoint.style.display = 'flex' buttonMountPoint.style.display = 'inline-flex'
const playerButtonMountPoint = document.createElement('div') const playerButtonMountPoint = document.createElement('div')
playerButtonMountPoint.style.display = 'flex' playerButtonMountPoint.style.display = 'inline-flex'
function WatchOnLbryButton({ source, target }: { source?: Source, target?: Target }) { function WatchOnLbryButton({ source, target }: { source?: Source, target?: Target }) {
if (!target || !source) return null if (!target || !source) return null
@ -118,26 +118,32 @@ import { getExtensionSettingsAsync, getSourcePlatfromSettingsFromHostname, getTa
return return
} }
const mountPlayerButtonBefore = params.source.platform.htmlQueries.mountPoints.mountPlayerButtonBefore ? {
document.querySelector(params.source.platform.htmlQueries.mountPoints.mountPlayerButtonBefore) : const mountPlayerButtonBefore = settings.videoPlayerButton ?
null document.querySelector(params.source.platform.htmlQueries.mountPoints.mountPlayerButtonBefore) :
if (!mountPlayerButtonBefore) render(<WatchOnLbryPlayerButton />, playerButtonMountPoint) null
else { if (!mountPlayerButtonBefore) render(<WatchOnLbryPlayerButton />, playerButtonMountPoint)
if (playerButtonMountPoint.getAttribute('data-id') !== params.source.id) { else {
mountPlayerButtonBefore.parentElement?.insertBefore(playerButtonMountPoint, mountPlayerButtonBefore) if (playerButtonMountPoint.getAttribute('data-id') !== params.source.id) {
playerButtonMountPoint.setAttribute('data-id', params.source.id) mountPlayerButtonBefore.parentElement?.insertBefore(playerButtonMountPoint, mountPlayerButtonBefore)
playerButtonMountPoint.setAttribute('data-id', params.source.id)
}
render(<WatchOnLbryPlayerButton target={params.target} source={params.source} />, playerButtonMountPoint)
} }
render(<WatchOnLbryPlayerButton target={params.target} source={params.source} />, playerButtonMountPoint)
} }
const mountButtonBefore = document.querySelector(params.source.platform.htmlQueries.mountPoints.mountButtonBefore[params.source.type]) {
if (!mountButtonBefore) render(<WatchOnLbryButton />, playerButtonMountPoint) const mountButtonBefore = settings[(`${params.source.type}SubButton`) as 'videoSubButton' | 'channelSubButton'] ?
else { document.querySelector(params.source.platform.htmlQueries.mountPoints.mountButtonBefore[params.source.type]) :
if (buttonMountPoint.getAttribute('data-id') !== params.source.id) { null
mountButtonBefore.parentElement?.insertBefore(buttonMountPoint, mountButtonBefore) if (!mountButtonBefore) render(<WatchOnLbryButton />, buttonMountPoint)
buttonMountPoint.setAttribute('data-id', params.source.id) else {
if (buttonMountPoint.getAttribute('data-id') !== params.source.id) {
mountButtonBefore.parentElement?.insertBefore(buttonMountPoint, mountButtonBefore)
buttonMountPoint.setAttribute('data-id', params.source.id)
}
render(<WatchOnLbryButton target={params.target} source={params.source} />, buttonMountPoint)
} }
render(<WatchOnLbryButton target={params.target} source={params.source} />, buttonMountPoint)
} }
} }

View file

@ -5,7 +5,10 @@ import type { ResolveUrlTypes } from "../modules/yt/urlResolve"
export interface ExtensionSettings { export interface ExtensionSettings {
redirect: boolean redirect: boolean
targetPlatform: TargetPlatformName targetPlatform: TargetPlatformName
urlResolver: YTUrlResolverName urlResolver: YTUrlResolverName,
videoSubButton: boolean
videoPlayerButton: boolean
channelSubButton: boolean
publicKey: string | null, publicKey: string | null,
privateKey: string | null privateKey: string | null
} }
@ -14,6 +17,9 @@ export const DEFAULT_SETTINGS: ExtensionSettings = {
redirect: true, redirect: true,
targetPlatform: 'odysee', targetPlatform: 'odysee',
urlResolver: 'odyseeApi', urlResolver: 'odyseeApi',
videoSubButton: true,
videoPlayerButton: true,
channelSubButton: true,
privateKey: null, privateKey: null,
publicKey: null publicKey: null
} }
@ -115,11 +121,11 @@ const sourcePlatform = (o: {
htmlQueries: { htmlQueries: {
mountPoints: { mountPoints: {
mountButtonBefore: Record<ResolveUrlTypes, string>, mountButtonBefore: Record<ResolveUrlTypes, string>,
mountPlayerButtonBefore: string | null, mountPlayerButtonBefore: string,
} }
videoPlayer: string, videoPlayer: string,
videoDescription: string videoDescription: string
channelLinks: string | null channelLinks: string
} }
}) => o }) => o
export type SourcePlatform = ReturnType<typeof sourcePlatform> export type SourcePlatform = ReturnType<typeof sourcePlatform>
@ -152,14 +158,14 @@ export const sourcePlatfromSettings = {
mountPoints: { mountPoints: {
mountButtonBefore: mountButtonBefore:
{ {
video: '#watch-on-youtube', video: '#subscribe',
channel: '#subscribe' channel: '#subscribe'
}, },
mountPlayerButtonBefore: null, mountPlayerButtonBefore: '#player-container ~ .h-box > h1 > a',
}, },
videoPlayer: '#player-container video', videoPlayer: '#player-container video',
videoDescription: '#descriptionWrapper', videoDescription: '#descriptionWrapper',
channelLinks: null channelLinks: '#descriptionWrapper'
} }
}) })
} }