update dependencies and add downloads page, various fixes
This commit is contained in:
@@ -69,31 +69,72 @@
|
||||
}
|
||||
}
|
||||
|
||||
function buildDesktopMpvUrl(url, title) {
|
||||
function buildIntentStringExtra(key, value) {
|
||||
const trimmed = (value || '').trim()
|
||||
if (!trimmed) return ''
|
||||
return `;S.${key}=${encodeURIComponent(trimmed)}`
|
||||
}
|
||||
|
||||
function isUsableTitle(title, url) {
|
||||
const trimmed = (title || '').trim()
|
||||
if (!trimmed) return false
|
||||
if (trimmed === url) return false
|
||||
if (/^https?:\/\//i.test(trimmed)) return false
|
||||
return true
|
||||
}
|
||||
|
||||
function extractFallbackTitle(url) {
|
||||
try {
|
||||
const parsed = new URL(url, location.href)
|
||||
const hydrusFileId = parsed.searchParams.get('file_id')
|
||||
if (hydrusFileId) return `Hydrus File ${hydrusFileId}`
|
||||
|
||||
const segments = parsed.pathname.split('/').filter(Boolean)
|
||||
const lastSegment = segments[segments.length - 1]
|
||||
return lastSegment ? decodeURIComponent(lastSegment) : 'Media'
|
||||
} catch {
|
||||
return 'Media'
|
||||
}
|
||||
}
|
||||
|
||||
function buildMediaMetadata(url, element) {
|
||||
const candidates = [
|
||||
element?.getAttribute?.('data-title') || '',
|
||||
element?.getAttribute?.('title') || '',
|
||||
element?.getAttribute?.('aria-label') || '',
|
||||
element?.textContent || '',
|
||||
document.title || '',
|
||||
]
|
||||
|
||||
const title = candidates.find((candidate) => isUsableTitle(candidate, url)) || extractFallbackTitle(url)
|
||||
return { title }
|
||||
}
|
||||
|
||||
function buildDesktopMpvUrl(url, metadata) {
|
||||
const encodedUrl = encodeUrlSafeBase64(url)
|
||||
const encodedTitle = title ? encodeUrlSafeBase64(title) : ''
|
||||
const encodedTitle = metadata.title ? encodeUrlSafeBase64(metadata.title) : ''
|
||||
const query = encodedTitle ? `?v_title=${encodedTitle}` : ''
|
||||
return `mpv-handler://play/${encodedUrl}/${query}`
|
||||
}
|
||||
|
||||
function buildAndroidMpvUrl(url, element) {
|
||||
function buildAndroidMpvUrl(url, element, metadata) {
|
||||
try {
|
||||
const parsed = new URL(url, location.href)
|
||||
const scheme = parsed.protocol.replace(':', '') || 'https'
|
||||
const intentPath = `${parsed.host}${parsed.pathname}${parsed.search}`
|
||||
const mimeType = looksLikeVideo(url, element) ? 'video/*' : 'audio/*'
|
||||
return `intent://${intentPath}#Intent;scheme=${scheme};package=is.xyz.mpv;action=android.intent.action.VIEW;type=${mimeType};end`
|
||||
return `intent://${intentPath}#Intent;scheme=${scheme};package=is.xyz.mpv;action=android.intent.action.VIEW;type=${mimeType}${buildIntentStringExtra('title', metadata.title)};end`
|
||||
} catch {
|
||||
return url
|
||||
}
|
||||
}
|
||||
|
||||
function buildExternalPlayerUrl(url, title, element) {
|
||||
function buildExternalPlayerUrl(url, metadata, element) {
|
||||
if (/Android/i.test(navigator.userAgent || '')) {
|
||||
return buildAndroidMpvUrl(url, element)
|
||||
return buildAndroidMpvUrl(url, element, metadata)
|
||||
}
|
||||
|
||||
return buildDesktopMpvUrl(url, title)
|
||||
return buildDesktopMpvUrl(url, metadata)
|
||||
}
|
||||
|
||||
function openInExternalPlayer(url, element) {
|
||||
@@ -105,8 +146,8 @@
|
||||
lastOpenedUrl = url
|
||||
lastOpenedAt = now
|
||||
|
||||
const title = document.title || ''
|
||||
const targetUrl = buildExternalPlayerUrl(url, title, element)
|
||||
const metadata = buildMediaMetadata(url, element)
|
||||
const targetUrl = buildExternalPlayerUrl(url, metadata, element)
|
||||
location.assign(targetUrl)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user