Skip to content

Commit c8cf1d4

Browse files
Merge pull request #387 from TheBFL/main
Implement setting query from URL
2 parents 14995fa + 7b81ad9 commit c8cf1d4

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

message-index/index.html

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,5 +56,20 @@ <h2>The Messages</h2>
5656
if (input) {
5757
input.setAttribute("placeholder", "🔍 Type here to filter ...");
5858
input.focus();
59+
60+
//Autofill the search from the URL
61+
let url = new URL(document.location.href);
62+
let query = url.searchParams.get('q');
63+
if(query !== null)
64+
{
65+
input.setAttribute('value',query)
66+
//Move cursor to end
67+
input.setSelectionRange(query.length,query.length);
68+
69+
//Make sure that the list gets filtered as if the query had been typed manually
70+
input.dispatchEvent(new KeyboardEvent('keyup'));
71+
72+
}
5973
}
74+
6075
</script>

0 commit comments

Comments
 (0)