diff --git a/assets/js/handlers.js b/assets/js/handlers.js index 1498f39a..a417fcca 100644 --- a/assets/js/handlers.js +++ b/assets/js/handlers.js @@ -142,4 +142,16 @@ var csrf_token = target.parentNode.querySelector('input[name="csrf_token"]').value; xhr.send('csrf_token=' + csrf_token); } + + // Handle keypresses + window.addEventListener('keydown', (event) => { + // Ignore modifier keys + if (event.ctrlKey || event.metaKey) { return; } + + // Focus search bar on '/' + if (event.key == "/") { + document.getElementById('searchbox').focus(); + event.preventDefault(); + } + }); })(); diff --git a/src/invidious/views/components/search_box.ecr b/src/invidious/views/components/search_box.ecr index 4144d161..1240e5bd 100644 --- a/src/invidious/views/components/search_box.ecr +++ b/src/invidious/views/components/search_box.ecr @@ -1,8 +1,8 @@
" + autocapitalize="none" spellcheck="false" <% if autofocus %>autofocus<% end %> + name="q" placeholder="<%= translate(locale, "search") %>" 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 45561d1e..2424a1cf 100644 --- a/src/invidious/views/search_homepage.ecr +++ b/src/invidious/views/search_homepage.ecr @@ -14,7 +14,7 @@
diff --git a/src/invidious/views/template.ecr b/src/invidious/views/template.ecr index efa434bf..240b523a 100644 --- a/src/invidious/views/template.ecr +++ b/src/invidious/views/template.ecr @@ -35,7 +35,7 @@ Invidious <% end %>