8000 [mv3] Add ability for admins to disable features · gorhill/uBlock@346b5de · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Commit 346b5de

Browse files
committed
[mv3] Add ability for admins to disable features
New managed setting: "disabledFeatures": { "title": "User interface features to disable", "description": "A list of tokens, each of which correspond to a user interface feature to disable.", "type": "array", "items": { "type": "string" } } Supported tokens: - `dashboard`: Prevent access to all dashboard settings - `filteringMode`: Prevent changes to the default filtering mode, or the current filtering mode of any site Related feedback: uBlockOrigin/uBOL-home#35 (reply in thread)
1 parent 4979aa5 commit 346b5de

File tree

9 files changed

+80
-7
lines changed

9 files changed

+80
-7
lines changed

platform/mv3/extension/css/filtering-mode.css

+13-4
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
border-radius: 30% 15% / 15% 30%;
1414
height: 100%;
1515
position: absolute;
16-
width: 25%;
16+
width: calc(25% + 2px);
1717
z-index: 10;
1818
}
1919

@@ -39,12 +39,18 @@
3939

4040
.filteringModeSlider span[data-level] {
4141
background-color: var(--accent-surface-1);
42+
border: 1px solid var(--accent-surface-1);
43+
box-sizing: border-box;
4244
display: inline-flex;
4345
height: 30%;
4446
margin-left: 1px;
4547
width: 25%;
4648
}
4749

50+
.filteringModeSlider span[data-level]:first-of-type {
51+
margin-left: 0;
52+
}
53+
4854
.filteringModeSlider.moving span[data-level] {
4955
pointer-events: none;
5056
}
@@ -53,13 +59,13 @@
5359
left: 0;
5460
}
5561
.filteringModeSlider[data-level="1"] .filteringModeButton {
56-
left: 25%;
62+
left: calc(25% - 1px);
5763
}
5864
.filteringModeSlider[data-level="2"] .filteringModeButton {
59-
left: 50%;
65+
left: calc(50% - 1px);
6066
}
6167
.filteringModeSlider[data-level="3"] .filteringModeButton {
62-
left: 75%;
68+
left: calc(75% - 1px);
6369
}
6470
[dir="rtl"] .filteringModeSlider[data-level="0"] .filteringModeButton {
6571
left: 75%;
@@ -77,14 +83,17 @@
7783

7884
.filteringModeSlider[data-level="0"] span[data-level] {
7985
background-color: var(--surface-2);
86+
border-color: var(--surface-2);
8087
}
8188

8289
.filteringModeSlider[data-level="1"] span[data-level]:nth-of-type(1) ~ span[data-level] {
8390
background-color: var(--surface-2);
91+
border-color: var(--surface-2);
8492
}
8593

8694
.filteringModeSlider[data-level="2"] span[data-level]:nth-of-type(2) ~ span[data-level] {
8795
background-color: var(--surface-2);
96+
border-color: var(--surface-2);
8897
}
8998

9099
.filteringModeSlider[data-level]:not(.moving) span[data-level]:hover {

platform/mv3/extension/css/popup.css

+7
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,13 @@ hr {
6363
font-weight: 600;
6464
}
6565

66+
body[data-forbid~="filteringMode"] .filteringModeSlider {
67+
pointer-events: none;
68+
}
69+
body[data-forbid~="dashboard"] #gotoDashboard {
70+
display: none;
71+
}
72+
6673
#filteringModeText {
6774
color: var(--ink-3);
6875
margin: var(--default-gap-small);

platform/mv3/extension/css/settings.css

+14
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
body.loading {
2+
visibility: hidden;
3+
}
14
body .firstRun {
25
display: none;
36
}
@@ -13,6 +16,17 @@ p {
1316
white-space: pre-line;
1417
}
1518

19+
body[data-forbid~="dashboard"] #dashboard-nav [data-pane="settings"],
20+
body[data-forbid~="dashboard"] section[data-pane="settings"],
21+
body[data-forbid~="dashboard"] #dashboard-nav [data-pane="rulesets"],
22+
body[data-forbid~="dashboard"] section[data-pane="rulesets"] {
23+
display: none;
24+
}
25+
body[data-forbid~="filteringMode"] section[data-pane="settings"] > div:has(> h3[data-i18n="defaultFilteringModeSectionLabel"]),
26+
body[data-forbid~="filteringMode"] section[data-pane="settings"] > div:has(> h3[data-i18n="filteringMode0Name"]) {
27+
display: none;
28+
}
29+
1630
#showBlockedCount:has(input[type="checkbox"][disabled]) {
1731
opacity: 0.5;
1832
}

platform/mv3/extension/dashboard.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
<link rel="shortcut icon" type="image/png" href="img/icon_64.png"/>
1717
</head>
1818

19-
<body data-pane="settings">
19+
<body data-pane="settings" class="loading">
2020
<!-- -------- -->
2121
<div id="dashboard-nav">
2222
<span class="logo"><img data-i18n-title="extName" src="img/ublock.svg" alt="uBO Lite"></span><!--

platform/mv3/extension/js/background.js

+15-1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ import {
4040
windows,
4141
} from './ext.js';
4242

43+
import {
44+
adminReadEx,
45+
getAdminRulesets,
46+
} from './admin.js';
47+
4348
import {
4449
enableRulesets,
4550
getEnabledRulesetsDetails,
@@ -62,7 +67,6 @@ import {
6267
} from './config.js';
6368

6469
import { broadcastMessage } from './utils.js';
65-
import { getAdminRulesets } from './admin.js';
6670
import { registerInjectables } from './scripting-manager.js';
6771

6872
/******************************************************************************/
@@ -189,13 +193,15 @@ function onMessage(request, sender, callback) {
189193
getRulesetDetails(),
190194
dnr.getEnabledRulesets(),
191195
getAdminRulesets(),
196+
adminReadEx('disabledFeatures'),
192197
]).then(results => {
193198
const [
194199
defaultFilteringMode,
195200
trustedSites,
196201
rulesetDetails,
197202
enabledRulesets,
198203
adminRulesets,
204+
disabledFeatures,
199205
] = results;
200206
callback({
201207
defaultFilteringMode,
@@ -210,6 +216,7 @@ function onMessage(request, sender, callback) {
210216
firstRun: process.firstRun,
211217
isSideloaded,
212218
developerMode: rulesetConfig.developerMode,
219+
disabledFeatures,
213220
});
214221
process.firstRun = false;
215222
});
@@ -251,6 +258,7 @@ function onMessage(request, sender, callback) {
251258
hasOmnipotence(),
252259
hasGreatPowers(request.origin),
253260
getEnabledRulesetsDetails(),
261+
adminReadEx('disabledFeatures'),
254262
]).then(results => {
255263
callback({
256264
level: results[0],
@@ -260,6 +268,7 @@ function onMessage(request, sender, callback) {
260268
rulesetDetails: results[3],
261269
isSideloaded,
262270
developerMode: rulesetConfig.developerMode,
271+
disabledFeatures: results[4],
263272
});
264273
});
265274
return true;
@@ -416,6 +425,11 @@ async function start() {
416425
}
417426

418427
toggleDeveloperMode(rulesetConfig.developerMode);
428+
429+
// Required to ensure the up to date property is available when needed
430+
if ( process.wakeupRun === false ) {
431+
adminReadEx('disabledFeatures');
432+
}
419433
}
420434

421435
// https://github.com/uBlockOrigin/uBOL-home/issues/199

platform/mv3/extension/js/popup.js

+10
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,14 @@ function normalizedHostname(hn) {
4444

4545
/******************************************************************************/
4646

47+
function renderAdminRules() {
48+
const { disabledFeatures: forbid = [] } = popupPanelData;
49+
if ( forbid.length === 0 ) { return; }
50+
dom.body.dataset.forbid = forbid.join(' ');
51+
}
52+
53+
/******************************************************************************/
54+
4755
const BLOCKING_MODE_MAX = 3;
4856

4957
function setFilteringMode(level, commit = false) {
@@ -325,6 +333,8 @@ async function init() {
325333
}
326334
}
327335

336+
renderAdminRules();
337+
328338
setFilteringMode(popupPanelData.level);
329339

330340
dom.text('#hostname', punycode.toUnicode(tabHostname));

platform/mv3/extension/js/settings.js

+13
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,17 @@ function hashFromIterable(iter) {
3636

3737
/******************************************************************************/
3838

39+
function renderAdminRules() {
40+
const { disabledFeatures: forbid = [] } = cachedRulesetData;
41+
if ( forbid.length === 0 ) { return; }
42+
dom.body.dataset.forbid = forbid.join(' ');
43+
if ( forbid.includes('dashboard') ) {
44+
dom.body.dataset.pane = 'about';
45+
}
46+
}
47+
48+
/******************************************************************************/
49+
3950
function renderWidgets() {
4051
if ( cachedRulesetData.firstRun ) {
4152
dom.cl.add(dom.body, 'firstRun');
@@ -256,8 +267,10 @@ sendMessage({
256267
if ( !data ) { return; }
257268
cachedRulesetData = data;
258269
try {
270+
renderAdminRules();
259271
renderFilterLists(cachedRulesetData);
260272
renderWidgets();
273+
dom.cl.remove(dom.body, 'loading');
261274
} catch(ex) {
262275
}
263276
listen();

platform/mv3/extension/managed_storage.json

+6
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@
1616
"description": "Prefix a ruleset id with '+' to add, or '-' to remove. Use '-*' to disable all non-default lists.",
1717
"type": "array",
1818
"items": { "type": "string" }
19+
},
20+
"disabledFeatures": {
21+
"title": "User interface features to disable",
22+
"description": "A list of tokens, each of which correspond to a user interface feature to disable.",
23+
"type": "array",
24+
"items": { "type": "string" }
1925
}
2026
}
2127
}

platform/mv3/extension/popup.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
<span></span>
3333
<span id="showMatchedRules" class="fa-icon tool" tabindex="0" title="Show matched rules">list-alt<span class="caption">Show matched rules</span></span>
3434
<span id="reportFilterIssue" class="fa-icon tool enabled" data-i18n-title="popupTipReport">comment-alt<span class="caption" data-i18n="popupTipReport"></span></span>
35-
<span class="fa-icon tool enabled" tabindex="0" data-i18n-title="popupTipDashboard">cogs<span class="caption" data-i18n="popupTipDashboard"></span></span>
35+
<span id="gotoDashboard" class="fa-icon tool enabled" tabindex="0" data-i18n-title="popupTipDashboard">cogs<span class="caption" data-i18n="popupTipDashboard"></span></span>
3636
</div>
3737
<!-- -------- -->
3838
<div id="rulesetStats" data-section="a">

0 commit comments

Comments
 (0)
0