diff --git a/config.json b/config.json index 7ee263e..d9f0c03 100644 --- a/config.json +++ b/config.json @@ -4,7 +4,7 @@ "color": "red", "links": [ { "name": "Spotify", "url": "https://open.spotify.com/" }, - { "name": "YoutubeMusic", "url": "https://music.youtube.com/" }, + { "name": "YoutubeMusic", "url": "https://music.youtube.com/", "newTab": false }, { "name": "Netflix", "url": "https://netflix.com" }, { "name": "Youtube", "url": "https://youtube.com" } ] @@ -35,6 +35,7 @@ ] } ], + "linkInNewTab": true, "title": "startpage", "searchEngine":"DuckDuckGo", "user": "Deepjyoti", @@ -64,6 +65,17 @@ "quickLinks": { "r": "https://reddit.com", "g": "https://github.com", - "y": "https://youtube.com" + "y": "https://youtube.com", + "d": { + "URL": "https://duckduckgo.com", + "Search": "/?q=" + }, + "b": "https://bing.com", + "p": "https://startpage.com", + "s": "https://stackoverflow.com", + "w": { + "URL":"https://wikipedia.org/wiki", + "Search": "/Special:Search?search=" + } } } diff --git a/js/main.js b/js/main.js index 08c9ba4..5c877ff 100644 --- a/js/main.js +++ b/js/main.js @@ -36,7 +36,11 @@ searchEngines = { "DuckDuckGo": "https://duckduckgo.com/?q=", "Bing": "https://www.bing.com/search?q=", "Yahoo": "https://search.yahoo.com/search?p=", - "Ecosia": "https://www.ecosia.org/search?q=" + "Ecosia": "https://www.ecosia.org/search?q=", + "Startpage": "https://startpage.com/do/search?query=", + "Yandex": "https://yandex.com/search/?text=", + "Qwant": "https://www.qwant.com/?q=", + "Baidu": "https://www.baidu.com/s?wd=" } validWeatherUnit = [ "fah", "cel" @@ -260,8 +264,14 @@ function parseAndCreate(jsonData) { sqrs = jsonData["squares"] + globalNewTabEnabled = false + passedNewTab = jsonData["linkInNewTab"] + if (passedNewTab != undefined) { + globalNewTabEnabled = passedNewTab + } + sqrs.forEach((element, index) => { - sqr = createSqr(element, index) + sqr = createSqr(element, index, globalNewTabEnabled) document.getElementById(otherContentId).appendChild(sqr) }) @@ -316,7 +326,7 @@ function parseAndCreate(jsonData) { extractQuickLinks(sqrs, jsonData["style"]); } -function createSqr(sqrData, index) { +function createSqr(sqrData, index, globalNewTabEnabled) { // Create a new square division with the passed element name = sqrData["name"]; link = sqrData["url"]; @@ -348,10 +358,29 @@ function createSqr(sqrData, index) { links.forEach(element => { aName = element["name"] aHref = element["url"] + + // Idea is to give preference to + // link specific newTab field over the global + // one. + // + // As a fallback, the global value will be used. + isNewTab = globalNewTabEnabled + newTabValue = element["newTab"] + + if (newTabValue != undefined) { + isNewTab = newTabValue + } a = document.createElement("a") attrHref = document.createAttribute("href") attrHref.value = aHref + + if (isNewTab) { + attrTarget = document.createAttribute("target") + attrTarget.value = "_blank" + a.setAttributeNode(attrTarget) + } + a.setAttributeNode(attrHref) a.textContent = aName