Skip to content

Commit 0ea2422

Browse files
authored
Add an option to open all providers by default (#41)
1 parent bb5d4a8 commit 0ea2422

File tree

4 files changed

+23
-3
lines changed

4 files changed

+23
-3
lines changed

_locales/en/messages.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@
1515
"message": "Open in background"
1616
},
1717

18+
"openAllByDefaultLabel": {
19+
"message": "Open all by default"
20+
},
21+
1822
"optionsPageTitle": {
1923
"message": "Options"
2024
},

background.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,10 @@ function createContextMenu(storedSettings) {
3030
const title = chrome.i18n.getMessage('contextMenuTitle');
3131

3232
const selectedProviders = storedSettings.storageProviders.filter(p => p.selected);
33+
const openAllByDefault = storedSettings.openAllByDefault;
3334

3435
/* If there is only one search provider, do not create a submenu */
35-
if (selectedProviders.length === 1) {
36+
if (selectedProviders.length === 1 || openAllByDefault) {
3637
chrome.contextMenus.create({
3738
id: selectedProviders[0].name,
3839
title,
@@ -78,6 +79,7 @@ function createContextMenu(storedSettings) {
7879
/* Default settings. If there is nothing in storage, use these values. */
7980
const defaultSettings = {
8081
openInBackground: false,
82+
openAllByDefault: false,
8183
openTabAt: 'right',
8284
storageProviders: getDefaultProvidersClone(),
8385
};
@@ -116,7 +118,7 @@ function reverseSearch(info, storedSettings) {
116118

117119
/* return array of url string */
118120
function getProviderURLs(targetProviderName) {
119-
if (targetProviderName === 'openAll') {
121+
if (targetProviderName === 'openAll' || storedSettings.openAllByDefault) {
120122
const urls = [];
121123
for (const p of storedSettings.storageProviders) {
122124
if (p.selected) {

options/options.html

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,17 @@
2929
</div>
3030
</div>
3131

32+
<!-- "Open all by default" checkbox -->
33+
<div class="form-group row">
34+
<label for="openAllByDefault" class="col-sm-3" id="openAllByDefaultLabel">{{i18n.openAllByDefaultLabel}}</label>
35+
<div class="col-sm-9">
36+
<label class="form-check-label custom-control custom-checkbox">
37+
<input class="form-check-input custom-control-input" type="checkbox" id="openAllByDefault" />
38+
<span class="custom-control-indicator"></span>
39+
</label>
40+
</div>
41+
</div>
42+
3243
<!-- "Open tab at" select dropdown -->
3344
<div class="form-group row">
3445
<label for="openTabAt" class="col-sm-3 col-form-label" id="openTabAtLabel">{{i18n.openTabAtLabel}}</label>
@@ -65,4 +76,4 @@
6576
<script src="options.js"></script>
6677
</body>
6778

68-
</html>
79+
</html>

options/options.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,7 @@ document.title = `${chrome.i18n.getMessage('extensionName')} | ${chrome.i18n.get
260260

261261
$('#navbarTitle').textContent = chrome.i18n.getMessage('extensionName');
262262
$('#openInBackgroundLabel').textContent = chrome.i18n.getMessage('openInBackgroundLabel');
263+
$('#openAllByDefaultLabel').textContent = chrome.i18n.getMessage('openAllByDefaultLabel');
263264

264265
$('#openTabAtLabel').textContent = chrome.i18n.getMessage('openTabAtLabel');
265266
$('#openTabAtRight').textContent = chrome.i18n.getMessage('openTabAtRight');
@@ -299,6 +300,7 @@ saveOptions.onclick = () => {
299300
const nameSet = new Set();
300301
const storedSettings = {
301302
openInBackground: $('#openInBackground').checked,
303+
openAllByDefault: $('#openAllByDefault').checked,
302304
openTabAt: $('#openTabAt')[$('#openTabAt').selectedIndex].value,
303305
storageProviders: [],
304306
};
@@ -361,6 +363,7 @@ function updateUI(storedSettings) {
361363
.map(opt => opt.value)
362364
.indexOf(storedSettings.openTabAt);
363365
$('#openInBackground').checked = storedSettings.openInBackground;
366+
$('#openAllByDefault').checked = storedSettings.openAllByDefault;
364367

365368
for (const p of storedSettings.storageProviders) {
366369
$('#searchProviderList').appendChild(createSearchProviderElement(p.name, p.icon, p.url, p.selected, false));

0 commit comments

Comments
 (0)