Skip to content

Commit 9926aa4

Browse files
committed
[UX] Improved UI labeling for automatically trusted top-level sites.
1 parent c64a7fc commit 9926aa4

File tree

3 files changed

+45
-8
lines changed

3 files changed

+45
-8
lines changed

src/_locales/en/messages.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@
5050
"AutoAllowTopLevel": {
5151
"message": "Temporarily set top-level sites to TRUSTED"
5252
},
53+
"AutoTrustedLabel": {
54+
"description": "Short label for CUSTOM preset when automatically filled with TRUSTED capabilities as a top-level site",
55+
"message": "Auto-trusted"
56+
},
5357
"AutoReload": {
5458
"message": "Automatically reload affected pages when permissions change"
5559
},

src/ui/ui.css

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -462,10 +462,14 @@ input.temp + label {
462462

463463
input.preset:checked ~ input.temp {
464464
opacity: .7;
465-
right: 0.4em;
465+
right: calc(var(--extra-preset-width) - .5em);
466466
pointer-events: all;
467467
}
468468

469+
.customizing input.preset:checked ~ input.temp {
470+
right: .5em;
471+
}
472+
469473
.presets input.preset:checked ~ input.temp:checked {
470474
opacity: 1 !important;
471475
background-size: 100%;
@@ -485,7 +489,10 @@ input.preset:checked ~ input.temp {
485489
.customizing input.preset:checked {
486490
margin: 0 0 -0.2em 0;
487491
background-position: 0 0;
488-
--extra-preset-width: 1em;
492+
}
493+
494+
span.preset.CUSTOM {
495+
--extra-preset-width: 2em;
489496
}
490497

491498
#presets span.preset {

src/ui/ui.js

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ var UI = (() => {
2323

2424
var UI = {
2525
initialized: false,
26-
isBrowserAction: false,
2726

2827
presets: {
2928
"DEFAULT": "Default",
@@ -404,9 +403,8 @@ var UI = (() => {
404403
UI.Sites = class {
405404
constructor(parentNode, presets = DEF_PRESETS) {
406405
this.parentNode = parentNode;
407-
let policy = UI.policy;
408406
this.uiCount = UI.Sites.count = (UI.Sites.count || 0) + 1;
409-
this.sites = policy.sites;
407+
this.sites = UI.policy.sites;
410408
this.presets = presets;
411409
this.customizing = null;
412410
this.typesMap = new Map();
@@ -499,7 +497,12 @@ var UI = (() => {
499497
let sizer = document.createElement("div");
500498
sizer.id = "presets-sizer";
501499
sizer.classList.add("sites");
502-
sizer.appendChild(presets.cloneNode(true));
500+
const presetsCopy = sizer.appendChild(presets.cloneNode(true));
501+
if ("isBrowserAction" in UI && UI.policy.autoAllowTop) {
502+
const customCopy = presetsCopy.querySelector(".preset.CUSTOM");
503+
customCopy.querySelector("label.preset").textContent = _("AutoTrustedLabel");
504+
customCopy.parentNode.appendChild(customCopy);
505+
}
503506
document.body.appendChild(sizer);
504507
let labelWidth = 0;
505508
let biggest = "";
@@ -663,6 +666,7 @@ var UI = (() => {
663666
} else if (!(isCap || isTemp || customizer) && ev.type === "click") {
664667
this.customize(row.perms, preset, row);
665668
}
669+
this._customOrAuto(row);
666670
}
667671

668672
setupCaps(perms, preset, row) {
@@ -1026,6 +1030,26 @@ var UI = (() => {
10261030
return changed;
10271031
}
10281032

1033+
_customOrAuto(row) {
1034+
const { policy } = UI;
1035+
const { perms, contextMatch, siteMatch } = row;
1036+
const isAuto = policy.autoAllowTop && perms.temp &&
1037+
contextMatch == siteMatch &&
1038+
perms.sameAs(policy.TRUSTED);
1039+
if (!(isAuto || row._wasAuto)) {
1040+
return;
1041+
}
1042+
row._wasAuto = true;
1043+
const [labelShort, title] = isAuto
1044+
? [_("AutoTrustedLabel"), _("autoAllowTop")]
1045+
: [_("Custom"), _("Custom") ];
1046+
const widgets = row.querySelectorAll(".preset.CUSTOM [title]");
1047+
for (const w of [...widgets]) {
1048+
w.title = title;
1049+
if (w.textContent) w.textContent = labelShort;
1050+
}
1051+
}
1052+
10291053
createSiteRow(
10301054
site,
10311055
siteMatch,
@@ -1040,9 +1064,10 @@ var UI = (() => {
10401064
contextMatch,
10411065
perms
10421066
);
1043-
let policy = UI.policy;
1067+
const { policy } = UI;
10441068
let row = this.rowTemplate.cloneNode(true);
10451069
row.sitesCount = sitesCount;
1070+
10461071
let url;
10471072
try {
10481073
url = new URL(site);
@@ -1123,7 +1148,6 @@ var UI = (() => {
11231148
: punycode.toUnicode(
11241149
hostname.substring(0, hostname.length - domain.length)
11251150
);
1126-
11271151
row.querySelector(".domain").textContent = unicodeDomain;
11281152
row.querySelector(".path").textContent =
11291153
siteMatch.length > url.origin.length ? url.pathname : "";
@@ -1222,6 +1246,8 @@ var UI = (() => {
12221246
}
12231247
preset.disabled = false;
12241248
}
1249+
1250+
this._customOrAuto(row);
12251251
return row;
12261252
}
12271253

0 commit comments

Comments
 (0)