From 2706339c9d59bfdc1b5552441379f98d30ede548 Mon Sep 17 00:00:00 2001 From: Haider Ali Punjabi Date: Thu, 14 May 2020 10:43:01 +0530 Subject: [PATCH 1/2] Added Search Engine Config to config.json --- config.json | 4 ++++ index.html | 2 +- js/main.js | 10 +++++----- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/config.json b/config.json index 484615f..bab0109 100644 --- a/config.json +++ b/config.json @@ -29,6 +29,10 @@ ] } ], + "searchEngine":{ + "name": "Google", + "searchUrl": "https://www.google.com/search?q=" + }, "user": "Deepjyoti", "disableMessage": false, "disableDate": false, diff --git a/index.html b/index.html index 2b3a175..ad5edfa 100644 --- a/index.html +++ b/index.html @@ -16,7 +16,7 @@

diff --git a/js/main.js b/js/main.js index 23b4227..dac056a 100644 --- a/js/main.js +++ b/js/main.js @@ -47,18 +47,18 @@ function initBody() { json = readJSON("config.json") } -function initSearchBar() { +function initSearchBar(config) { // Clear the search bar on load, just in case document.getElementById(searchBarId).value = "" document.getElementById(searchBarId).focus() - + document.getElementById(searchBarId).placeholder = `Search something on ${config["name"]}` document.getElementById(searchBarId).addEventListener("keypress", (event) => { if (event.key != 'Enter') return // Open google with the search results. - googleSearchUrl = "https://www.google.com/search?q=" + searchUrl = config["searchUrl"] 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"]) document.getElementById(searchBarDivId).style.display = "none" else - initSearchBar() + initSearchBar(jsonData["searchEngine"]) sqrs = jsonData["squares"] From d4bcb6f4c08d9884c5fb15e2fe6bc9dc7d18abd2 Mon Sep 17 00:00:00 2001 From: Haider Ali Punjabi Date: Thu, 14 May 2020 11:22:21 +0530 Subject: [PATCH 2/2] Added Search Engine config to config.json --- config.json | 7 +++++++ index.html | 2 +- js/main.js | 15 ++++++++++----- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/config.json b/config.json index 484615f..581ee64 100644 --- a/config.json +++ b/config.json @@ -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, diff --git a/index.html b/index.html index 2b3a175..ad5edfa 100644 --- a/index.html +++ b/index.html @@ -16,7 +16,7 @@

diff --git a/js/main.js b/js/main.js index 23b4227..e30bfaf 100644 --- a/js/main.js +++ b/js/main.js @@ -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"]