// ==UserScript== // @name OGame Redesign (v.6): Auction Timer // @author MomoCow // @namespace https://github.com/momocow // @version 3.0.3 // @description Displays a countdown timer for the Auction in OGame 6.* // @include *.ogame*gameforge.com/game/index.php?page=* // @updateURL https://raw.githubusercontent.com/momocow/OGame-Redesign-v.6-Auction-Timer/master/dist/auction-timer.meta.js // @downloadURL https://raw.githubusercontent.com/momocow/OGame-Redesign-v.6-Auction-Timer/master/dist/auction-timer.user.js // @supportURL https://github.com/momocow/OGame-Redesign-v.6-Auction-Timer/issues // @run-at document-idle // @grant GM_getValue // @grant GM_setValue // @grant GM_addStyle // ==/UserScript== /***************************************************************************** * Originaly developed by Vesselin * Currently developed by MomoCow after v3.0.0 * Released under MIT *****************************************************************************/ /***************************************************************************** * Changelog * ### v3.0.0 * - [Add] provide a more stateful timer * - [Changed] rewritten as a ES6 script with eslint `standard` coding style * - [Optmized] more stable dependency check *****************************************************************************/ /* jshint asi:true */ 'use strict'; var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } var MAX_LOG_ENTRIES = 500; var MAX_DEP_TIMEOUT = 10000; var DEP_CHECK_PERIOD = 500; var DEP_LIST = { AUCTION: ['io', '$', 'nodeParams', 'simpleCountdown', 'loca'], NON_AUCTION: ['$', 'simpleCountdown'] }; var hasOwn = Object.prototype.hasOwnProperty; var toStr = Object.prototype.toString; var defineProperty = Object.defineProperty; var gOPD = Object.getOwnPropertyDescriptor; var isArray = function isArray(arr) { if (typeof Array.isArray === 'function') { return Array.isArray(arr); } return toStr.call(arr) === '[object Array]'; }; var isPlainObject = function isPlainObject(obj) { if (!obj || toStr.call(obj) !== '[object Object]') { return false; } var hasOwnConstructor = hasOwn.call(obj, 'constructor'); var hasIsPrototypeOf = obj.constructor && obj.constructor.prototype && hasOwn.call(obj.constructor.prototype, 'isPrototypeOf'); if (obj.constructor && !hasOwnConstructor && !hasIsPrototypeOf) { return false; } var key; for (key in obj) {} return typeof key === 'undefined' || hasOwn.call(obj, key); }; var setProperty = function setProperty(target, options) { if (defineProperty && options.name === '__proto__') { defineProperty(target, options.name, { enumerable: true, configurable: true, value: options.newValue, writable: true }); } else { target[options.name] = options.newValue; } }; var getProperty = function getProperty(obj, name) { if (name === '__proto__') { if (!hasOwn.call(obj, name)) { return void 0; } else if (gOPD) { return gOPD(obj, name).value; } } return obj[name]; }; var extend = function extend() { var options, name, src, copy, copyIsArray, clone; var target = arguments[0]; var i = 1; var length = arguments.length; var deep = false; if (typeof target === 'boolean') { deep = target; target = arguments[1] || {}; i = 2; } if (target == null || (typeof target === 'undefined' ? 'undefined' : _typeof(target)) !== 'object' && typeof target !== 'function') { target = {}; } for (; i < length; ++i) { options = arguments[i]; if (options != null) { for (name in options) { src = getProperty(target, name); copy = getProperty(options, name); if (target !== copy) { if (deep && copy && (isPlainObject(copy) || (copyIsArray = isArray(copy)))) { if (copyIsArray) { copyIsArray = false; clone = src && isArray(src) ? src : []; } else { clone = src && isPlainObject(src) ? src : {}; } setProperty(target, { name: name, newValue: extend(deep, clone, copy) }); } else if (typeof copy !== 'undefined') { setProperty(target, { name: name, newValue: copy }); } } } } } return target; }; var domain; function EventHandlers() {} EventHandlers.prototype = Object.create(null); function EventEmitter() { EventEmitter.init.call(this); } EventEmitter.EventEmitter = EventEmitter; EventEmitter.usingDomains = false; EventEmitter.prototype.domain = undefined; EventEmitter.prototype._events = undefined; EventEmitter.prototype._maxListeners = undefined; EventEmitter.defaultMaxListeners = 10; EventEmitter.init = function () { this.domain = null; if (EventEmitter.usingDomains) { if (domain.active && !(this instanceof domain.Domain)) { this.domain = domain.active; } } if (!this._events || this._events === Object.getPrototypeOf(this)._events) { this._events = new EventHandlers(); this._eventsCount = 0; } this._maxListeners = this._maxListeners || undefined; }; EventEmitter.prototype.setMaxListeners = function setMaxListeners(n) { if (typeof n !== 'number' || n < 0 || isNaN(n)) throw new TypeError('"n" argument must be a positive number'); this._maxListeners = n; return this; }; function $getMaxListeners(that) { if (that._maxListeners === undefined) return EventEmitter.defaultMaxListeners; return that._maxListeners; } EventEmitter.prototype.getMaxListeners = function getMaxListeners() { return $getMaxListeners(this); }; function emitNone(handler, isFn, self) { if (isFn) handler.call(self);else { var len = handler.length; var listeners = arrayClone(handler, len); for (var i = 0; i < len; ++i) { listeners[i].call(self); } } } function emitOne(handler, isFn, self, arg1) { if (isFn) handler.call(self, arg1);else { var len = handler.length; var listeners = arrayClone(handler, len); for (var i = 0; i < len; ++i) { listeners[i].call(self, arg1); } } } function emitTwo(handler, isFn, self, arg1, arg2) { if (isFn) handler.call(self, arg1, arg2);else { var len = handler.length; var listeners = arrayClone(handler, len); for (var i = 0; i < len; ++i) { listeners[i].call(self, arg1, arg2); } } } function emitThree(handler, isFn, self, arg1, arg2, arg3) { if (isFn) handler.call(self, arg1, arg2, arg3);else { var len = handler.length; var listeners = arrayClone(handler, len); for (var i = 0; i < len; ++i) { listeners[i].call(self, arg1, arg2, arg3); } } } function emitMany(handler, isFn, self, args) { if (isFn) handler.apply(self, args);else { var len = handler.length; var listeners = arrayClone(handler, len); for (var i = 0; i < len; ++i) { listeners[i].apply(self, args); } } } EventEmitter.prototype.emit = function emit(type) { var er, handler, len, args, i, events, domain; var needDomainExit = false; var doError = type === 'error'; events = this._events; if (events) doError = doError && events.error == null;else if (!doError) return false; domain = this.domain; if (doError) { er = arguments[1]; if (domain) { if (!er) er = new Error('Uncaught, unspecified "error" event'); er.domainEmitter = this; er.domain = domain; er.domainThrown = false; domain.emit('error', er); } else if (er instanceof Error) { throw er; } else { var err = new Error('Uncaught, unspecified "error" event. (' + er + ')'); err.context = er; throw err; } return false; } handler = events[type]; if (!handler) return false; var isFn = typeof handler === 'function'; len = arguments.length; switch (len) { case 1: emitNone(handler, isFn, this); break; case 2: emitOne(handler, isFn, this, arguments[1]); break; case 3: emitTwo(handler, isFn, this, arguments[1], arguments[2]); break; case 4: emitThree(handler, isFn, this, arguments[1], arguments[2], arguments[3]); break; default: args = new Array(len - 1); for (i = 1; i < len; i++) { args[i - 1] = arguments[i]; }emitMany(handler, isFn, this, args); } if (needDomainExit) domain.exit(); return true; }; function _addListener(target, type, listener, prepend) { var m; var events; var existing; if (typeof listener !== 'function') throw new TypeError('"listener" argument must be a function'); events = target._events; if (!events) { events = target._events = new EventHandlers(); target._eventsCount = 0; } else { if (events.newListener) { target.emit('newListener', type, listener.listener ? listener.listener : listener); events = target._events; } existing = events[type]; } if (!existing) { existing = events[type] = listener; ++target._eventsCount; } else { if (typeof existing === 'function') { existing = events[type] = prepend ? [listener, existing] : [existing, listener]; } else { if (prepend) { existing.unshift(listener); } else { existing.push(listener); } } if (!existing.warned) { m = $getMaxListeners(target); if (m && m > 0 && existing.length > m) { existing.warned = true; var w = new Error('Possible EventEmitter memory leak detected. ' + existing.length + ' ' + type + ' listeners added. ' + 'Use emitter.setMaxListeners() to increase limit'); w.name = 'MaxListenersExceededWarning'; w.emitter = target; w.type = type; w.count = existing.length; emitWarning(w); } } } return target; } function emitWarning(e) { typeof console.warn === 'function' ? console.warn(e) : console.log(e); } EventEmitter.prototype.addListener = function addListener(type, listener) { return _addListener(this, type, listener, false); }; EventEmitter.prototype.on = EventEmitter.prototype.addListener; EventEmitter.prototype.prependListener = function prependListener(type, listener) { return _addListener(this, type, listener, true); }; function _onceWrap(target, type, listener) { var fired = false; function g() { target.removeListener(type, g); if (!fired) { fired = true; listener.apply(target, arguments); } } g.listener = listener; return g; } EventEmitter.prototype.once = function once(type, listener) { if (typeof listener !== 'function') throw new TypeError('"listener" argument must be a function'); this.on(type, _onceWrap(this, type, listener)); return this; }; EventEmitter.prototype.prependOnceListener = function prependOnceListener(type, listener) { if (typeof listener !== 'function') throw new TypeError('"listener" argument must be a function'); this.prependListener(type, _onceWrap(this, type, listener)); return this; }; EventEmitter.prototype.removeListener = function removeListener(type, listener) { var list, events, position, i, originalListener; if (typeof listener !== 'function') throw new TypeError('"listener" argument must be a function'); events = this._events; if (!events) return this; list = events[type]; if (!list) return this; if (list === listener || list.listener && list.listener === listener) { if (--this._eventsCount === 0) this._events = new EventHandlers();else { delete events[type]; if (events.removeListener) this.emit('removeListener', type, list.listener || listener); } } else if (typeof list !== 'function') { position = -1; for (i = list.length; i-- > 0;) { if (list[i] === listener || list[i].listener && list[i].listener === listener) { originalListener = list[i].listener; position = i; break; } } if (position < 0) return this; if (list.length === 1) { list[0] = undefined; if (--this._eventsCount === 0) { this._events = new EventHandlers(); return this; } else { delete events[type]; } } else { spliceOne(list, position); } if (events.removeListener) this.emit('removeListener', type, originalListener || listener); } return this; }; EventEmitter.prototype.removeAllListeners = function removeAllListeners(type) { var listeners, events; events = this._events; if (!events) return this; if (!events.removeListener) { if (arguments.length === 0) { this._events = new EventHandlers(); this._eventsCount = 0; } else if (events[type]) { if (--this._eventsCount === 0) this._events = new EventHandlers();else delete events[type]; } return this; } if (arguments.length === 0) { var keys = Object.keys(events); for (var i = 0, key; i < keys.length; ++i) { key = keys[i]; if (key === 'removeListener') continue; this.removeAllListeners(key); } this.removeAllListeners('removeListener'); this._events = new EventHandlers(); this._eventsCount = 0; return this; } listeners = events[type]; if (typeof listeners === 'function') { this.removeListener(type, listeners); } else if (listeners) { do { this.removeListener(type, listeners[listeners.length - 1]); } while (listeners[0]); } return this; }; EventEmitter.prototype.listeners = function listeners(type) { var evlistener; var ret; var events = this._events; if (!events) ret = [];else { evlistener = events[type]; if (!evlistener) ret = [];else if (typeof evlistener === 'function') ret = [evlistener.listener || evlistener];else ret = unwrapListeners(evlistener); } return ret; }; EventEmitter.listenerCount = function (emitter, type) { if (typeof emitter.listenerCount === 'function') { return emitter.listenerCount(type); } else { return listenerCount.call(emitter, type); } }; EventEmitter.prototype.listenerCount = listenerCount; function listenerCount(type) { var events = this._events; if (events) { var evlistener = events[type]; if (typeof evlistener === 'function') { return 1; } else if (evlistener) { return evlistener.length; } } return 0; } EventEmitter.prototype.eventNames = function eventNames() { return this._eventsCount > 0 ? Reflect.ownKeys(this._events) : []; }; function spliceOne(list, index) { for (var i = index, k = i + 1, n = list.length; k < n; i += 1, k += 1) { list[i] = list[k]; }list.pop(); } function arrayClone(arr, i) { var copy = new Array(i); while (i--) { copy[i] = arr[i]; }return copy; } function unwrapListeners(arr) { var ret = new Array(arr.length); for (var i = 0; i < ret.length; ++i) { ret[i] = arr[i].listener || arr[i]; } return ret; } function Callable(property) { var func = this.constructor.prototype[property]; var apply = function apply() { return func.apply(apply, arguments); }; Object.setPrototypeOf(apply, this.constructor.prototype); Object.getOwnPropertyNames(func).forEach(function (p) { Object.defineProperty(apply, p, Object.getOwnPropertyDescriptor(func, p)); }); return apply; } Callable.prototype = Object.create(Function.prototype); var SafeFunction = function (_Callable) { _inherits(SafeFunction, _Callable); function SafeFunction(fn, defaultReturn) { _classCallCheck(this, SafeFunction); if (typeof fn !== 'function') { throw new TypeError('fn\' is not a function.'); } var _this = _possibleConstructorReturn(this, (SafeFunction.__proto__ || Object.getPrototypeOf(SafeFunction)).call(this, '__call__')); _this._fn = fn; _this._rtn = defaultReturn; extend(true, _this, new EventEmitter()); return _this; } _createClass(SafeFunction, [{ key: '__call__', value: function __call__() { try { return this._fn.apply(this, arguments); } catch (err) { this.emit('error', err); return this._rtn; } } }]); return SafeFunction; }(Callable); var NOT_SUPPORTED_ENV = '[Auction Timer] The script will not work on your browser since it is out-of-date.\n\nYou can either disable the script or update your browser to avoid the alert.'; var DependencyError = function (_Error) { _inherits(DependencyError, _Error); function DependencyError(deps) { _classCallCheck(this, DependencyError); var _this2 = _possibleConstructorReturn(this, (DependencyError.__proto__ || Object.getPrototypeOf(DependencyError)).call(this, 'Dependency check failed. Dependencies, ' + deps.map(function (e) { return '"' + e + '"'; }).join(', ') + ', are not found.')); _this2.name = 'DependencyError'; return _this2; } return DependencyError; }(Error); var NotSupportedError = function (_Error2) { _inherits(NotSupportedError, _Error2); function NotSupportedError() { _classCallCheck(this, NotSupportedError); var _this3 = _possibleConstructorReturn(this, (NotSupportedError.__proto__ || Object.getPrototypeOf(NotSupportedError)).call(this, '' + NOT_SUPPORTED_ENV)); _this3.name = 'NotSupportedError'; return _this3; } return NotSupportedError; }(Error); var global$1 = typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}; var lookup = []; var revLookup = []; var Arr = typeof Uint8Array !== 'undefined' ? Uint8Array : Array; var inited = false; function init() { inited = true; var code = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'; for (var i = 0, len = code.length; i < len; ++i) { lookup[i] = code[i]; revLookup[code.charCodeAt(i)] = i; } revLookup['-'.charCodeAt(0)] = 62; revLookup['_'.charCodeAt(0)] = 63; } function toByteArray(b64) { if (!inited) { init(); } var i, j, l, tmp, placeHolders, arr; var len = b64.length; if (len % 4 > 0) { throw new Error('Invalid string. Length must be a multiple of 4'); } placeHolders = b64[len - 2] === '=' ? 2 : b64[len - 1] === '=' ? 1 : 0; arr = new Arr(len * 3 / 4 - placeHolders); l = placeHolders > 0 ? len - 4 : len; var L = 0; for (i = 0, j = 0; i < l; i += 4, j += 3) { tmp = revLookup[b64.charCodeAt(i)] << 18 | revLookup[b64.charCodeAt(i + 1)] << 12 | revLookup[b64.charCodeAt(i + 2)] << 6 | revLookup[b64.charCodeAt(i + 3)]; arr[L++] = tmp >> 16 & 0xFF; arr[L++] = tmp >> 8 & 0xFF; arr[L++] = tmp & 0xFF; } if (placeHolders === 2) { tmp = revLookup[b64.charCodeAt(i)] << 2 | revLookup[b64.charCodeAt(i + 1)] >> 4; arr[L++] = tmp & 0xFF; } else if (placeHolders === 1) { tmp = revLookup[b64.charCodeAt(i)] << 10 | revLookup[b64.charCodeAt(i + 1)] << 4 | revLookup[b64.charCodeAt(i + 2)] >> 2; arr[L++] = tmp >> 8 & 0xFF; arr[L++] = tmp & 0xFF; } return arr; } function tripletToBase64(num) { return lookup[num >> 18 & 0x3F] + lookup[num >> 12 & 0x3F] + lookup[num >> 6 & 0x3F] + lookup[num & 0x3F]; } function encodeChunk(uint8, start, end) { var tmp; var output = []; for (var i = start; i < end; i += 3) { tmp = (uint8[i] << 16) + (uint8[i + 1] << 8) + uint8[i + 2]; output.push(tripletToBase64(tmp)); } return output.join(''); } function fromByteArray(uint8) { if (!inited) { init(); } var tmp; var len = uint8.length; var extraBytes = len % 3; var output = ''; var parts = []; var maxChunkLength = 16383; for (var i = 0, len2 = len - extraBytes; i < len2; i += maxChunkLength) { parts.push(encodeChunk(uint8, i, i + maxChunkLength > len2 ? len2 : i + maxChunkLength)); } if (extraBytes === 1) { tmp = uint8[len - 1]; output += lookup[tmp >> 2]; output += lookup[tmp << 4 & 0x3F]; output += '=='; } else if (extraBytes === 2) { tmp = (uint8[len - 2] << 8) + uint8[len - 1]; output += lookup[tmp >> 10]; output += lookup[tmp >> 4 & 0x3F]; output += lookup[tmp << 2 & 0x3F]; output += '='; } parts.push(output); return parts.join(''); } function read(buffer, offset, isLE, mLen, nBytes) { var e, m; var eLen = nBytes * 8 - mLen - 1; var eMax = (1 << eLen) - 1; var eBias = eMax >> 1; var nBits = -7; var i = isLE ? nBytes - 1 : 0; var d = isLE ? -1 : 1; var s = buffer[offset + i]; i += d; e = s & (1 << -nBits) - 1; s >>= -nBits; nBits += eLen; for (; nBits > 0; e = e * 256 + buffer[offset + i], i += d, nBits -= 8) {} m = e & (1 << -nBits) - 1; e >>= -nBits; nBits += mLen; for (; nBits > 0; m = m * 256 + buffer[offset + i], i += d, nBits -= 8) {} if (e === 0) { e = 1 - eBias; } else if (e === eMax) { return m ? NaN : (s ? -1 : 1) * Infinity; } else { m = m + Math.pow(2, mLen); e = e - eBias; } return (s ? -1 : 1) * m * Math.pow(2, e - mLen); } function write(buffer, value, offset, isLE, mLen, nBytes) { var e, m, c; var eLen = nBytes * 8 - mLen - 1; var eMax = (1 << eLen) - 1; var eBias = eMax >> 1; var rt = mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0; var i = isLE ? 0 : nBytes - 1; var d = isLE ? 1 : -1; var s = value < 0 || value === 0 && 1 / value < 0 ? 1 : 0; value = Math.abs(value); if (isNaN(value) || value === Infinity) { m = isNaN(value) ? 1 : 0; e = eMax; } else { e = Math.floor(Math.log(value) / Math.LN2); if (value * (c = Math.pow(2, -e)) < 1) { e--; c *= 2; } if (e + eBias >= 1) { value += rt / c; } else { value += rt * Math.pow(2, 1 - eBias); } if (value * c >= 2) { e++; c /= 2; } if (e + eBias >= eMax) { m = 0; e = eMax; } else if (e + eBias >= 1) { m = (value * c - 1) * Math.pow(2, mLen); e = e + eBias; } else { m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen); e = 0; } } for (; mLen >= 8; buffer[offset + i] = m & 0xff, i += d, m /= 256, mLen -= 8) {} e = e << mLen | m; eLen += mLen; for (; eLen > 0; buffer[offset + i] = e & 0xff, i += d, e /= 256, eLen -= 8) {} buffer[offset + i - d] |= s * 128; } var toString = {}.toString; var isArray$1 = Array.isArray || function (arr) { return toString.call(arr) == '[object Array]'; }; var INSPECT_MAX_BYTES = 50; Buffer.TYPED_ARRAY_SUPPORT = global$1.TYPED_ARRAY_SUPPORT !== undefined ? global$1.TYPED_ARRAY_SUPPORT : true; function kMaxLength() { return Buffer.TYPED_ARRAY_SUPPORT ? 0x7fffffff : 0x3fffffff; } function createBuffer(that, length) { if (kMaxLength() < length) { throw new RangeError('Invalid typed array length'); } if (Buffer.TYPED_ARRAY_SUPPORT) { that = new Uint8Array(length); that.__proto__ = Buffer.prototype; } else { if (that === null) { that = new Buffer(length); } that.length = length; } return that; } function Buffer(arg, encodingOrOffset, length) { if (!Buffer.TYPED_ARRAY_SUPPORT && !(this instanceof Buffer)) { return new Buffer(arg, encodingOrOffset, length); } if (typeof arg === 'number') { if (typeof encodingOrOffset === 'string') { throw new Error('If encoding is specified then the first argument must be a string'); } return allocUnsafe(this, arg); } return from(this, arg, encodingOrOffset, length); } Buffer.poolSize = 8192; Buffer._augment = function (arr) { arr.__proto__ = Buffer.prototype; return arr; }; function from(that, value, encodingOrOffset, length) { if (typeof value === 'number') { throw new TypeError('"value" argument must not be a number'); } if (typeof ArrayBuffer !== 'undefined' && value instanceof ArrayBuffer) { return fromArrayBuffer(that, value, encodingOrOffset, length); } if (typeof value === 'string') { return fromString(that, value, encodingOrOffset); } return fromObject(that, value); } Buffer.from = function (value, encodingOrOffset, length) { return from(null, value, encodingOrOffset, length); }; if (Buffer.TYPED_ARRAY_SUPPORT) { Buffer.prototype.__proto__ = Uint8Array.prototype; Buffer.__proto__ = Uint8Array; } function assertSize(size) { if (typeof size !== 'number') { throw new TypeError('"size" argument must be a number'); } else if (size < 0) { throw new RangeError('"size" argument must not be negative'); } } function alloc(that, size, fill, encoding) { assertSize(size); if (size <= 0) { return createBuffer(that, size); } if (fill !== undefined) { return typeof encoding === 'string' ? createBuffer(that, size).fill(fill, encoding) : createBuffer(that, size).fill(fill); } return createBuffer(that, size); } Buffer.alloc = function (size, fill, encoding) { return alloc(null, size, fill, encoding); }; function allocUnsafe(that, size) { assertSize(size); that = createBuffer(that, size < 0 ? 0 : checked(size) | 0); if (!Buffer.TYPED_ARRAY_SUPPORT) { for (var i = 0; i < size; ++i) { that[i] = 0; } } return that; } Buffer.allocUnsafe = function (size) { return allocUnsafe(null, size); }; Buffer.allocUnsafeSlow = function (size) { return allocUnsafe(null, size); }; function fromString(that, string, encoding) { if (typeof encoding !== 'string' || encoding === '') { encoding = 'utf8'; } if (!Buffer.isEncoding(encoding)) { throw new TypeError('"encoding" must be a valid string encoding'); } var length = byteLength(string, encoding) | 0; that = createBuffer(that, length); var actual = that.write(string, encoding); if (actual !== length) { that = that.slice(0, actual); } return that; } function fromArrayLike(that, array) { var length = array.length < 0 ? 0 : checked(array.length) | 0; that = createBuffer(that, length); for (var i = 0; i < length; i += 1) { that[i] = array[i] & 255; } return that; } function fromArrayBuffer(that, array, byteOffset, length) { array.byteLength; if (byteOffset < 0 || array.byteLength < byteOffset) { throw new RangeError('\'offset\' is out of bounds'); } if (array.byteLength < byteOffset + (length || 0)) { throw new RangeError('\'length\' is out of bounds'); } if (byteOffset === undefined && length === undefined) { array = new Uint8Array(array); } else if (length === undefined) { array = new Uint8Array(array, byteOffset); } else { array = new Uint8Array(array, byteOffset, length); } if (Buffer.TYPED_ARRAY_SUPPORT) { that = array; that.__proto__ = Buffer.prototype; } else { that = fromArrayLike(that, array); } return that; } function fromObject(that, obj) { if (internalIsBuffer(obj)) { var len = checked(obj.length) | 0; that = createBuffer(that, len); if (that.length === 0) { return that; } obj.copy(that, 0, 0, len); return that; } if (obj) { if (typeof ArrayBuffer !== 'undefined' && obj.buffer instanceof ArrayBuffer || 'length' in obj) { if (typeof obj.length !== 'number' || isnan(obj.length)) { return createBuffer(that, 0); } return fromArrayLike(that, obj); } if (obj.type === 'Buffer' && isArray$1(obj.data)) { return fromArrayLike(that, obj.data); } } throw new TypeError('First argument must be a string, Buffer, ArrayBuffer, Array, or array-like object.'); } function checked(length) { if (length >= kMaxLength()) { throw new RangeError('Attempt to allocate Buffer larger than maximum ' + 'size: 0x' + kMaxLength().toString(16) + ' bytes'); } return length | 0; } Buffer.isBuffer = isBuffer; function internalIsBuffer(b) { return !!(b != null && b._isBuffer); } Buffer.compare = function compare(a, b) { if (!internalIsBuffer(a) || !internalIsBuffer(b)) { throw new TypeError('Arguments must be Buffers'); } if (a === b) return 0; var x = a.length; var y = b.length; for (var i = 0, len = Math.min(x, y); i < len; ++i) { if (a[i] !== b[i]) { x = a[i]; y = b[i]; break; } } if (x < y) return -1; if (y < x) return 1; return 0; }; Buffer.isEncoding = function isEncoding(encoding) { switch (String(encoding).toLowerCase()) { case 'hex': case 'utf8': case 'utf-8': case 'ascii': case 'latin1': case 'binary': case 'base64': case 'ucs2': case 'ucs-2': case 'utf16le': case 'utf-16le': return true; default: return false; } }; Buffer.concat = function concat(list, length) { if (!isArray$1(list)) { throw new TypeError('"list" argument must be an Array of Buffers'); } if (list.length === 0) { return Buffer.alloc(0); } var i; if (length === undefined) { length = 0; for (i = 0; i < list.length; ++i) { length += list[i].length; } } var buffer = Buffer.allocUnsafe(length); var pos = 0; for (i = 0; i < list.length; ++i) { var buf = list[i]; if (!internalIsBuffer(buf)) { throw new TypeError('"list" argument must be an Array of Buffers'); } buf.copy(buffer, pos); pos += buf.length; } return buffer; }; function byteLength(string, encoding) { if (internalIsBuffer(string)) { return string.length; } if (typeof ArrayBuffer !== 'undefined' && typeof ArrayBuffer.isView === 'function' && (ArrayBuffer.isView(string) || string instanceof ArrayBuffer)) { return string.byteLength; } if (typeof string !== 'string') { string = '' + string; } var len = string.length; if (len === 0) return 0; var loweredCase = false; for (;;) { switch (encoding) { case 'ascii': case 'latin1': case 'binary': return len; case 'utf8': case 'utf-8': case undefined: return utf8ToBytes(string).length; case 'ucs2': case 'ucs-2': case 'utf16le': case 'utf-16le': return len * 2; case 'hex': return len >>> 1; case 'base64': return base64ToBytes(string).length; default: if (loweredCase) return utf8ToBytes(string).length; encoding = ('' + encoding).toLowerCase(); loweredCase = true; } } } Buffer.byteLength = byteLength; function slowToString(encoding, start, end) { var loweredCase = false; if (start === undefined || start < 0) { start = 0; } if (start > this.length) { return ''; } if (end === undefined || end > this.length) { end = this.length; } if (end <= 0) { return ''; } end >>>= 0; start >>>= 0; if (end <= start) { return ''; } if (!encoding) encoding = 'utf8'; while (true) { switch (encoding) { case 'hex': return hexSlice(this, start, end); case 'utf8': case 'utf-8': return utf8Slice(this, start, end); case 'ascii': return asciiSlice(this, start, end); case 'latin1': case 'binary': return latin1Slice(this, start, end); case 'base64': return base64Slice(this, start, end); case 'ucs2': case 'ucs-2': case 'utf16le': case 'utf-16le': return utf16leSlice(this, start, end); default: if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding); encoding = (encoding + '').toLowerCase(); loweredCase = true; } } } Buffer.prototype._isBuffer = true; function swap(b, n, m) { var i = b[n]; b[n] = b[m]; b[m] = i; } Buffer.prototype.swap16 = function swap16() { var len = this.length; if (len % 2 !== 0) { throw new RangeError('Buffer size must be a multiple of 16-bits'); } for (var i = 0; i < len; i += 2) { swap(this, i, i + 1); } return this; }; Buffer.prototype.swap32 = function swap32() { var len = this.length; if (len % 4 !== 0) { throw new RangeError('Buffer size must be a multiple of 32-bits'); } for (var i = 0; i < len; i += 4) { swap(this, i, i + 3); swap(this, i + 1, i + 2); } return this; }; Buffer.prototype.swap64 = function swap64() { var len = this.length; if (len % 8 !== 0) { throw new RangeError('Buffer size must be a multiple of 64-bits'); } for (var i = 0; i < len; i += 8) { swap(this, i, i + 7); swap(this, i + 1, i + 6); swap(this, i + 2, i + 5); swap(this, i + 3, i + 4); } return this; }; Buffer.prototype.toString = function toString() { var length = this.length | 0; if (length === 0) return ''; if (arguments.length === 0) return utf8Slice(this, 0, length); return slowToString.apply(this, arguments); }; Buffer.prototype.equals = function equals(b) { if (!internalIsBuffer(b)) throw new TypeError('Argument must be a Buffer'); if (this === b) return true; return Buffer.compare(this, b) === 0; }; Buffer.prototype.inspect = function inspect() { var str = ''; var max = INSPECT_MAX_BYTES; if (this.length > 0) { str = this.toString('hex', 0, max).match(/.{2}/g).join(' '); if (this.length > max) str += ' ... '; } return ''; }; Buffer.prototype.compare = function compare(target, start, end, thisStart, thisEnd) { if (!internalIsBuffer(target)) { throw new TypeError('Argument must be a Buffer'); } if (start === undefined) { start = 0; } if (end === undefined) { end = target ? target.length : 0; } if (thisStart === undefined) { thisStart = 0; } if (thisEnd === undefined) { thisEnd = this.length; } if (start < 0 || end > target.length || thisStart < 0 || thisEnd > this.length) { throw new RangeError('out of range index'); } if (thisStart >= thisEnd && start >= end) { return 0; } if (thisStart >= thisEnd) { return -1; } if (start >= end) { return 1; } start >>>= 0; end >>>= 0; thisStart >>>= 0; thisEnd >>>= 0; if (this === target) return 0; var x = thisEnd - thisStart; var y = end - start; var len = Math.min(x, y); var thisCopy = this.slice(thisStart, thisEnd); var targetCopy = target.slice(start, end); for (var i = 0; i < len; ++i) { if (thisCopy[i] !== targetCopy[i]) { x = thisCopy[i]; y = targetCopy[i]; break; } } if (x < y) return -1; if (y < x) return 1; return 0; }; function bidirectionalIndexOf(buffer, val, byteOffset, encoding, dir) { if (buffer.length === 0) return -1; if (typeof byteOffset === 'string') { encoding = byteOffset; byteOffset = 0; } else if (byteOffset > 0x7fffffff) { byteOffset = 0x7fffffff; } else if (byteOffset < -0x80000000) { byteOffset = -0x80000000; } byteOffset = +byteOffset; if (isNaN(byteOffset)) { byteOffset = dir ? 0 : buffer.length - 1; } if (byteOffset < 0) byteOffset = buffer.length + byteOffset; if (byteOffset >= buffer.length) { if (dir) return -1;else byteOffset = buffer.length - 1; } else if (byteOffset < 0) { if (dir) byteOffset = 0;else return -1; } if (typeof val === 'string') { val = Buffer.from(val, encoding); } if (internalIsBuffer(val)) { if (val.length === 0) { return -1; } return arrayIndexOf(buffer, val, byteOffset, encoding, dir); } else if (typeof val === 'number') { val = val & 0xFF; if (Buffer.TYPED_ARRAY_SUPPORT && typeof Uint8Array.prototype.indexOf === 'function') { if (dir) { return Uint8Array.prototype.indexOf.call(buffer, val, byteOffset); } else { return Uint8Array.prototype.lastIndexOf.call(buffer, val, byteOffset); } } return arrayIndexOf(buffer, [val], byteOffset, encoding, dir); } throw new TypeError('val must be string, number or Buffer'); } function arrayIndexOf(arr, val, byteOffset, encoding, dir) { var indexSize = 1; var arrLength = arr.length; var valLength = val.length; if (encoding !== undefined) { encoding = String(encoding).toLowerCase(); if (encoding === 'ucs2' || encoding === 'ucs-2' || encoding === 'utf16le' || encoding === 'utf-16le') { if (arr.length < 2 || val.length < 2) { return -1; } indexSize = 2; arrLength /= 2; valLength /= 2; byteOffset /= 2; } } function read$$1(buf, i) { if (indexSize === 1) { return buf[i]; } else { return buf.readUInt16BE(i * indexSize); } } var i; if (dir) { var foundIndex = -1; for (i = byteOffset; i < arrLength; i++) { if (read$$1(arr, i) === read$$1(val, foundIndex === -1 ? 0 : i - foundIndex)) { if (foundIndex === -1) foundIndex = i; if (i - foundIndex + 1 === valLength) return foundIndex * indexSize; } else { if (foundIndex !== -1) i -= i - foundIndex; foundIndex = -1; } } } else { if (byteOffset + valLength > arrLength) byteOffset = arrLength - valLength; for (i = byteOffset; i >= 0; i--) { var found = true; for (var j = 0; j < valLength; j++) { if (read$$1(arr, i + j) !== read$$1(val, j)) { found = false; break; } } if (found) return i; } } return -1; } Buffer.prototype.includes = function includes(val, byteOffset, encoding) { return this.indexOf(val, byteOffset, encoding) !== -1; }; Buffer.prototype.indexOf = function indexOf(val, byteOffset, encoding) { return bidirectionalIndexOf(this, val, byteOffset, encoding, true); }; Buffer.prototype.lastIndexOf = function lastIndexOf(val, byteOffset, encoding) { return bidirectionalIndexOf(this, val, byteOffset, encoding, false); }; function hexWrite(buf, string, offset, length) { offset = Number(offset) || 0; var remaining = buf.length - offset; if (!length) { length = remaining; } else { length = Number(length); if (length > remaining) { length = remaining; } } var strLen = string.length; if (strLen % 2 !== 0) throw new TypeError('Invalid hex string'); if (length > strLen / 2) { length = strLen / 2; } for (var i = 0; i < length; ++i) { var parsed = parseInt(string.substr(i * 2, 2), 16); if (isNaN(parsed)) return i; buf[offset + i] = parsed; } return i; } function utf8Write(buf, string, offset, length) { return blitBuffer(utf8ToBytes(string, buf.length - offset), buf, offset, length); } function asciiWrite(buf, string, offset, length) { return blitBuffer(asciiToBytes(string), buf, offset, length); } function latin1Write(buf, string, offset, length) { return asciiWrite(buf, string, offset, length); } function base64Write(buf, string, offset, length) { return blitBuffer(base64ToBytes(string), buf, offset, length); } function ucs2Write(buf, string, offset, length) { return blitBuffer(utf16leToBytes(string, buf.length - offset), buf, offset, length); } Buffer.prototype.write = function write$$1(string, offset, length, encoding) { if (offset === undefined) { encoding = 'utf8'; length = this.length; offset = 0; } else if (length === undefined && typeof offset === 'string') { encoding = offset; length = this.length; offset = 0; } else if (isFinite(offset)) { offset = offset | 0; if (isFinite(length)) { length = length | 0; if (encoding === undefined) encoding = 'utf8'; } else { encoding = length; length = undefined; } } else { throw new Error('Buffer.write(string, encoding, offset[, length]) is no longer supported'); } var remaining = this.length - offset; if (length === undefined || length > remaining) length = remaining; if (string.length > 0 && (length < 0 || offset < 0) || offset > this.length) { throw new RangeError('Attempt to write outside buffer bounds'); } if (!encoding) encoding = 'utf8'; var loweredCase = false; for (;;) { switch (encoding) { case 'hex': return hexWrite(this, string, offset, length); case 'utf8': case 'utf-8': return utf8Write(this, string, offset, length); case 'ascii': return asciiWrite(this, string, offset, length); case 'latin1': case 'binary': return latin1Write(this, string, offset, length); case 'base64': return base64Write(this, string, offset, length); case 'ucs2': case 'ucs-2': case 'utf16le': case 'utf-16le': return ucs2Write(this, string, offset, length); default: if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding); encoding = ('' + encoding).toLowerCase(); loweredCase = true; } } }; Buffer.prototype.toJSON = function toJSON() { return { type: 'Buffer', data: Array.prototype.slice.call(this._arr || this, 0) }; }; function base64Slice(buf, start, end) { if (start === 0 && end === buf.length) { return fromByteArray(buf); } else { return fromByteArray(buf.slice(start, end)); } } function utf8Slice(buf, start, end) { end = Math.min(buf.length, end); var res = []; var i = start; while (i < end) { var firstByte = buf[i]; var codePoint = null; var bytesPerSequence = firstByte > 0xEF ? 4 : firstByte > 0xDF ? 3 : firstByte > 0xBF ? 2 : 1; if (i + bytesPerSequence <= end) { var secondByte, thirdByte, fourthByte, tempCodePoint; switch (bytesPerSequence) { case 1: if (firstByte < 0x80) { codePoint = firstByte; } break; case 2: secondByte = buf[i + 1]; if ((secondByte & 0xC0) === 0x80) { tempCodePoint = (firstByte & 0x1F) << 0x6 | secondByte & 0x3F; if (tempCodePoint > 0x7F) { codePoint = tempCodePoint; } } break; case 3: secondByte = buf[i + 1]; thirdByte = buf[i + 2]; if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80) { tempCodePoint = (firstByte & 0xF) << 0xC | (secondByte & 0x3F) << 0x6 | thirdByte & 0x3F; if (tempCodePoint > 0x7FF && (tempCodePoint < 0xD800 || tempCodePoint > 0xDFFF)) { codePoint = tempCodePoint; } } break; case 4: secondByte = buf[i + 1]; thirdByte = buf[i + 2]; fourthByte = buf[i + 3]; if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80 && (fourthByte & 0xC0) === 0x80) { tempCodePoint = (firstByte & 0xF) << 0x12 | (secondByte & 0x3F) << 0xC | (thirdByte & 0x3F) << 0x6 | fourthByte & 0x3F; if (tempCodePoint > 0xFFFF && tempCodePoint < 0x110000) { codePoint = tempCodePoint; } } } } if (codePoint === null) { codePoint = 0xFFFD; bytesPerSequence = 1; } else if (codePoint > 0xFFFF) { codePoint -= 0x10000; res.push(codePoint >>> 10 & 0x3FF | 0xD800); codePoint = 0xDC00 | codePoint & 0x3FF; } res.push(codePoint); i += bytesPerSequence; } return decodeCodePointsArray(res); } var MAX_ARGUMENTS_LENGTH = 0x1000; function decodeCodePointsArray(codePoints) { var len = codePoints.length; if (len <= MAX_ARGUMENTS_LENGTH) { return String.fromCharCode.apply(String, codePoints); } var res = ''; var i = 0; while (i < len) { res += String.fromCharCode.apply(String, codePoints.slice(i, i += MAX_ARGUMENTS_LENGTH)); } return res; } function asciiSlice(buf, start, end) { var ret = ''; end = Math.min(buf.length, end); for (var i = start; i < end; ++i) { ret += String.fromCharCode(buf[i] & 0x7F); } return ret; } function latin1Slice(buf, start, end) { var ret = ''; end = Math.min(buf.length, end); for (var i = start; i < end; ++i) { ret += String.fromCharCode(buf[i]); } return ret; } function hexSlice(buf, start, end) { var len = buf.length; if (!start || start < 0) start = 0; if (!end || end < 0 || end > len) end = len; var out = ''; for (var i = start; i < end; ++i) { out += toHex(buf[i]); } return out; } function utf16leSlice(buf, start, end) { var bytes = buf.slice(start, end); var res = ''; for (var i = 0; i < bytes.length; i += 2) { res += String.fromCharCode(bytes[i] + bytes[i + 1] * 256); } return res; } Buffer.prototype.slice = function slice(start, end) { var len = this.length; start = ~~start; end = end === undefined ? len : ~~end; if (start < 0) { start += len; if (start < 0) start = 0; } else if (start > len) { start = len; } if (end < 0) { end += len; if (end < 0) end = 0; } else if (end > len) { end = len; } if (end < start) end = start; var newBuf; if (Buffer.TYPED_ARRAY_SUPPORT) { newBuf = this.subarray(start, end); newBuf.__proto__ = Buffer.prototype; } else { var sliceLen = end - start; newBuf = new Buffer(sliceLen, undefined); for (var i = 0; i < sliceLen; ++i) { newBuf[i] = this[i + start]; } } return newBuf; }; function checkOffset(offset, ext, length) { if (offset % 1 !== 0 || offset < 0) throw new RangeError('offset is not uint'); if (offset + ext > length) throw new RangeError('Trying to access beyond buffer length'); } Buffer.prototype.readUIntLE = function readUIntLE(offset, byteLength, noAssert) { offset = offset | 0; byteLength = byteLength | 0; if (!noAssert) checkOffset(offset, byteLength, this.length); var val = this[offset]; var mul = 1; var i = 0; while (++i < byteLength && (mul *= 0x100)) { val += this[offset + i] * mul; } return val; }; Buffer.prototype.readUIntBE = function readUIntBE(offset, byteLength, noAssert) { offset = offset | 0; byteLength = byteLength | 0; if (!noAssert) { checkOffset(offset, byteLength, this.length); } var val = this[offset + --byteLength]; var mul = 1; while (byteLength > 0 && (mul *= 0x100)) { val += this[offset + --byteLength] * mul; } return val; }; Buffer.prototype.readUInt8 = function readUInt8(offset, noAssert) { if (!noAssert) checkOffset(offset, 1, this.length); return this[offset]; }; Buffer.prototype.readUInt16LE = function readUInt16LE(offset, noAssert) { if (!noAssert) checkOffset(offset, 2, this.length); return this[offset] | this[offset + 1] << 8; }; Buffer.prototype.readUInt16BE = function readUInt16BE(offset, noAssert) { if (!noAssert) checkOffset(offset, 2, this.length); return this[offset] << 8 | this[offset + 1]; }; Buffer.prototype.readUInt32LE = function readUInt32LE(offset, noAssert) { if (!noAssert) checkOffset(offset, 4, this.length); return (this[offset] | this[offset + 1] << 8 | this[offset + 2] << 16) + this[offset + 3] * 0x1000000; }; Buffer.prototype.readUInt32BE = function readUInt32BE(offset, noAssert) { if (!noAssert) checkOffset(offset, 4, this.length); return this[offset] * 0x1000000 + (this[offset + 1] << 16 | this[offset + 2] << 8 | this[offset + 3]); }; Buffer.prototype.readIntLE = function readIntLE(offset, byteLength, noAssert) { offset = offset | 0; byteLength = byteLength | 0; if (!noAssert) checkOffset(offset, byteLength, this.length); var val = this[offset]; var mul = 1; var i = 0; while (++i < byteLength && (mul *= 0x100)) { val += this[offset + i] * mul; } mul *= 0x80; if (val >= mul) val -= Math.pow(2, 8 * byteLength); return val; }; Buffer.prototype.readIntBE = function readIntBE(offset, byteLength, noAssert) { offset = offset | 0; byteLength = byteLength | 0; if (!noAssert) checkOffset(offset, byteLength, this.length); var i = byteLength; var mul = 1; var val = this[offset + --i]; while (i > 0 && (mul *= 0x100)) { val += this[offset + --i] * mul; } mul *= 0x80; if (val >= mul) val -= Math.pow(2, 8 * byteLength); return val; }; Buffer.prototype.readInt8 = function readInt8(offset, noAssert) { if (!noAssert) checkOffset(offset, 1, this.length); if (!(this[offset] & 0x80)) return this[offset]; return (0xff - this[offset] + 1) * -1; }; Buffer.prototype.readInt16LE = function readInt16LE(offset, noAssert) { if (!noAssert) checkOffset(offset, 2, this.length); var val = this[offset] | this[offset + 1] << 8; return val & 0x8000 ? val | 0xFFFF0000 : val; }; Buffer.prototype.readInt16BE = function readInt16BE(offset, noAssert) { if (!noAssert) checkOffset(offset, 2, this.length); var val = this[offset + 1] | this[offset] << 8; return val & 0x8000 ? val | 0xFFFF0000 : val; }; Buffer.prototype.readInt32LE = function readInt32LE(offset, noAssert) { if (!noAssert) checkOffset(offset, 4, this.length); return this[offset] | this[offset + 1] << 8 | this[offset + 2] << 16 | this[offset + 3] << 24; }; Buffer.prototype.readInt32BE = function readInt32BE(offset, noAssert) { if (!noAssert) checkOffset(offset, 4, this.length); return this[offset] << 24 | this[offset + 1] << 16 | this[offset + 2] << 8 | this[offset + 3]; }; Buffer.prototype.readFloatLE = function readFloatLE(offset, noAssert) { if (!noAssert) checkOffset(offset, 4, this.length); return read(this, offset, true, 23, 4); }; Buffer.prototype.readFloatBE = function readFloatBE(offset, noAssert) { if (!noAssert) checkOffset(offset, 4, this.length); return read(this, offset, false, 23, 4); }; Buffer.prototype.readDoubleLE = function readDoubleLE(offset, noAssert) { if (!noAssert) checkOffset(offset, 8, this.length); return read(this, offset, true, 52, 8); }; Buffer.prototype.readDoubleBE = function readDoubleBE(offset, noAssert) { if (!noAssert) checkOffset(offset, 8, this.length); return read(this, offset, false, 52, 8); }; function checkInt(buf, value, offset, ext, max, min) { if (!internalIsBuffer(buf)) throw new TypeError('"buffer" argument must be a Buffer instance'); if (value > max || value < min) throw new RangeError('"value" argument is out of bounds'); if (offset + ext > buf.length) throw new RangeError('Index out of range'); } Buffer.prototype.writeUIntLE = function writeUIntLE(value, offset, byteLength, noAssert) { value = +value; offset = offset | 0; byteLength = byteLength | 0; if (!noAssert) { var maxBytes = Math.pow(2, 8 * byteLength) - 1; checkInt(this, value, offset, byteLength, maxBytes, 0); } var mul = 1; var i = 0; this[offset] = value & 0xFF; while (++i < byteLength && (mul *= 0x100)) { this[offset + i] = value / mul & 0xFF; } return offset + byteLength; }; Buffer.prototype.writeUIntBE = function writeUIntBE(value, offset, byteLength, noAssert) { value = +value; offset = offset | 0; byteLength = byteLength | 0; if (!noAssert) { var maxBytes = Math.pow(2, 8 * byteLength) - 1; checkInt(this, value, offset, byteLength, maxBytes, 0); } var i = byteLength - 1; var mul = 1; this[offset + i] = value & 0xFF; while (--i >= 0 && (mul *= 0x100)) { this[offset + i] = value / mul & 0xFF; } return offset + byteLength; }; Buffer.prototype.writeUInt8 = function writeUInt8(value, offset, noAssert) { value = +value; offset = offset | 0; if (!noAssert) checkInt(this, value, offset, 1, 0xff, 0); if (!Buffer.TYPED_ARRAY_SUPPORT) value = Math.floor(value); this[offset] = value & 0xff; return offset + 1; }; function objectWriteUInt16(buf, value, offset, littleEndian) { if (value < 0) value = 0xffff + value + 1; for (var i = 0, j = Math.min(buf.length - offset, 2); i < j; ++i) { buf[offset + i] = (value & 0xff << 8 * (littleEndian ? i : 1 - i)) >>> (littleEndian ? i : 1 - i) * 8; } } Buffer.prototype.writeUInt16LE = function writeUInt16LE(value, offset, noAssert) { value = +value; offset = offset | 0; if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0); if (Buffer.TYPED_ARRAY_SUPPORT) { this[offset] = value & 0xff; this[offset + 1] = value >>> 8; } else { objectWriteUInt16(this, value, offset, true); } return offset + 2; }; Buffer.prototype.writeUInt16BE = function writeUInt16BE(value, offset, noAssert) { value = +value; offset = offset | 0; if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0); if (Buffer.TYPED_ARRAY_SUPPORT) { this[offset] = value >>> 8; this[offset + 1] = value & 0xff; } else { objectWriteUInt16(this, value, offset, false); } return offset + 2; }; function objectWriteUInt32(buf, value, offset, littleEndian) { if (value < 0) value = 0xffffffff + value + 1; for (var i = 0, j = Math.min(buf.length - offset, 4); i < j; ++i) { buf[offset + i] = value >>> (littleEndian ? i : 3 - i) * 8 & 0xff; } } Buffer.prototype.writeUInt32LE = function writeUInt32LE(value, offset, noAssert) { value = +value; offset = offset | 0; if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0); if (Buffer.TYPED_ARRAY_SUPPORT) { this[offset + 3] = value >>> 24; this[offset + 2] = value >>> 16; this[offset + 1] = value >>> 8; this[offset] = value & 0xff; } else { objectWriteUInt32(this, value, offset, true); } return offset + 4; }; Buffer.prototype.writeUInt32BE = function writeUInt32BE(value, offset, noAssert) { value = +value; offset = offset | 0; if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0); if (Buffer.TYPED_ARRAY_SUPPORT) { this[offset] = value >>> 24; this[offset + 1] = value >>> 16; this[offset + 2] = value >>> 8; this[offset + 3] = value & 0xff; } else { objectWriteUInt32(this, value, offset, false); } return offset + 4; }; Buffer.prototype.writeIntLE = function writeIntLE(value, offset, byteLength, noAssert) { value = +value; offset = offset | 0; if (!noAssert) { var limit = Math.pow(2, 8 * byteLength - 1); checkInt(this, value, offset, byteLength, limit - 1, -limit); } var i = 0; var mul = 1; var sub = 0; this[offset] = value & 0xFF; while (++i < byteLength && (mul *= 0x100)) { if (value < 0 && sub === 0 && this[offset + i - 1] !== 0) { sub = 1; } this[offset + i] = (value / mul >> 0) - sub & 0xFF; } return offset + byteLength; }; Buffer.prototype.writeIntBE = function writeIntBE(value, offset, byteLength, noAssert) { value = +value; offset = offset | 0; if (!noAssert) { var limit = Math.pow(2, 8 * byteLength - 1); checkInt(this, value, offset, byteLength, limit - 1, -limit); } var i = byteLength - 1; var mul = 1; var sub = 0; this[offset + i] = value & 0xFF; while (--i >= 0 && (mul *= 0x100)) { if (value < 0 && sub === 0 && this[offset + i + 1] !== 0) { sub = 1; } this[offset + i] = (value / mul >> 0) - sub & 0xFF; } return offset + byteLength; }; Buffer.prototype.writeInt8 = function writeInt8(value, offset, noAssert) { value = +value; offset = offset | 0; if (!noAssert) checkInt(this, value, offset, 1, 0x7f, -0x80); if (!Buffer.TYPED_ARRAY_SUPPORT) value = Math.floor(value); if (value < 0) value = 0xff + value + 1; this[offset] = value & 0xff; return offset + 1; }; Buffer.prototype.writeInt16LE = function writeInt16LE(value, offset, noAssert) { value = +value; offset = offset | 0; if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000); if (Buffer.TYPED_ARRAY_SUPPORT) { this[offset] = value & 0xff; this[offset + 1] = value >>> 8; } else { objectWriteUInt16(this, value, offset, true); } return offset + 2; }; Buffer.prototype.writeInt16BE = function writeInt16BE(value, offset, noAssert) { value = +value; offset = offset | 0; if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000); if (Buffer.TYPED_ARRAY_SUPPORT) { this[offset] = value >>> 8; this[offset + 1] = value & 0xff; } else { objectWriteUInt16(this, value, offset, false); } return offset + 2; }; Buffer.prototype.writeInt32LE = function writeInt32LE(value, offset, noAssert) { value = +value; offset = offset | 0; if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000); if (Buffer.TYPED_ARRAY_SUPPORT) { this[offset] = value & 0xff; this[offset + 1] = value >>> 8; this[offset + 2] = value >>> 16; this[offset + 3] = value >>> 24; } else { objectWriteUInt32(this, value, offset, true); } return offset + 4; }; Buffer.prototype.writeInt32BE = function writeInt32BE(value, offset, noAssert) { value = +value; offset = offset | 0; if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000); if (value < 0) value = 0xffffffff + value + 1; if (Buffer.TYPED_ARRAY_SUPPORT) { this[offset] = value >>> 24; this[offset + 1] = value >>> 16; this[offset + 2] = value >>> 8; this[offset + 3] = value & 0xff; } else { objectWriteUInt32(this, value, offset, false); } return offset + 4; }; function checkIEEE754(buf, value, offset, ext, max, min) { if (offset + ext > buf.length) throw new RangeError('Index out of range'); if (offset < 0) throw new RangeError('Index out of range'); } function writeFloat(buf, value, offset, littleEndian, noAssert) { if (!noAssert) { checkIEEE754(buf, value, offset, 4, 3.4028234663852886e+38, -3.4028234663852886e+38); } write(buf, value, offset, littleEndian, 23, 4); return offset + 4; } Buffer.prototype.writeFloatLE = function writeFloatLE(value, offset, noAssert) { return writeFloat(this, value, offset, true, noAssert); }; Buffer.prototype.writeFloatBE = function writeFloatBE(value, offset, noAssert) { return writeFloat(this, value, offset, false, noAssert); }; function writeDouble(buf, value, offset, littleEndian, noAssert) { if (!noAssert) { checkIEEE754(buf, value, offset, 8, 1.7976931348623157E+308, -1.7976931348623157E+308); } write(buf, value, offset, littleEndian, 52, 8); return offset + 8; } Buffer.prototype.writeDoubleLE = function writeDoubleLE(value, offset, noAssert) { return writeDouble(this, value, offset, true, noAssert); }; Buffer.prototype.writeDoubleBE = function writeDoubleBE(value, offset, noAssert) { return writeDouble(this, value, offset, false, noAssert); }; Buffer.prototype.copy = function copy(target, targetStart, start, end) { if (!start) start = 0; if (!end && end !== 0) end = this.length; if (targetStart >= target.length) targetStart = target.length; if (!targetStart) targetStart = 0; if (end > 0 && end < start) end = start; if (end === start) return 0; if (target.length === 0 || this.length === 0) return 0; if (targetStart < 0) { throw new RangeError('targetStart out of bounds'); } if (start < 0 || start >= this.length) throw new RangeError('sourceStart out of bounds'); if (end < 0) throw new RangeError('sourceEnd out of bounds'); if (end > this.length) end = this.length; if (target.length - targetStart < end - start) { end = target.length - targetStart + start; } var len = end - start; var i; if (this === target && start < targetStart && targetStart < end) { for (i = len - 1; i >= 0; --i) { target[i + targetStart] = this[i + start]; } } else if (len < 1000 || !Buffer.TYPED_ARRAY_SUPPORT) { for (i = 0; i < len; ++i) { target[i + targetStart] = this[i + start]; } } else { Uint8Array.prototype.set.call(target, this.subarray(start, start + len), targetStart); } return len; }; Buffer.prototype.fill = function fill(val, start, end, encoding) { if (typeof val === 'string') { if (typeof start === 'string') { encoding = start; start = 0; end = this.length; } else if (typeof end === 'string') { encoding = end; end = this.length; } if (val.length === 1) { var code = val.charCodeAt(0); if (code < 256) { val = code; } } if (encoding !== undefined && typeof encoding !== 'string') { throw new TypeError('encoding must be a string'); } if (typeof encoding === 'string' && !Buffer.isEncoding(encoding)) { throw new TypeError('Unknown encoding: ' + encoding); } } else if (typeof val === 'number') { val = val & 255; } if (start < 0 || this.length < start || this.length < end) { throw new RangeError('Out of range index'); } if (end <= start) { return this; } start = start >>> 0; end = end === undefined ? this.length : end >>> 0; if (!val) val = 0; var i; if (typeof val === 'number') { for (i = start; i < end; ++i) { this[i] = val; } } else { var bytes = internalIsBuffer(val) ? val : utf8ToBytes(new Buffer(val, encoding).toString()); var len = bytes.length; for (i = 0; i < end - start; ++i) { this[i + start] = bytes[i % len]; } } return this; }; var INVALID_BASE64_RE = /[^+\/0-9A-Za-z-_]/g; function base64clean(str) { str = stringtrim(str).replace(INVALID_BASE64_RE, ''); if (str.length < 2) return ''; while (str.length % 4 !== 0) { str = str + '='; } return str; } function stringtrim(str) { if (str.trim) return str.trim(); return str.replace(/^\s+|\s+$/g, ''); } function toHex(n) { if (n < 16) return '0' + n.toString(16); return n.toString(16); } function utf8ToBytes(string, units) { units = units || Infinity; var codePoint; var length = string.length; var leadSurrogate = null; var bytes = []; for (var i = 0; i < length; ++i) { codePoint = string.charCodeAt(i); if (codePoint > 0xD7FF && codePoint < 0xE000) { if (!leadSurrogate) { if (codePoint > 0xDBFF) { if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD); continue; } else if (i + 1 === length) { if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD); continue; } leadSurrogate = codePoint; continue; } if (codePoint < 0xDC00) { if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD); leadSurrogate = codePoint; continue; } codePoint = (leadSurrogate - 0xD800 << 10 | codePoint - 0xDC00) + 0x10000; } else if (leadSurrogate) { if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD); } leadSurrogate = null; if (codePoint < 0x80) { if ((units -= 1) < 0) break; bytes.push(codePoint); } else if (codePoint < 0x800) { if ((units -= 2) < 0) break; bytes.push(codePoint >> 0x6 | 0xC0, codePoint & 0x3F | 0x80); } else if (codePoint < 0x10000) { if ((units -= 3) < 0) break; bytes.push(codePoint >> 0xC | 0xE0, codePoint >> 0x6 & 0x3F | 0x80, codePoint & 0x3F | 0x80); } else if (codePoint < 0x110000) { if ((units -= 4) < 0) break; bytes.push(codePoint >> 0x12 | 0xF0, codePoint >> 0xC & 0x3F | 0x80, codePoint >> 0x6 & 0x3F | 0x80, codePoint & 0x3F | 0x80); } else { throw new Error('Invalid code point'); } } return bytes; } function asciiToBytes(str) { var byteArray = []; for (var i = 0; i < str.length; ++i) { byteArray.push(str.charCodeAt(i) & 0xFF); } return byteArray; } function utf16leToBytes(str, units) { var c, hi, lo; var byteArray = []; for (var i = 0; i < str.length; ++i) { if ((units -= 2) < 0) break; c = str.charCodeAt(i); hi = c >> 8; lo = c % 256; byteArray.push(lo); byteArray.push(hi); } return byteArray; } function base64ToBytes(str) { return toByteArray(base64clean(str)); } function blitBuffer(src, dst, offset, length) { for (var i = 0; i < length; ++i) { if (i + offset >= dst.length || i >= src.length) break; dst[i + offset] = src[i]; } return i; } function isnan(val) { return val !== val; } function isBuffer(obj) { return obj != null && (!!obj._isBuffer || isFastBuffer(obj) || isSlowBuffer(obj)); } function isFastBuffer(obj) { return !!obj.constructor && typeof obj.constructor.isBuffer === 'function' && obj.constructor.isBuffer(obj); } function isSlowBuffer(obj) { return typeof obj.readFloatLE === 'function' && typeof obj.slice === 'function' && isFastBuffer(obj.slice(0, 0)); } if (typeof global$1.setTimeout === 'function') {} if (typeof global$1.clearTimeout === 'function') {} var performance = global$1.performance || {}; var performanceNow = performance.now || performance.mozNow || performance.msNow || performance.oNow || performance.webkitNow || function () { return new Date().getTime(); }; var formatRegExp = /%[sdj%]/g; function format(f) { if (!isString(f)) { var objects = []; for (var i = 0; i < arguments.length; i++) { objects.push(inspect(arguments[i])); } return objects.join(' '); } var i = 1; var args = arguments; var len = args.length; var str = String(f).replace(formatRegExp, function (x) { if (x === '%%') return '%'; if (i >= len) return x; switch (x) { case '%s': return String(args[i++]); case '%d': return Number(args[i++]); case '%j': try { return JSON.stringify(args[i++]); } catch (_) { return '[Circular]'; } default: return x; } }); for (var x = args[i]; i < len; x = args[++i]) { if (isNull(x) || !isObject(x)) { str += ' ' + x; } else { str += ' ' + inspect(x); } } return str; } function inspect(obj, opts) { var ctx = { seen: [], stylize: stylizeNoColor }; if (arguments.length >= 3) ctx.depth = arguments[2]; if (arguments.length >= 4) ctx.colors = arguments[3]; if (isBoolean(opts)) { ctx.showHidden = opts; } else if (opts) { _extend(ctx, opts); } if (isUndefined(ctx.showHidden)) ctx.showHidden = false; if (isUndefined(ctx.depth)) ctx.depth = 2; if (isUndefined(ctx.colors)) ctx.colors = false; if (isUndefined(ctx.customInspect)) ctx.customInspect = true; if (ctx.colors) ctx.stylize = stylizeWithColor; return formatValue(ctx, obj, ctx.depth); } inspect.colors = { 'bold': [1, 22], 'italic': [3, 23], 'underline': [4, 24], 'inverse': [7, 27], 'white': [37, 39], 'grey': [90, 39], 'black': [30, 39], 'blue': [34, 39], 'cyan': [36, 39], 'green': [32, 39], 'magenta': [35, 39], 'red': [31, 39], 'yellow': [33, 39] }; inspect.styles = { 'special': 'cyan', 'number': 'yellow', 'boolean': 'yellow', 'undefined': 'grey', 'null': 'bold', 'string': 'green', 'date': 'magenta', 'regexp': 'red' }; function stylizeWithColor(str, styleType) { var style = inspect.styles[styleType]; if (style) { return '\x1B[' + inspect.colors[style][0] + 'm' + str + '\x1B[' + inspect.colors[style][1] + 'm'; } else { return str; } } function stylizeNoColor(str, styleType) { return str; } function arrayToHash(array) { var hash = {}; array.forEach(function (val, idx) { hash[val] = true; }); return hash; } function formatValue(ctx, value, recurseTimes) { if (ctx.customInspect && value && isFunction(value.inspect) && value.inspect !== inspect && !(value.constructor && value.constructor.prototype === value)) { var ret = value.inspect(recurseTimes, ctx); if (!isString(ret)) { ret = formatValue(ctx, ret, recurseTimes); } return ret; } var primitive = formatPrimitive(ctx, value); if (primitive) { return primitive; } var keys = Object.keys(value); var visibleKeys = arrayToHash(keys); if (ctx.showHidden) { keys = Object.getOwnPropertyNames(value); } if (isError(value) && (keys.indexOf('message') >= 0 || keys.indexOf('description') >= 0)) { return formatError(value); } if (keys.length === 0) { if (isFunction(value)) { var name = value.name ? ': ' + value.name : ''; return ctx.stylize('[Function' + name + ']', 'special'); } if (isRegExp(value)) { return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp'); } if (isDate(value)) { return ctx.stylize(Date.prototype.toString.call(value), 'date'); } if (isError(value)) { return formatError(value); } } var base = '', array = false, braces = ['{', '}']; if (isArray$2(value)) { array = true; braces = ['[', ']']; } if (isFunction(value)) { var n = value.name ? ': ' + value.name : ''; base = ' [Function' + n + ']'; } if (isRegExp(value)) { base = ' ' + RegExp.prototype.toString.call(value); } if (isDate(value)) { base = ' ' + Date.prototype.toUTCString.call(value); } if (isError(value)) { base = ' ' + formatError(value); } if (keys.length === 0 && (!array || value.length == 0)) { return braces[0] + base + braces[1]; } if (recurseTimes < 0) { if (isRegExp(value)) { return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp'); } else { return ctx.stylize('[Object]', 'special'); } } ctx.seen.push(value); var output; if (array) { output = formatArray(ctx, value, recurseTimes, visibleKeys, keys); } else { output = keys.map(function (key) { return formatProperty(ctx, value, recurseTimes, visibleKeys, key, array); }); } ctx.seen.pop(); return reduceToSingleString(output, base, braces); } function formatPrimitive(ctx, value) { if (isUndefined(value)) return ctx.stylize('undefined', 'undefined'); if (isString(value)) { var simple = '\'' + JSON.stringify(value).replace(/^"|"$/g, '').replace(/'/g, "\\'").replace(/\\"/g, '"') + '\''; return ctx.stylize(simple, 'string'); } if (isNumber(value)) return ctx.stylize('' + value, 'number'); if (isBoolean(value)) return ctx.stylize('' + value, 'boolean'); if (isNull(value)) return ctx.stylize('null', 'null'); } function formatError(value) { return '[' + Error.prototype.toString.call(value) + ']'; } function formatArray(ctx, value, recurseTimes, visibleKeys, keys) { var output = []; for (var i = 0, l = value.length; i < l; ++i) { if (hasOwnProperty(value, String(i))) { output.push(formatProperty(ctx, value, recurseTimes, visibleKeys, String(i), true)); } else { output.push(''); } } keys.forEach(function (key) { if (!key.match(/^\d+$/)) { output.push(formatProperty(ctx, value, recurseTimes, visibleKeys, key, true)); } }); return output; } function formatProperty(ctx, value, recurseTimes, visibleKeys, key, array) { var name, str, desc; desc = Object.getOwnPropertyDescriptor(value, key) || { value: value[key] }; if (desc.get) { if (desc.set) { str = ctx.stylize('[Getter/Setter]', 'special'); } else { str = ctx.stylize('[Getter]', 'special'); } } else { if (desc.set) { str = ctx.stylize('[Setter]', 'special'); } } if (!hasOwnProperty(visibleKeys, key)) { name = '[' + key + ']'; } if (!str) { if (ctx.seen.indexOf(desc.value) < 0) { if (isNull(recurseTimes)) { str = formatValue(ctx, desc.value, null); } else { str = formatValue(ctx, desc.value, recurseTimes - 1); } if (str.indexOf('\n') > -1) { if (array) { str = str.split('\n').map(function (line) { return ' ' + line; }).join('\n').substr(2); } else { str = '\n' + str.split('\n').map(function (line) { return ' ' + line; }).join('\n'); } } } else { str = ctx.stylize('[Circular]', 'special'); } } if (isUndefined(name)) { if (array && key.match(/^\d+$/)) { return str; } name = JSON.stringify('' + key); if (name.match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)) { name = name.substr(1, name.length - 2); name = ctx.stylize(name, 'name'); } else { name = name.replace(/'/g, "\\'").replace(/\\"/g, '"').replace(/(^"|"$)/g, "'"); name = ctx.stylize(name, 'string'); } } return name + ': ' + str; } function reduceToSingleString(output, base, braces) { var numLinesEst = 0; var length = output.reduce(function (prev, cur) { numLinesEst++; if (cur.indexOf('\n') >= 0) numLinesEst++; return prev + cur.replace(/\u001b\[\d\d?m/g, '').length + 1; }, 0); if (length > 60) { return braces[0] + (base === '' ? '' : base + '\n ') + ' ' + output.join(',\n ') + ' ' + braces[1]; } return braces[0] + base + ' ' + output.join(', ') + ' ' + braces[1]; } function isArray$2(ar) { return Array.isArray(ar); } function isBoolean(arg) { return typeof arg === 'boolean'; } function isNull(arg) { return arg === null; } function isNumber(arg) { return typeof arg === 'number'; } function isString(arg) { return typeof arg === 'string'; } function isUndefined(arg) { return arg === void 0; } function isRegExp(re) { return isObject(re) && objectToString(re) === '[object RegExp]'; } function isObject(arg) { return (typeof arg === 'undefined' ? 'undefined' : _typeof(arg)) === 'object' && arg !== null; } function isDate(d) { return isObject(d) && objectToString(d) === '[object Date]'; } function isError(e) { return isObject(e) && (objectToString(e) === '[object Error]' || e instanceof Error); } function isFunction(arg) { return typeof arg === 'function'; } function objectToString(o) { return Object.prototype.toString.call(o); } function _extend(origin, add) { if (!add || !isObject(add)) return origin; var keys = Object.keys(add); var i = keys.length; while (i--) { origin[keys[i]] = add[keys[i]]; } return origin; } function hasOwnProperty(obj, prop) { return Object.prototype.hasOwnProperty.call(obj, prop); } var dialogContainer = document.body.appendChild(document.createElement('div')); dialogContainer.classList.add('auc-timer-dialog-container'); var Dialog = function (_EventEmitter) { _inherits(Dialog, _EventEmitter); function Dialog(type, msg, options) { _classCallCheck(this, Dialog); if (typeof type !== 'string') type = 'info'; if (typeof msg !== 'string') msg = ''; if ((typeof options === 'undefined' ? 'undefined' : _typeof(options)) !== 'object') { options = { ttl: 5000, listeners: {} }; } var _this4 = _possibleConstructorReturn(this, (Dialog.__proto__ || Object.getPrototypeOf(Dialog)).call(this)); _this4._elListeners = {}; options.ttl = typeof options.ttl === 'number' ? options.ttl : 5000; options.listeners = _typeof(options.listeners) === 'object' ? options.listeners : {}; _this4.options = options; _this4._id = ''; _this4.isShown = false; _this4.el = dialogContainer.appendChild(document.createElement('div')); _this4.msgList = _this4.el.appendChild(document.createElement('ul')); _this4.footer = _this4.el.appendChild(document.createElement('div')); _this4.append(msg); _this4.el.classList.add('auc-timer-dialog', 'auc-timer-' + type); _this4.el.addEventListener('click', function () { _this4.hide(); }); _this4.el.addEventListener('transitionend', function (e) { if (e.propertyName === 'opacity') { if (_this4.el.classList.contains('active')) { _this4.isShown = true; _this4.emit('show'); } else if (_this4.el.classList.contains('idle')) { _this4.emit('idle'); } else { _this4.isShown = false; _this4.emit('hide'); } } }); _this4.on('show', function () { setTimeout(function () { _this4.idle(); }, _this4.options.ttl); }).on('hide', function () { dialogContainer.style.zIndex = -1000000; _this4.clear(); }); Object.keys(options.listeners).forEach(function (listener) { _this4.el.addEventListener(listener, options.listeners[listener]); }); return _this4; } _createClass(Dialog, [{ key: 'show', value: function show() { if (this.el) { dialogContainer.style.zIndex = 1000000; this.el.classList.remove('idle'); this.el.classList.add('active'); } return this; } }, { key: 'idle', value: function idle() { if (this.el) { this.el.classList.remove('active'); this.el.classList.add('idle'); } return this; } }, { key: 'hide', value: function hide() { if (this.el) { this.el.classList.remove('active', 'idle'); } return this; } }, { key: 'clear', value: function clear() { this.msgList.innerHTML = ''; this.footer.innerHTML = ''; } }, { key: 'append', value: function append(msg) { if (msg) this.msgList.appendChild(document.createElement('li')).innerHTML = msg; return this; } }, { key: 'onEl', value: function onEl(event, cb) { if (this._elListeners[event]) return this; this._elListeners[event] = cb; this.el.addEventListener(event, cb); return this; } }, { key: 'unElAll', value: function unElAll() { var _this5 = this; Object.keys(this._elListeners).forEach(function (event) { _this5.el.removeEventListener(event, _this5._elListeners[event]); }); return this; } }, { key: 'unEl', value: function unEl(event) { this.el.removeEventListener(event, this._elListeners[event]); return this; } }, { key: 'setFooter', value: function setFooter(msg) { this.footer.innerHTML = msg; return this; } }]); return Dialog; }(EventEmitter); Dialog.SHOWUP_DELAY = 500; Dialog.TRANSITION_DURATION = 500; GM_addStyle('\n .auc-timer-dialog-container {\n float: right;\n width: 280px;\n z-index: -1000000;\n position: fixed;\n right: 0;\n bottom: 20px;\n padding: 20px;\n overflow: hidden;\n }\n\n .auc-timer-dialog {\n width: 240px;\n margin-top: 8px;\n padding: 20px;\n color: #ededed;\n font-size: 16px;\n cursor: pointer;\n position: relative;\n border-radius: 2px;\n opacity: 0;\n left: 300px;\n -webkit-transition: opacity ' + Dialog.TRANSITION_DURATION + 'ms, left ' + Dialog.TRANSITION_DURATION + 'ms;\n transition: opacity ' + Dialog.TRANSITION_DURATION + 'ms, left ' + Dialog.TRANSITION_DURATION + 'ms;\n }\n\n .auc-timer-dialog>ul{\n list-style-type: square;\n position: relative;\n left: 10px;\n }\n\n .auc-timer-dialog.auc-timer-error {\n background-color: #c8181888;\n }\n\n .auc-timer-dialog.active {\n left: 0;\n opacity: 1;\n }\n\n .auc-timer-dialog.idle {\n left: 0;\n opacity: 0.5;\n }\n\n .auc-timer-dialog.idle:hover {\n opacity: 1;\n }\n'); function hasDialogShown(type) { switch (type) { case 'error': return error.dialog && error.dialog.isShown; default: return false; } } function error(msg, options) { error.dialog = error.dialog || new Dialog('error', ''); error.dialog.append(msg); if (typeof options === 'function') { error.dialog.onEl('click', options); } else if ((typeof options === 'undefined' ? 'undefined' : _typeof(options)) === 'object') { if (typeof options.click === 'function') { error.dialog.onEl('click', options.click); } if (typeof options.footer === 'string') { error.dialog.setFooter(options.footer); } } else if (typeof options === 'string') { error.dialog.setFooter(options); } setTimeout(function () { error.dialog.show(); }, Dialog.SHOWUP_DELAY); return error.dialog; } var EMPTY_LOGS = 'No logs available for the current filter.'; GM_getValue = GM_getValue || function (key, defaultVal) { if (!window.localStorage && !window.localStorage.getItem) throw new NotSupportedError(); var storage = window.localStorage.getItem(key); return storage === null ? defaultVal : storage; }; GM_setValue = GM_setValue || function (key, val) { if (!window.localStorage && !window.localStorage.setItem) throw new NotSupportedError(); window.localStorage.setItem(key, val); }; GM_addStyle('\n .auc-timer-logger {\n width: 585px;\n height: calc((100vh - 300px) * 0.9);\n background-color: #00000077;\n padding-left: 65px;\n padding-top: calc((100vh - 300px) * 0.05);\n }\n\n .auc-timer-logger.hidden {\n display: none;\n }\n\n .auc-timer-logger-logs {\n width: 520px;\n height: 80%;\n background-color: #b3c3cb;\n border: 1px solid #668599;\n border-bottom-color: #d3d9de;\n border-radius: 3px;\n box-shadow: inset 0 1px 3px 0 #454f54;\n font-size: 14px;\n font-family: Arial,Helvetica,sans-serif;\n min-height: 130px;\n padding: 5px;\n overflow-y: auto;\n }\n\n .auc-timer-logger-fn {\n width: 246px;\n height: 20px;\n cursor: pointer;\n border-radius: 4px;\n color: white;\n text-align: center;\n padding: 10px;\n font-size: 16px;\n }\n\n .auc-timer-logger-copy {\n display: inline-block;\n background-color: #0058a277;\n }\n\n .auc-timer-logger-copy:hover {\n background-color: #7cc3ff77;\n }\n\n .auc-timer-logger-reset {\n display: inline-block;\n background-color: #e4353577;\n }\n\n .auc-timer-logger-reset:hover {\n background-color: #ffa5a577;\n }\n\n .auc-timer-logger-info {\n color: green;\n }\n\n .auc-timer-logger-warn {\n color: #d88720;\n }\n\n .auc-timer-logger-debug {\n color: grey;\n }\n\n .auc-timer-logger-error {\n font-wieght: 500;\n color: red;\n }\n\n hr.auc-timer-logger-sep {\n margin-top: 4px;\n margin-bottom: 4px;\n }\n\n .auc-timer-copyzone {\n position: absolute;\n left: -10000px;\n top: -10000px;\n }\n\n .auc-timer-logger-filter {\n width: 160px;\n }\n'); var GMLogEntry = function () { function GMLogEntry(time, level, msg) { _classCallCheck(this, GMLogEntry); this.time = time; this.level = level; this.msg = msg; } _createClass(GMLogEntry, [{ key: 'toHTML', value: function toHTML() { return '
[' + this.time + '][' + this.level + '] ' + this.msg + '
'; } }, { key: 'toString', value: function toString() { return '[' + this.time + '][' + this.level + '] ' + this.msg; } }]); return GMLogEntry; }(); var GMLogger = function () { function GMLogger(config) { var _this6 = this; _classCallCheck(this, GMLogger); this.constructor.prototype.prototype = console.prototype; this._GM_key = '__logs__'; this._state_key = '__state__'; this._MAX_LOG_ENTRIES = config.MAX_LOG_ENTRIES; this._cache = []; this.level = 'error'; this.isShown = false; this.content = null; this.menuBtn = document.getElementById('menuTable').appendChild(document.createElement('li')); var menuAnchor = this.menuBtn.appendChild(document.createElement('a')); menuAnchor.href = 'javascript:void(0)'; menuAnchor.innerHTML = 'Auc. Timer'; menuAnchor.classList.add('menubutton'); menuAnchor.addEventListener('click', function () { if (_this6.isShown) { _this6.closePanel(); } else { _this6.showPanel(); } }); this._load(); } _createClass(GMLogger, [{ key: 'setLevel', value: function setLevel(level) { this.level = level; } }, { key: 'showPanel', value: function showPanel() { var _this7 = this; var logsDisplay = void 0; if (!this.content) { this.content = document.getElementById('middle').appendChild(document.createElement('div')); this.content.classList.add('auc-timer-logger'); var logFilterLabel = this.content.appendChild(document.createElement('label')); logFilterLabel.htmlFor = 'auc-timer-logfilter'; logFilterLabel.innerHTML = 'Log Level:    '; var logFilter = logFilterLabel.appendChild(document.createElement('select')); logFilter.id = 'auc-timer-logfilter'; logFilter.classList.add('auc-timer-logger-filter'); logFilter.innerHTML = '\n \n \n \n \n \n '; try { $(logFilter).ogameDropDown().on('change', function () { _this7.level = $(logFilter).val(); GM_setValue(_this7._state_key, { level: _this7.level }); _this7.loadLogs(logsDisplay); }); } catch (err) { console.error(err); } logsDisplay = this.content.appendChild(document.createElement('div')); logsDisplay.classList.add('auc-timer-logger-logs'); var resetBtn = this.content.appendChild(document.createElement('div')); resetBtn.classList.add('auc-timer-logger-reset', 'auc-timer-logger-fn'); resetBtn.innerHTML = 'Reset'; resetBtn.addEventListener('click', function () { _this7._cache = []; _this7._save(); _this7.loadLogs(logsDisplay); }); var copyBtn = this.content.appendChild(document.createElement('div')); copyBtn.classList.add('auc-timer-logger-copy', 'auc-timer-logger-fn'); copyBtn.innerHTML = 'Copy'; copyBtn.addEventListener('click', function () { var copyzone = document.body.appendChild(document.createElement('textarea')); copyzone.classList.add('auc-timer-copyzone'); copyzone.value = _this7._cache.filter(function (entry) { return GMLogger.levelMap[entry.level] >= GMLogger.levelMap[_this7.level]; }).join('\n').trim() || EMPTY_LOGS; copyzone.select(); document.execCommand('copy'); }); } else { logsDisplay = this.content.childNodes[1]; } this.loadLogs(logsDisplay); logsDisplay.scrollTop = logsDisplay.scrollHeight; this.content.classList.remove('hidden'); $(this.content).prevUntil().hide(); this.isShown = true; } }, { key: 'loadLogs', value: function loadLogs(logsDisplay) { var _this8 = this; var logs = this._cache.filter(function (entry) { return GMLogger.levelMap[entry.level] >= GMLogger.levelMap[_this8.level]; }).map(function (entry) { return entry.toHTML(); }).join('
'); logsDisplay.innerHTML = logs.trim() ? logs : '
' + EMPTY_LOGS + '
'; } }, { key: 'closePanel', value: function closePanel() { if (this.content && !this.content.classList.contains('hidden')) { this.content.classList.add('hidden'); $(this.content).prevUntil().show(); } this.isShown = false; } }, { key: '_gc', value: function _gc() { if (this._cache.length > this._MAX_LOG_ENTRIES) { this._cache.splice(0, this._cache.length - this._MAX_LOG_ENTRIES); } } }, { key: '_log', value: function _log(level) { var _this9 = this; var time = new Date(); for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { args[_key - 1] = arguments[_key]; } var msg = format.apply(undefined, args); this._cache.push(new GMLogEntry(time, level, msg)); this._save(); if (level === 'error' && !hasDialogShown('error')) { error('Error occurs.', { click: function click() { _this9.showPanel(); }, footer: '(Click to view details)' }); } } }, { key: '_load', value: function _load() { this.level = GM_getValue(this._state_key, {}).level || 'error'; this._cache = GM_getValue(this._GM_key, []).map(function (rawEntry) { return rawEntry.match(/^\[(.*?)\]\[(.*?)\] (.*)$/); }).filter(function (matchedEntry) { return matchedEntry !== null; }).map(function (matchedEntry) { return new GMLogEntry(new Date(matchedEntry[1]), matchedEntry[2], matchedEntry[3]); }); } }, { key: '_save', value: function _save() { this._gc(); GM_setValue(this._GM_key, this._cache.map(function (entry) { return entry.toString(); })); } }, { key: 'debug', value: function debug() { var _console; for (var _len2 = arguments.length, args = Array(_len2), _key2 = 0; _key2 < _len2; _key2++) { args[_key2] = arguments[_key2]; } (_console = console).debug.apply(_console, args); this._log.apply(this, ['debug'].concat(args)); } }, { key: 'info', value: function info() { var _console2; for (var _len3 = arguments.length, args = Array(_len3), _key3 = 0; _key3 < _len3; _key3++) { args[_key3] = arguments[_key3]; } if (arguments.length === 0) return; (_console2 = console).info.apply(_console2, args); this._log.apply(this, ['info'].concat(args)); } }, { key: 'warn', value: function warn() { var _console3; for (var _len4 = arguments.length, args = Array(_len4), _key4 = 0; _key4 < _len4; _key4++) { args[_key4] = arguments[_key4]; } if (arguments.length === 0) return; (_console3 = console).warn.apply(_console3, args); this._log.apply(this, ['warn'].concat(args)); } }, { key: 'error', value: function error() { var _console4; for (var _len5 = arguments.length, args = Array(_len5), _key5 = 0; _key5 < _len5; _key5++) { args[_key5] = arguments[_key5]; } if (arguments.length === 0) return; (_console4 = console).error.apply(_console4, args); this._log.apply(this, ['error'].concat(args)); } }]); return GMLogger; }(); GMLogger.levelMap = { 'debug': 0, 'info': 10, 'warn': 20, 'error': 30, 'off': 40 }; function getLogger() { try { return new GMLogger({ MAX_LOG_ENTRIES: MAX_LOG_ENTRIES }); } catch (e) { if (e instanceof NotSupportedError) { window.alert(e.message); } return console; } } var LOG = getLogger(); function checkDependencies(scope, deps, cb, due) { due = due instanceof Date ? due : new Date(new Date().getTime() + MAX_DEP_TIMEOUT); var lacks = []; deps.forEach(function (dep) { if (!scope[dep]) { lacks.push(dep); } }); if (lacks.length === 0) { cb(null); } else if (lacks.length > 0) { if (new Date().getTime() <= due.getTime()) { var safeFn = new SafeFunction(checkDependencies.bind(undefined, scope, lacks, cb, due)); safeFn.on('error', function (err) { LOG.error('Error occurs in #checkDependencies()'); LOG.error(err); }); setTimeout(safeFn, DEP_CHECK_PERIOD); } else { cb(new DependencyError(lacks)); } } } var SimpleCountdown = simpleCountdown; function changeTimeLeft(timer, timeLeft) { if ((typeof timer === 'undefined' ? 'undefined' : _typeof(timer)) !== 'object') { return; } var time = new Date(); if (_typeof(timer.countdown) === 'object') { timer.countdown.startTime = time.getTime(); timer.countdown.startLeftoverTime = timeLeft; } else if (_typeof(timer.countdownObject) === 'object') { timer.countdownObject.startTime = time.getTime(); timer.countdownObject.startLeftoverTime = timeLeft; } } function handleAuction() { var createTimer = function createTimer() { var oldMins = -1; var first = false; var overflowAuctionTimer = null; var newMins = void 0, mins = void 0, secs = void 0, auctionTimer = void 0, auctionEndTime = void 0, currentTime = void 0; var uni = document.location.href.replace(/^https:\/\/([^/]+).+/, '$1'); if ($('#auctionTimer').length > 0) { return; } $('p.auction_info').next().before(''); if ($('#div_traderAuctioneer .left_header h2').text().indexOf(loca.auctionFinished) < 0) { auctionEndTime = GM_getValue(uni + '_auctionEndTime', -1); currentTime = new Date().getTime(); if (auctionEndTime >= currentTime) { secs = Math.round((auctionEndTime - currentTime) / 1000); oldMins = Math.ceil(secs / 60); first = false; LOG.info('Ending time is found in storage. Action will end at ' + new Date(auctionEndTime).toLocaleString()); document.getElementById('auctionTimer').classList.add('service'); } else { var matched = $('p.auction_info').text().match(/\d+/g); if (!matched) return; oldMins = parseInt(matched[0]); secs = oldMins * 60; first = true; } mins = oldMins; auctionTimer = new SimpleCountdown($('#auctionTimer').get(0), secs, function () { $('#auctionTimer').text(''); }); } var mySock = io.connect(':' + nodePort + '/auctioneer', nodeParams); var onConnect = new SafeFunction(function () { mySock.on('timeLeft', function (msg) { if ($('#div_traderAuctioneer .left_header h2').text().indexOf(loca.auctionFinished) >= 0) { first = true; GM_setValue(uni + '_auctionEndTime', '-1'); LOG.info('Auction ends'); document.getElementById('auctionTimer').classList.remove('service'); return; } auctionEndTime = GM_getValue(uni + '_auctionEndTime', -1); currentTime = new Date().getTime(); newMins = parseInt(/\D+(\d+)/.exec(msg)[1]); if (newMins === oldMins) { mins--; if (first) { first = false; } else if (auctionEndTime >= 0) { GM_setValue(uni + '_auctionEndTime', currentTime + mins * 60 * 1000); LOG.info('Auction ending time is locked'); document.getElementById('auctionTimer').classList.add('service'); } } else { if (newMins > oldMins && auctionEndTime >= currentTime) { newMins = Math.round((auctionEndTime - currentTime) / (1000 * 60)); } if (first) { first = false; } else if (oldMins >= 0) { GM_setValue(uni + '_auctionEndTime', currentTime + newMins * 60 * 1000); LOG.info('Auction ending time is locked'); document.getElementById('auctionTimer').classList.add('service'); } oldMins = newMins; mins = newMins; } if (mins) { changeTimeLeft(auctionTimer, mins * 60); } else { overflowAuctionTimer = new SimpleCountdown($('#auctionTimer').get(0), 30, function () { $('#auctionTimer').text(''); }); } setTimeout(function () { $('#auctionTimer').css('color', $('p.auction_info span').css('color')); }, 100); }); mySock.on('new auction', function (msg) { /\D+(\d+)/.exec(msg.info); mins = parseInt(RegExp.$1); auctionTimer = new SimpleCountdown($('#auctionTimer').get(0), mins * 60, function () { $('#auctionTimer').text(''); }); overflowAuctionTimer = null; first = true; LOG.info('Auction starts'); setTimeout(function () { $('#auctionTimer').css('color', $('p.auction_info span').css('color')); }, 100); }); mySock.on('auction finished', function (msg) { changeTimeLeft(auctionTimer, 0); changeTimeLeft(overflowAuctionTimer, 0); first = true; GM_setValue(uni + '_auctionEndTime', '-1'); LOG.info('Auction ends'); document.getElementById('auctionTimer').classList.remove('service'); }); }); onConnect.on('error', function (err) { LOG.error('Error occurs in #onConnect()'); LOG.error(err); }); mySock.on('connect', onConnect).on('connect_error', function (err) { LOG.error('Connect error.'); LOG.error(err); }); }; if (document.getElementById('div_traderAuctioneer')) { createTimer(); } else { $(document).ajaxSuccess(function () { if ($('#auctionTimer').length === 0) { createTimer(); } }); } } var SimpleCountdown$1 = simpleCountdown; function handleNonAuction() { var uni = document.location.href.replace(/^https:\/\/([^/]+).+/, '$1'); var auctionEndTime = GM_getValue(uni + '_auctionEndTime', -1); auctionEndTime = parseInt(auctionEndTime); var currentTime = new Date().getTime(); var clock = $('.OGameClock'); clock.parent().append('
  • '); if (auctionEndTime < currentTime) { LOG.info('Invalid ending time: ' + new Date(auctionEndTime).toLocaleString() + ' (' + auctionEndTime + 'ms)'); $('#auctionTimer').text('Pending...').addClass('pending'); } else { LOG.info('Ending time is found in storage. Action will end at ' + new Date(auctionEndTime).toLocaleString()); $('#auctionTimer').addClass('service'); var auctionTimer = new SimpleCountdown$1($('#auctionTimer').get(0), Math.round((auctionEndTime - currentTime) / 1000), function () { $('#auctionTimer').text(''); }); } } GM_addStyle('\n #auctionTimer {\n display: inline-block;\n width: 100%;\n text-align: center;\n background-color: initial;\n transition: background-color 0.5s;\n padding-top: 5px;\n padding-bottom: 5px;\n }\n\n #auctionTimer.service {\n background-color: #1d5a1d;\n }\n\n #auctionTimer.pending {\n background-color: #922929;\n }\n'); (function () { if (document.location.href.indexOf('/game/index.php?') < 0) { return; } try { var handle = function handle(cb, err) { if (err) { LOG.error('Failed to pass dependency check.'); LOG.error(err); return; } LOG.info('Dependency check passed'); cb(); }; var deps = void 0; if (location.pathname === "/game/index.php" && location.search.includes("component=traderOverview")) { LOG.debug('This is traderOverview page'); deps = DEP_LIST.AUCTION; handle = handle.bind(null, handleAuction); } else if (document.getElementById('bar')) { LOG.debug('This is not traderOverview page'); deps = DEP_LIST.NON_AUCTION; handle = handle.bind(null, handleNonAuction); } LOG.info('Start dependency check'); checkDependencies(unsafeWindow, deps, handle); } catch (e) { LOG.error('Error is caught in the entry.'); LOG.error(e); } })();