Skip to content

Commit

Permalink
Add custom overlay for YouTube iframes (#620)
Browse files Browse the repository at this point in the history
* Add custom overlay for YouTube iframes

* Refactor embed cleaner in JS
  • Loading branch information
jocmp authored Dec 22, 2024
1 parent b343b17 commit 491fbdd
Show file tree
Hide file tree
Showing 15 changed files with 321 additions and 13 deletions.
2 changes: 2 additions & 0 deletions app/src/main/java/com/capyreader/app/ui/components/WebView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,8 @@ class WebViewState(

scope.launch {
withContext(Dispatchers.IO) {


val html = renderer.render(
article,
hideImages = !showImages,
Expand Down
1 change: 1 addition & 0 deletions article_forge/Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ GEM

PLATFORMS
arm64-darwin-23
arm64-darwin-24
x86_64-linux

DEPENDENCIES
Expand Down
1 change: 1 addition & 0 deletions article_forge/articles.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,4 @@ def self.extracted_content
require "./articles/one_pezeshk"
require "./articles/secretclub"
require "./articles/andreyor"
require "./articles/androidauthority"
17 changes: 17 additions & 0 deletions article_forge/articles/androidauthority.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
require "json"

module Articles
class << self
def androidauthority
extracted = File.read("articles/fixtures/androidauthority.html")

Article.new(
title: "Samsung Galaxy S25 series rumors and leaks: Everything we know so far",
feed_name: "Android Authority",
external_link: "https://www.androidauthority.com/samsung-galaxy-s25-3437280/",
byline: nil,
body: extracted
)
end
end
end
35 changes: 35 additions & 0 deletions article_forge/articles/fixtures/androidauthority.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

106 changes: 106 additions & 0 deletions article_forge/public/assets/media.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions article_forge/public/assets/play-arrow.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
38 changes: 37 additions & 1 deletion article_forge/style/stylesheet.scss
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,39 @@ pre {
padding: 1em;
}

.iframe-embed {
display: block;
position: relative;
width: 100%;
border: 0;
border-radius: var(--corner-radius);

.iframe-embed__image {
width: 100%;
aspect-ratio: 16 / 9;
object-fit: cover;
border-radius: var(--corner-radius);
}

.iframe-embed__play-button {
background-color: rgba(0, 0, 0, 0.6);
backdrop-filter: blur(0.5em);
border-radius: 50%;
position: absolute;
left: 0;
right: 0;
bottom: 0;
top: 0;
margin: auto;
width: 4rem;
height: 4em !important;
background-image: url("/assets/play-arrow.svg");
background-repeat: no-repeat;
background-size: 3em;
background-position: center;
}
}

img,
figure,
video,
Expand All @@ -110,7 +143,10 @@ iframe {
max-width: 100%;
margin: 0 auto;

&[src*="youtube-nocookie.com"], &[src*="youtube.com"] {
&[src*="youtube-nocookie.com"],
&[src*="youtube.com"],
&[src*="youtu.be"] {
background-color: #000000;
width: 100%;
aspect-ratio: 16 / 9;
border: 0;
Expand Down
103 changes: 103 additions & 0 deletions capy/src/main/assets/media.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions capy/src/main/assets/play-arrow.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion capy/src/main/assets/stylesheet.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions capy/src/main/java/com/jocmp/capy/articles/ParseHTML.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,19 @@ fun parseHtml(article: Article, document: Document, hideImages: Boolean): String
extracted.id = "article-body-content"
extracted.innerHTML = article.content;
let hasEmbed = cleanEmbeds(extracted);
let shouldAddImage = article.lead_image_url &&
!hideImages &&
![...extracted.querySelectorAll("img")].some(img => img.src.includes(article.lead_image_url));
!hasEmbed &&
![...extracted.querySelectorAll("img")].some(img => img.src.includes(article.lead_image_url));
if (shouldAddImage) {
let leadImage = document.createElement("img");
leadImage.src = article.lead_image_url;
extracted.prepend(leadImage);
}
let content = document.getElementById("article-body-content");
content.replaceWith(extracted);
});
Expand Down
Loading

0 comments on commit 491fbdd

Please sign in to comment.