aboutsummaryrefslogtreecommitdiffstats
path: root/js/cloud-ui.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/cloud-ui.js')
-rw-r--r--js/cloud-ui.js140
1 files changed, 53 insertions, 87 deletions
diff --git a/js/cloud-ui.js b/js/cloud-ui.js
index 0f81833..fed262a 100644
--- a/js/cloud-ui.js
+++ b/js/cloud-ui.js
@@ -21,16 +21,9 @@
uMatrix Home: https://github.com/gorhill/uBlock
*/
-/* global uDom */
-
'use strict';
-/******************************************************************************/
-
-(function() {
-
- /******************************************************************************/
-
+(function () {
self.cloud = {
options: {},
datakey: '',
@@ -39,22 +32,18 @@
onPull: null
};
- /******************************************************************************/
-
- var widget = uDom.nodeFromId('cloudWidget');
- if ( widget === null ) {
+ let widget = uDom.nodeFromId('cloudWidget');
+ if (widget === null) {
return;
}
self.cloud.datakey = widget.getAttribute('data-cloud-entry') || '';
- if ( self.cloud.datakey === '' ) {
+ if (self.cloud.datakey === '') {
return;
}
- /******************************************************************************/
-
- var onCloudDataReceived = function(entry) {
- if ( typeof entry !== 'object' || entry === null ) {
+ let onCloudDataReceived = function (entry) {
+ if (typeof entry !== 'object' || entry === null) {
return;
}
@@ -63,7 +52,7 @@
uDom.nodeFromId('cloudPull').removeAttribute('disabled');
uDom.nodeFromId('cloudPullAndMerge').removeAttribute('disabled');
- var timeOptions = {
+ let timeOptions = {
weekday: 'short',
year: 'numeric',
month: 'short',
@@ -71,85 +60,64 @@
hour: 'numeric',
minute: 'numeric',
second: 'numeric',
- timeZoneName: 'short'
+ timeZoneName: 'short',
};
- var time = new Date(entry.tstamp);
- widget.querySelector('span').textContent =
- entry.source + '\n' +
- time.toLocaleString('fullwide', timeOptions);
+ let time = new Date(entry.tstamp);
+ widget.querySelector('span').textContent = entry.source
+ + '\n'
+ + time.toLocaleString('fullwide', timeOptions);
};
- /******************************************************************************/
-
- var fetchCloudData = function() {
- vAPI.messaging.send(
- 'cloud-ui.js',
- {
- what: 'cloudPull',
- datakey: self.cloud.datakey
- },
- onCloudDataReceived
- );
+ let fetchCloudData = function () {
+ vAPI.messaging.send('cloud-ui.js', {
+ what: 'cloudPull',
+ datakey: self.cloud.datakey
+ }, onCloudDataReceived);
};
- /******************************************************************************/
-
- var pushData = function() {
- if ( typeof self.cloud.onPush !== 'function' ) {
+ let pushData = function () {
+ if (typeof self.cloud.onPush !== 'function') {
return;
}
- vAPI.messaging.send(
- 'cloud-ui.js',
- {
- what: 'cloudPush',
- datakey: self.cloud.datakey,
- data: self.cloud.onPush()
- },
- fetchCloudData
- );
- };
- /******************************************************************************/
+ vAPI.messaging.send('cloud-ui.js', {
+ what: 'cloudPush',
+ datakey: self.cloud.datakey,
+ data: self.cloud.onPush()
+ }, fetchCloudData);
+ };
- var pullData = function(ev) {
- if ( typeof self.cloud.onPull === 'function' ) {
+ let pullData = function (ev) {
+ if (typeof self.cloud.onPull === 'function') {
self.cloud.onPull(self.cloud.data, ev.shiftKey);
}
};
- /******************************************************************************/
-
- var pullAndMergeData = function() {
- if ( typeof self.cloud.onPull === 'function' ) {
+ let pullAndMergeData = function () {
+ if (typeof self.cloud.onPull === 'function') {
self.cloud.onPull(self.cloud.data, true);
}
};
- /******************************************************************************/
-
- var openOptions = function() {
- var input = uDom.nodeFromId('cloudDeviceName');
+ let openOptions = function () {
+ let input = uDom.nodeFromId('cloudDeviceName');
input.value = self.cloud.options.deviceName;
input.setAttribute('placeholder', self.cloud.options.defaultDeviceName);
uDom.nodeFromId('cloudOptions').classList.add('show');
};
- /******************************************************************************/
-
- var closeOptions = function(ev) {
- var root = uDom.nodeFromId('cloudOptions');
- if ( ev.target !== root ) {
+ let closeOptions = function (ev) {
+ let root = uDom.nodeFromId('cloudOptions');
+ if (ev.target !== root) {
return;
}
root.classList.remove('show');
};
- /******************************************************************************/
-
- var submitOptions = function() {
- var onOptions = function(options) {
- if ( typeof options !== 'object' || options === null ) {
+ let submitOptions = function () {
+ let onOptions = function (options) {
+ if (typeof options !== 'object' || options === null) {
return;
}
self.cloud.options = options;
@@ -164,31 +132,29 @@
uDom.nodeFromId('cloudOptions').classList.remove('show');
};
- /******************************************************************************/
-
- var onInitialize = function(options) {
- if ( typeof options !== 'object' || options === null ) {
+ let onInitialize = function (options) {
+ if (typeof options !== 'object' || options === null) {
return;
}
- if ( !options.enabled ) {
+ if (!options.enabled) {
return;
}
self.cloud.options = options;
- var xhr = new XMLHttpRequest();
+ let xhr = new XMLHttpRequest();
xhr.open('GET', 'cloud-ui.html', true);
xhr.overrideMimeType('text/html;charset=utf-8');
xhr.responseType = 'text';
- xhr.onload = function() {
+ xhr.onload = function () {
this.onload = null;
- var parser = new DOMParser(),
- parsed = parser.parseFromString(this.responseText, 'text/html'),
- fromParent = parsed.body;
- while ( fromParent.firstElementChild !== null ) {
- widget.appendChild(
- document.adoptNode(fromParent.firstElementChild)
- );
+ let parser = new DOMParser();
+ let parsed = parser.parseFromString(this.responseText, 'text/html');
+ let fromParent = parsed.body;
+
+ while (fromParent.firstElementChild !== null) {
+ widget.appendChild(document
+ .adoptNode(fromParent.firstElementChild));
}
vAPI.i18n.render(widget);
@@ -203,13 +169,13 @@
fetchCloudData();
};
+
xhr.send();
};
- vAPI.messaging.send('cloud-ui.js', { what: 'cloudGetOptions' }, onInitialize);
-
- /******************************************************************************/
+ vAPI.messaging.send('cloud-ui.js', {
+ what: 'cloudGetOptions'
+ }, onInitialize);
// https://www.youtube.com/watch?v=aQFp67VoiDA
-
})();