Added Search Engine config to config.json

This commit is contained in:
Haider Ali Punjabi
2020-05-14 11:22:21 +05:30
parent 3226072a53
commit d4bcb6f4c0
3 changed files with 18 additions and 6 deletions

View File

@@ -29,6 +29,13 @@
]
}
],
"searchEngines":{
"Google":"https://www.google.com/search?q=",
"DuckDuckGo":"https://duckduckgo.com/?q=",
"Bing":"https://www.bing.com/search?q=",
"Yahoo":"https://search.yahoo.com/search?p="
},
"searchEngine":"Google",
"user": "Deepjyoti",
"disableMessage": false,
"disableDate": false,

View File

@@ -16,7 +16,7 @@
<h2 id="date-text"></h2>
</div>
<div id="search-bar">
<input id="search-bar-input" placeholder="Search something on Google"></input>
<input id="search-bar-input"></input>
</div>
<div id="other-content">
</div>

View File

@@ -47,18 +47,23 @@ function initBody() {
json = readJSON("config.json")
}
function initSearchBar() {
function initSearchBar(jsonData) {
// Clear the search bar on load, just in case
document.getElementById(searchBarId).value = ""
document.getElementById(searchBarId).focus()
searchEngine = jsonData["searchEngine"]
if(!Object.keys(jsonData["searchEngines"]).includes(searchEngine)){
searchEngine = "Google"
}
searchUrl = jsonData["searchEngines"][searchEngine]
document.getElementById(searchBarId).placeholder = `Search something on ${searchEngine}`
document.getElementById(searchBarId).addEventListener("keypress", (event) => {
if (event.key != 'Enter') return
// Open google with the search results.
googleSearchUrl = "https://www.google.com/search?q="
query = document.getElementById(searchBarId).value.replace(/\ /g, "+")
document.location = googleSearchUrl + query
document.location = searchUrl + query
})
}
@@ -150,7 +155,7 @@ function parseAndCreate(jsonData) {
if (jsonData["disableSearchBar"])
document.getElementById(searchBarDivId).style.display = "none"
else
initSearchBar()
initSearchBar(jsonData)
sqrs = jsonData["squares"]