mirror of
https://github.com/LBRYFoundation/Watch-on-LBRY.git
synced 2025-08-23 17:47:26 +00:00
commit
f087d0d1e5
2 changed files with 38 additions and 23 deletions
|
@ -38,31 +38,37 @@ import { getExtensionSettingsAsync, getSourcePlatfromSettingsFromHostname, getTa
|
||||||
if (!target || !source) return null
|
if (!target || !source) return null
|
||||||
const url = getLbryUrlByTarget(target)
|
const url = getLbryUrlByTarget(target)
|
||||||
|
|
||||||
return <div style={{ display: 'flex', justifyContent: 'center', flexDirection: 'column' }}>
|
return <div
|
||||||
|
style={{
|
||||||
|
display: 'grid',
|
||||||
|
gridTemplateRows: '36px',
|
||||||
|
gridAutoColumns: 'auto',
|
||||||
|
alignContent: 'center'
|
||||||
|
}}
|
||||||
|
>
|
||||||
<a href={`${url.href}`} target={target.platform === targetPlatformSettings.app ? '' : '_blank'} role='button'
|
<a href={`${url.href}`} target={target.platform === targetPlatformSettings.app ? '' : '_blank'} role='button'
|
||||||
style={{
|
style={{
|
||||||
display: 'flex',
|
display: 'flex',
|
||||||
alignItems: 'center',
|
alignItems: 'center',
|
||||||
justifyContent: 'center',
|
gap: '7px',
|
||||||
gap: '12px',
|
|
||||||
borderRadius: '2px',
|
borderRadius: '2px',
|
||||||
backgroundColor: target.platform.theme,
|
padding: '0 16px',
|
||||||
backgroundImage: target.platform.theme,
|
margin: '0 4px',
|
||||||
|
|
||||||
fontWeight: 'bold',
|
fontWeight: 'bold',
|
||||||
border: '0',
|
border: '0',
|
||||||
color: 'whitesmoke',
|
color: 'whitesmoke',
|
||||||
padding: '10px 16px',
|
|
||||||
marginRight: source?.type === 'channel' ? '10px' : '4px',
|
|
||||||
fontSize: '14px',
|
fontSize: '14px',
|
||||||
textDecoration: 'none',
|
textDecoration: 'none',
|
||||||
|
backgroundColor: target.platform.theme,
|
||||||
|
backgroundImage: target.platform.theme,
|
||||||
...target.platform.button.style?.button,
|
...target.platform.button.style?.button,
|
||||||
}}
|
}}
|
||||||
onClick={() => findVideoElementAwait(source).then((videoElement) => {
|
onClick={() => findVideoElementAwait(source).then((videoElement) => {
|
||||||
videoElement.pause()
|
videoElement.pause()
|
||||||
})}
|
})}
|
||||||
>
|
>
|
||||||
<img src={target.platform.button.icon} height={16}
|
<img src={target.platform.button.icon} height={24} style={{ ...target.platform.button.style?.icon }} />
|
||||||
style={{ transform: 'scale(1.5)', ...target.platform.button.style?.icon }} />
|
|
||||||
<span>{target.type === 'channel' ? 'Channel on' : 'Watch on'} {target.platform.button.platformNameText}</span>
|
<span>{target.type === 'channel' ? 'Channel on' : 'Watch on'} {target.platform.button.platformNameText}</span>
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
|
@ -72,17 +78,25 @@ import { getExtensionSettingsAsync, getSourcePlatfromSettingsFromHostname, getTa
|
||||||
if (!target || !source) return null
|
if (!target || !source) return null
|
||||||
const url = getLbryUrlByTarget(target)
|
const url = getLbryUrlByTarget(target)
|
||||||
|
|
||||||
return <div style={{ display: 'flex', justifyContent: 'center', flexDirection: 'column' }}>
|
return <div
|
||||||
|
style={{
|
||||||
|
display: 'grid',
|
||||||
|
gridTemplateRows: '36px',
|
||||||
|
gridAutoColumns: 'auto',
|
||||||
|
alignContent: 'center'
|
||||||
|
}}
|
||||||
|
>
|
||||||
<a href={`${url.href}`} target={target.platform === targetPlatformSettings.app ? '' : '_blank'} role='button'
|
<a href={`${url.href}`} target={target.platform === targetPlatformSettings.app ? '' : '_blank'} role='button'
|
||||||
style={{
|
style={{
|
||||||
display: 'flex',
|
display: 'flex',
|
||||||
alignItems: 'center',
|
alignItems: 'center',
|
||||||
justifyContent: 'center',
|
gap: '7px',
|
||||||
gap: '12px',
|
borderRadius: '2px',
|
||||||
|
paddingRight: '10px',
|
||||||
|
|
||||||
fontWeight: 'bold',
|
fontWeight: 'bold',
|
||||||
border: '0',
|
border: '0',
|
||||||
color: 'whitesmoke',
|
color: 'whitesmoke',
|
||||||
marginRight: '10px',
|
|
||||||
fontSize: '14px',
|
fontSize: '14px',
|
||||||
textDecoration: 'none',
|
textDecoration: 'none',
|
||||||
...target.platform.button.style?.button,
|
...target.platform.button.style?.button,
|
||||||
|
@ -91,8 +105,7 @@ import { getExtensionSettingsAsync, getSourcePlatfromSettingsFromHostname, getTa
|
||||||
videoElement.pause()
|
videoElement.pause()
|
||||||
})}
|
})}
|
||||||
>
|
>
|
||||||
<img src={target.platform.button.icon} height={16}
|
<img src={target.platform.button.icon} height={24} style={{ ...target.platform.button.style?.icon }} />
|
||||||
style={{ transform: 'scale(1.5)', ...target.platform.button.style?.icon }} />
|
|
||||||
<span>{target.type === 'channel' ? 'Channel on' : 'Watch on'} {target.platform.button.platformNameText}</span>
|
<span>{target.type === 'channel' ? 'Channel on' : 'Watch on'} {target.platform.button.platformNameText}</span>
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
|
@ -110,16 +123,20 @@ import { getExtensionSettingsAsync, getSourcePlatfromSettingsFromHostname, getTa
|
||||||
null
|
null
|
||||||
if (!mountPlayerButtonBefore) render(<WatchOnLbryPlayerButton />, playerButtonMountPoint)
|
if (!mountPlayerButtonBefore) render(<WatchOnLbryPlayerButton />, playerButtonMountPoint)
|
||||||
else {
|
else {
|
||||||
if (mountPlayerButtonBefore.previousSibling !== playerButtonMountPoint)
|
if (playerButtonMountPoint.getAttribute('data-id') !== params.source.id) {
|
||||||
mountPlayerButtonBefore.parentElement?.insertBefore(playerButtonMountPoint, mountPlayerButtonBefore)
|
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])
|
const mountButtonBefore = document.querySelector(params.source.platform.htmlQueries.mountPoints.mountButtonBefore[params.source.type])
|
||||||
if (!mountButtonBefore) render(<WatchOnLbryButton />, playerButtonMountPoint)
|
if (!mountButtonBefore) render(<WatchOnLbryButton />, playerButtonMountPoint)
|
||||||
else {
|
else {
|
||||||
if (mountButtonBefore.previousSibling !== buttonMountPoint)
|
if (buttonMountPoint.getAttribute('data-id') !== params.source.id) {
|
||||||
mountButtonBefore.parentElement?.insertBefore(buttonMountPoint, mountButtonBefore)
|
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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -174,7 +191,7 @@ import { getExtensionSettingsAsync, getSourcePlatfromSettingsFromHostname, getTa
|
||||||
const params: Parameters<typeof requestResolveById>[0] = sources.map((source) => ({ id: source.id, type: source.type }))
|
const params: Parameters<typeof requestResolveById>[0] = sources.map((source) => ({ id: source.id, type: source.type }))
|
||||||
const platform = targetPlatformSettings[settings.targetPlatform]
|
const platform = targetPlatformSettings[settings.targetPlatform]
|
||||||
|
|
||||||
const results = await requestResolveById(params)
|
const results = await requestResolveById(params) ?? []
|
||||||
const targets: Record<string, Target | null> = Object.fromEntries(
|
const targets: Record<string, Target | null> = Object.fromEntries(
|
||||||
sources.map((source) => {
|
sources.map((source) => {
|
||||||
const result = results[source.id]
|
const result = results[source.id]
|
||||||
|
@ -259,8 +276,6 @@ import { getExtensionSettingsAsync, getSourcePlatfromSettingsFromHostname, getTa
|
||||||
document.querySelector(source.platform.htmlQueries.videoDescription) :
|
document.querySelector(source.platform.htmlQueries.videoDescription) :
|
||||||
source.platform.htmlQueries.channelLinks ? document.querySelector(source.platform.htmlQueries.channelLinks) : null
|
source.platform.htmlQueries.channelLinks ? document.querySelector(source.platform.htmlQueries.channelLinks) : null
|
||||||
|
|
||||||
console.log(linksContainer)
|
|
||||||
|
|
||||||
if (linksContainer) {
|
if (linksContainer) {
|
||||||
const anchors = Array.from(linksContainer.querySelectorAll<HTMLAnchorElement>('a'))
|
const anchors = Array.from(linksContainer.querySelectorAll<HTMLAnchorElement>('a'))
|
||||||
|
|
||||||
|
|
|
@ -84,7 +84,7 @@ export const targetPlatformSettings = {
|
||||||
icon: chrome.runtime.getURL('assets/icons/lbry/madiator-logo.svg'),
|
icon: chrome.runtime.getURL('assets/icons/lbry/madiator-logo.svg'),
|
||||||
style: {
|
style: {
|
||||||
button: { flexDirection: 'row-reverse' },
|
button: { flexDirection: 'row-reverse' },
|
||||||
icon: { transform: 'scale(1.2)' }
|
icon: { }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
|
@ -137,9 +137,9 @@ export const sourcePlatfromSettings = {
|
||||||
mountPoints: {
|
mountPoints: {
|
||||||
mountButtonBefore: {
|
mountButtonBefore: {
|
||||||
video: 'ytd-video-owner-renderer~#subscribe-button',
|
video: 'ytd-video-owner-renderer~#subscribe-button',
|
||||||
channel: '#channel-header-container #buttons'
|
channel: '#channel-header-container #buttons #subscribe-button'
|
||||||
},
|
},
|
||||||
mountPlayerButtonBefore: 'ytd-player .ytp-right-controls',
|
mountPlayerButtonBefore: 'ytd-watch-flexy ytd-player .ytp-right-controls',
|
||||||
},
|
},
|
||||||
videoPlayer: '#ytd-player video',
|
videoPlayer: '#ytd-player video',
|
||||||
videoDescription: 'ytd-video-secondary-info-renderer #description',
|
videoDescription: 'ytd-video-secondary-info-renderer #description',
|
||||||
|
|
Loading…
Add table
Reference in a new issue