From 29ae29c4669f19d45f2192ed1dc9ed4d072b6d93 Mon Sep 17 00:00:00 2001 From: Deepjyoti Barman Date: Fri, 1 Jul 2022 21:25:17 +0530 Subject: [PATCH 1/4] Add init changes to support per link new tab --- js/main.js | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/js/main.js b/js/main.js index 0bba74d..71f09c2 100644 --- a/js/main.js +++ b/js/main.js @@ -320,7 +320,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"]; @@ -352,10 +352,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 (newTab != undefined) { + isNewTab = newTab + } 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 From c6842d013c439cdf643e1debd0db84cd395f5f46 Mon Sep 17 00:00:00 2001 From: Deepjyoti Barman Date: Fri, 1 Jul 2022 21:26:43 +0530 Subject: [PATCH 2/4] Make changes to read the global new tab flag --- js/main.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/js/main.js b/js/main.js index 71f09c2..300f0b6 100644 --- a/js/main.js +++ b/js/main.js @@ -264,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) }) From 89cf15a8b78b6f90db37699efbb6847f0eba19ca Mon Sep 17 00:00:00 2001 From: Deepjyoti Barman Date: Fri, 1 Jul 2022 21:31:28 +0530 Subject: [PATCH 3/4] Add some changes to support global and local setting for newTab --- config.json | 1 + js/main.js | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/config.json b/config.json index 84f9923..64c606c 100644 --- a/config.json +++ b/config.json @@ -35,6 +35,7 @@ ] } ], + "linkInNewTab": true, "title": "startpage", "searchEngine":"DuckDuckGo", "user": "Deepjyoti", diff --git a/js/main.js b/js/main.js index 300f0b6..5c877ff 100644 --- a/js/main.js +++ b/js/main.js @@ -367,8 +367,8 @@ function createSqr(sqrData, index, globalNewTabEnabled) { isNewTab = globalNewTabEnabled newTabValue = element["newTab"] - if (newTab != undefined) { - isNewTab = newTab + if (newTabValue != undefined) { + isNewTab = newTabValue } a = document.createElement("a") From 8543c0ec4f565ee7f920cfc79f8217a91209ee71 Mon Sep 17 00:00:00 2001 From: Deepjyoti Barman Date: Fri, 1 Jul 2022 21:31:59 +0530 Subject: [PATCH 4/4] Add an example to show how newTab on links are respected --- config.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config.json b/config.json index 64c606c..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" } ]