From 68cbc11810fd746a776f6b8fefd61cec89ac9b55 Mon Sep 17 00:00:00 2001 From: Samantaz Fox Date: Tue, 7 Dec 2021 04:30:05 +0100 Subject: [PATCH 1/6] Fix the search box Fix #277 : autoselect search field Fix #1107: no spell checking/auto-correct on search field --- assets/css/default.css | 34 ++++++++----------- src/invidious/views/components/search_box.ecr | 9 +++++ src/invidious/views/search_homepage.ecr | 6 +--- src/invidious/views/template.ecr | 6 +--- 4 files changed, 25 insertions(+), 30 deletions(-) create mode 100644 src/invidious/views/components/search_box.ecr diff --git a/assets/css/default.css b/assets/css/default.css index 95c1f55c..2cda980c 100644 --- a/assets/css/default.css +++ b/assets/css/default.css @@ -192,20 +192,24 @@ img.thumbnail { display: inline; } -.searchbar .pure-form input[type="search"] { - margin-bottom: 1px; +.searchbar .pure-form fieldset { padding: 0; } - border-top: 0; - border-left: 0; - border-right: 0; - border-bottom: 1px solid #ccc; - border-radius: 0; +.searchbar input[type="search"] { + width: 100%; + margin: 1px; - padding: initial 0; + border: 1px solid; + border-color: #0000 #0000 #CCC #0000; + border-radius: 0; - box-shadow: none; + box-shadow: none; + -webkit-appearance: none; +} - -webkit-appearance: none; +.searchbar input[type="search"]:focus { + margin: 0 0 0.5px 0; + border: 2px solid; + border-color: #0000 #0000 #FED #0000; } /* https://stackoverflow.com/a/55170420 */ @@ -217,16 +221,6 @@ input[type="search"]::-webkit-search-cancel-button { background-size: 14px; } -.searchbar .pure-form fieldset { - padding: 0; -} - -/* attract focus to the searchbar by adding a subtle transition */ -.searchbar .pure-form input[type="search"]:focus { - margin-bottom: 0px; - border-bottom: 2px solid #aaa; -} - .user-field { display: flex; flex-direction: row; diff --git a/src/invidious/views/components/search_box.ecr b/src/invidious/views/components/search_box.ecr new file mode 100644 index 00000000..4144d161 --- /dev/null +++ b/src/invidious/views/components/search_box.ecr @@ -0,0 +1,9 @@ +
+
+ " + title="<%= translate(locale, "search") %>" + value="<%= env.get?("search").try {|x| HTML.escape(x.as(String)) } %>"> +
+
diff --git a/src/invidious/views/search_homepage.ecr b/src/invidious/views/search_homepage.ecr index 7d2dab83..45561d1e 100644 --- a/src/invidious/views/search_homepage.ecr +++ b/src/invidious/views/search_homepage.ecr @@ -14,11 +14,7 @@
diff --git a/src/invidious/views/template.ecr b/src/invidious/views/template.ecr index 5b6e6ab8..efa434bf 100644 --- a/src/invidious/views/template.ecr +++ b/src/invidious/views/template.ecr @@ -35,11 +35,7 @@ Invidious <% end %> From 1769b0fdcebbbd6a42deb49d5e8ee7150d8b2d25 Mon Sep 17 00:00:00 2001 From: Samantaz Fox Date: Tue, 7 Dec 2021 04:55:14 +0100 Subject: [PATCH 2/6] Fix "video can't be added to playlist without JS" Fixes #2686 --- src/invidious/views/watch.ecr | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/invidious/views/watch.ecr b/src/invidious/views/watch.ecr index b85ea59d..52262df7 100644 --- a/src/invidious/views/watch.ecr +++ b/src/invidious/views/watch.ecr @@ -140,7 +140,7 @@ we're going to need to do it here in order to allow for translations. <% if user %> <% playlists = PG_DB.query_all("SELECT id,title FROM playlists WHERE author = $1 AND id LIKE 'IV%'", user.email, as: {String, String}) %> <% if !playlists.empty? %> -
+
+ "> + + From 6c8a5a1e7f5ab33fd4f5f4ab9c251af0aac563de Mon Sep 17 00:00:00 2001 From: Samantaz Fox Date: Tue, 7 Dec 2021 05:40:19 +0100 Subject: [PATCH 3/6] Fix leading spaces being collapsed in descriptions Fixes #1954 --- assets/css/default.css | 3 ++- src/invidious/channels/about.cr | 4 ++-- src/invidious/comments.cr | 4 ++-- src/invidious/playlists.cr | 2 +- src/invidious/videos.cr | 2 +- src/invidious/views/playlist.ecr | 4 +--- src/invidious/views/watch.ecr | 8 ++------ 7 files changed, 11 insertions(+), 16 deletions(-) diff --git a/assets/css/default.css b/assets/css/default.css index 2cda980c..8b2b3578 100644 --- a/assets/css/default.css +++ b/assets/css/default.css @@ -540,7 +540,8 @@ p, } #descriptionWrapper { - max-width: 600px; + max-width: 600px; + white-space: pre-wrap; } /* Center the "invidious" logo on the search page */ diff --git a/src/invidious/channels/about.cr b/src/invidious/channels/about.cr index c87c53e0..d93ee681 100644 --- a/src/invidious/channels/about.cr +++ b/src/invidious/channels/about.cr @@ -59,7 +59,7 @@ def get_about_info(ucid, locale) banner = banners.try &.[-1]?.try &.["url"].as_s? description = initdata["header"]["interactiveTabbedHeaderRenderer"]["description"]["simpleText"].as_s - description_html = HTML.escape(description).gsub("\n", "
") + description_html = HTML.escape(description) is_family_friendly = initdata["microformat"]["microformatDataRenderer"]["familySafe"].as_bool allowed_regions = initdata["microformat"]["microformatDataRenderer"]["availableCountries"].as_a.map(&.as_s) @@ -81,7 +81,7 @@ def get_about_info(ucid, locale) # end description = initdata["metadata"]["channelMetadataRenderer"]?.try &.["description"]?.try &.as_s? || "" - description_html = HTML.escape(description).gsub("\n", "
") + description_html = HTML.escape(description) is_family_friendly = initdata["microformat"]["microformatDataRenderer"]["familySafe"].as_bool allowed_regions = initdata["microformat"]["microformatDataRenderer"]["availableCountries"].as_a.map(&.as_s) diff --git a/src/invidious/comments.cr b/src/invidious/comments.cr index 12a80bc4..5b7d63e0 100644 --- a/src/invidious/comments.cr +++ b/src/invidious/comments.cr @@ -550,12 +550,12 @@ end def parse_content(content : JSON::Any) : String content["simpleText"]?.try &.as_s.rchop('\ufeff').try { |b| HTML.escape(b) }.to_s || - content["runs"]?.try &.as_a.try { |r| content_to_comment_html(r).try &.to_s } || "" + content["runs"]?.try &.as_a.try { |r| content_to_comment_html(r).try &.to_s.gsub("\n", "
") } || "" end def content_to_comment_html(content) comment_html = content.map do |run| - text = HTML.escape(run["text"].as_s).gsub("\n", "
") + text = HTML.escape(run["text"].as_s) if run["bold"]? text = "#{text}" diff --git a/src/invidious/playlists.cr b/src/invidious/playlists.cr index f37667b5..fc41ecd2 100644 --- a/src/invidious/playlists.cr +++ b/src/invidious/playlists.cr @@ -242,7 +242,7 @@ struct InvidiousPlaylist end def description_html - HTML.escape(self.description).gsub("\n", "
") + HTML.escape(self.description) end end diff --git a/src/invidious/videos.cr b/src/invidious/videos.cr index d4ef0900..b1c60947 100644 --- a/src/invidious/videos.cr +++ b/src/invidious/videos.cr @@ -945,7 +945,7 @@ def extract_video_info(video_id : String, proxy_region : String? = nil, context_ # Description description_html = video_secondary_renderer.try &.dig?("description", "runs") - .try &.as_a.try { |t| content_to_comment_html(t).gsub("\n", "
") } + .try &.as_a.try { |t| content_to_comment_html(t) } params["descriptionHtml"] = JSON::Any.new(description_html || "

") diff --git a/src/invidious/views/playlist.ecr b/src/invidious/views/playlist.ecr index 136981da..dd918404 100644 --- a/src/invidious/views/playlist.ecr +++ b/src/invidious/views/playlist.ecr @@ -74,9 +74,7 @@
-
-

<%= playlist.description_html %>

-
+
<%= playlist.description_html %>
<% if playlist.is_a?(InvidiousPlaylist) && playlist.author == user.try &.email %> diff --git a/src/invidious/views/watch.ecr b/src/invidious/views/watch.ecr index 52262df7..11e738ab 100644 --- a/src/invidious/views/watch.ecr +++ b/src/invidious/views/watch.ecr @@ -257,14 +257,10 @@ we're going to need to do it here in order to allow for translations.
<% if video.description.size < 200 || params.extend_desc %> -
- <%= video.description_html %> -
+
<%= video.description_html %>
<% else %> -
- <%= video.description_html %> -
+
<%= video.description_html %>
From 3b1a2862907ed5a567db9aad6180cad730f590ac Mon Sep 17 00:00:00 2001 From: Samantaz Fox Date: Wed, 8 Dec 2021 01:38:09 +0100 Subject: [PATCH 4/6] Use dig?() for playlist title --- src/invidious/playlists.cr | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/invidious/playlists.cr b/src/invidious/playlists.cr index fc41ecd2..1a8c2adc 100644 --- a/src/invidious/playlists.cr +++ b/src/invidious/playlists.cr @@ -352,7 +352,7 @@ def fetch_playlist(plid, locale) playlist_info = playlist_sidebar_renderer[0]["playlistSidebarPrimaryInfoRenderer"]? raise InfoException.new("Could not extract playlist info") if !playlist_info - title = playlist_info["title"]?.try &.["runs"][0]?.try &.["text"]?.try &.as_s || "" + title = playlist_info.dig?("title", "runs", 0, "text").try &.as_s || "" desc_item = playlist_info["description"]? From 444b1c99d0a0c69b6dc60559ef6b1647984623ab Mon Sep 17 00:00:00 2001 From: Samantaz Fox Date: Wed, 5 Jan 2022 02:43:17 +0100 Subject: [PATCH 5/6] Show unavailable videos in playlists --- spec/helpers_spec.cr | 6 +++--- src/invidious/playlists.cr | 14 ++++++-------- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/spec/helpers_spec.cr b/spec/helpers_spec.cr index 4215b2bd..c1592048 100644 --- a/spec/helpers_spec.cr +++ b/spec/helpers_spec.cr @@ -43,11 +43,11 @@ describe "Helper" do describe "#produce_playlist_continuation" do it "correctly produces ctoken for requesting index `x` of a playlist" do - produce_playlist_continuation("UUCla9fZca4I7KagBtgRGnOw", 100).should eq("4qmFsgJNEhpWTFVVQ2xhOWZaY2E0STdLYWdCdGdSR25PdxoUQ0FGNkJsQlVPa05IVVElM0QlM0SaAhhVVUNsYTlmWmNhNEk3S2FnQnRnUkduT3c%3D") + produce_playlist_continuation("UUCla9fZca4I7KagBtgRGnOw", 100).should eq("4qmFsgJNEhpWTFVVQ2xhOWZaY2E0STdLYWdCdGdSR25PdxoUQ0FGNkJsQlVPa05CUmNJR0FnZ0GaAhhVVUNsYTlmWmNhNEk3S2FnQnRnUkduT3c%3D") - produce_playlist_continuation("UCCla9fZca4I7KagBtgRGnOw", 200).should eq("4qmFsgJLEhpWTFVVQ2xhOWZaY2E0STdLYWdCdGdSR25PdxoSQ0FKNkIxQlVPa05OWjBJJTNEmgIYVVVDbGE5ZlpjYTRJN0thZ0J0Z1JHbk93") + produce_playlist_continuation("UCCla9fZca4I7KagBtgRGnOw", 200).should eq("4qmFsgJNEhpWTFVDQ2xhOWZaY2E0STdLYWdCdGdSR25PdxoUQ0FGNkJsQlVPa05CU2NJR0FnZ0GaAhhVQ0NsYTlmWmNhNEk3S2FnQnRnUkduT3c%3D") - produce_playlist_continuation("PL55713C70BA91BD6E", 100).should eq("4qmFsgJBEhRWTFBMNTU3MTNDNzBCQTkxQkQ2RRoUQ0FGNkJsQlVPa05IVVElM0QlM0SaAhJQTDU1NzEzQzcwQkE5MUJENkU%3D") + produce_playlist_continuation("PL55713C70BA91BD6E", 100).should eq("4qmFsgJDEhRWTFBMNTU3MTNDNzBCQTkxQkQ2RRoUQ0FGNkJsQlVPa05CUmNJR0FnZ0GaAhRVQ1BMNTU3MTNDNzBCQTkxQkQ2RQ%3D%3D") end end diff --git a/src/invidious/playlists.cr b/src/invidious/playlists.cr index 1a8c2adc..e40be974 100644 --- a/src/invidious/playlists.cr +++ b/src/invidious/playlists.cr @@ -305,16 +305,14 @@ def produce_playlist_continuation(id, index) .try { |i| Protodec::Any.from_json(i) } .try { |i| Base64.urlsafe_encode(i, padding: false) } - data_wrapper = {"1:varint" => request_count, "15:string" => "PT:#{data}"} - .try { |i| Protodec::Any.cast_json(i) } - .try { |i| Protodec::Any.from_json(i) } - .try { |i| Base64.urlsafe_encode(i) } - .try { |i| URI.encode_www_form(i) } - object = { "80226972:embedded" => { - "2:string" => plid, - "3:string" => data_wrapper, + "2:string" => plid, + "3:base64" => { + "1:varint" => request_count, + "15:string" => "PT:#{data}", + "104:embedded" => {"1:0:varint" => 0_i64}, + }, "35:string" => id, }, } From db04f1556edd652b2823cb7b643cba8c6ef3f6df Mon Sep 17 00:00:00 2001 From: Samantaz Fox Date: Wed, 5 Jan 2022 03:42:41 +0100 Subject: [PATCH 6/6] Remove spec for playlist continuation --- spec/helpers_spec.cr | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/spec/helpers_spec.cr b/spec/helpers_spec.cr index c1592048..3319252f 100644 --- a/spec/helpers_spec.cr +++ b/spec/helpers_spec.cr @@ -41,16 +41,6 @@ describe "Helper" do end end - describe "#produce_playlist_continuation" do - it "correctly produces ctoken for requesting index `x` of a playlist" do - produce_playlist_continuation("UUCla9fZca4I7KagBtgRGnOw", 100).should eq("4qmFsgJNEhpWTFVVQ2xhOWZaY2E0STdLYWdCdGdSR25PdxoUQ0FGNkJsQlVPa05CUmNJR0FnZ0GaAhhVVUNsYTlmWmNhNEk3S2FnQnRnUkduT3c%3D") - - produce_playlist_continuation("UCCla9fZca4I7KagBtgRGnOw", 200).should eq("4qmFsgJNEhpWTFVDQ2xhOWZaY2E0STdLYWdCdGdSR25PdxoUQ0FGNkJsQlVPa05CU2NJR0FnZ0GaAhhVQ0NsYTlmWmNhNEk3S2FnQnRnUkduT3c%3D") - - produce_playlist_continuation("PL55713C70BA91BD6E", 100).should eq("4qmFsgJDEhRWTFBMNTU3MTNDNzBCQTkxQkQ2RRoUQ0FGNkJsQlVPa05CUmNJR0FnZ0GaAhRVQ1BMNTU3MTNDNzBCQTkxQkQ2RQ%3D%3D") - end - end - describe "#produce_search_params" do it "correctly produces token for searching with specified filters" do produce_search_params.should eq("CAASAhABSAA%3D")