Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
deepjyoti30 committed Jul 1, 2022
2 parents 0714a81 + 2b29b96 commit 0c27734
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 5 deletions.
16 changes: 14 additions & 2 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
]
Expand Down Expand Up @@ -35,6 +35,7 @@
]
}
],
"linkInNewTab": true,
"title": "startpage",
"searchEngine":"DuckDuckGo",
"user": "Deepjyoti",
Expand Down Expand Up @@ -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="
}
}
}
35 changes: 32 additions & 3 deletions js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
})

Expand Down Expand Up @@ -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"];
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 0c27734

Please sign in to comment.