Skip to content

Commit

Permalink
Immediately copy hash to search box (closes #36)
Browse files Browse the repository at this point in the history
  • Loading branch information
haukex committed Oct 11, 2024
1 parent 882c2a2 commit edf2811
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/js/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,8 @@ window.addEventListener('DOMContentLoaded', async () => {
search_status.innerText = 'Showing a random entry.'
}

// Starts a search using a value in the URL hash, if any
const searchFromUrl = () => {
// Get search term from URL and copy it to the search box
const hashToSearchTerm = () => {
// query overrides hash (see GitHub Issue #7: some links to the app use '?' instead of '#')
if ( window.location.search.length > 1 ) {
const loc = new URL(''+window.location)
Expand All @@ -237,9 +237,14 @@ window.addEventListener('DOMContentLoaded', async () => {
console.warn('ignoring bad window.location.hash',error)
}
}
console.debug(`Search from URL for '${what}'`)
search_term.value = what
doSearch(what, false)
}

// Starts a search using a value in the URL hash, if any
const searchFromUrl = () => {
hashToSearchTerm()
console.debug(`Search from URL for '${search_term.value}'`)
doSearch(search_term.value, false)
}

// handler in case the worker does not get back to us with a search result
Expand Down Expand Up @@ -308,6 +313,7 @@ window.addEventListener('DOMContentLoaded', async () => {
initScrollTop()
initFlags()
initPopups()
hashToSearchTerm() // just updates the text box, actual search is later

// handler for dictionary load failures
const dictLoadFail = (message :string) => {
Expand Down

0 comments on commit edf2811

Please sign in to comment.