Skip to content

Commit 1efa082

Browse files
authored
Add sidebar support (#140)
1 parent faa2964 commit 1efa082

File tree

8 files changed

+39
-47
lines changed

8 files changed

+39
-47
lines changed

package-lock.json

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

source/app.svelte

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@
1818
let showInfoMessage = !localStorage.getItem('undo-info-message');
1919
let userClickedHideInfoMessage = false; // "Disable/enable all" shows the button again, unless the user clicked already "hide" in the current session
2020
21-
options.then(({showButtons, width}) => {
21+
options.then(({showButtons, width, position}) => {
2222
if (showButtons === 'always') {
2323
showExtras = true;
2424
}
2525
26-
if (new URLSearchParams(location.search).get('type') !== 'window') {
27-
document.body.style.width = (width || 400) + 'px';
26+
if (position === 'popup' || position === 'window') {
27+
document.documentElement.style.width = (width || 400) + 'px';
2828
}
2929
});
3030
$: {

source/background.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,11 @@ chrome.storage.onChanged.addListener(async (changes, areaName) => {
1010
// Must be registered on the top level
1111
chrome.action.onClicked.addListener(async () => {
1212
let {position, width} = await optionsStorage.getAll();
13-
if (position === 'popup') {
14-
return;
15-
}
13+
14+
// 'popup' and 'sidebar' are handled by the browser
1615

1716
if (position === 'tab') {
18-
chrome.tabs.create({url: chrome.runtime.getURL('index.html?type=tab')});
17+
chrome.tabs.create({url: chrome.runtime.getURL('index.html')});
1918
return;
2019
}
2120

@@ -25,7 +24,7 @@ chrome.action.onClicked.addListener(async () => {
2524
const currentWindow = await chrome.windows.getCurrent();
2625
await chrome.windows.create({
2726
type: 'popup',
28-
url: chrome.runtime.getURL('index.html?type=window'),
27+
url: chrome.runtime.getURL('index.html?auto-fit=true'),
2928
width,
3029
height,
3130
top: currentWindow.top + Math.round((currentWindow.height - height) / 2),
@@ -37,4 +36,4 @@ chrome.action.onClicked.addListener(async () => {
3736
matchOptions();
3837

3938
// DEVELOPMENT MODE: uncomment this so the tab will reopen on extension reload
40-
// chrome.tabs.create({url:'chrome-extension://aknaajkpkdhfnbdfopjlkpkmajdckgfk/index.html?type=tab'})
39+
// chrome.tabs.create({url: chrome.runtime.getURL('index.html')});

source/main.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,8 @@ new App({
55
target: document.body,
66
});
77

8-
const type = new URLSearchParams(location.search).get('type');
9-
document.body.dataset.type = type;
10-
if (type === 'window') {
8+
const autoFit = new URLSearchParams(location.search).has('auto-fit');
9+
if (autoFit) {
1110
fitWindow();
1211
}
1312

source/manifest.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,18 @@
55
"manifest_version": 3,
66
"homepage_url": "https://github.com/hankxdev/one-click-extensions-manager",
77
"default_locale": "en",
8-
"permissions": ["management", "storage"],
8+
"permissions": ["management", "storage", "sidePanel"],
99
"minimum_chrome_version": "110",
1010
"icons": {
1111
"16": "logo.png",
1212
"128": "logo.png"
1313
},
1414
"action": {
1515
"default_icon": "logo.png",
16-
"default_popup": "index.html?type=popup"
16+
"default_popup": "index.html"
17+
},
18+
"side_panel": {
19+
"default_path": "index.html"
1720
},
1821
"options_ui": {
1922
"page": "options/options.html"

source/options-storage.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,10 @@ const defaultPopup = chrome.runtime.getManifest().action.default_popup;
2929
export async function matchOptions() {
3030
const {position} = await optionsStorage.getAll();
3131
chrome.action.setPopup({popup: position === 'popup' ? defaultPopup : ''});
32+
33+
const inSidebar = position === 'sidebar';
34+
chrome.sidePanel.setOptions({enabled: inSidebar});
35+
chrome.sidePanel.setPanelBehavior({
36+
openPanelOnActionClick: inSidebar,
37+
});
3238
}

source/options/options.html

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,27 +18,30 @@
1818
ul {
1919
padding-left: 1em;
2020
}
21+
p:has([value='tab']:checked, [value='sidebar']:checked)
22+
~ p:has(label[for='width']) {
23+
display: none;
24+
}
2125
</style>
2226
<form id="options-form">
27+
<p>
28+
<label for="showButtons">Show buttons</label>
29+
<select name="showButtons" id="showButtons">
30+
<option value="on-demand">On right click (default)</option>
31+
<option value="always">Always</option>
32+
</select>
33+
</p>
2334
<p>
2435
<label for="position">Position</label>
2536
<select name="position" id="position">
2637
<option value="popup">Menu (default)</option>
2738
<option value="window">Popup window</option>
2839
<option value="tab">Tab</option>
40+
<option value="sidebar">Sidebar</option>
2941
</select>
3042
</p>
3143
<p>
32-
<label for="showButtons">Show buttons</label>
33-
<select name="showButtons" id="showButtons">
34-
<option value="on-demand">On right click (default)</option>
35-
<option value="always">Always</option>
36-
</select>
37-
</p>
38-
<p>
39-
<label for="width"
40-
>List width <small>(in pixels, or leave empty)</small></label
41-
>
44+
<label for="width"> Width <small>(in pixels)</small> </label>
4245
<input type="text" name="width" id="width" placeholder="400" />
4346
</p>
4447
</form>

source/style.css

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,13 @@
66
}
77

88
body {
9-
width: 400px;
9+
width: auto;
1010
margin: auto;
11+
max-width: 800px;
1112
padding: var(--margin);
1213
direction: auto;
1314
}
1415

15-
body[data-type='popup'] {
16-
width: 320px;
17-
}
18-
19-
body[data-type='tab'],
20-
body[data-type='window'] {
21-
width: auto;
22-
}
23-
24-
body[data-type='tab'] {
25-
max-width: 800px;
26-
}
27-
2816
main {
2917
gap: 1em;
3018
display: flex;
@@ -159,15 +147,6 @@ button:hover,
159147
}
160148

161149
@media (prefers-color-scheme: dark) {
162-
/* Border around improves contrast */
163-
[data-type='popup'] body::before {
164-
content: '';
165-
position: fixed;
166-
inset: 0;
167-
z-index: -1;
168-
border: solid 1px #595a5e;
169-
}
170-
171150
body {
172151
background-color: #292a2d;
173152
color: #e8eaed;

0 commit comments

Comments
 (0)