Skip to content

Commit 043d5a3

Browse files
committed
add a header in popup to toggle styles
1 parent 820039a commit 043d5a3

File tree

5 files changed

+97
-21
lines changed

5 files changed

+97
-21
lines changed

src/_locales/en/messages.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1837,6 +1837,20 @@
18371837
"message": "Toggle style",
18381838
"description": "Label for the checkbox to enable/disable a style"
18391839
},
1840+
"toggleStylesHeading": {
1841+
"message": "Toggle styles"
1842+
},
1843+
"toggleStylesHint": {
1844+
"message": "Toggle the initially enabled styles, same as ✱"
1845+
},
1846+
"toggleStylesPerm": {
1847+
"message": "permanently",
1848+
"description": "Label for controls that reads like a continuation of the heading above:\nToggle these styles\n[x] [ ] [*] permanently\n[x] [ ] [*] in this tab only"
1849+
},
1850+
"toggleStylesTab": {
1851+
"message": "in this tab only",
1852+
"description": "Label for controls that reads like a continuation of the heading above:\nToggle these styles\n[x] [ ] [*] permanently\n[x] [ ] [*] in this tab only"
1853+
},
18401854
"undo": {
18411855
"message": "Undo",
18421856
"description": "Button label"

src/popup.html

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,25 @@
5757
<p i18n="stylusUnavailableForURLdetails"></p>
5858
</div>
5959

60+
<header>
61+
<details>
62+
<summary i18n="toggleStylesHeading"></summary>
63+
<% _.forEach([
64+
/*i18n*/'toggleStylesPerm',
65+
/*i18n*/'toggleStylesTab',
66+
], (text, i) => { i = i ? 't' : ''; %>
67+
<div class="flex">
68+
<input type="checkbox" data-toggle="+<%= i %>" i18n="title:enableStyleLabel" checked>
69+
<input type="checkbox" data-toggle="-<%= i %>" i18n="title:disableStyleLabel">
70+
<label i18n="+<%= text %>, title:toggleStylesHint"><input type="checkbox" data-toggle="*<%= i %>" style="-webkit-appearance: auto"></label>
71+
</div>
72+
<% }) %>
73+
</details>
74+
<a id="help" data-cmd="note" tabindex="0">
75+
<i class="i-info"></i>
76+
</a>
77+
</header>
78+
6079
<main id="installed" i18n="data-no-styles:noStylesForSite, data-find:findStylesOnline"></main>
6180

6281
<div class="actions flex" id="main-actions">
@@ -66,8 +85,8 @@
6685
<i class=i-usercss></i>
6786
</label>
6887
<div id="write-style" class="no-stretch">
69-
<header id="write-style-for" class="ellipsis"
70-
i18n="data-text:writeStyleFor, data-blocked:addStyleLabel"></header>
88+
<span id="write-style-for" class="ellipsis"
89+
i18n="data-text:writeStyleFor, data-blocked:addStyleLabel"></span>
7190
</div>
7291
</div>
7392
<label id="disableAll-label" i18n="data-off:disableAllStylesOff">
@@ -90,11 +109,6 @@
90109
menu-uso="UserStyles"
91110
menu-gf="GreasyFork"></button>
92111
</div>
93-
<button class="icon">
94-
<a id="help" data-cmd="note" tabindex="0">
95-
<i class="i-info"></i>
96-
</a>
97-
</button>
98112
<button id="options-btn" i18n="title:openOptions" class="icon">
99113
<svg class="hollow-gear" viewBox="0 0 20 20">
100114
<text y="100%"></text>

src/popup/hotkeys.js

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ const MENU_KEYS = {
1616
ContextMenu: 1,
1717
Enter: 1,
1818
};
19+
const isEnabled = () => $id(kStyleIdPrefix + togglables[0]).styleMeta.enabled;
1920
let infoOn;
2021
let menuKey = 0;
2122
let oldBodyStyle;
@@ -33,6 +34,18 @@ window.on('keyup', /** @param {KeyboardEvent} evt */ evt => {
3334
menuKey = 0;
3435
}
3536
});
37+
$('header').on('click', evt => {
38+
const el = evt.target;
39+
const cmd = el.dataset.toggle;
40+
if (!cmd)
41+
return;
42+
evt.preventDefault();
43+
const cycle = cmd[0] === '*';
44+
const enable = cmd[0] === '+';
45+
const list = cycle ? togglables : entries;
46+
if (cmd[1]) toggleStateInTab(list, cycle ? null : enable);
47+
else toggleState(list, cycle ? !isEnabled() : enable);
48+
});
3649

3750
export async function pause(fn, ...args) {
3851
window.off('keydown', onKeyDown);
@@ -89,7 +102,7 @@ function onKeyDown(evt) {
89102
if (!togglables.length) getTogglables(true);
90103
if (!togglables.length) return;
91104
if (!altKey) {
92-
toggleState(togglables, !$id(kStyleIdPrefix + togglables[0]).styleMeta.enabled);
105+
toggleState(togglables, !isEnabled());
93106
} else if ((toggledTab = (toggledTab + 1) % 3) < 2) {
94107
toggleStateInTab(togglables, !!toggledTab);
95108
} else {
@@ -178,14 +191,16 @@ export function initHotkeys(data) {
178191
getTogglables();
179192
const el = $('#help');
180193
const tAll = t('popupHotkeysInfo');
194+
const tMain = tAll.replace(/\n.+$/, '');
195+
const tWiki = tAll.match(/(.+)?$/)[0];
181196
const tMenu = t('popupHotkeysInfoMenu');
182197
let tTab = t('popupHotkeysInfoTab');
183198
if (MAC) tTab = tTab.replace('<Alt>', '<⌥>');
184199
el.onShowNote = showInfo;
185200
el.onHideNote = hideInfo;
186-
el.title = `${tTab}\n${tMenu}\n${tAll}`;
187-
el.dataset.title = `${tTab}\n${tMenu}\n${tAll.replace(/\n.+$/, '')}`.replace(/\n/g, '<hr>');
188-
wikiText = tAll.match(/(.+)?$/)[0] || t('linkStylusWiki');
201+
el.title = [tMain, tTab, tMenu].join('\n');
202+
el.dataset.title = el.title.replace(/\n/g, '<hr>');
203+
wikiText = tWiki || t('linkStylusWiki');
189204
}
190205

191206
function hideInfo() {

src/popup/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ if (!__.MV3 && CHROME >= 66 && CHROME <= 69) {
6262
// Chrome 66-69 adds a gap, https://crbug.com/821143
6363
$root.style.overflow = 'overlay';
6464
}
65+
for (const el of $$('header input[style]'))
66+
el.indeterminate = true;
6567

6668
function onRuntimeMessage(msg) {
6769
if (!tabUrl) return;

src/popup/popup.css

Lines changed: 41 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,44 @@ body {
3535
display: flex;
3636
flex-direction: column;
3737
}
38+
header {
39+
$headerBorderH: 3px;
40+
padding: var(--outer-padding) var(--outer-padding) calc(var(--outer-padding) - $headerBorderH);
41+
border-bottom: $headerBorderH double var(--c75);
42+
display: flex;
43+
align-items: center;
44+
background: var(--c95);
45+
user-select: none;
46+
> :first-child {
47+
flex: 1;
48+
}
49+
div {
50+
margin-top: 1ex;
51+
}
52+
div, summary {
53+
transition: opacity .25s;
54+
}
55+
label:hover, #help:hover i {
56+
color: var(--accent-1);
57+
}
58+
#help {
59+
i {
60+
color: var(--c50);
61+
font-size: 18px;
62+
}
63+
}
64+
.touch & {
65+
div {
66+
margin-top: var(--outer-padding);
67+
}
68+
input {
69+
margin-right: var(--outer-padding) !important;
70+
}
71+
}
72+
.non-touch &:not(:hover) :is(div, summary) {
73+
opacity: .7;
74+
}
75+
}
3876
#installed {
3977
overflow-y: auto;
4078
}
@@ -697,15 +735,6 @@ a:hover i {
697735
max-width: calc(50% - var(--btn-gap) - var(--inner-padding));
698736
}
699737
}
700-
#help {
701-
$helpIconSize: 18px;
702-
line-height: $helpIconSize;
703-
padding: 0 1px;
704-
i {
705-
color: var(--c40);
706-
font-size: $helpIconSize;
707-
}
708-
}
709738
button.icon {
710739
padding: 2px;
711740
border-radius: 50%;
@@ -729,6 +758,7 @@ button.icon {
729758
flex-direction: column;
730759
}
731760
.blocked-info,
761+
header,
732762
#installed {
733763
order: 2;
734764
}
@@ -798,7 +828,8 @@ button.icon {
798828
color: var(--fg);
799829
background: linear-gradient(var(--c80), var(--bg));
800830
padding: 1px 6px 0;
801-
margin: 2px;
831+
margin: 0 2px;
832+
line-height: 1.1;
802833
border: 1px solid var(--bg);
803834
border-radius: 4px;
804835
box-shadow: 1px 1px 4px rgba(0, 0, 0, .3);

0 commit comments

Comments
 (0)