mirror of https://github.com/gorhill/uBlock.git
Adding to and further reviewing admin-managed settings
This commit is contained in:
parent
2ab11603f0
commit
cc9c45f1e4
|
@ -7,26 +7,24 @@
|
||||||
"description": "All entries present will overwrite local settings.",
|
"description": "All entries present will overwrite local settings.",
|
||||||
"type": "string"
|
"type": "string"
|
||||||
},
|
},
|
||||||
"toSet": {
|
"advancedSettings": {
|
||||||
"title": "Settings to overwrite at launch time",
|
"title": "A list of [name,value] pairs to populate advanced settings",
|
||||||
"type": "object",
|
"type": "array",
|
||||||
"properties": {
|
"items": {
|
||||||
"hiddenSettings": {
|
"title": "A [name,value] pair",
|
||||||
"title": "A list of [name,value] pairs to populate hidden settings",
|
"type": "array",
|
||||||
"type": "array",
|
"items": { "type": "string" }
|
||||||
"items": {
|
|
||||||
"title": "A [name,value] pair",
|
|
||||||
"type": "array",
|
|
||||||
"items": { "type": "string" }
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"trustedSiteDirectives": {
|
|
||||||
"title": "A list of trusted-site directives",
|
|
||||||
"type": "array",
|
|
||||||
"items": { "type": "string" }
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"disableDashboard": {
|
||||||
|
"title": "Set to true to prevent access to configuration options",
|
||||||
|
"type": "boolean"
|
||||||
|
},
|
||||||
|
"disabledPopupPanelParts": {
|
||||||
|
"title": "An array of strings used to remove parts of the popup panel",
|
||||||
|
"type": "array",
|
||||||
|
"items": { "type": "string" }
|
||||||
|
},
|
||||||
"toAdd": {
|
"toAdd": {
|
||||||
"title": "Settings to add at launch time",
|
"title": "Settings to add at launch time",
|
||||||
"type": "object",
|
"type": "object",
|
||||||
|
@ -38,6 +36,17 @@
|
||||||
"items": { "type": "string" }
|
"items": { "type": "string" }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"toOverwrite": {
|
||||||
|
"title": "Settings to overwrite at launch time",
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"trustedSiteDirectives": {
|
||||||
|
"title": "A list of trusted-site directives",
|
||||||
|
"type": "array",
|
||||||
|
"items": { "type": "string" }
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -72,6 +72,12 @@ iframe {
|
||||||
body:not(.canUpdateShortcuts) .tabButton[data-pane="shortcuts.html"] {
|
body:not(.canUpdateShortcuts) .tabButton[data-pane="shortcuts.html"] {
|
||||||
display: none;
|
display: none;
|
||||||
}
|
}
|
||||||
|
body .tabButton[data-pane="no-dashboard.html"] {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
body.noDashboard #dashboard-nav {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
/* high dpi devices */
|
/* high dpi devices */
|
||||||
:root.hidpi .tabButton {
|
:root.hidpi .tabButton {
|
||||||
|
|
|
@ -19,7 +19,8 @@
|
||||||
--><span class="tabButton" data-pane="dyna-rules.html" data-i18n="rulesPageName"></span><!--
|
--><span class="tabButton" data-pane="dyna-rules.html" data-i18n="rulesPageName"></span><!--
|
||||||
--><span class="tabButton" data-pane="whitelist.html" data-i18n="whitelistPageName"></span><!--
|
--><span class="tabButton" data-pane="whitelist.html" data-i18n="whitelistPageName"></span><!--
|
||||||
--><span class="tabButton" data-pane="shortcuts.html" data-i18n="shortcutsPageName"></span><!--
|
--><span class="tabButton" data-pane="shortcuts.html" data-i18n="shortcutsPageName"></span><!--
|
||||||
--><span class="tabButton" data-pane="about.html" data-i18n="aboutPageName"></span>
|
--><span class="tabButton" data-pane="about.html" data-i18n="aboutPageName"></span><!--
|
||||||
|
--><span class="tabButton" data-pane="no-dashboard.html"></span>
|
||||||
</div>
|
</div>
|
||||||
<div id="unsavedWarning">
|
<div id="unsavedWarning">
|
||||||
<div>
|
<div>
|
||||||
|
|
|
@ -111,6 +111,8 @@ const µBlock = (( ) => { // jshint ignore:line
|
||||||
hiddenSettingsAdmin: {},
|
hiddenSettingsAdmin: {},
|
||||||
hiddenSettings: Object.assign({}, hiddenSettingsDefault),
|
hiddenSettings: Object.assign({}, hiddenSettingsDefault),
|
||||||
|
|
||||||
|
noDashboard: false,
|
||||||
|
|
||||||
// Features detection.
|
// Features detection.
|
||||||
privacySettingsSupported: vAPI.browserSettings instanceof Object,
|
privacySettingsSupported: vAPI.browserSettings instanceof Object,
|
||||||
cloudStorageSupported: vAPI.cloud instanceof Object,
|
cloudStorageSupported: vAPI.cloud instanceof Object,
|
||||||
|
|
|
@ -84,7 +84,9 @@ const loadDashboardPanel = function(pane, first) {
|
||||||
tabButton.classList.add('selected');
|
tabButton.classList.add('selected');
|
||||||
tabButton.scrollIntoView();
|
tabButton.scrollIntoView();
|
||||||
uDom.nodeFromId('iframe').setAttribute('src', pane);
|
uDom.nodeFromId('iframe').setAttribute('src', pane);
|
||||||
vAPI.localStorage.setItem('dashboardLastVisitedPane', pane);
|
if ( pane !== 'no-dashboard.html' ) {
|
||||||
|
vAPI.localStorage.setItem('dashboardLastVisitedPane', pane);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
if ( first ) {
|
if ( first ) {
|
||||||
return loadPane();
|
return loadPane();
|
||||||
|
@ -104,25 +106,48 @@ const onTabClickHandler = function(ev) {
|
||||||
loadDashboardPanel(ev.target.getAttribute('data-pane'));
|
loadDashboardPanel(ev.target.getAttribute('data-pane'));
|
||||||
};
|
};
|
||||||
|
|
||||||
// https://github.com/uBlockOrigin/uBlock-issues/issues/106
|
if ( self.location.hash.slice(1) === 'no-dashboard.html' ) {
|
||||||
vAPI.messaging.send('dashboard', {
|
document.body.classList.add('noDashboard');
|
||||||
what: 'canUpdateShortcuts',
|
}
|
||||||
}).then(response => {
|
|
||||||
document.body.classList.toggle('canUpdateShortcuts', response === true);
|
|
||||||
});
|
|
||||||
|
|
||||||
vAPI.localStorage.getItemAsync('dashboardLastVisitedPane').then(value => {
|
(async ( ) => {
|
||||||
loadDashboardPanel(value !== null ? value : 'settings.html', true);
|
const results = await Promise.all([
|
||||||
|
// https://github.com/uBlockOrigin/uBlock-issues/issues/106
|
||||||
|
vAPI.messaging.send('dashboard', { what: 'dashboardConfig' }),
|
||||||
|
vAPI.localStorage.getItemAsync('dashboardLastVisitedPane'),
|
||||||
|
]);
|
||||||
|
|
||||||
uDom('.tabButton').on('click', onTabClickHandler);
|
{
|
||||||
|
const details = results[0];
|
||||||
|
document.body.classList.toggle(
|
||||||
|
'canUpdateShortcuts',
|
||||||
|
details.canUpdateShortcuts === true
|
||||||
|
);
|
||||||
|
if ( details.noDashboard ) {
|
||||||
|
self.location.hash = '#no-dashboard.html';
|
||||||
|
document.body.classList.add('noDashboard');
|
||||||
|
} else if ( self.location.hash === '#no-dashboard.html' ) {
|
||||||
|
self.location.hash = '';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// https://developer.mozilla.org/en-US/docs/Web/API/Window/beforeunload_event
|
{
|
||||||
window.addEventListener('beforeunload', ( ) => {
|
let pane = results[1];
|
||||||
if ( discardUnsavedData(true) ) { return; }
|
if ( self.location.hash !== '' ) {
|
||||||
event.preventDefault();
|
pane = self.location.hash.slice(1) || null;
|
||||||
event.returnValue = '';
|
}
|
||||||
});
|
loadDashboardPanel(pane !== null ? pane : 'settings.html', true);
|
||||||
});
|
|
||||||
|
uDom('.tabButton').on('click', onTabClickHandler);
|
||||||
|
|
||||||
|
// https://developer.mozilla.org/en-US/docs/Web/API/Window/beforeunload_event
|
||||||
|
window.addEventListener('beforeunload', ( ) => {
|
||||||
|
if ( discardUnsavedData(true) ) { return; }
|
||||||
|
event.preventDefault();
|
||||||
|
event.returnValue = '';
|
||||||
|
});
|
||||||
|
}
|
||||||
|
})();
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
|
|
|
@ -1214,8 +1214,11 @@ const onMessage = function(request, sender, callback) {
|
||||||
let response;
|
let response;
|
||||||
|
|
||||||
switch ( request.what ) {
|
switch ( request.what ) {
|
||||||
case 'canUpdateShortcuts':
|
case 'dashboardConfig':
|
||||||
response = µb.canUpdateShortcuts;
|
response = {
|
||||||
|
canUpdateShortcuts: µb.canUpdateShortcuts,
|
||||||
|
noDashboard: µb.noDashboard,
|
||||||
|
};
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'getAutoCompleteDetails':
|
case 'getAutoCompleteDetails':
|
||||||
|
|
|
@ -97,23 +97,49 @@
|
||||||
const hsUser = this.hiddenSettings;
|
const hsUser = this.hiddenSettings;
|
||||||
|
|
||||||
const results = await Promise.all([
|
const results = await Promise.all([
|
||||||
vAPI.adminStorage.get('toSet'),
|
vAPI.adminStorage.get([
|
||||||
|
'advancedSettings',
|
||||||
|
'disableDashboard',
|
||||||
|
'disabledPopupPanelParts',
|
||||||
|
]),
|
||||||
vAPI.storage.get('hiddenSettings'),
|
vAPI.storage.get('hiddenSettings'),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
if (
|
if ( results[0] instanceof Object ) {
|
||||||
results[0] instanceof Object &&
|
const {
|
||||||
Array.isArray(results[0].hiddenSettings)
|
advancedSettings,
|
||||||
) {
|
disableDashboard,
|
||||||
for ( const entry of results[0].hiddenSettings ) {
|
disabledPopupPanelParts
|
||||||
if ( entry.length < 1 ) { continue; }
|
} = results[0];
|
||||||
const name = entry[0];
|
if ( Array.isArray(advancedSettings) ) {
|
||||||
if ( hsDefault.hasOwnProperty(name) === false ) { continue; }
|
for ( const entry of advancedSettings ) {
|
||||||
const value = entry.length < 2
|
if ( entry.length < 1 ) { continue; }
|
||||||
? hsDefault[name]
|
const name = entry[0];
|
||||||
: this.hiddenSettingValueFromString(name, entry[1]);
|
if ( hsDefault.hasOwnProperty(name) === false ) { continue; }
|
||||||
if ( value === undefined ) { continue; }
|
const value = entry.length < 2
|
||||||
hsDefault[name] = hsAdmin[name] = hsUser[name] = value;
|
? hsDefault[name]
|
||||||
|
: this.hiddenSettingValueFromString(name, entry[1]);
|
||||||
|
if ( value === undefined ) { continue; }
|
||||||
|
hsDefault[name] = hsAdmin[name] = hsUser[name] = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
µBlock.noDashboard = disableDashboard === true;
|
||||||
|
if ( Array.isArray(disabledPopupPanelParts) ) {
|
||||||
|
const partNameToBit = new Map([
|
||||||
|
[ 'globalStats', 0b00010 ],
|
||||||
|
[ 'basicTools', 0b00100 ],
|
||||||
|
[ 'extraTools', 0b01000 ],
|
||||||
|
[ 'firewall', 0b10000 ],
|
||||||
|
]);
|
||||||
|
let bits = hsDefault.popupPanelDisabledSections;
|
||||||
|
for ( const part of disabledPopupPanelParts ) {
|
||||||
|
const bit = partNameToBit.get(part);
|
||||||
|
if ( bit === undefined ) { continue; }
|
||||||
|
bits |= bit;
|
||||||
|
}
|
||||||
|
hsDefault.popupPanelDisabledSections =
|
||||||
|
hsAdmin.popupPanelDisabledSections =
|
||||||
|
hsUser.popupPanelDisabledSections = bits;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1260,15 +1286,15 @@ self.addEventListener('hiddenSettingsChanged', ( ) => {
|
||||||
// values are left to the user's choice.
|
// values are left to the user's choice.
|
||||||
|
|
||||||
µBlock.restoreAdminSettings = async function() {
|
µBlock.restoreAdminSettings = async function() {
|
||||||
let toSet = {};
|
let toOverwrite = {};
|
||||||
let data;
|
let data;
|
||||||
try {
|
try {
|
||||||
const store = await vAPI.adminStorage.get([
|
const store = await vAPI.adminStorage.get([
|
||||||
'adminSettings',
|
'adminSettings',
|
||||||
'toSet',
|
'toOverwrite',
|
||||||
]) || {};
|
]) || {};
|
||||||
if ( store.toSet instanceof Object ) {
|
if ( store.toOverwrite instanceof Object ) {
|
||||||
toSet = store.toSet;
|
toOverwrite = store.toOverwrite;
|
||||||
}
|
}
|
||||||
const json = store.adminSettings;
|
const json = store.adminSettings;
|
||||||
if ( typeof json === 'string' && json !== '' ) {
|
if ( typeof json === 'string' && json !== '' ) {
|
||||||
|
@ -1315,9 +1341,9 @@ self.addEventListener('hiddenSettingsChanged', ( ) => {
|
||||||
binNotEmpty = true;
|
binNotEmpty = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( Array.isArray(toSet.trustedSiteDirectives) ) {
|
if ( Array.isArray(toOverwrite.trustedSiteDirectives) ) {
|
||||||
µBlock.netWhitelistDefault = toSet.trustedSiteDirectives.slice();
|
µBlock.netWhitelistDefault = toOverwrite.trustedSiteDirectives.slice();
|
||||||
bin.netWhitelist = toSet.trustedSiteDirectives.slice();
|
bin.netWhitelist = toOverwrite.trustedSiteDirectives.slice();
|
||||||
binNotEmpty = true;
|
binNotEmpty = true;
|
||||||
} else if ( Array.isArray(data.whitelist) ) {
|
} else if ( Array.isArray(data.whitelist) ) {
|
||||||
bin.netWhitelist = data.whitelist;
|
bin.netWhitelist = data.whitelist;
|
||||||
|
|
Loading…
Reference in New Issue