From 8f668be7d64153ffef664fcdf8d1fdc5bb2af4fe Mon Sep 17 00:00:00 2001 From: Patrizio Bekerle Date: Sat, 10 Feb 2024 14:13:06 +0100 Subject: [PATCH] #58 add: allow opening bookmarks in private window --- CHANGELOG.md | 2 ++ src-bex/_locales/en/messages.json | 6 +++++ src/helpers/utils.js | 19 ++++++++++++++-- src/pages/PopupPage.vue | 37 +++++++++++++++++++++++++++---- 4 files changed, 58 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 420b77d..7f782c2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,8 @@ - now only a delete button is shown in the bookmarks list if the bookmark can be deleted (for [#57](https://github.com/qownnotes/web-companion/issues/57)) - fixed a problem where links without name couldn't be opened when the link directly was clicked +- there now is a new private mode switch, that allows opening bookmarks in + a private window (for [#58](https://github.com/qownnotes/web-companion/issues/58)) ## 2024.2.3 - the missing delete code was added (for [#57](https://github.com/qownnotes/web-companion/issues/57)) diff --git a/src-bex/_locales/en/messages.json b/src-bex/_locales/en/messages.json index 28d3bbc..fc618cb 100644 --- a/src-bex/_locales/en/messages.json +++ b/src-bex/_locales/en/messages.json @@ -134,5 +134,11 @@ }, "UninstallButton": { "message": "Uninstall extension" + }, + "PrivateMode": { + "message": "Private mode" + }, + "PrivateModeTooltip": { + "message": "Open bookmarks in private browser window" } } diff --git a/src/helpers/utils.js b/src/helpers/utils.js index 96c1e1c..029c4b9 100644 --- a/src/helpers/utils.js +++ b/src/helpers/utils.js @@ -20,6 +20,21 @@ export const truncateText = (text, limit) => { } }; -export const openUrl = (url) => { - chrome.tabs.create({ url }); +export const openPrivateUrl = (url) => { + // Check if there's an incognito window already open + chrome.windows.getAll({ 'populate': true }, function(windows) { + console.log("windows", windows); + const incognitoWindow = windows.find(window => window.incognito); + console.log("incognitoWindow", incognitoWindow); + if (incognitoWindow) { + // If there's already an incognito window, open a new tab in it + chrome.tabs.create({ url: url, windowId: incognitoWindow.id }); + } else { + // If there isn't an incognito window, create one and open a tab in it + chrome.windows.create({ incognito: true, url: url, focused: true }, function(window) { + console.log("window", window); + // chrome.tabs.create({ url: url, windowId: window.id }); + }); + } + }); } diff --git a/src/pages/PopupPage.vue b/src/pages/PopupPage.vue index bf71fff..d6873d5 100644 --- a/src/pages/PopupPage.vue +++ b/src/pages/PopupPage.vue @@ -90,6 +90,14 @@ +
+ + {{ getLocale('PrivateModeTooltip') }} + +
{{ getLocale('OpenAllBookmarks') }} @@ -119,7 +127,7 @@