Skip to content

Commit

Permalink
Merge pull request #265 from hawkeye116477/advancedEx
Browse files Browse the repository at this point in the history
 Select existing "Advanced settings" page if any
  • Loading branch information
JustOff authored Oct 10, 2020
2 parents ece30d3 + a1be7fa commit fc0b3a5
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 57 deletions.
21 changes: 11 additions & 10 deletions src/js/about.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,21 @@

/* global uDom */

/******************************************************************************/

uDom.onLoad(function() {

'use strict';

/******************************************************************************/

var onAppDataReady = function(appData) {
uDom('#aboutNameVer').text(appData.name + ' v' + appData.version);
};
(( ) => {

vAPI.messaging.send('dashboard', { what: 'getAppData' }, onAppDataReady);
vAPI.messaging.send('dashboard', { what: 'getAppData' }, appData => {
uDom('#aboutNameVer').text(appData.name + ' v' + appData.version);
});

/******************************************************************************/
document.querySelector(
'[href="logger-ui.html"]'
).addEventListener(
'click',
self.uBlockDashboard.openOrSelectPage
);

});
})();
15 changes: 15 additions & 0 deletions src/js/dashboard-common.js
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,21 @@ self.uBlockDashboard.patchCodeMirrorEditor = (function() {

/******************************************************************************/

self.uBlockDashboard.openOrSelectPage = function(url, options = {}) {
let ev;
if ( url instanceof MouseEvent ) {
ev = url;
url = ev.target.getAttribute('href');
}
const details = Object.assign({ url, select: true, index: -1 }, options);
vAPI.messaging.send('default', { what: 'gotoURL', details });
if ( ev ) {
ev.preventDefault();
}
};

/******************************************************************************/

// Open links in the proper window
uDom('a').attr('target', '_blank');
uDom('a[href*="dashboard.html"]').attr('target', '_parent');
Expand Down
98 changes: 51 additions & 47 deletions src/js/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,30 +21,27 @@

/* global uDom */

'use strict';

/******************************************************************************/

(function() {

'use strict';
(( ) => {

/******************************************************************************/

var messaging = vAPI.messaging;
const messaging = vAPI.messaging;

/******************************************************************************/

var handleImportFilePicker = function() {
var file = this.files[0];
if ( file === undefined || file.name === '' ) {
return;
}
if ( file.type.indexOf('text') !== 0 ) {
return;
}
var filename = file.name;
const handleImportFilePicker = function() {
const file = this.files[0];
if ( file === undefined || file.name === '' ) { return; }
if ( file.type.indexOf('text') !== 0 ) { return; }

const filename = file.name;

var fileReaderOnLoadHandler = function() {
var userData;
const fileReaderOnLoadHandler = function() {
let userData;
try {
userData = JSON.parse(this.result);
if ( typeof userData !== 'object' ) {
Expand All @@ -70,10 +67,10 @@ var handleImportFilePicker = function() {
window.alert(vAPI.i18n('aboutRestoreDataError'));
return;
}
var time = new Date(userData.timeStamp);
var msg = vAPI.i18n('aboutRestoreDataConfirm')
.replace('{{time}}', time.toLocaleString());
var proceed = window.confirm(msg);
const time = new Date(userData.timeStamp);
const msg = vAPI.i18n('aboutRestoreDataConfirm')
.replace('{{time}}', time.toLocaleString());
const proceed = window.confirm(msg);
if ( proceed ) {
messaging.send(
'dashboard',
Expand All @@ -86,15 +83,15 @@ var handleImportFilePicker = function() {
}
};

var fr = new FileReader();
const fr = new FileReader();
fr.onload = fileReaderOnLoadHandler;
fr.readAsText(file);
};

/******************************************************************************/

var startImportFilePicker = function() {
var input = document.getElementById('restoreFilePicker');
const startImportFilePicker = function() {
const input = document.getElementById('restoreFilePicker');
// Reset to empty string, this will ensure an change event is properly
// triggered if the user pick a file, even if it is the same as the last
// one picked.
Expand All @@ -104,8 +101,8 @@ var startImportFilePicker = function() {

/******************************************************************************/

var exportToFile = function() {
messaging.send('dashboard', { what: 'backupUserData' }, function(response) {
const exportToFile = function() {
messaging.send('dashboard', { what: 'backupUserData' }, response => {
if (
response instanceof Object === false ||
response.userData instanceof Object === false
Expand All @@ -123,7 +120,7 @@ var exportToFile = function() {

/******************************************************************************/

var onLocalDataReceived = function(details) {
const onLocalDataReceived = function(details) {
uDom('#localData > ul > li:nth-of-type(1)').text(
vAPI.i18n('settingsStorageUsed')
.replace(
Expand All @@ -132,8 +129,7 @@ var onLocalDataReceived = function(details) {
)
);

var elem, dt;
var timeOptions = {
const timeOptions = {
weekday: 'long',
year: 'numeric',
month: 'long',
Expand All @@ -142,18 +138,19 @@ var onLocalDataReceived = function(details) {
minute: 'numeric',
timeZoneName: 'short'
};
var lastBackupFile = details.lastBackupFile || '';

const lastBackupFile = details.lastBackupFile || '';
if ( lastBackupFile !== '' ) {
dt = new Date(details.lastBackupTime);
const dt = new Date(details.lastBackupTime);
uDom('#localData > ul > li:nth-of-type(2) > ul > li:nth-of-type(1)').text(dt.toLocaleString('fullwide', timeOptions));
//uDom('#localData > ul > li:nth-of-type(2) > ul > li:nth-of-type(2)').text(lastBackupFile);
uDom('#localData > ul > li:nth-of-type(2)').css('display', '');
}

var lastRestoreFile = details.lastRestoreFile || '';
elem = uDom('#localData > p:nth-of-type(3)');
const lastRestoreFile = details.lastRestoreFile || '';
uDom('#localData > p:nth-of-type(3)');
if ( lastRestoreFile !== '' ) {
dt = new Date(details.lastRestoreTime);
const dt = new Date(details.lastRestoreTime);
uDom('#localData > ul > li:nth-of-type(3) > ul > li:nth-of-type(1)').text(dt.toLocaleString('fullwide', timeOptions));
uDom('#localData > ul > li:nth-of-type(3) > ul > li:nth-of-type(2)').text(lastRestoreFile);
uDom('#localData > ul > li:nth-of-type(3)').css('display', '');
Expand All @@ -162,6 +159,7 @@ var onLocalDataReceived = function(details) {
if ( details.cloudStorageSupported === false ) {
uDom('#cloud-storage-enabled').attr('disabled', '');
}

if ( details.privacySettingsSupported === false ) {
uDom('#prefetching-disabled').attr('disabled', '');
uDom('#hyperlink-auditing-disabled').attr('disabled', '');
Expand All @@ -171,17 +169,17 @@ var onLocalDataReceived = function(details) {

/******************************************************************************/

var resetUserData = function() {
var msg = vAPI.i18n('aboutResetDataConfirm');
var proceed = window.confirm(msg);
const resetUserData = function() {
const msg = vAPI.i18n('aboutResetDataConfirm');
const proceed = window.confirm(msg);
if ( proceed ) {
messaging.send('dashboard', { what: 'resetUserData' });
}
};

/******************************************************************************/

var synchronizeDOM = function() {
const synchronizeDOM = function() {
document.body.classList.toggle(
'advancedUser',
uDom.nodeFromId('advanced-user-enabled').checked === true
Expand All @@ -190,7 +188,7 @@ var synchronizeDOM = function() {

/******************************************************************************/

var changeUserSettings = function(name, value) {
const changeUserSettings = function(name, value) {
messaging.send(
'dashboard',
{
Expand All @@ -203,10 +201,10 @@ var changeUserSettings = function(name, value) {

/******************************************************************************/

var onInputChanged = function(ev) {
var input = ev.target;
var name = this.getAttribute('data-setting-name');
var value = input.value;
const onInputChanged = function(ev) {
const input = ev.target;
const name = this.getAttribute('data-setting-name');
let value = input.value;
if ( name === 'largeMediaSize' ) {
value = Math.min(Math.max(Math.floor(parseInt(value, 10) || 0), 0), 1000000);
}
Expand All @@ -221,7 +219,7 @@ var onInputChanged = function(ev) {
// Workaround for:
// https://github.com/gorhill/uBlock/issues/1448

var onPreventDefault = function(ev) {
const onPreventDefault = function(ev) {
ev.target.focus();
ev.preventDefault();
};
Expand All @@ -230,7 +228,7 @@ var onPreventDefault = function(ev) {

// TODO: use data-* to declare simple settings

var onUserSettingsReceived = function(details) {
const onUserSettingsReceived = function(details) {
uDom('[data-setting-type="bool"]').forEach(function(uNode) {
uNode.prop('checked', details[uNode.attr('data-setting-name')] === true)
.on('change', function() {
Expand Down Expand Up @@ -262,10 +260,16 @@ var onUserSettingsReceived = function(details) {

/******************************************************************************/

uDom.onLoad(function() {
messaging.send('dashboard', { what: 'userSettings' }, onUserSettingsReceived);
messaging.send('dashboard', { what: 'getLocalData' }, onLocalDataReceived);
});
messaging.send('dashboard', { what: 'userSettings' }, onUserSettingsReceived);
messaging.send('dashboard', { what: 'getLocalData' }, onLocalDataReceived);

// https://github.com/uBlockOrigin/uBlock-issues/issues/591
document.querySelector(
'[href="advanced-settings.html"]'
).addEventListener(
'click',
self.uBlockDashboard.openOrSelectPage
);

/******************************************************************************/

Expand Down

0 comments on commit fc0b3a5

Please sign in to comment.