Skip to content

Commit 2e84b8c

Browse files
committed
Add sidebar support
1 parent 14ee1e5 commit 2e84b8c

File tree

8 files changed

+24
-28
lines changed

8 files changed

+24
-28
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: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ chrome.action.onClicked.addListener(async () => {
1919
return;
2020
}
2121

22+
if (position === 'sidebar') {
23+
return;
24+
}
25+
2226
if (position === 'window') {
2327
width = width === '' ? 400 : Number.parseInt(width, 10); // Must be an integer
2428
const height = 600;

source/main.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ new App({
66
});
77

88
const type = new URLSearchParams(location.search).get('type');
9-
document.body.dataset.type = type;
9+
document.documentElement.dataset.type = type;
1010
if (type === 'window') {
1111
fitWindow();
1212
}

source/manifest.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
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",
@@ -15,6 +15,9 @@
1515
"default_icon": "logo.png",
1616
"default_popup": "index.html?type=popup"
1717
},
18+
"side_panel": {
19+
"default_path": "index.html"
20+
},
1821
"options_ui": {
1922
"page": "options/options.html"
2023
},

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: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
<option value="popup">Menu (default)</option>
2727
<option value="window">Popup window</option>
2828
<option value="tab">Tab</option>
29+
<option value="sidebar">Sidebar</option>
2930
</select>
3031
</p>
3132
<p>

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)