Added Search Engine config to config.json
This commit is contained in:
@@ -29,10 +29,13 @@
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"searchEngine":{
|
"searchEngines":{
|
||||||
"name": "Google",
|
"Google":"https://www.google.com/search?q=",
|
||||||
"searchUrl": "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",
|
"user": "Deepjyoti",
|
||||||
"disableMessage": false,
|
"disableMessage": false,
|
||||||
"disableDate": false,
|
"disableDate": false,
|
||||||
|
|||||||
12
js/main.js
12
js/main.js
@@ -47,16 +47,20 @@ function initBody() {
|
|||||||
json = readJSON("config.json")
|
json = readJSON("config.json")
|
||||||
}
|
}
|
||||||
|
|
||||||
function initSearchBar(config) {
|
function initSearchBar(jsonData) {
|
||||||
// Clear the search bar on load, just in case
|
// Clear the search bar on load, just in case
|
||||||
document.getElementById(searchBarId).value = ""
|
document.getElementById(searchBarId).value = ""
|
||||||
document.getElementById(searchBarId).focus()
|
document.getElementById(searchBarId).focus()
|
||||||
document.getElementById(searchBarId).placeholder = `Search something on ${config["name"]}`
|
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) => {
|
document.getElementById(searchBarId).addEventListener("keypress", (event) => {
|
||||||
if (event.key != 'Enter') return
|
if (event.key != 'Enter') return
|
||||||
|
|
||||||
// Open google with the search results.
|
// Open google with the search results.
|
||||||
searchUrl = config["searchUrl"]
|
|
||||||
query = document.getElementById(searchBarId).value.replace(/\ /g, "+")
|
query = document.getElementById(searchBarId).value.replace(/\ /g, "+")
|
||||||
document.location = searchUrl + query
|
document.location = searchUrl + query
|
||||||
})
|
})
|
||||||
@@ -150,7 +154,7 @@ function parseAndCreate(jsonData) {
|
|||||||
if (jsonData["disableSearchBar"])
|
if (jsonData["disableSearchBar"])
|
||||||
document.getElementById(searchBarDivId).style.display = "none"
|
document.getElementById(searchBarDivId).style.display = "none"
|
||||||
else
|
else
|
||||||
initSearchBar(jsonData["searchEngine"])
|
initSearchBar(jsonData)
|
||||||
|
|
||||||
|
|
||||||
sqrs = jsonData["squares"]
|
sqrs = jsonData["squares"]
|
||||||
|
|||||||
Reference in New Issue
Block a user