haukex / de-en-dict

German-English Dictionary
https://dict.zero-g.net/
GNU General Public License v2.0
12 stars 2 forks source link

Enable search via URL hash, and update browser history when searching #1

Closed orrc closed 4 months ago

orrc commented 4 months ago

Hi there!

As a long-term user of the Beolingus dictionary, I was sad to learn today that it has been taken offline.

However, I was happy to find that they recommended this simple, modern and speedy open source project as a replacement. Thank you!

I have always accessed Beolingus via a browser search shortcut (e.g. https://dict.tu-chemnitz.de/dings.cgi?…&query=%s). But with this web app, I noticed that it's not possible to pass in the search term via the URL, so I can't create a similar shortcut.

Therefore I added the ability to specify a search term via URL hash (e.g. https://example.com/#q=beispiel) — specifically using a URL hash rather than a query parameter, so that the search term doesn't get sent to the server hosting this webapp.

Furthermore, I update the URL hash when the input field changes, so you can follow your browser history of searched words. To make that history and navigation a bit nicer, the search term is also now appended to the page title.

Hopefully this seems useful, and you're open to PRs! If so, I could also add a note about this functionality on the index page to help users. Though it should also become clear that the URL updates when users start entering search terms.

Screenshot:

image
haukex commented 4 months ago

Very nice, thank you very much! I added a small tweak in f622bc7eb95f28e9cf38b7520825f397d881c0c6 .

orrc commented 4 months ago

Amazing, thanks very much! ❤️