mirror of
https://github.com/Ranchero-Software/NetNewsWire.git
synced 2025-01-27 09:21:21 +01:00
Automatically loop and play Twitter animated gifs without video controls
This commit is contained in:
parent
198a5c29bf
commit
5338cd88fe
@ -36,8 +36,10 @@ struct TwitterExtendedMedia: Codable {
|
|||||||
switch type {
|
switch type {
|
||||||
case "photo":
|
case "photo":
|
||||||
html += renderPhotoAsHTML()
|
html += renderPhotoAsHTML()
|
||||||
case "video", "animated_gif":
|
case "video":
|
||||||
html += renderVideoAsHTML()
|
html += renderVideoAsHTML()
|
||||||
|
case "animated_gif":
|
||||||
|
html += renderAnimatedGIFAsHTML()
|
||||||
default:
|
default:
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
@ -74,6 +76,21 @@ private extension TwitterExtendedMedia {
|
|||||||
return html
|
return html
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func renderAnimatedGIFAsHTML() -> String {
|
||||||
|
guard let bestVariantURL = findBestVariant()?.url else { return "" }
|
||||||
|
|
||||||
|
var html = "<video class=\"nnwAnimatedGIF\" "
|
||||||
|
|
||||||
|
if let httpsMediaURL = httpsMediaURL {
|
||||||
|
html += "poster=\"\(httpsMediaURL)\" "
|
||||||
|
} else if let mediaURL = mediaURL {
|
||||||
|
html += "poster=\"\(mediaURL)\" "
|
||||||
|
}
|
||||||
|
|
||||||
|
html += "src=\"\(bestVariantURL)\" autoplay muted loop></video>"
|
||||||
|
return html
|
||||||
|
}
|
||||||
|
|
||||||
func findBestVariant() -> TwitterVideo.Variant? {
|
func findBestVariant() -> TwitterVideo.Variant? {
|
||||||
var best: TwitterVideo.Variant? = nil
|
var best: TwitterVideo.Variant? = nil
|
||||||
if let variants = video?.variants {
|
if let variants = video?.variants {
|
||||||
|
@ -53,7 +53,9 @@ function wrapTables() {
|
|||||||
function inlineVideos() {
|
function inlineVideos() {
|
||||||
document.querySelectorAll("video").forEach(element => {
|
document.querySelectorAll("video").forEach(element => {
|
||||||
element.setAttribute("playsinline", true)
|
element.setAttribute("playsinline", true)
|
||||||
element.setAttribute("controls", true)
|
if !element.classList.contains("nnwAnimatedGIF") {
|
||||||
|
element.setAttribute("controls", true)
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user