Added Search Engine Config to config.json
This commit is contained in:
@@ -29,6 +29,10 @@
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
"searchEngine":{
|
||||||
|
"name": "Google",
|
||||||
|
"searchUrl": "https://www.google.com/search?q="
|
||||||
|
},
|
||||||
"user": "Deepjyoti",
|
"user": "Deepjyoti",
|
||||||
"disableMessage": false,
|
"disableMessage": false,
|
||||||
"disableDate": false,
|
"disableDate": false,
|
||||||
|
|||||||
@@ -16,7 +16,7 @@
|
|||||||
<h2 id="date-text"></h2>
|
<h2 id="date-text"></h2>
|
||||||
</div>
|
</div>
|
||||||
<div id="search-bar">
|
<div id="search-bar">
|
||||||
<input id="search-bar-input" placeholder="Search something on Google"></input>
|
<input id="search-bar-input"></input>
|
||||||
</div>
|
</div>
|
||||||
<div id="other-content">
|
<div id="other-content">
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
10
js/main.js
10
js/main.js
@@ -47,18 +47,18 @@ function initBody() {
|
|||||||
json = readJSON("config.json")
|
json = readJSON("config.json")
|
||||||
}
|
}
|
||||||
|
|
||||||
function initSearchBar() {
|
function initSearchBar(config) {
|
||||||
// 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"]}`
|
||||||
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.
|
||||||
googleSearchUrl = "https://www.google.com/search?q="
|
searchUrl = config["searchUrl"]
|
||||||
query = document.getElementById(searchBarId).value.replace(/\ /g, "+")
|
query = document.getElementById(searchBarId).value.replace(/\ /g, "+")
|
||||||
document.location = googleSearchUrl + query
|
document.location = searchUrl + query
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -150,7 +150,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()
|
initSearchBar(jsonData["searchEngine"])
|
||||||
|
|
||||||
|
|
||||||
sqrs = jsonData["squares"]
|
sqrs = jsonData["squares"]
|
||||||
|
|||||||
Reference in New Issue
Block a user