Skip to content

Commit 8f668be

Browse files
committed
#58 add: allow opening bookmarks in private window
1 parent 4ab60fb commit 8f668be

File tree

4 files changed

+58
-6
lines changed

4 files changed

+58
-6
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
- now only a delete button is shown in the bookmarks list if the bookmark
55
can be deleted (for [#57](https://github.com/qownnotes/web-companion/issues/57))
66
- fixed a problem where links without name couldn't be opened when the link directly was clicked
7+
- there now is a new private mode switch, that allows opening bookmarks in
8+
a private window (for [#58](https://github.com/qownnotes/web-companion/issues/58))
79

810
## 2024.2.3
911
- the missing delete code was added (for [#57](https://github.com/qownnotes/web-companion/issues/57))

src-bex/_locales/en/messages.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,5 +134,11 @@
134134
},
135135
"UninstallButton": {
136136
"message": "Uninstall extension"
137+
},
138+
"PrivateMode": {
139+
"message": "Private mode"
140+
},
141+
"PrivateModeTooltip": {
142+
"message": "Open bookmarks in private browser window"
137143
}
138144
}

src/helpers/utils.js

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,21 @@ export const truncateText = (text, limit) => {
2020
}
2121
};
2222

23-
export const openUrl = (url) => {
24-
chrome.tabs.create({ url });
23+
export const openPrivateUrl = (url) => {
24+
// Check if there's an incognito window already open
25+
chrome.windows.getAll({ 'populate': true }, function(windows) {
26+
console.log("windows", windows);
27+
const incognitoWindow = windows.find(window => window.incognito);
28+
console.log("incognitoWindow", incognitoWindow);
29+
if (incognitoWindow) {
30+
// If there's already an incognito window, open a new tab in it
31+
chrome.tabs.create({ url: url, windowId: incognitoWindow.id });
32+
} else {
33+
// If there isn't an incognito window, create one and open a tab in it
34+
chrome.windows.create({ incognito: true, url: url, focused: true }, function(window) {
35+
console.log("window", window);
36+
// chrome.tabs.create({ url: url, windowId: window.id });
37+
});
38+
}
39+
});
2540
}

src/pages/PopupPage.vue

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,14 @@
9090
</template>
9191
</q-select>
9292
</div>
93+
<div class="col q-pa-sm q-gutter-sm">
94+
<q-toggle
95+
v-model="privateMode"
96+
:label="getLocale('PrivateMode')"
97+
>
98+
<q-tooltip class="bg-accent">{{ getLocale('PrivateModeTooltip') }}</q-tooltip>
99+
</q-toggle>
100+
</div>
93101
<div class="col q-pa-sm q-gutter-sm text-right">
94102
<q-btn size="sm" round color="secondary" icon="open_in_new" @click="openFilteredBookmarks" accesskey="o">
95103
<q-tooltip class="bg-accent">{{ getLocale('OpenAllBookmarks') }}</q-tooltip>
@@ -119,7 +127,7 @@
119127
<template v-if="props.row.name">
120128
<q-td key="name" :props="props" @click="openUrl(props.row.url)" class="click">
121129
<div>
122-
<div class="column-name" tabindex="2" :accesskey="props.rowIndex + 1" @keyup.enter="openUrl(props.row.url)">{{ truncateText( props.row.name, 40 ) }}</div>
130+
<a class="column-name" :href="props.row.url" @click="openUrl(props.row.url, $event)" tabindex="2" :accesskey="props.rowIndex + 1" @keyup.enter="openUrl(props.row.url)">{{ truncateText( props.row.name, 40 ) }}</a>
123131
<q-tooltip>
124132
<div class="column-name" v-if="props.row.name">{{ props.row.name }}</div>
125133
<div>{{ props.row.url }}</div>
@@ -137,7 +145,7 @@
137145
<template v-else>
138146
<q-td colspan="2" key="url" :props="props" @click="openUrl(props.row.url)" class="click">
139147
<div>
140-
<a class="column-name" tabindex="2" :href="props.row.url" @click="$event.stopPropagation(); openUrl(props.row.url)" :accesskey="props.rowIndex + 1" :title="props.row.url">{{ truncateText( props.row.url, 80 ) }}</a>
148+
<a class="column-name" tabindex="2" :href="props.row.url" @click="openUrl(props.row.url, $event)" :accesskey="props.rowIndex + 1" :title="props.row.url">{{ truncateText( props.row.url, 80 ) }}</a>
141149
</div>
142150
</q-td>
143151
</template>
@@ -166,7 +174,7 @@
166174

167175
<script>
168176
import {computed, defineComponent, nextTick, onMounted, reactive, ref, watch} from 'vue'
169-
import { getLocale, openUrl, truncateText } from '../helpers/utils'
177+
import { getLocale, openPrivateUrl, truncateText } from '../helpers/utils'
170178
import { QWebSocket } from '../services/qwebsocket'
171179
import InputTokenDialog from '../components/InputTokenDialog.vue'
172180
import AddBookmarkDialog from "components/AddBookmarkDialog.vue";
@@ -186,6 +194,7 @@ export default defineComponent({
186194
setup () {
187195
const $q = useQuasar();
188196
const leftDrawerOpen = ref(false)
197+
const privateMode = ref(false)
189198
let bookmarks = ref([]);
190199
let loadingBookmarks = ref(false);
191200
let search = ref('');
@@ -338,11 +347,25 @@ export default defineComponent({
338347
});
339348
}
340349
350+
const openUrl = (url, event) => {
351+
if (event) {
352+
event.stopPropagation();
353+
event.preventDefault();
354+
}
355+
356+
if (privateMode.value) {
357+
openPrivateUrl(url);
358+
} else {
359+
chrome.tabs.create({url});
360+
}
361+
}
362+
341363
const searchInput = ref(null);
342364
343365
onMounted(() => {
344366
chrome.storage.sync.get((data) => {
345-
search.value = data.search;
367+
search.value = data.search || '';
368+
privateMode.value = data.privateMode || false;
346369
347370
// Select the text in the search input field after it was updated by the data from the storage
348371
nextTick(() => searchInput.value.select());
@@ -449,6 +472,10 @@ export default defineComponent({
449472
console.log("selectedTags stored", newSelectedTags);
450473
});
451474
475+
watch(privateMode, (newPrivateMode, oldPrivateMode) => {
476+
chrome.storage.sync.set({ privateMode: newPrivateMode });
477+
});
478+
452479
const loadBookmarks = () => {
453480
loadingBookmarks.value = true;
454481
@@ -469,6 +496,7 @@ export default defineComponent({
469496
// Return the variables that you want to use in the template
470497
return {
471498
leftDrawerOpen,
499+
privateMode,
472500
toggleLeftDrawer,
473501
columns,
474502
bookmarks,
@@ -555,6 +583,7 @@ export default defineComponent({
555583
556584
.column-name {
557585
font-weight: bold;
586+
text-decoration: none;
558587
}
559588
560589
.column-description {

0 commit comments

Comments
 (0)