You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
1 line
39 KiB
1 line
39 KiB
10 months ago
|
/*jshint sub:true*/(function () {'use strict';function $(selector) {return document.querySelector(selector);}function $$(selector, callback) {var elems = document.querySelectorAll(selector);for (var i = 0; i < elems.length; ++i) {if (callback && typeof callback == 'function')callback.call(this, elems[i]);}}var debounce = function (func, wait, now) {var timeout;return function debounced () {var that = this, args = arguments;function delayed() {if (!now)func.apply(that, args);timeout = null;}if (timeout) {clearTimeout(timeout);} else if (now) {func.apply(obj, args);}timeout = setTimeout(delayed, wait || 250);};};window.GoAccess = window.GoAccess || {initialize: function (options) {this.opts = options;this.AppState = {};this.AppTpls = {};this.AppCharts = {};this.AppUIData = (this.opts || {}).uiData || {};this.AppData = (this.opts || {}).panelData || {};this.AppWSConn = (this.opts || {}).wsConnection || {};this.i18n = (this.opts || {}).i18n || {};this.AppPrefs = {'autoHideTables': true,'layout': 'horizontal','perPage': 7,'theme': 'darkPurple',};this.AppPrefs = GoAccess.Util.merge(this.AppPrefs, this.opts.prefs);if (GoAccess.Util.hasLocalStorage()) {var ls = JSON.parse(localStorage.getItem('AppPrefs'));this.AppPrefs = GoAccess.Util.merge(this.AppPrefs, ls);}if (Object.keys(this.AppWSConn).length)this.setWebSocket(this.AppWSConn);},getPanelUI: function (panel) {return panel ? this.AppUIData[panel] : this.AppUIData;},getPrefs: function (panel) {return panel ? this.AppPrefs[panel] : this.AppPrefs;},setPrefs: function () {if (GoAccess.Util.hasLocalStorage()) {localStorage.setItem('AppPrefs', JSON.stringify(GoAccess.getPrefs()));}},getPanelData: function (panel) {return panel ? this.AppData[panel] : this.AppData;},setWebSocket: function (wsConn) {var host = null;host = wsConn.url ? wsConn.url : window.location.hostname ? window.location.hostname : "localhost";var str = /^(wss?:\/\/)?[^\/]+:[0-9]{1,5}\//.test(host + "/") ? host : String(host + ':' + wsConn.port);str = !/^wss?:\/\//i.test(str) ? (window.location.protocol === "https:" ? 'wss://' : 'ws://') + str : str;var socket = new WebSocket(str);socket.onopen = function (event) {GoAccess.Nav.WSOpen();}.bind(this);socket.onmessage = function (event) {this.AppState['updated'] = true;this.AppData = JSON.parse(event.data);this.App.renderData();}.bind(this);socket.onclose = function (event) {GoAccess.Nav.WSClose();}.bind(this);},};GoAccess.Util = {months: ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul","Aug", "Sep", "Oct", "Nov", "Dec"],merge: function (o, n) {var obj = {}, i = 0, il = arguments.length, key;for (; i < il; i++) {for (key in arguments[i]) {if (arguments[i].hasOwnProperty(key)) {obj[key] = arguments[i][key];}}}return obj;},hashCode: function (s) {return (s.split('').reduce(function (a, b) {a = ((a << 5) - a) + b.charCodeAt(0);return a&a;}, 0) >>> 0).toString(16);},formatBytes: function (bytes, decimals, numOnly) {if (bytes == 0)return numOnly ? 0 : '0 Byte';var k = 1024;var dm = decimals + 1 || 2;var sizes = ['B', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB'];var i = Math.floor(Math.log(bytes) / Math.log(k));return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + (numOnly ? '' : (' ' + sizes[i]));},isNumeric: function (n) {return !isNaN(parseFloat(n)) && isFinite(n);},utime2str: function (usec) {if (usec >= 864E8)return ((usec) / 864E8).toFixed(2) + ' d';else if (usec >= 36E8)return ((usec) / 36E8).toFixed(2) + ' h';else if (usec >= 6E7)return ((usec) / 6E7).toFixed(2) + ' m';else if (usec >= 1E6)return ((usec) / 1E6).toFixed(2) + ' s';else if (usec >= 1E3)return ((usec) / 1E3).toFixed(2) + ' ms';return (usec).toFixed(2) + ' us';},formatDate: function (str) {var y = str.substr(0,4), m = str.substr(4,2) - 1, d = str.substr(6,2),h = str.substr(8,2) || 0, i = str.substr(10, 2) || 0, s = str.substr(12, 2) || 0;var date = new Date(y,m,d,h,i,s);var out = ('0' + date.getDate()).slice(-2) + '/' + this.months[date.getMonth()] + '/' + date.getFullYear();10 <= str.length && (out += ":" + h);12 <= str.length && (out += ":" + i);14 <= str.length && (out += ":" + s);return out;},fmtVa
|