From 2375506066c1e5d7a5308aa06f43223a15dd116d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20B=C3=BCttner?= Date: Tue, 2 May 2017 11:47:56 +0200 Subject: [PATCH 1/8] fixes #317 and fixes some formatting in the readme :P --- README.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 036e88a..7981a9e 100644 --- a/README.md +++ b/README.md @@ -20,4 +20,9 @@ We prefer the usage of the [tracker](https://github.com/IDotD/Userscript/issues) ## How To Help -We can use helpers for the following: update and improve the wiki, help coding the userscript and testing any of the branches. For any of the later two have a look at the related documentation in the [wiki](https://idotd.github.io/). +We can use helpers for the following: +- update and improve the wiki +- help coding the userscript +- testing any of the branches. + +For any of the later two have a look at the related documentation in the [wiki](https://idotd.github.io/). From e987fd858cbd250169ecf869ac3b89d95c360639 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20B=C3=BCttner?= Date: Tue, 2 May 2017 11:52:28 +0200 Subject: [PATCH 2/8] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 7981a9e..ed53d1f 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # IDotD -A script for dawn of the dragons, that works based on data provided to https://dotd.idrinth.de via UgUp. +A script for Dawn of the Dragons, that works based on data provided to https://dotd.idrinth.de via UgUp. [![Codacy Badge](https://api.codacy.com/project/badge/Grade/e80204911a734a56a471ab9b9ac649db)](https://www.codacy.com/app/IDotD/IDotD?utm_source=github.com&utm_medium=referral&utm_content=IDotD/Userscript&utm_campaign=Badge_Grade) From 04a73efcf4ad6bbb2479e48298989e5e3531c050 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20B=C3=BCttner?= Date: Tue, 2 May 2017 15:31:59 +0200 Subject: [PATCH 3/8] Update README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index ed53d1f..9da2c80 100644 --- a/README.md +++ b/README.md @@ -18,6 +18,8 @@ Most information is avaible at [this project's wiki](https://idotd.github.io/) - We prefer the usage of the [tracker](https://github.com/IDotD/Userscript/issues) here, otherwise we do import requests from [GoogleDocs](https://docs.google.com/document/d/1ozOWQuAEKCNnt2cwQ4SZtkpYM_pvrl8Bnj0e_O1KKWs/edit) from time to time. [Previous GoogleDoc Tickets](https://github.com/IDotD/Userscript/issues?utf8=%E2%9C%93&q=is%3Aissue%20label%3A%22Source%20GoogleDocs%22%20) +Otherwise feel free to contact us via chat. + ## How To Help We can use helpers for the following: From 15fd3cb210a0094bd76667f0194bd03d2fda29dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20B=C3=BCttner?= Date: Tue, 2 May 2017 15:37:14 +0200 Subject: [PATCH 4/8] Update landbuy.js --- tests/landbuy.js | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/landbuy.js b/tests/landbuy.js index e69de29..357d385 100644 --- a/tests/landbuy.js +++ b/tests/landbuy.js @@ -0,0 +1 @@ +//to be done From 95ad9a91832f4ad1b760177e7d8262f0fc5cfc68 Mon Sep 17 00:00:00 2001 From: IdrinthGitbot Date: Tue, 2 May 2017 15:38:49 +0200 Subject: [PATCH 5/8] prettyfiing branch --- src/libs/big.js | 1588 ++++++++--------- src/libs/matches-selector-polyfill.js | 32 +- src/loader.js | 116 +- src/mods/chat.js | 2265 ++++++++++++++----------- src/mods/core.js | 593 ++++--- src/mods/inframe.js | 150 +- src/mods/land.js | 339 ++-- src/mods/names.js | 423 +++-- src/mods/newgrounds.js | 145 +- src/mods/observer.js | 228 +-- src/mods/raids.js | 673 ++++---- src/mods/settings.js | 486 +++--- src/mods/stats.js | 230 ++- src/mods/text.js | 115 +- src/mods/tier.js | 825 +++++---- src/mods/ui.js | 2168 ++++++++++++----------- src/mods/user.js | 164 +- src/mods/war.js | 599 ++++--- src/stable.js | 182 +- 19 files changed, 6135 insertions(+), 5186 deletions(-) diff --git a/src/libs/big.js b/src/libs/big.js index 1ab64c5..b098b42 100644 --- a/src/libs/big.js +++ b/src/libs/big.js @@ -1,8 +1,7 @@ /* big.js v3.1.3 https://github.com/MikeMcl/big.js/LICENCE */ -;(function (global) { - 'use strict'; - -/* +(function(global) { + "use strict"; + /* big.js v3.1.3 A small, fast, easy-to-use library for arbitrary-precision decimal arithmetic. https://github.com/MikeMcl/big.js/ @@ -10,17 +9,16 @@ MIT Expat Licence */ -/***************************** EDITABLE DEFAULTS ******************************/ + /***************************** EDITABLE DEFAULTS ******************************/ - // The default values below must be integers within the stated ranges. + // The default values below must be integers within the stated ranges. - /* + /* * The maximum number of decimal places of the results of operations * involving division: div and sqrt, and pow with negative exponents. */ - var DP = 20, // 0 to MAX_DP - - /* + var DP = 20, // 0 to MAX_DP + /* * The rounding mode used when rounding to the above decimal places. * * 0 Towards zero (i.e. truncate, no rounding). (ROUND_DOWN) @@ -28,89 +26,80 @@ * 2 To nearest neighbour. If equidistant, to even. (ROUND_HALF_EVEN) * 3 Away from zero. (ROUND_UP) */ - RM = 1, // 0, 1, 2 or 3 - - // The maximum value of DP and Big.DP. - MAX_DP = 1E6, // 0 to 1000000 - - // The maximum magnitude of the exponent argument to the pow method. - MAX_POWER = 1E6, // 1 to 1000000 - - /* + RM = 1, // 0, 1, 2 or 3 + // The maximum value of DP and Big.DP. + MAX_DP = 1e6, // 0 to 1000000 + // The maximum magnitude of the exponent argument to the pow method. + MAX_POWER = 1e6, // 1 to 1000000 + /* * The exponent value at and beneath which toString returns exponential * notation. * JavaScript's Number type: -7 * -1000000 is the minimum recommended exponent value of a Big. */ - E_NEG = -7, // 0 to -1000000 - - /* + E_NEG = -7, // 0 to -1000000 + /* * The exponent value at and above which toString returns exponential * notation. * JavaScript's Number type: 21 * 1000000 is the maximum recommended exponent value of a Big. * (This limit is not enforced or checked.) */ - E_POS = 21, // 0 to 1000000 - -/******************************************************************************/ + E_POS = 21, // 0 to 1000000 + /******************************************************************************/ - // The shared prototype object. - P = {}, - isValid = /^-?(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i, - Big; + // The shared prototype object. + P = {}, + isValid = /^-?(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i, + Big; - - /* + /* * Create and return a Big constructor. * */ - function bigFactory() { - - /* + function bigFactory() { + /* * The Big constructor and exported function. * Create and return a new instance of a Big number object. * * n {number|string|Big} A numeric value. */ - function Big(n) { - var x = this; - - // Enable constructor usage without new. - if (!(x instanceof Big)) { - return n === void 0 ? bigFactory() : new Big(n); - } - - // Duplicate. - if (n instanceof Big) { - x.s = n.s; - x.e = n.e; - x.c = n.c.slice(); - } else { - parse(x, n); - } - - /* + function Big(n) { + var x = this; + + // Enable constructor usage without new. + if (!(x instanceof Big)) { + return n === void 0 ? bigFactory() : new Big(n); + } + + // Duplicate. + if (n instanceof Big) { + x.s = n.s; + x.e = n.e; + x.c = n.c.slice(); + } else { + parse(x, n); + } + + /* * Retain a reference to this Big constructor, and shadow * Big.prototype.constructor which points to Object. */ - x.constructor = Big; - } - - Big.prototype = P; - Big.DP = DP; - Big.RM = RM; - Big.E_NEG = E_NEG; - Big.E_POS = E_POS; - - return Big; + x.constructor = Big; } + Big.prototype = P; + Big.DP = DP; + Big.RM = RM; + Big.E_NEG = E_NEG; + Big.E_POS = E_POS; - // Private functions + return Big; + } + // Private functions - /* + /* * Return a string representing the value of Big x in normal or exponential * notation to dp fixed decimal places or significant digits. * @@ -118,123 +107,114 @@ * dp {number} Integer, 0 to MAX_DP inclusive. * toE {number} 1 (toExponential), 2 (toPrecision) or undefined (toFixed). */ - function format(x, dp, toE) { - var Big = x.constructor, - - // The index (normal notation) of the digit that may be rounded up. - i = dp - (x = new Big(x)).e, - c = x.c; - - // Round? - if (c.length > ++dp) { - rnd(x, i, Big.RM); - } + function format(x, dp, toE) { + var Big = x.constructor, + // The index (normal notation) of the digit that may be rounded up. + i = dp - (x = new Big(x)).e, + c = x.c; + + // Round? + if (c.length > ++dp) { + rnd(x, i, Big.RM); + } - if (!c[0]) { - ++i; - } else if (toE) { - i = dp; + if (!c[0]) { + ++i; + } else if (toE) { + i = dp; - // toFixed - } else { - c = x.c; + // toFixed + } else { + c = x.c; - // Recalculate i as x.e may have changed if value rounded up. - i = x.e + i + 1; - } + // Recalculate i as x.e may have changed if value rounded up. + i = x.e + i + 1; + } - // Append zeros? - for (; c.length < i; c.push(0)) { - } - i = x.e; + // Append zeros? + for (; c.length < i; c.push(0)) { + } + i = x.e; - /* + /* * toPrecision returns exponential notation if the number of * significant digits specified is less than the number of digits * necessary to represent the integer part of the value in normal * notation. */ - return toE === 1 || toE && (dp <= i || i <= Big.E_NEG) ? - - // Exponential notation. - (x.s < 0 && c[0] ? '-' : '') + - (c.length > 1 ? c[0] + '.' + c.join('').slice(1) : c[0]) + - (i < 0 ? 'e' : 'e+') + i - - // Normal notation. - : x.toString(); - } - - - /* + return toE === 1 || (toE && (dp <= i || i <= Big.E_NEG)) + ? // Exponential notation. + (x.s < 0 && c[0] ? "-" : "") + + (c.length > 1 ? c[0] + "." + c.join("").slice(1) : c[0]) + + (i < 0 ? "e" : "e+") + + i + : // Normal notation. + x.toString(); + } + + /* * Parse the number or string value passed to a Big constructor. * * x {Big} A Big number instance. * n {number|string} A numeric value. */ - function parse(x, n) { - var e, i, nL; - - // Minus zero? - if (n === 0 && 1 / n < 0) { - n = '-0'; - - // Ensure n is string and check validity. - } else if (!isValid.test(n += '')) { - throwErr(NaN); - } - - // Determine sign. - x.s = n.charAt(0) == '-' ? (n = n.slice(1), -1) : 1; - - // Decimal point? - if ((e = n.indexOf('.')) > -1) { - n = n.replace('.', ''); - } - - // Exponential form? - if ((i = n.search(/e/i)) > 0) { - - // Determine exponent. - if (e < 0) { - e = i; - } - e += +n.slice(i + 1); - n = n.substring(0, i); + function parse(x, n) { + var e, i, nL; - } else if (e < 0) { + // Minus zero? + if (n === 0 && 1 / n < 0) { + n = "-0"; - // Integer. - e = n.length; - } + // Ensure n is string and check validity. + } else if (!isValid.test((n += ""))) { + throwErr(NaN); + } - // Determine leading zeros. - for (i = 0; n.charAt(i) == '0'; i++) { - } + // Determine sign. + x.s = n.charAt(0) == "-" ? ((n = n.slice(1)), -1) : 1; - if (i == (nL = n.length)) { + // Decimal point? + if ((e = n.indexOf(".")) > -1) { + n = n.replace(".", ""); + } - // Zero. - x.c = [ x.e = 0 ]; - } else { + // Exponential form? + if ((i = n.search(/e/i)) > 0) { + // Determine exponent. + if (e < 0) { + e = i; + } + e += +n.slice(i + 1); + n = n.substring(0, i); + } else if (e < 0) { + // Integer. + e = n.length; + } - // Determine trailing zeros. - for (; n.charAt(--nL) == '0';) { - } + // Determine leading zeros. + for (i = 0; n.charAt(i) == "0"; i++) { + } - x.e = e - i - 1; - x.c = []; + if (i == (nL = n.length)) { + // Zero. + x.c = [(x.e = 0)]; + } else { + // Determine trailing zeros. + for (; n.charAt(--nL) == "0"; ) { + } - // Convert string to array of digits without leading/trailing zeros. - for (e = 0; i <= nL; x.c[e++] = +n.charAt(i++)) { - } - } + x.e = e - i - 1; + x.c = []; - return x; + // Convert string to array of digits without leading/trailing zeros. + for (e = 0; i <= nL; x.c[e++] = +n.charAt(i++)) { + } } + return x; + } - /* + /* * Round Big x to a maximum of dp decimal places using rounding mode rm. * Called by div, sqrt and round. * @@ -243,590 +223,538 @@ * rm {number} 0, 1, 2 or 3 (DOWN, HALF_UP, HALF_EVEN, UP) * [more] {boolean} Whether the result of division was truncated. */ - function rnd(x, dp, rm, more) { - var u, - xc = x.c, - i = x.e + dp + 1; - - if (rm === 1) { - - // xc[i] is the digit after the digit that may be rounded up. - more = xc[i] >= 5; - } else if (rm === 2) { - more = xc[i] > 5 || xc[i] == 5 && - (more || i < 0 || xc[i + 1] !== u || xc[i - 1] & 1); - } else if (rm === 3) { - more = more || xc[i] !== u || i < 0; - } else { - more = false; - - if (rm !== 0) { - throwErr('!Big.RM!'); - } - } - - if (i < 1 || !xc[0]) { - - if (more) { - - // 1, 0.1, 0.01, 0.001, 0.0001 etc. - x.e = -dp; - x.c = [1]; - } else { - - // Zero. - x.c = [x.e = 0]; - } - } else { - - // Remove any digits after the required decimal places. - xc.length = i--; - - // Round up? - if (more) { - - // Rounding up may mean the previous digit has to be rounded up. - for (; ++xc[i] > 9;) { - xc[i] = 0; + function rnd(x, dp, rm, more) { + var u, xc = x.c, i = x.e + dp + 1; + + if (rm === 1) { + // xc[i] is the digit after the digit that may be rounded up. + more = xc[i] >= 5; + } else if (rm === 2) { + more = + xc[i] > 5 || + (xc[i] == 5 && (more || i < 0 || xc[i + 1] !== u || xc[i - 1] & 1)); + } else if (rm === 3) { + more = more || xc[i] !== u || i < 0; + } else { + more = false; - if (!i--) { - ++x.e; - xc.unshift(1); - } - } - } + if (rm !== 0) { + throwErr("!Big.RM!"); + } + } - // Remove trailing zeros. - for (i = xc.length; !xc[--i]; xc.pop()) { - } + if (i < 1 || !xc[0]) { + if (more) { + // 1, 0.1, 0.01, 0.001, 0.0001 etc. + x.e = -dp; + x.c = [1]; + } else { + // Zero. + x.c = [(x.e = 0)]; + } + } else { + // Remove any digits after the required decimal places. + xc.length = i--; + + // Round up? + if (more) { + // Rounding up may mean the previous digit has to be rounded up. + for (; ++xc[i] > 9; ) { + xc[i] = 0; + + if (!i--) { + ++x.e; + xc.unshift(1); + } } + } - return x; + // Remove trailing zeros. + for (i = xc.length; !xc[--i]; xc.pop()) { + } } + return x; + } - /* + /* * Throw a BigError. * * message {string} The error message. */ - function throwErr(message) { - var err = new Error(message); - err.name = 'BigError'; - - throw err; - } + function throwErr(message) { + var err = new Error(message); + err.name = "BigError"; + throw err; + } - // Prototype/instance methods + // Prototype/instance methods - - /* + /* * Return a new Big whose value is the absolute value of this Big. */ - P.abs = function () { - var x = new this.constructor(this); - x.s = 1; + P.abs = function() { + var x = new this.constructor(this); + x.s = 1; - return x; - }; + return x; + }; - - /* + /* * Return * 1 if the value of this Big is greater than the value of Big y, * -1 if the value of this Big is less than the value of Big y, or * 0 if they have the same value. */ - P.cmp = function (y) { - var xNeg, - x = this, - xc = x.c, - yc = (y = new x.constructor(y)).c, - i = x.s, - j = y.s, - k = x.e, - l = y.e; - - // Either zero? - if (!xc[0] || !yc[0]) { - return !xc[0] ? !yc[0] ? 0 : -j : i; - } - - // Signs differ? - if (i != j) { - return i; - } - xNeg = i < 0; - - // Compare exponents. - if (k != l) { - return k > l ^ xNeg ? 1 : -1; - } + P.cmp = function(y) { + var xNeg, + x = this, + xc = x.c, + yc = (y = new x.constructor(y)).c, + i = x.s, + j = y.s, + k = x.e, + l = y.e; + + // Either zero? + if (!xc[0] || !yc[0]) { + return !xc[0] ? !yc[0] ? 0 : -j : i; + } - i = -1; - j = (k = xc.length) < (l = yc.length) ? k : l; + // Signs differ? + if (i != j) { + return i; + } + xNeg = i < 0; - // Compare digit by digit. - for (; ++i < j;) { + // Compare exponents. + if (k != l) { + return (k > l) ^ xNeg ? 1 : -1; + } - if (xc[i] != yc[i]) { - return xc[i] > yc[i] ^ xNeg ? 1 : -1; - } - } + i = -1; + j = (k = xc.length) < (l = yc.length) ? k : l; - // Compare lengths. - return k == l ? 0 : k > l ^ xNeg ? 1 : -1; - }; + // Compare digit by digit. + for (; ++i < j; ) { + if (xc[i] != yc[i]) { + return (xc[i] > yc[i]) ^ xNeg ? 1 : -1; + } + } + // Compare lengths. + return k == l ? 0 : (k > l) ^ xNeg ? 1 : -1; + }; - /* + /* * Return a new Big whose value is the value of this Big divided by the * value of Big y, rounded, if necessary, to a maximum of Big.DP decimal * places using rounding mode Big.RM. */ - P.div = function (y) { - var x = this, - Big = x.constructor, - // dividend - dvd = x.c, - //divisor - dvs = (y = new Big(y)).c, - s = x.s == y.s ? 1 : -1, - dp = Big.DP; - - if (dp !== ~~dp || dp < 0 || dp > MAX_DP) { - throwErr('!Big.DP!'); - } - - // Either 0? - if (!dvd[0] || !dvs[0]) { - - // If both are 0, throw NaN - if (dvd[0] == dvs[0]) { - throwErr(NaN); - } - - // If dvs is 0, throw +-Infinity. - if (!dvs[0]) { - throwErr(s / 0); - } + P.div = function(y) { + var x = this, + Big = x.constructor, + // dividend + dvd = x.c, + //divisor + dvs = (y = new Big(y)).c, + s = x.s == y.s ? 1 : -1, + dp = Big.DP; + + if (dp !== ~~dp || dp < 0 || dp > MAX_DP) { + throwErr("!Big.DP!"); + } - // dvd is 0, return +-0. - return new Big(s * 0); - } + // Either 0? + if (!dvd[0] || !dvs[0]) { + // If both are 0, throw NaN + if (dvd[0] == dvs[0]) { + throwErr(NaN); + } - var dvsL, dvsT, next, cmp, remI, u, - dvsZ = dvs.slice(), - dvdI = dvsL = dvs.length, - dvdL = dvd.length, - // remainder - rem = dvd.slice(0, dvsL), - remL = rem.length, - // quotient - q = y, - qc = q.c = [], - qi = 0, - digits = dp + (q.e = x.e - y.e) + 1; - - q.s = s; - s = digits < 0 ? 0 : digits; - - // Create version of divisor with leading zero. - dvsZ.unshift(0); - - // Add zeros to make remainder as long as divisor. - for (; remL++ < dvsL; rem.push(0)) { - } + // If dvs is 0, throw +-Infinity. + if (!dvs[0]) { + throwErr(s / 0); + } - do { - - // 'next' is how many times the divisor goes into current remainder. - for (next = 0; next < 10; next++) { - - // Compare divisor and remainder. - if (dvsL != (remL = rem.length)) { - cmp = dvsL > remL ? 1 : -1; - } else { - - for (remI = -1, cmp = 0; ++remI < dvsL;) { - - if (dvs[remI] != rem[remI]) { - cmp = dvs[remI] > rem[remI] ? 1 : -1; - break; - } - } - } - - // If divisor < remainder, subtract divisor from remainder. - if (cmp < 0) { - - // Remainder can't be more than 1 digit longer than divisor. - // Equalise lengths using divisor with extra leading zero? - for (dvsT = remL == dvsL ? dvs : dvsZ; remL;) { - - if (rem[--remL] < dvsT[remL]) { - remI = remL; - - for (; remI && !rem[--remI]; rem[remI] = 9) { - } - --rem[remI]; - rem[remL] += 10; - } - rem[remL] -= dvsT[remL]; - } - for (; !rem[0]; rem.shift()) { - } - } else { - break; - } - } + // dvd is 0, return +-0. + return new Big(s * 0); + } - // Add the 'next' digit to the result array. - qc[qi++] = cmp ? next : ++next; + var dvsL, + dvsT, + next, + cmp, + remI, + u, + dvsZ = dvs.slice(), + dvdI = (dvsL = dvs.length), + dvdL = dvd.length, + // remainder + rem = dvd.slice(0, dvsL), + remL = rem.length, + // quotient + q = y, + qc = (q.c = []), + qi = 0, + digits = dp + (q.e = x.e - y.e) + 1; + + q.s = s; + s = digits < 0 ? 0 : digits; + + // Create version of divisor with leading zero. + dvsZ.unshift(0); + + // Add zeros to make remainder as long as divisor. + for (; remL++ < dvsL; rem.push(0)) { + } - // Update the remainder. - if (rem[0] && cmp) { - rem[remL] = dvd[dvdI] || 0; - } else { - rem = [ dvd[dvdI] ]; + do { + // 'next' is how many times the divisor goes into current remainder. + for (next = 0; next < 10; next++) { + // Compare divisor and remainder. + if (dvsL != (remL = rem.length)) { + cmp = dvsL > remL ? 1 : -1; + } else { + for ((remI = -1), (cmp = 0); ++remI < dvsL; ) { + if (dvs[remI] != rem[remI]) { + cmp = dvs[remI] > rem[remI] ? 1 : -1; + break; } - - } while ((dvdI++ < dvdL || rem[0] !== u) && s--); - - // Leading zero? Do not remove if result is simply zero (qi == 1). - if (!qc[0] && qi != 1) { - - // There can't be more than one zero. - qc.shift(); - q.e--; + } } - // Round? - if (qi > digits) { - rnd(q, dp, Big.RM, rem[0] !== u); + // If divisor < remainder, subtract divisor from remainder. + if (cmp < 0) { + // Remainder can't be more than 1 digit longer than divisor. + // Equalise lengths using divisor with extra leading zero? + for (dvsT = remL == dvsL ? dvs : dvsZ; remL; ) { + if (rem[--remL] < dvsT[remL]) { + remI = remL; + + for (; remI && !rem[--remI]; rem[remI] = 9) { + } + --rem[remI]; + rem[remL] += 10; + } + rem[remL] -= dvsT[remL]; + } + for (; !rem[0]; rem.shift()) { + } + } else { + break; } + } + + // Add the 'next' digit to the result array. + qc[qi++] = cmp ? next : ++next; + + // Update the remainder. + if (rem[0] && cmp) { + rem[remL] = dvd[dvdI] || 0; + } else { + rem = [dvd[dvdI]]; + } + } while ((dvdI++ < dvdL || rem[0] !== u) && s--); + + // Leading zero? Do not remove if result is simply zero (qi == 1). + if (!qc[0] && qi != 1) { + // There can't be more than one zero. + qc.shift(); + q.e--; + } - return q; - }; + // Round? + if (qi > digits) { + rnd(q, dp, Big.RM, rem[0] !== u); + } + return q; + }; - /* + /* * Return true if the value of this Big is equal to the value of Big y, * otherwise returns false. */ - P.eq = function (y) { - return !this.cmp(y); - }; - + P.eq = function(y) { + return !this.cmp(y); + }; - /* + /* * Return true if the value of this Big is greater than the value of Big y, * otherwise returns false. */ - P.gt = function (y) { - return this.cmp(y) > 0; - }; - + P.gt = function(y) { + return this.cmp(y) > 0; + }; - /* + /* * Return true if the value of this Big is greater than or equal to the * value of Big y, otherwise returns false. */ - P.gte = function (y) { - return this.cmp(y) > -1; - }; - + P.gte = function(y) { + return this.cmp(y) > -1; + }; - /* + /* * Return true if the value of this Big is less than the value of Big y, * otherwise returns false. */ - P.lt = function (y) { - return this.cmp(y) < 0; - }; - + P.lt = function(y) { + return this.cmp(y) < 0; + }; - /* + /* * Return true if the value of this Big is less than or equal to the value * of Big y, otherwise returns false. */ - P.lte = function (y) { - return this.cmp(y) < 1; - }; - + P.lte = function(y) { + return this.cmp(y) < 1; + }; - /* + /* * Return a new Big whose value is the value of this Big minus the value * of Big y. */ - P.sub = P.minus = function (y) { - var i, j, t, xLTy, - x = this, - Big = x.constructor, - a = x.s, - b = (y = new Big(y)).s; - - // Signs differ? - if (a != b) { - y.s = -b; - return x.plus(y); - } - - var xc = x.c.slice(), - xe = x.e, - yc = y.c, - ye = y.e; - - // Either zero? - if (!xc[0] || !yc[0]) { - - // y is non-zero? x is non-zero? Or both are zero. - return yc[0] ? (y.s = -b, y) : new Big(xc[0] ? x : 0); - } - - // Determine which is the bigger number. - // Prepend zeros to equalise exponents. - if (a = xe - ye) { + P.sub = P.minus = function(y) { + var i, + j, + t, + xLTy, + x = this, + Big = x.constructor, + a = x.s, + b = (y = new Big(y)).s; + + // Signs differ? + if (a != b) { + y.s = -b; + return x.plus(y); + } - if (xLTy = a < 0) { - a = -a; - t = xc; - } else { - ye = xe; - t = yc; - } + var xc = x.c.slice(), xe = x.e, yc = y.c, ye = y.e; - t.reverse(); - for (b = a; b--; t.push(0)) { - } - t.reverse(); - } else { - - // Exponents equal. Check digit by digit. - j = ((xLTy = xc.length < yc.length) ? xc : yc).length; + // Either zero? + if (!xc[0] || !yc[0]) { + // y is non-zero? x is non-zero? Or both are zero. + return yc[0] ? ((y.s = -b), y) : new Big(xc[0] ? x : 0); + } - for (a = b = 0; b < j; b++) { + // Determine which is the bigger number. + // Prepend zeros to equalise exponents. + if ((a = xe - ye)) { + if ((xLTy = a < 0)) { + a = -a; + t = xc; + } else { + ye = xe; + t = yc; + } + + t.reverse(); + for (b = a; b--; t.push(0)) { + } + t.reverse(); + } else { + // Exponents equal. Check digit by digit. + j = ((xLTy = xc.length < yc.length) ? xc : yc).length; - if (xc[b] != yc[b]) { - xLTy = xc[b] < yc[b]; - break; - } - } + for (a = b = 0; b < j; b++) { + if (xc[b] != yc[b]) { + xLTy = xc[b] < yc[b]; + break; } + } + } - // x < y? Point xc to the array of the bigger number. - if (xLTy) { - t = xc; - xc = yc; - yc = t; - y.s = -y.s; - } + // x < y? Point xc to the array of the bigger number. + if (xLTy) { + t = xc; + xc = yc; + yc = t; + y.s = -y.s; + } - /* + /* * Append zeros to xc if shorter. No need to add zeros to yc if shorter * as subtraction only needs to start at yc.length. */ - if (( b = (j = yc.length) - (i = xc.length) ) > 0) { - - for (; b--; xc[i++] = 0) { - } - } - - // Subtract yc from xc. - for (b = i; j > a;){ - - if (xc[--j] < yc[j]) { - - for (i = j; i && !xc[--i]; xc[i] = 9) { - } - --xc[i]; - xc[j] += 10; - } - xc[j] -= yc[j]; - } - - // Remove trailing zeros. - for (; xc[--b] === 0; xc.pop()) { - } + if ((b = (j = yc.length) - (i = xc.length)) > 0) { + for (; b--; xc[i++] = 0) { + } + } - // Remove leading zeros and adjust exponent accordingly. - for (; xc[0] === 0;) { - xc.shift(); - --ye; + // Subtract yc from xc. + for (b = i; j > a; ) { + if (xc[--j] < yc[j]) { + for (i = j; i && !xc[--i]; xc[i] = 9) { } + --xc[i]; + xc[j] += 10; + } + xc[j] -= yc[j]; + } - if (!xc[0]) { + // Remove trailing zeros. + for (; xc[--b] === 0; xc.pop()) { + } - // n - n = +0 - y.s = 1; + // Remove leading zeros and adjust exponent accordingly. + for (; xc[0] === 0; ) { + xc.shift(); + --ye; + } - // Result must be zero. - xc = [ye = 0]; - } + if (!xc[0]) { + // n - n = +0 + y.s = 1; - y.c = xc; - y.e = ye; + // Result must be zero. + xc = [(ye = 0)]; + } - return y; - }; + y.c = xc; + y.e = ye; + return y; + }; - /* + /* * Return a new Big whose value is the value of this Big modulo the * value of Big y. */ - P.mod = function (y) { - var yGTx, - x = this, - Big = x.constructor, - a = x.s, - b = (y = new Big(y)).s; - - if (!y.c[0]) { - throwErr(NaN); - } + P.mod = function(y) { + var yGTx, x = this, Big = x.constructor, a = x.s, b = (y = new Big(y)).s; - x.s = y.s = 1; - yGTx = y.cmp(x) == 1; - x.s = a; - y.s = b; + if (!y.c[0]) { + throwErr(NaN); + } - if (yGTx) { - return new Big(x); - } + x.s = y.s = 1; + yGTx = y.cmp(x) == 1; + x.s = a; + y.s = b; - a = Big.DP; - b = Big.RM; - Big.DP = Big.RM = 0; - x = x.div(y); - Big.DP = a; - Big.RM = b; + if (yGTx) { + return new Big(x); + } - return this.minus( x.times(y) ); - }; + a = Big.DP; + b = Big.RM; + Big.DP = Big.RM = 0; + x = x.div(y); + Big.DP = a; + Big.RM = b; + return this.minus(x.times(y)); + }; - /* + /* * Return a new Big whose value is the value of this Big plus the value * of Big y. */ - P.add = P.plus = function (y) { - var t, - x = this, - Big = x.constructor, - a = x.s, - b = (y = new Big(y)).s; - - // Signs differ? - if (a != b) { - y.s = -b; - return x.minus(y); - } + P.add = P.plus = function(y) { + var t, x = this, Big = x.constructor, a = x.s, b = (y = new Big(y)).s; - var xe = x.e, - xc = x.c, - ye = y.e, - yc = y.c; + // Signs differ? + if (a != b) { + y.s = -b; + return x.minus(y); + } - // Either zero? - if (!xc[0] || !yc[0]) { + var xe = x.e, xc = x.c, ye = y.e, yc = y.c; - // y is non-zero? x is non-zero? Or both are zero. - return yc[0] ? y : new Big(xc[0] ? x : a * 0); - } - xc = xc.slice(); - - // Prepend zeros to equalise exponents. - // Note: Faster to use reverse then do unshifts. - if (a = xe - ye) { - - if (a > 0) { - ye = xe; - t = yc; - } else { - a = -a; - t = xc; - } - - t.reverse(); - for (; a--; t.push(0)) { - } - t.reverse(); - } + // Either zero? + if (!xc[0] || !yc[0]) { + // y is non-zero? x is non-zero? Or both are zero. + return yc[0] ? y : new Big(xc[0] ? x : a * 0); + } + xc = xc.slice(); + + // Prepend zeros to equalise exponents. + // Note: Faster to use reverse then do unshifts. + if ((a = xe - ye)) { + if (a > 0) { + ye = xe; + t = yc; + } else { + a = -a; + t = xc; + } + + t.reverse(); + for (; a--; t.push(0)) { + } + t.reverse(); + } - // Point xc to the longer array. - if (xc.length - yc.length < 0) { - t = yc; - yc = xc; - xc = t; - } - a = yc.length; + // Point xc to the longer array. + if (xc.length - yc.length < 0) { + t = yc; + yc = xc; + xc = t; + } + a = yc.length; - /* + /* * Only start adding at yc.length - 1 as the further digits of xc can be * left as they are. */ - for (b = 0; a;) { - b = (xc[--a] = xc[a] + yc[a] + b) / 10 | 0; - xc[a] %= 10; - } - - // No need to check for zero, as +x + +y != 0 && -x + -y != 0 + for (b = 0; a; ) { + b = ((xc[--a] = xc[a] + yc[a] + b) / 10) | 0; + xc[a] %= 10; + } - if (b) { - xc.unshift(b); - ++ye; - } + // No need to check for zero, as +x + +y != 0 && -x + -y != 0 - // Remove trailing zeros. - for (a = xc.length; xc[--a] === 0; xc.pop()) { - } + if (b) { + xc.unshift(b); + ++ye; + } - y.c = xc; - y.e = ye; + // Remove trailing zeros. + for (a = xc.length; xc[--a] === 0; xc.pop()) { + } - return y; - }; + y.c = xc; + y.e = ye; + return y; + }; - /* + /* * Return a Big whose value is the value of this Big raised to the power n. * If n is negative, round, if necessary, to a maximum of Big.DP decimal * places using rounding mode Big.RM. * * n {number} Integer, -MAX_POWER to MAX_POWER inclusive. */ - P.pow = function (n) { - var x = this, - one = new x.constructor(1), - y = one, - isNeg = n < 0; - - if (n !== ~~n || n < -MAX_POWER || n > MAX_POWER) { - throwErr('!pow!'); - } + P.pow = function(n) { + var x = this, one = new x.constructor(1), y = one, isNeg = n < 0; - n = isNeg ? -n : n; - - for (;;) { + if (n !== ~~n || n < -MAX_POWER || n > MAX_POWER) { + throwErr("!pow!"); + } - if (n & 1) { - y = y.times(x); - } - n >>= 1; + n = isNeg ? -n : n; - if (!n) { - break; - } - x = x.times(x); - } + for (;;) { + if (n & 1) { + y = y.times(x); + } + n >>= 1; - return isNeg ? one.div(y) : y; - }; + if (!n) { + break; + } + x = x.times(x); + } + return isNeg ? one.div(y) : y; + }; - /* + /* * Return a new Big whose value is the value of this Big rounded to a * maximum of dp decimal places using rounding mode rm. * If dp is not specified, round to 0 decimal places. @@ -835,205 +763,200 @@ * [dp] {number} Integer, 0 to MAX_DP inclusive. * [rm] 0, 1, 2 or 3 (ROUND_DOWN, ROUND_HALF_UP, ROUND_HALF_EVEN, ROUND_UP) */ - P.round = function (dp, rm) { - var x = this, - Big = x.constructor; - - if (dp == null) { - dp = 0; - } else if (dp !== ~~dp || dp < 0 || dp > MAX_DP) { - throwErr('!round!'); - } - rnd(x = new Big(x), dp, rm == null ? Big.RM : rm); + P.round = function(dp, rm) { + var x = this, Big = x.constructor; - return x; - }; + if (dp == null) { + dp = 0; + } else if (dp !== ~~dp || dp < 0 || dp > MAX_DP) { + throwErr("!round!"); + } + rnd((x = new Big(x)), dp, rm == null ? Big.RM : rm); + return x; + }; - /* + /* * Return a new Big whose value is the square root of the value of this Big, * rounded, if necessary, to a maximum of Big.DP decimal places using * rounding mode Big.RM. */ - P.sqrt = function () { - var estimate, r, approx, - x = this, - Big = x.constructor, - xc = x.c, - i = x.s, - e = x.e, - half = new Big('0.5'); - - // Zero? - if (!xc[0]) { - return new Big(x); - } + P.sqrt = function() { + var estimate, + r, + approx, + x = this, + Big = x.constructor, + xc = x.c, + i = x.s, + e = x.e, + half = new Big("0.5"); + + // Zero? + if (!xc[0]) { + return new Big(x); + } - // If negative, throw NaN. - if (i < 0) { - throwErr(NaN); - } + // If negative, throw NaN. + if (i < 0) { + throwErr(NaN); + } - // Estimate. - i = Math.sqrt(x.toString()); + // Estimate. + i = Math.sqrt(x.toString()); - // Math.sqrt underflow/overflow? - // Pass x to Math.sqrt as integer, then adjust the result exponent. - if (i === 0 || i === 1 / 0) { - estimate = xc.join(''); + // Math.sqrt underflow/overflow? + // Pass x to Math.sqrt as integer, then adjust the result exponent. + if (i === 0 || i === 1 / 0) { + estimate = xc.join(""); - if (!(estimate.length + e & 1)) { - estimate += '0'; - } + if (!((estimate.length + e) & 1)) { + estimate += "0"; + } - r = new Big( Math.sqrt(estimate).toString() ); - r.e = ((e + 1) / 2 | 0) - (e < 0 || e & 1); - } else { - r = new Big(i.toString()); - } - - i = r.e + (Big.DP += 4); + r = new Big(Math.sqrt(estimate).toString()); + r.e = (((e + 1) / 2) | 0) - (e < 0 || e & 1); + } else { + r = new Big(i.toString()); + } - // Newton-Raphson iteration. - do { - approx = r; - r = half.times( approx.plus( x.div(approx) ) ); - } while ( approx.c.slice(0, i).join('') !== - r.c.slice(0, i).join('') ); + i = r.e + (Big.DP += 4); - rnd(r, Big.DP -= 4, Big.RM); + // Newton-Raphson iteration. + do { + approx = r; + r = half.times(approx.plus(x.div(approx))); + } while (approx.c.slice(0, i).join("") !== r.c.slice(0, i).join("")); - return r; - }; + rnd(r, (Big.DP -= 4), Big.RM); + return r; + }; - /* + /* * Return a new Big whose value is the value of this Big times the value of * Big y. */ - P.mul = P.times = function (y) { - var c, - x = this, - Big = x.constructor, - xc = x.c, - yc = (y = new Big(y)).c, - a = xc.length, - b = yc.length, - i = x.e, - j = y.e; - - // Determine sign of result. - y.s = x.s == y.s ? 1 : -1; - - // Return signed 0 if either 0. - if (!xc[0] || !yc[0]) { - return new Big(y.s * 0); - } - - // Initialise exponent of result as x.e + y.e. - y.e = i + j; - - // If array xc has fewer digits than yc, swap xc and yc, and lengths. - if (a < b) { - c = xc; - xc = yc; - yc = c; - j = a; - a = b; - b = j; - } - - // Initialise coefficient array of result with zeros. - for (c = new Array(j = a + b); j--; c[j] = 0) { - } + P.mul = P.times = function(y) { + var c, + x = this, + Big = x.constructor, + xc = x.c, + yc = (y = new Big(y)).c, + a = xc.length, + b = yc.length, + i = x.e, + j = y.e; + + // Determine sign of result. + y.s = x.s == y.s ? 1 : -1; + + // Return signed 0 if either 0. + if (!xc[0] || !yc[0]) { + return new Big(y.s * 0); + } - // Multiply. + // Initialise exponent of result as x.e + y.e. + y.e = i + j; + + // If array xc has fewer digits than yc, swap xc and yc, and lengths. + if (a < b) { + c = xc; + xc = yc; + yc = c; + j = a; + a = b; + b = j; + } - // i is initially xc.length. - for (i = b; i--;) { - b = 0; + // Initialise coefficient array of result with zeros. + for (c = new Array((j = a + b)); j--; c[j] = 0) { + } - // a is yc.length. - for (j = a + i; j > i;) { + // Multiply. - // Current sum of products at this digit position, plus carry. - b = c[j] + yc[i] * xc[j - i - 1] + b; - c[j--] = b % 10; + // i is initially xc.length. + for (i = b; i--; ) { + b = 0; - // carry - b = b / 10 | 0; - } - c[j] = (c[j] + b) % 10; - } + // a is yc.length. + for (j = a + i; j > i; ) { + // Current sum of products at this digit position, plus carry. + b = c[j] + yc[i] * xc[j - i - 1] + b; + c[j--] = b % 10; - // Increment result exponent if there is a final carry. - if (b) { - ++y.e; - } + // carry + b = (b / 10) | 0; + } + c[j] = (c[j] + b) % 10; + } - // Remove any leading zero. - if (!c[0]) { - c.shift(); - } + // Increment result exponent if there is a final carry. + if (b) { + ++y.e; + } - // Remove trailing zeros. - for (i = c.length; !c[--i]; c.pop()) { - } - y.c = c; + // Remove any leading zero. + if (!c[0]) { + c.shift(); + } - return y; - }; + // Remove trailing zeros. + for (i = c.length; !c[--i]; c.pop()) { + } + y.c = c; + return y; + }; - /* + /* * Return a string representing the value of this Big. * Return exponential notation if this Big has a positive exponent equal to * or greater than Big.E_POS, or a negative exponent equal to or less than * Big.E_NEG. */ - P.toString = P.valueOf = P.toJSON = function () { - var x = this, - Big = x.constructor, - e = x.e, - str = x.c.join(''), - strL = str.length; - - // Exponential notation? - if (e <= Big.E_NEG || e >= Big.E_POS) { - str = str.charAt(0) + (strL > 1 ? '.' + str.slice(1) : '') + - (e < 0 ? 'e' : 'e+') + e; - - // Negative exponent? - } else if (e < 0) { - - // Prepend zeros. - for (; ++e; str = '0' + str) { - } - str = '0.' + str; - - // Positive exponent? - } else if (e > 0) { - - if (++e > strL) { - - // Append zeros. - for (e -= strL; e-- ; str += '0') { - } - } else if (e < strL) { - str = str.slice(0, e) + '.' + str.slice(e); - } - - // Exponent zero. - } else if (strL > 1) { - str = str.charAt(0) + '.' + str.slice(1); + P.toString = P.valueOf = P.toJSON = function() { + var x = this, + Big = x.constructor, + e = x.e, + str = x.c.join(""), + strL = str.length; + + // Exponential notation? + if (e <= Big.E_NEG || e >= Big.E_POS) { + str = + str.charAt(0) + + (strL > 1 ? "." + str.slice(1) : "") + + (e < 0 ? "e" : "e+") + + e; + + // Negative exponent? + } else if (e < 0) { + // Prepend zeros. + for (; ++e; str = "0" + str) { + } + str = "0." + str; + + // Positive exponent? + } else if (e > 0) { + if (++e > strL) { + // Append zeros. + for (e -= strL; e--; str += "0") { } + } else if (e < strL) { + str = str.slice(0, e) + "." + str.slice(e); + } - // Avoid '-0' - return x.s < 0 && x.c[0] ? '-' + str : str; - }; + // Exponent zero. + } else if (strL > 1) { + str = str.charAt(0) + "." + str.slice(1); + } + // Avoid '-0' + return x.s < 0 && x.c[0] ? "-" + str : str; + }; - /* + /* *************************************************************************** * If toExponential, toFixed, toPrecision and format are not required they * can safely be commented-out or deleted. No redundant code will be left. @@ -1041,66 +964,58 @@ *************************************************************************** */ - - /* + /* * Return a string representing the value of this Big in exponential * notation to dp fixed decimal places and rounded, if necessary, using * Big.RM. * * [dp] {number} Integer, 0 to MAX_DP inclusive. */ - P.toExponential = function (dp) { - - if (dp == null) { - dp = this.c.length - 1; - } else if (dp !== ~~dp || dp < 0 || dp > MAX_DP) { - throwErr('!toExp!'); - } - - return format(this, dp, 1); - }; + P.toExponential = function(dp) { + if (dp == null) { + dp = this.c.length - 1; + } else if (dp !== ~~dp || dp < 0 || dp > MAX_DP) { + throwErr("!toExp!"); + } + return format(this, dp, 1); + }; - /* + /* * Return a string representing the value of this Big in normal notation * to dp fixed decimal places and rounded, if necessary, using Big.RM. * * [dp] {number} Integer, 0 to MAX_DP inclusive. */ - P.toFixed = function (dp) { - var str, - x = this, - Big = x.constructor, - neg = Big.E_NEG, - pos = Big.E_POS; - - // Prevent the possibility of exponential notation. - Big.E_NEG = -(Big.E_POS = 1 / 0); - - if (dp == null) { - str = x.toString(); - } else if (dp === ~~dp && dp >= 0 && dp <= MAX_DP) { - str = format(x, x.e + dp); - - // (-0).toFixed() is '0', but (-0.1).toFixed() is '-0'. - // (-0).toFixed(1) is '0.0', but (-0.01).toFixed(1) is '-0.0'. - if (x.s < 0 && x.c[0] && str.indexOf('-') < 0) { - //E.g. -0.5 if rounded to -0 will cause toString to omit the minus sign. - str = '-' + str; - } - } - Big.E_NEG = neg; - Big.E_POS = pos; + P.toFixed = function(dp) { + var str, x = this, Big = x.constructor, neg = Big.E_NEG, pos = Big.E_POS; - if (!str) { - throwErr('!toFix!'); - } + // Prevent the possibility of exponential notation. + Big.E_NEG = -(Big.E_POS = 1 / 0); + + if (dp == null) { + str = x.toString(); + } else if (dp === ~~dp && dp >= 0 && dp <= MAX_DP) { + str = format(x, x.e + dp); - return str; - }; + // (-0).toFixed() is '0', but (-0.1).toFixed() is '-0'. + // (-0).toFixed(1) is '0.0', but (-0.01).toFixed(1) is '-0.0'. + if (x.s < 0 && x.c[0] && str.indexOf("-") < 0) { + //E.g. -0.5 if rounded to -0 will cause toString to omit the minus sign. + str = "-" + str; + } + } + Big.E_NEG = neg; + Big.E_POS = pos; + if (!str) { + throwErr("!toFix!"); + } - /* + return str; + }; + + /* * Return a string representing the value of this Big rounded to sd * significant digits using Big.RM. Use exponential notation if sd is less * than the number of digits necessary to represent the integer part of the @@ -1108,35 +1023,32 @@ * * sd {number} Integer, 1 to MAX_DP inclusive. */ - P.toPrecision = function (sd) { - - if (sd == null) { - return this.toString(); - } else if (sd !== ~~sd || sd < 1 || sd > MAX_DP) { - throwErr('!toPre!'); - } - - return format(this, sd - 1, 2); - }; - + P.toPrecision = function(sd) { + if (sd == null) { + return this.toString(); + } else if (sd !== ~~sd || sd < 1 || sd > MAX_DP) { + throwErr("!toPre!"); + } - // Export + return format(this, sd - 1, 2); + }; + // Export - Big = bigFactory(); + Big = bigFactory(); - //AMD. - if (typeof define === 'function' && define.amd) { - define(function () { - return Big; - }); + //AMD. + if (typeof define === "function" && define.amd) { + define(function() { + return Big; + }); // Node and other CommonJS-like environments that support module.exports. - } else if (typeof module !== 'undefined' && module.exports) { - module.exports = Big; + } else if (typeof module !== "undefined" && module.exports) { + module.exports = Big; //Browser. - } else { - global.Big = Big; - } + } else { + global.Big = Big; + } })(this); diff --git a/src/libs/matches-selector-polyfill.js b/src/libs/matches-selector-polyfill.js index bac5b8b..3e2fa8d 100644 --- a/src/libs/matches-selector-polyfill.js +++ b/src/libs/matches-selector-polyfill.js @@ -2,19 +2,19 @@ * from https://developer.mozilla.org/de/docs/Web/API/Element/matches */ Element.prototype.matches = - Element.prototype.matches || - Element.prototype.matchesSelector || - Element.prototype.mozMatchesSelector || - Element.prototype.msMatchesSelector || - Element.prototype.oMatchesSelector || - Element.prototype.webkitMatchesSelector || - function ( s ) { - var matches = ( this.document || this.ownerDocument ).querySelectorAll ( s ); - var i = matches.length; - while ( --i >= 0 ) { - if ( matches.item ( i ) === this ) { - return true; - } - } - return false; - }; \ No newline at end of file + Element.prototype.matches || + Element.prototype.matchesSelector || + Element.prototype.mozMatchesSelector || + Element.prototype.msMatchesSelector || + Element.prototype.oMatchesSelector || + Element.prototype.webkitMatchesSelector || + function(s) { + var matches = (this.document || this.ownerDocument).querySelectorAll(s); + var i = matches.length; + while (--i >= 0) { + if (matches.item(i) === this) { + return true; + } + } + return false; + }; diff --git a/src/loader.js b/src/loader.js index df42b7f..6d5eea9 100644 --- a/src/loader.js +++ b/src/loader.js @@ -27,51 +27,73 @@ // @include https://web1.dawnofthedragons.com/* // @include https://50.18.191.15/* // ==/UserScript== -( function () { - if(window.location.host==='50.18.191.15'||window.location.host==='web1.dawnofthedragons.com') { - window.idrinth = {}; - window.idrinth.add=function(data) { - var s=document.createElement('script'); - s.appendChild(document.createTextNode(data)); - document.getElementsByTagName('head')[0].appendChild(s); - }; - window.addEventListener( - "message", - function (event){ - try{ - var data = JSON.parse(event.data); - if(data.to !== 'idotd'||!window.idrinth.hasOwnProperty (data.task)||!data.data) { - return; - } - window.idrinth[data.task](data.data); - } catch(e) { - //nothing - } - }, - false - ); - return; - } - var sc = document.createElement ( 'script' ); - sc.setAttribute ( 'src', 'https://dotd.idrinth.de/static/userscript/' + GM_info.script.version + '/' ); - sc.setAttribute ( 'id', 'idotd-loader' ); - sc.setAttribute ( 'async', 'async' ); - sc.errorCounter = 0; - sc.errorFunction = function () { - var self = document.getElementById ( 'idotd-loader' ); - self.parentNode.removeChild ( self ); - var sc = document.createElement ( 'script' ); - sc.onerror = self.onerror; - sc.errorCounter = self.errorCounter + 1; - sc.errorFunction = self.errorFunction; - sc.setAttribute ( 'id', 'idotd-loader' ); - sc.setAttribute ( 'async', 'async' ); - sc.setAttribute ( 'src', ( self.getAttribute ( 'src' ) + '' ).replace ( /(userscript\/.*?\/).*$/, '$1' ) + Math.random () + '/' ); - document.getElementsByTagName ( 'head' )[0].appendChild ( sc ); +(function() { + if ( + window.location.host === "50.18.191.15" || + window.location.host === "web1.dawnofthedragons.com" + ) { + window.idrinth = {}; + window.idrinth.add = function(data) { + var s = document.createElement("script"); + s.appendChild(document.createTextNode(data)); + document.getElementsByTagName("head")[0].appendChild(s); }; - sc.onerror = function () { - console.log ( "Failed loading IDotD, retry in " + ( 500 + 100 * this.errorCounter * this.errorCounter ) / 1000 + "sec." ); - window.setTimeout ( this.errorFunction, 500 + 100 * this.errorCounter * this.errorCounter ); - }; - document.getElementsByTagName ( 'head' )[0].appendChild ( sc ); -} () ); + window.addEventListener( + "message", + function(event) { + try { + var data = JSON.parse(event.data); + if ( + data.to !== "idotd" || + !window.idrinth.hasOwnProperty(data.task) || + !data.data + ) { + return; + } + window.idrinth[data.task](data.data); + } catch (e) { + //nothing + } + }, + false + ); + return; + } + var sc = document.createElement("script"); + sc.setAttribute( + "src", + "https://dotd.idrinth.de/static/userscript/" + GM_info.script.version + "/" + ); + sc.setAttribute("id", "idotd-loader"); + sc.setAttribute("async", "async"); + sc.errorCounter = 0; + sc.errorFunction = function() { + var self = document.getElementById("idotd-loader"); + self.parentNode.removeChild(self); + var sc = document.createElement("script"); + sc.onerror = self.onerror; + sc.errorCounter = self.errorCounter + 1; + sc.errorFunction = self.errorFunction; + sc.setAttribute("id", "idotd-loader"); + sc.setAttribute("async", "async"); + sc.setAttribute( + "src", + (self.getAttribute("src") + "").replace(/(userscript\/.*?\/).*$/, "$1") + + Math.random() + + "/" + ); + document.getElementsByTagName("head")[0].appendChild(sc); + }; + sc.onerror = function() { + console.log( + "Failed loading IDotD, retry in " + + (500 + 100 * this.errorCounter * this.errorCounter) / 1000 + + "sec." + ); + window.setTimeout( + this.errorFunction, + 500 + 100 * this.errorCounter * this.errorCounter + ); + }; + document.getElementsByTagName("head")[0].appendChild(sc); +})(); diff --git a/src/mods/chat.js b/src/mods/chat.js index ed07980..1623e37 100644 --- a/src/mods/chat.js +++ b/src/mods/chat.js @@ -1,76 +1,76 @@ idrinth.chat = { - /** + /** * own user id * @type Number */ - self: 0, - /** + self: 0, + /** * Maximum message id * @type Number */ - maxId: 0, - /** + maxId: 0, + /** * * @type Array */ - messages: [ ], - /** + messages: [], + /** * * @type Array */ - oldMessages: [ ], - /** + oldMessages: [], + /** * * @type Object */ - elements: { - /** + elements: { + /** * * @type HTMLElement */ - chats: null, - /** + chats: null, + /** * * @type HTMLElement */ - menu: null - }, - /** + menu: null + }, + /** * * @type {Object} */ - chatRank: { }, - /** + chatRank: {}, + /** * * @type Number */ - refreshCount: 0, - /** + refreshCount: 0, + /** * * @returns {undefined} */ - refreshChats: function () { - /** + refreshChats: function() { + /** * * @param {String} data * @returns {undefined} */ - var applyMessages = function ( data ) { - /** + var applyMessages = function(data) { + /** * * @param {String} messages * @returns {undefined} */ - var processMessages = function ( messages ) { - /** + var processMessages = function(messages) { + /** * * @param {Array} chatMessages * @param {Number} chatId * @param {HTMLElement} chatElement * @returns {Boolean} */ - var addMessages = function ( chatMessages, chatId, chatElement ) { - /** + var addMessages = function(chatMessages, chatId, chatElement) { + /** * * @param {String} message * @param {HTMLElement} chat @@ -78,468 +78,576 @@ idrinth.chat = { * @param {Number} messageId * @returns {undefined} */ - var buildMessage = function ( message, chat, chatId, messageId ) { - /** + var buildMessage = function(message, chat, chatId, messageId) { + /** * * @returns {String} */ - var getfullDateInt = function () { - /** + var getfullDateInt = function() { + /** * * @param {Number} x * @param {Number} n * @returns {String} */ - function addZero ( x, n ) { - while ( x.toString ().length < n ) { - x = "0" + x; - } - return x; - } - var d = new Date (); - return addZero ( d.getFullYear (), 2 ) + - addZero ( d.getMonth (), 2 ) + - addZero ( d.getDate (), 2 ) + - addZero ( d.getHours (), 2 ) + - addZero ( d.getMinutes (), 2 ) + - addZero ( d.getSeconds (), 2 ) + - addZero ( d.getMilliseconds (), 3 ); - }; - /** + function addZero(x, n) { + while (x.toString().length < n) { + x = "0" + x; + } + return x; + } + var d = new Date(); + return ( + addZero(d.getFullYear(), 2) + + addZero(d.getMonth(), 2) + + addZero(d.getDate(), 2) + + addZero(d.getHours(), 2) + + addZero(d.getMinutes(), 2) + + addZero(d.getSeconds(), 2) + + addZero(d.getMilliseconds(), 3) + ); + }; + /** * * @param {String} message * @param {Boolean} own * @param {Number} chatId * @returns {undefined} */ - var notify = function ( message, own, chatId ) { - /** + var notify = function(message, own, chatId) { + /** * * @param {Number} chatId * @returns {Boolean} */ - var notActive = function ( chatId ) { - try { - return !idrinth.windowactive || - !( document.getElementById ( 'idrinth-chat-tab-click-' + chatId ).getAttribute ( 'class' ) ).match ( /(\s|^)active( |$)/ ) || - !( document.getElementById ( 'idrinth-chat' ).getAttribute ( 'class' ) ).match ( /(\s|^)active( |$)/ ); - } catch ( e ) { - idrinth.core.log ( e.getMessage ); - return true; - } - }; - /** + var notActive = function(chatId) { + try { + return ( + !idrinth.windowactive || + !document + .getElementById("idrinth-chat-tab-click-" + chatId) + .getAttribute("class") + .match(/(\s|^)active( |$)/) || + !document + .getElementById("idrinth-chat") + .getAttribute("class") + .match(/(\s|^)active( |$)/) + ); + } catch (e) { + idrinth.core.log(e.getMessage); + return true; + } + }; + /** * * @param {String} text * @returns {Boolean} */ - var messageAllowed = function ( text ) { - try { - return ( idrinth.settings.get ( "notification#message" ) && text.match ( /\{[A-Z]{2}-Raid / ) === null ) || - ( idrinth.settings.get ( "notification#mention" ) && text.match ( new RegExp ( '(\s|^)' + idrinth.core.escapeRegExp ( idrinth.chat.users[idrinth.chat.self].name ) + '(\s|$)', 'i' ) ) !== null ) || - ( idrinth.settings.get ( "notification#raid" ) && text.match ( /\{[A-Z]{2}-Raid / ) !== null ); - } catch ( e ) { - idrinth.core.log ( e.getMessage () ); - return false; - } - }; - if ( !own && notActive ( chatId ) && messageAllowed ( message.text ) ) { - try { - idrinth.core.sendNotification ( - message.time.split ( ' ' )[1] + ' ' + document.getElementById ( 'idrinth-chat-tab-click-' + chatId ).innerHTML + ':', - idrinth.chat.users[message.user].name + ': ' + message.text - ); - } catch ( exception ) { - idrinth.core.log ( exception.getMessage () ); - } - } - }; - var own = parseInt ( message.user, 10 ) === parseInt ( idrinth.chat.self, 10 ); - notify ( message, own, chatId ); - chat.appendChild ( idrinth.ui.buildElement ( - { - type: 'li', - id: 'idrinth-single-chat-message-' + messageId + ( parseInt ( messageId, 10 ) < 1 ? '-' + getfullDateInt () : '' ), - css: own ? 'self-written ' : '', - children: [ - { - type: 'span', - css: 'time', - content: message.time.split ( ' ' )[1], - attributes: [ { - name: 'title', - value: message.time - } ] - }, - { - type: 'span', - css: 'user ' + idrinth.chat.ranks[parseInt ( idrinth.chat.chatRank[chatId][message.user], 10 )] + ( message.user === 0 ? ' system-message' : '' ), - content: idrinth.chat.users[message.user].name, - attributes: [ - { - name: 'data-id', - value: message.user - }, - { - name: 'onclick', - value: 'idrinth.chat.userclick(this,' + message.user + ',' + chatId + ')' - } - ] - }, - { - type: '#text', - content: ':' - }, - { - type: 'span', - children: idrinth.chat.buildMessageText ( message.text ) - } - ] - } - ) ); - }; - var isNew = false; - for (var messageId in chatMessages) { - if ( parseInt ( messageId, 10 ) < 1 || !document.getElementById ( 'idrinth-single-chat-message-' + messageId ) ) { - isNew = true; - buildMessage ( messages[chatId][messageId], chatElement, chatId, messageId ); - if ( parseInt ( messageId, 10 ) > parseInt ( idrinth.chat.maxId, 10 ) ) { - idrinth.chat.maxId = messageId; - } - } - } - return isNew; - }; - /** + var messageAllowed = function(text) { + try { + return ( + (idrinth.settings.get("notification#message") && + text.match(/\{[A-Z]{2}-Raid /) === null) || + (idrinth.settings.get("notification#mention") && + text.match( + new RegExp( + "(\s|^)" + + idrinth.core.escapeRegExp( + idrinth.chat.users[idrinth.chat.self].name + ) + + "(\s|$)", + "i" + ) + ) !== null) || + (idrinth.settings.get("notification#raid") && + text.match(/\{[A-Z]{2}-Raid /) !== null) + ); + } catch (e) { + idrinth.core.log(e.getMessage()); + return false; + } + }; + if (!own && notActive(chatId) && messageAllowed(message.text)) { + try { + idrinth.core.sendNotification( + message.time.split(" ")[1] + + " " + + document.getElementById( + "idrinth-chat-tab-click-" + chatId + ).innerHTML + + ":", + idrinth.chat.users[message.user].name + ": " + message.text + ); + } catch (exception) { + idrinth.core.log(exception.getMessage()); + } + } + }; + var own = + parseInt(message.user, 10) === parseInt(idrinth.chat.self, 10); + notify(message, own, chatId); + chat.appendChild( + idrinth.ui.buildElement({ + type: "li", + id: "idrinth-single-chat-message-" + + messageId + + (parseInt(messageId, 10) < 1 ? "-" + getfullDateInt() : ""), + css: own ? "self-written " : "", + children: [ + { + type: "span", + css: "time", + content: message.time.split(" ")[1], + attributes: [ + { + name: "title", + value: message.time + } + ] + }, + { + type: "span", + css: "user " + + idrinth.chat.ranks[ + parseInt( + idrinth.chat.chatRank[chatId][message.user], + 10 + ) + ] + + (message.user === 0 ? " system-message" : ""), + content: idrinth.chat.users[message.user].name, + attributes: [ + { + name: "data-id", + value: message.user + }, + { + name: "onclick", + value: "idrinth.chat.userclick(this," + + message.user + + "," + + chatId + + ")" + } + ] + }, + { + type: "#text", + content: ":" + }, + { + type: "span", + children: idrinth.chat.buildMessageText(message.text) + } + ] + }) + ); + }; + var isNew = false; + for (var messageId in chatMessages) { + if ( + parseInt(messageId, 10) < 1 || + !document.getElementById( + "idrinth-single-chat-message-" + messageId + ) + ) { + isNew = true; + buildMessage( + messages[chatId][messageId], + chatElement, + chatId, + messageId + ); + if (parseInt(messageId, 10) > parseInt(idrinth.chat.maxId, 10)) { + idrinth.chat.maxId = messageId; + } + } + } + return isNew; + }; + /** * * @param {Boolean} isNew * @param {HTMLElement} chat * @param {Number} chatId * @returns {undefined} */ - var setChatClass = function ( isNew, chat, chatId ) { - /** + var setChatClass = function(isNew, chat, chatId) { + /** * * @param {HTMLElement} element * @returns {Boolean} */ - var isActive = function ( element ) { - var cssClass = element.getAttribute ( 'class' ); - return !( !cssClass ) && !( !cssClass.match ( /(^|\s)active(\s|$)/ ) ); - }; - var chatActive = isActive ( document.getElementById ( 'idrinth-chat' ) ); - if ( isNew && !chatActive ) { - document.getElementById ( 'idrinth-chat' ).setAttribute ( 'class', 'new-message' ); - } - var tab = document.getElementById ( 'idrinth-chat-tab-click-' + chatId ); - var tabActive = isActive ( tab ); - if ( isNew && !tabActive ) { - tab.setAttribute ( 'class', tab.getAttribute ( 'class' ) + ' new-message' ); - } else if ( tabActive && chatActive && chat.lastChild.scrollTop < chat.lastChild.scrollHeight ) { - try { - chat.lastChild.scrollIntoView ( false ); - } catch ( e ) { - idrinth.core.log ( e ); - } - chat.lastChild.scrollTop = chat.lastChild.scrollHeight; - } - }; - if ( idrinth.chat.maxId === 0 ) { - idrinth.chat.maxId = 1; - } - for (var key in messages) { - if ( - !isNaN ( parseInt ( key, 10 ) ) && - document.getElementById ( 'idrinth-chat-tab-' + key ) && document.getElementById ( 'idrinth-chat-tab-' + key ).getElementsByTagName ( 'ul' )[1] ) { - var chat = document.getElementById ( 'idrinth-chat-tab-' + key ).getElementsByTagName ( 'ul' )[1]; - setChatClass ( addMessages ( messages[key], key, chat ), chat, key ); - } - } - }; - if ( !data ) { - return idrinth.chat.returnMessages ( data ); - } - data = JSON.parse ( data ); - if ( !data ) { - return idrinth.chat.returnMessages ( data ); + var isActive = function(element) { + var cssClass = element.getAttribute("class"); + return !!cssClass && !!cssClass.match(/(^|\s)active(\s|$)/); + }; + var chatActive = isActive(document.getElementById("idrinth-chat")); + if (isNew && !chatActive) { + document + .getElementById("idrinth-chat") + .setAttribute("class", "new-message"); + } + var tab = document.getElementById("idrinth-chat-tab-click-" + chatId); + var tabActive = isActive(tab); + if (isNew && !tabActive) { + tab.setAttribute( + "class", + tab.getAttribute("class") + " new-message" + ); + } else if ( + tabActive && + chatActive && + chat.lastChild.scrollTop < chat.lastChild.scrollHeight + ) { + try { + chat.lastChild.scrollIntoView(false); + } catch (e) { + idrinth.core.log(e); } - if ( data.login ) { - return idrinth.chat.relogin (); - } - if ( data.messages ) { - processMessages ( data.messages ); - } - idrinth.chat.oldMessages = [ ]; - idrinth.core.timeouts.add ( 'chat', idrinth.chat.refreshChats, 999 ); + chat.lastChild.scrollTop = chat.lastChild.scrollHeight; + } }; - /** + if (idrinth.chat.maxId === 0) { + idrinth.chat.maxId = 1; + } + for (var key in messages) { + if ( + !isNaN(parseInt(key, 10)) && + document.getElementById("idrinth-chat-tab-" + key) && + document + .getElementById("idrinth-chat-tab-" + key) + .getElementsByTagName("ul")[1] + ) { + var chat = document + .getElementById("idrinth-chat-tab-" + key) + .getElementsByTagName("ul")[1]; + setChatClass(addMessages(messages[key], key, chat), chat, key); + } + } + }; + if (!data) { + return idrinth.chat.returnMessages(data); + } + data = JSON.parse(data); + if (!data) { + return idrinth.chat.returnMessages(data); + } + if (data.login) { + return idrinth.chat.relogin(); + } + if (data.messages) { + processMessages(data.messages); + } + idrinth.chat.oldMessages = []; + idrinth.core.timeouts.add("chat", idrinth.chat.refreshChats, 999); + }; + /** * * @returns {undefined} */ - var refreshMembers = function () { - /** + var refreshMembers = function() { + /** * * @param {String} data * @returns {undefined} */ - var applyMembers = function ( data ) { - /** + var applyMembers = function(data) { + /** * * @returns {undefined} */ - var applyMemberData = function () { - /** + var applyMemberData = function() { + /** * * @param {HTMLElement} chat * @param {Number} chatId * @param {Number} userId * @returns {undefined} */ - var addMemberElement = function ( chat, chatId, userId ) { - var usedPlatforms = ''; - for (var pkey in idrinth.chat.users[userId].platforms) { - if ( idrinth.chat.users[userId].platforms[pkey] ) { - usedPlatforms += pkey; - } - } - chat.appendChild ( idrinth.ui.buildElement ( { - type: 'li', - css: 'user ' + idrinth.chat.ranks[parseInt ( idrinth.chat.chatRank[chatId][userId], 10 )], - content: ( usedPlatforms === '' ? '' : '[' + usedPlatforms.toUpperCase () + '] ' ) + idrinth.chat.users[userId].name, - attributes: [ - { - name: 'data-id', - value: userId - }, - { - name: 'onclick', - value: 'idrinth.chat.userclick(this,' + userId + ', ' + chatId + ')' - } - ] - } - ) ); - }; - for (var chatId in idrinth.chat.chatRank) { - if ( document.getElementById ( 'idrinth-chat-tab-' + chatId ) ) { - var chat = document.getElementById ( 'idrinth-chat-tab-' + chatId ).getElementsByTagName ( 'ul' )[0]; - while ( chat.firstChild ) { - chat.removeChild ( chat.firstChild ); - } - for (var userId in idrinth.chat.chatRank[chatId]) { - if ( idrinth.chat.chatRank[chatId].hasOwnProperty ( userId ) ) { - addMemberElement ( chat, chatId, userId ); - } - } - } - } - }; - if ( !data ) { - return; - } - data = JSON.parse ( data ); - if ( !data ) { - return; + var addMemberElement = function(chat, chatId, userId) { + var usedPlatforms = ""; + for (var pkey in idrinth.chat.users[userId].platforms) { + if (idrinth.chat.users[userId].platforms[pkey]) { + usedPlatforms += pkey; + } + } + chat.appendChild( + idrinth.ui.buildElement({ + type: "li", + css: "user " + + idrinth.chat.ranks[ + parseInt(idrinth.chat.chatRank[chatId][userId], 10) + ], + content: (usedPlatforms === "" + ? "" + : "[" + usedPlatforms.toUpperCase() + "] ") + + idrinth.chat.users[userId].name, + attributes: [ + { + name: "data-id", + value: userId + }, + { + name: "onclick", + value: "idrinth.chat.userclick(this," + + userId + + ", " + + chatId + + ")" + } + ] + }) + ); + }; + for (var chatId in idrinth.chat.chatRank) { + if (document.getElementById("idrinth-chat-tab-" + chatId)) { + var chat = document + .getElementById("idrinth-chat-tab-" + chatId) + .getElementsByTagName("ul")[0]; + while (chat.firstChild) { + chat.removeChild(chat.firstChild); + } + for (var userId in idrinth.chat.chatRank[chatId]) { + if (idrinth.chat.chatRank[chatId].hasOwnProperty(userId)) { + addMemberElement(chat, chatId, userId); } - idrinth.chat.self = data.self; - idrinth.chat.users = data.users; - idrinth.chat.chatRank = data.members; - applyMemberData (); - }; - idrinth.core.ajax.runHome ( - 'chat-service/accounts/', - applyMembers - ); + } + } + } }; - idrinth.chat.oldMessages = JSON.parse ( JSON.stringify ( idrinth.chat.messages ) ); - idrinth.chat.messages = [ ]; - idrinth.core.ajax.runHome ( - 'chat-service/update/', - applyMessages, - idrinth.chat.returnMessages, - idrinth.chat.returnMessages, - JSON.stringify ( { - maxId: idrinth.chat.maxId, - messages: idrinth.chat.oldMessages - } ) - ); - if ( idrinth.chat.refreshCount % 25 === 0 ) { - refreshMembers (); + if (!data) { + return; } - idrinth.chat.refreshCount++; - }, - /** + data = JSON.parse(data); + if (!data) { + return; + } + idrinth.chat.self = data.self; + idrinth.chat.users = data.users; + idrinth.chat.chatRank = data.members; + applyMemberData(); + }; + idrinth.core.ajax.runHome("chat-service/accounts/", applyMembers); + }; + idrinth.chat.oldMessages = JSON.parse( + JSON.stringify(idrinth.chat.messages) + ); + idrinth.chat.messages = []; + idrinth.core.ajax.runHome( + "chat-service/update/", + applyMessages, + idrinth.chat.returnMessages, + idrinth.chat.returnMessages, + JSON.stringify({ + maxId: idrinth.chat.maxId, + messages: idrinth.chat.oldMessages + }) + ); + if (idrinth.chat.refreshCount % 25 === 0) { + refreshMembers(); + } + idrinth.chat.refreshCount++; + }, + /** * * @param {String} data * @returns {undefined} */ - returnMessages: function ( data ) { - for (var count = idrinth.chat.oldMessages.length - 1; count >= 0; count--) { - idrinth.chat.messages.unshift ( idrinth.chat.oldMessages[count] ); - } - idrinth.chat.oldMessages = [ ]; - idrinth.core.timeouts.add ( 'chat', idrinth.chat.refreshChats, 999 ); - }, - /** + returnMessages: function(data) { + for (var count = idrinth.chat.oldMessages.length - 1; count >= 0; count--) { + idrinth.chat.messages.unshift(idrinth.chat.oldMessages[count]); + } + idrinth.chat.oldMessages = []; + idrinth.core.timeouts.add("chat", idrinth.chat.refreshChats, 999); + }, + /** * * @param {HTMLElement} element * @param {Number} user * @param {Number} chat * @returns {undefined} */ - userclick: function ( element, user, chat ) { - if ( !idrinth.chat.chatRank[chat][idrinth.chat.self] || parseInt ( user, 10 ) === parseInt ( idrinth.chat.self, 10 ) ) { - return; - } - /** + userclick: function(element, user, chat) { + if ( + !idrinth.chat.chatRank[chat][idrinth.chat.self] || + parseInt(user, 10) === parseInt(idrinth.chat.self, 10) + ) { + return; + } + /** * * @param {Number} chat * @param {Number} user * @param {Number} rankId * @returns {Array} */ - var getPopupContent = function ( chat, user, rankId ) { - /** + var getPopupContent = function(chat, user, rankId) { + /** * * @param {Number} chat * @returns {Array} */ - var getPromotionOptions = function ( chat ) { - var promotionModes = [ - { - chat: chat, - label: 'chat.actions.banUser', - rank: 'Banned', - requiredRank: 3 - }, - { - chat: chat, - label: 'chat.actions.makeMod', - rank: 'Mod', - requiredRank: 3 - }, - { - chat: chat, - label: 'chat.actions.makeAdmin', - rank: 'Owner', - requiredRank: 4 - }, - { - chat: chat, - label: 'chat.actions.makeUser', - rank: 'User', - requiredRank: 3 - } - ]; - for (var chatId in idrinth.chat.chatRank) { - if ( idrinth.chat.chatRank.hasOwnProperty ( chatId ) ) { - var intChatId = parseInt ( chatId, 10 ); - if ( document.getElementById ( 'idrinth-chat-tab-click-' + chatId ) && intChatId !== chat && intChatId > 1 && !( user in idrinth.chat.chatRank[chatId] ) ) { - promotionModes.push ( { - chat: chatId, - label: 'Invite to Chat ' + document.getElementById ( 'idrinth-chat-tab-click-' + chatId ).innerHTML, - rank: 'User', - requiredRank: 1 - } ); - } - } - } - return promotionModes; - }; - /** + var getPromotionOptions = function(chat) { + var promotionModes = [ + { + chat: chat, + label: "chat.actions.banUser", + rank: "Banned", + requiredRank: 3 + }, + { + chat: chat, + label: "chat.actions.makeMod", + rank: "Mod", + requiredRank: 3 + }, + { + chat: chat, + label: "chat.actions.makeAdmin", + rank: "Owner", + requiredRank: 4 + }, + { + chat: chat, + label: "chat.actions.makeUser", + rank: "User", + requiredRank: 3 + } + ]; + for (var chatId in idrinth.chat.chatRank) { + if (idrinth.chat.chatRank.hasOwnProperty(chatId)) { + var intChatId = parseInt(chatId, 10); + if ( + document.getElementById("idrinth-chat-tab-click-" + chatId) && + intChatId !== chat && + intChatId > 1 && + !(user in idrinth.chat.chatRank[chatId]) + ) { + promotionModes.push({ + chat: chatId, + label: "Invite to Chat " + + document.getElementById("idrinth-chat-tab-click-" + chatId) + .innerHTML, + rank: "User", + requiredRank: 1 + }); + } + } + } + return promotionModes; + }; + /** * * @param {Object} node * @param {Number} user * @param {Number} ownRank * @returns {Array} */ - var promoteNode = function ( node, user, ownRank ) { - /** + var promoteNode = function(node, user, ownRank) { + /** * * @param {Number} reqRank * @param {Number} ownRank * @returns {Boolean} */ - var hasRights = function ( reqRank, ownRank ) { - return reqRank <= ownRank; - }; - if ( !hasRights ( node.requiredRank, ownRank ) ) { - return; - } - var translation = idrinth.text.get ( node.label ); - return { - content: translation === idrinth.text.data.default ? node.label : translation, - type: 'li', - attributes: [ { - name: 'onclick', - value: 'idrinth.chat.useroptions(' + node.chat + ',' + user + ',\'' + node.rank + '\');this.parentNode.parentNode.removeChild(this.parentNode);' - } ] - }; - }; - var popupContent = [ ]; - var promotionModes = getPromotionOptions ( parseInt ( chat, 10 ), user ); - for (var count = 0; count < promotionModes.length; count++) { - var tmp = promoteNode ( promotionModes[count], user, rankId ); - if ( tmp ) { - popupContent.push ( tmp ); - } + var hasRights = function(reqRank, ownRank) { + return reqRank <= ownRank; + }; + if (!hasRights(node.requiredRank, ownRank)) { + return; + } + var translation = idrinth.text.get(node.label); + return { + content: translation === idrinth.text.data.default + ? node.label + : translation, + type: "li", + attributes: [ + { + name: "onclick", + value: "idrinth.chat.useroptions(" + + node.chat + + "," + + user + + ",'" + + node.rank + + "');this.parentNode.parentNode.removeChild(this.parentNode);" } - return popupContent; + ] }; - var rankId = parseInt ( idrinth.chat.chatRank[chat][idrinth.chat.self], 10 ); - var popupContent = getPopupContent ( chat, user, rankId ); - if ( popupContent.length === 0 ) { - return; + }; + var popupContent = []; + var promotionModes = getPromotionOptions(parseInt(chat, 10), user); + for (var count = 0; count < promotionModes.length; count++) { + var tmp = promoteNode(promotionModes[count], user, rankId); + if (tmp) { + popupContent.push(tmp); } - popupContent.push ( { - type: 'li', - content: 'Close', - attributes: [ { - name: 'onclick', - value: 'this.parentNode.parentNode.removeChild(this.parentNode);' - } ] - } ); - idrinth.ui.base.appendChild ( idrinth.ui.buildElement ( { - type: 'ul', - children: popupContent, - css: 'idrinth-userinfo-box', - attributes: [ { - name: 'style', - value: idrinth.ui.getElementPositioning ( element ) - } ] - } ) ); - }, - /** + } + return popupContent; + }; + var rankId = parseInt(idrinth.chat.chatRank[chat][idrinth.chat.self], 10); + var popupContent = getPopupContent(chat, user, rankId); + if (popupContent.length === 0) { + return; + } + popupContent.push({ + type: "li", + content: "Close", + attributes: [ + { + name: "onclick", + value: "this.parentNode.parentNode.removeChild(this.parentNode);" + } + ] + }); + idrinth.ui.base.appendChild( + idrinth.ui.buildElement({ + type: "ul", + children: popupContent, + css: "idrinth-userinfo-box", + attributes: [ + { + name: "style", + value: idrinth.ui.getElementPositioning(element) + } + ] + }) + ); + }, + /** * changes the rank of a person * @param {Number} chat * @param {String} user * @param {String} rank * @returns {undefined} */ - useroptions: function ( chat, user, rank ) { - idrinth.core.ajax.runHome ( - 'chat-service/rank/', - function ( reply ) { - try { - reply = JSON.parse ( reply ); - idrinth.core.alert ( reply.message ); - } catch ( e ) { - idrinth.core.log ( e ); - } - }, - function ( reply ) { - idrinth.core.alert ( idrinth.text.get ( "chat.error.modify" ) ); - }, - function ( reply ) { - idrinth.core.alert ( idrinth.text.get ( "chat.error.modify" ) ); - }, - JSON.stringify ( { - chat: chat, - user: user, - access: rank - } ) - ); - }, - /** + useroptions: function(chat, user, rank) { + idrinth.core.ajax.runHome( + "chat-service/rank/", + function(reply) { + try { + reply = JSON.parse(reply); + idrinth.core.alert(reply.message); + } catch (e) { + idrinth.core.log(e); + } + }, + function(reply) { + idrinth.core.alert(idrinth.text.get("chat.error.modify")); + }, + function(reply) { + idrinth.core.alert(idrinth.text.get("chat.error.modify")); + }, + JSON.stringify({ + chat: chat, + user: user, + access: rank + }) + ); + }, + /** * * @param {String} message * @param {RegExp} regex @@ -547,8 +655,8 @@ idrinth.chat = { * @param {String} lastField * @returns {Array} */ - replaceInText: function ( message, regex, callbacks, lastField ) { - /** + replaceInText: function(message, regex, callbacks, lastField) { + /** * * @param {String} message * @param {RegExp} regex @@ -556,8 +664,8 @@ idrinth.chat = { * @param {String} lastField * @returns {Array} */ - var complexHandler = function ( message, regex, callbacks, lastField ) { - /** + var complexHandler = function(message, regex, callbacks, lastField) { + /** * * @param {Number} count * @param {Array} callbacks @@ -565,706 +673,863 @@ idrinth.chat = { * @param {Array} textcontent * @returns {Array} */ - var partHandler = function ( count, callbacks, text, textcontent ) { - /** + var partHandler = function(count, callbacks, text, textcontent) { + /** * * @param {Array} textcontent * @param {Function} func * @param {String} text * @returns {unresolved} */ - var callbackHandler = function ( textcontent, func, text ) { - var tmp = func ( text ); - for (var c2 = 0; c2 < tmp.length; c2++) { - if ( tmp[c2] !== undefined ) { - textcontent.push ( tmp[c2] ); - } - } - return textcontent; - }; - if ( count % 2 === 0 && typeof callbacks[1] === 'function' ) { - textcontent = callbackHandler ( textcontent, callbacks[1], text[Math.ceil ( count / 2 )] ); - } else if ( count % 2 === 0 && text[Math.ceil ( count / 2 )] !== undefined ) { - textcontent.push ( { - type: '#text', - content: text[Math.ceil ( count / 2 )] - } ); - } else { - textcontent.push ( callbacks[0] ( matches[Math.ceil ( ( count - 1 ) / 2 )] ) ); - } - return textcontent; - }; - var matches = message.match ( regex ); - var text = ( message.replace ( regex, '$1########$' + lastField ) ).split ( '########' ); - var textcontent = [ ]; - var length = ( matches && Array.isArray ( matches ) ? matches.length : 0 ) + ( text && Array.isArray ( text ) ? text.length : 0 ); - for (var count = 0; count < length; count++) { - textcontent = partHandler ( count, callbacks, text, textcontent ); + var callbackHandler = function(textcontent, func, text) { + var tmp = func(text); + for (var c2 = 0; c2 < tmp.length; c2++) { + if (tmp[c2] !== undefined) { + textcontent.push(tmp[c2]); } - return textcontent; + } + return textcontent; }; - /** + if (count % 2 === 0 && typeof callbacks[1] === "function") { + textcontent = callbackHandler( + textcontent, + callbacks[1], + text[Math.ceil(count / 2)] + ); + } else if ( + count % 2 === 0 && + text[Math.ceil(count / 2)] !== undefined + ) { + textcontent.push({ + type: "#text", + content: text[Math.ceil(count / 2)] + }); + } else { + textcontent.push(callbacks[0](matches[Math.ceil((count - 1) / 2)])); + } + return textcontent; + }; + var matches = message.match(regex); + var text = message + .replace(regex, "$1########$" + lastField) + .split("########"); + var textcontent = []; + var length = + (matches && Array.isArray(matches) ? matches.length : 0) + + (text && Array.isArray(text) ? text.length : 0); + for (var count = 0; count < length; count++) { + textcontent = partHandler(count, callbacks, text, textcontent); + } + return textcontent; + }; + /** * * @param {String} message * @param {Array} callbacks * @returns {Array} */ - var simpleHandler = function ( message, callbacks ) { - if ( typeof callbacks[1] === 'function' ) { - var textcontent = [ ]; - var tmp = callbacks[1] ( message ); - for (var c2 = 0; c2 < tmp.length; c2++) { - textcontent.push ( tmp[c2] ); - } - return textcontent; - } - return [ { - type: '#text', - content: message - } ]; - }; - try { - return complexHandler ( message, regex, callbacks, lastField ); - } catch ( e ) { - return simpleHandler ( message, callbacks ); + var simpleHandler = function(message, callbacks) { + if (typeof callbacks[1] === "function") { + var textcontent = []; + var tmp = callbacks[1](message); + for (var c2 = 0; c2 < tmp.length; c2++) { + textcontent.push(tmp[c2]); } - }, - /** + return textcontent; + } + return [ + { + type: "#text", + content: message + } + ]; + }; + try { + return complexHandler(message, regex, callbacks, lastField); + } catch (e) { + return simpleHandler(message, callbacks); + } + }, + /** * * @param {String} message * @returns {Object} */ - buildEmoticons: function ( message ) { - if ( !idrinth.chat.emotes.lookup ) { - return message; + buildEmoticons: function(message) { + if (!idrinth.chat.emotes.lookup) { + return message; + } + var part = idrinth.core.escapeRegExp( + Object.keys(idrinth.chat.emotes.lookup).join("TTTT") + ); + var reg = new RegExp("(^| )(" + part.replace(/TTTT/g, "|") + ")($| )", "g"); + return idrinth.chat.replaceInText( + message, + reg, + [ + function(match) { + var el = + idrinth.chat.emotes.positions[ + idrinth.chat.emotes.lookup[match.replace(/ /g, "")] + ]; + return { + type: "span", + css: "idrinth-emoticon", + attributes: [ + { + name: "style", + value: "background-position: 0px -" + el / 8 + "px;" + }, + { + name: "title", + value: message + } + ], + children: [ + { + type: "span", + attributes: [ + { + name: "style", + value: "background-position: 0px -" + el / 2 + "px;" + } + ] + } + ] + }; } - var part = idrinth.core.escapeRegExp ( Object.keys ( idrinth.chat.emotes.lookup ).join ( 'TTTT' ) ); - var reg = new RegExp ( '(^| )(' + part.replace ( /TTTT/g, '|' ) + ')($| )', 'g' ); - return idrinth.chat.replaceInText ( message, reg, [ function ( match ) { - var el = idrinth.chat.emotes.positions[idrinth.chat.emotes.lookup[match.replace ( / /g, '' )]]; - return { - type: 'span', - css: 'idrinth-emoticon', - attributes: [ - { - name: 'style', - value: 'background-position: 0px -' + el / 8 + 'px;' - }, - { - name: 'title', - value: message - } - ], - children: [ - { - type: 'span', - attributes: [ { - name: 'style', - value: 'background-position: 0px -' + el / 2 + 'px;' - } ] - } - ] - }; - } ], 3 ); - }, - /** + ], + 3 + ); + }, + /** * * @param {String} message * @returns {Object} **/ - buildMessageText: function ( message ) { - var reg = new RegExp ( '(^|\\W)(https?://([^/ ]+)(/.*?)?)($| )', 'ig' ); - return idrinth.chat.replaceInText ( message, reg, [ - function ( match ) { - return { - type: 'a', - content: match.match ( /:\/\/([^\/]+?)(\/|$)/ )[1], - attributes: [ - { - name: 'href', - value: match - }, - { - name: 'title', - value: 'Go to ' + match - }, - { - name: 'target', - value: '_blank' - } - ] - }; - }, idrinth.chat.buildEmoticons ], 5 ); - }, - /** + buildMessageText: function(message) { + var reg = new RegExp("(^|\\W)(https?://([^/ ]+)(/.*?)?)($| )", "ig"); + return idrinth.chat.replaceInText( + message, + reg, + [ + function(match) { + return { + type: "a", + content: match.match(/:\/\/([^\/]+?)(\/|$)/)[1], + attributes: [ + { + name: "href", + value: match + }, + { + name: "title", + value: "Go to " + match + }, + { + name: "target", + value: "_blank" + } + ] + }; + }, + idrinth.chat.buildEmoticons + ], + 5 + ); + }, + /** * Rank-Classes & Names * @type Array */ - ranks: [ '', 'banned', 'user', 'mod', 'owner' ], - /** + ranks: ["", "banned", "user", "mod", "owner"], + /** * @type Object */ - emotes: { }, - /** + emotes: {}, + /** * * @returns {undefined} */ - start: function () { - /** + start: function() { + /** * * @returns {HTMLElement} */ - var build = function () { - /** + var build = function() { + /** * * @param {String} label * @returns {Object} */ - var makeInput = function ( label ) { - var translation = idrinth.text.get ( label ); - return { - type: 'li', - children: [ - { - type: 'label', - content: translation === idrinth.text.data.default ? label : translation - }, - { - type: 'input', - attributes: [ - { - name: 'type', - value: 'text' - }, - { - name: 'onchange', - value: 'this.setAttribute(\'value\',this.value);' - } - ] - } - ] - }; - }; - /** + var makeInput = function(label) { + var translation = idrinth.text.get(label); + return { + type: "li", + children: [ + { + type: "label", + content: translation === idrinth.text.data.default + ? label + : translation + }, + { + type: "input", + attributes: [ + { + name: "type", + value: "text" + }, + { + name: "onchange", + value: "this.setAttribute('value',this.value);" + } + ] + } + ] + }; + }; + /** * * @param {String} label * @param {String} onclick * @returns {Object} */ - var makeButton = function ( label, onclick ) { - var translation = idrinth.text.get ( label ); - return { - type: 'li', + var makeButton = function(label, onclick) { + var translation = idrinth.text.get(label); + return { + type: "li", + children: [ + { + type: "button", + attributes: [ + { + name: "type", + value: "button" + }, + { + name: "onclick", + value: onclick + } + ], + content: translation === idrinth.text.data.default + ? label + : translation + } + ] + }; + }; + return idrinth.ui.buildElement({ + id: "idrinth-chat", + css: "idrinth-hovering-box" + + (!idrinth.settings.get("chatHiddenOnStart") ? " active" : "") + + (idrinth.settings.get("moveLeft") ? " left-sided" : ""), + children: [ + { + type: "button", + content: idrinth.settings.get("chatHiddenOnStart") ? "<<" : ">>", + attributes: [ + { + name: "onclick", + value: "idrinth.chat.openCloseChat(this);" + } + ] + }, + { + type: "ul", + css: "styles-scrollbar chat-labels", + children: [ + { + type: "li", + css: "active", + content: "\u2699", + attributes: [ + { + name: "onclick", + value: "idrinth.chat.enableChat(this);" + }, + { + name: "data-id", + value: "0" + } + ] + } + ] + }, + { + type: "ul", + css: "chat-tabs", + children: [ + { + type: "li", + css: "styles-scrollbar active", + attributes: [ + { + name: "data-id", + value: "0" + } + ], + children: [ + { + type: "h1", + content: idrinth.text.get("chat.texts.title") + }, + { + type: "p", + content: idrinth.text.get("chat.texts.optional") + }, + { + id: "idrinth-chat-login", children: [ - { - type: 'button', - attributes: [ - { - name: 'type', - value: 'button' - }, - { - name: 'onclick', - value: onclick - } - ], - content: translation === idrinth.text.data.default ? label : translation - } + { + type: "h2", + content: idrinth.text.get("chat.texts.account") + }, + { + type: "p", + content: idrinth.text.get("chat.texts.invalid") + }, + { + type: "ul", + css: "settings", + children: [ + makeInput("Username"), + makeInput("Password"), + makeButton( + "chat.texts.offline", + "idrinth.chat.login()" + ) + ] + } ] - }; - }; - return idrinth.ui.buildElement ( { - id: 'idrinth-chat', - css: 'idrinth-hovering-box' + ( !idrinth.settings.get ( "chatHiddenOnStart" ) ? ' active' : '' ) + ( idrinth.settings.get ( "moveLeft" ) ? ' left-sided' : '' ), - children: [ - { - type: 'button', - content: ( idrinth.settings.get ( "chatHiddenOnStart" ) ? '<<' : '>>' ), - attributes: [ { - name: 'onclick', - value: 'idrinth.chat.openCloseChat(this);' - } ] - }, { - type: 'ul', - css: 'styles-scrollbar chat-labels', - children: [ { - type: 'li', - css: 'active', - content: "\u2699", - attributes: [ - { - name: 'onclick', - value: 'idrinth.chat.enableChat(this);' - }, - { - name: 'data-id', - value: '0' - } - ] - } ] - }, { - type: 'ul', - css: 'chat-tabs', - children: [ { - type: 'li', - css: 'styles-scrollbar active', - attributes: [ - { - name: 'data-id', - value: '0' - } - ], - children: [ - { - type: 'h1', - content: idrinth.text.get ( "chat.texts.title" ) - }, - { - type: 'p', - content: idrinth.text.get ( "chat.texts.optional" ) - }, { - id: 'idrinth-chat-login', - children: [ - { - type: 'h2', - content: idrinth.text.get ( "chat.texts.account" ) - }, - { - type: 'p', - content: idrinth.text.get ( "chat.texts.invalid" ) - }, - { - type: 'ul', - css: 'settings', - children: [ - makeInput ( 'Username' ), - makeInput ( 'Password' ), - makeButton ( 'chat.texts.offline', "idrinth.chat.login()" ) - ] - } - ] - }, { - id: 'idrinth-add-chat', - children: [ - { - type: 'h2', - content: idrinth.text.get ( "chat.actions.joinChat" ) - }, - { - type: 'ul', - css: 'settings', - children: [ - makeInput ( 'Chat-ID' ), - makeInput ( 'Chat-Password' ), - makeButton ( 'chat.actions.createAddChat', "idrinth.chat.add()" ) - ] - } - ] - }, - { - id: 'idrinth-make-chat', - children: [ - { - type: 'h2', - content: idrinth.text.get ( "chat.actions.createChat" ) - }, - { - type: 'ul', - css: 'settings', - children: [ - makeInput ( "Name" ), - makeButton ( 'chat.actions.createAddChat', "idrinth.chat.create()" ) - ] - } - ] - }, { - type: 'li', - children: [ - { - type: '#text', - content: idrinth.text.get ( "chat.texts.settings" ) - }, - { - type: 'a', - content: 'dotd.idrinth.de/' + idrinth.platform + '/chat/', - attributes: [ - { - name: 'target', - value: '_blank' - }, - { - name: 'href', - value: 'https://dotd.idrinth.de/' + idrinth.platform + '/chat/' - } - ] - }, - { - type: '#text', - content: '.' - } - ] - }, { - type: 'li', - children: [ - { - type: '#text', - content: idrinth.text.get ( "chat.texts.creditEmoticon" ) - }, - { - type: 'a', - content: 'emoticonshd.com', - attributes: [ - { - name: 'target', - value: '_blank' - }, - { - name: 'href', - value: 'http://emoticonshd.com/' - } - ] - }, - { - type: '#text', - content: '.' - } - ] - } - ] - } + }, + { + id: "idrinth-add-chat", + children: [ + { + type: "h2", + content: idrinth.text.get("chat.actions.joinChat") + }, + { + type: "ul", + css: "settings", + children: [ + makeInput("Chat-ID"), + makeInput("Chat-Password"), + makeButton( + "chat.actions.createAddChat", + "idrinth.chat.add()" + ) + ] + } + ] + }, + { + id: "idrinth-make-chat", + children: [ + { + type: "h2", + content: idrinth.text.get("chat.actions.createChat") + }, + { + type: "ul", + css: "settings", + children: [ + makeInput("Name"), + makeButton( + "chat.actions.createAddChat", + "idrinth.chat.create()" + ) + ] + } + ] + }, + { + type: "li", + children: [ + { + type: "#text", + content: idrinth.text.get("chat.texts.settings") + }, + { + type: "a", + content: "dotd.idrinth.de/" + + idrinth.platform + + "/chat/", + attributes: [ + { + name: "target", + value: "_blank" + }, + { + name: "href", + value: "https://dotd.idrinth.de/" + + idrinth.platform + + "/chat/" + } ] - } + }, + { + type: "#text", + content: "." + } + ] + }, + { + type: "li", + children: [ + { + type: "#text", + content: idrinth.text.get("chat.texts.creditEmoticon") + }, + { + type: "a", + content: "emoticonshd.com", + attributes: [ + { + name: "target", + value: "_blank" + }, + { + name: "href", + value: "http://emoticonshd.com/" + } + ] + }, + { + type: "#text", + content: "." + } + ] + } ] - } ); - }; - if ( !idrinth.settings.get ( "chatting" ) ) { - return; - } - if ( !document.getElementById ( 'idrinth-chat' ) ) { - idrinth.ui.base.appendChild ( build () ); - idrinth.chat.elements.chats = document.getElementById ( 'idrinth-chat' ).getElementsByTagName ( 'ul' )[1]; - idrinth.chat.elements.menu = document.getElementById ( 'idrinth-chat' ).getElementsByTagName ( 'ul' )[0]; - } - idrinth.core.timeouts.add ( 'chat.login', function () { - idrinth.core.ajax.runHome ( - 'chat-service/login/', - idrinth.chat.startLoginCallback, - function ( reply ) { - }, - function ( reply ) { - idrinth.core.timeouts.add ( 'chat.login', idrinth.chat.login, 1 ); - }, - JSON.stringify ( { - user: idrinth.settings.get ( "chatuser" ), - pass: idrinth.settings.get ( "chatpass" ) - } ) - ); - }, 2500 ); - idrinth.core.timeouts.add ( 'chat.emoticons', function () { - idrinth.core.ajax.runHome ( - 'emoticons/data/', - function ( reply ) { - idrinth.chat.emotes = JSON.parse ( reply ); - }, - function ( reply ) { - }, - function ( reply ) { - }, - '', - true - ); - }, 1 ); - }, - /** + } + ] + } + ] + }); + }; + if (!idrinth.settings.get("chatting")) { + return; + } + if (!document.getElementById("idrinth-chat")) { + idrinth.ui.base.appendChild(build()); + idrinth.chat.elements.chats = document + .getElementById("idrinth-chat") + .getElementsByTagName("ul")[1]; + idrinth.chat.elements.menu = document + .getElementById("idrinth-chat") + .getElementsByTagName("ul")[0]; + } + idrinth.core.timeouts.add( + "chat.login", + function() { + idrinth.core.ajax.runHome( + "chat-service/login/", + idrinth.chat.startLoginCallback, + function(reply) {}, + function(reply) { + idrinth.core.timeouts.add("chat.login", idrinth.chat.login, 1); + }, + JSON.stringify({ + user: idrinth.settings.get("chatuser"), + pass: idrinth.settings.get("chatpass") + }) + ); + }, + 2500 + ); + idrinth.core.timeouts.add( + "chat.emoticons", + function() { + idrinth.core.ajax.runHome( + "emoticons/data/", + function(reply) { + idrinth.chat.emotes = JSON.parse(reply); + }, + function(reply) {}, + function(reply) {}, + "", + true + ); + }, + 1 + ); + }, + /** * * @returns {undefined} */ - create: function () { - idrinth.core.ajax.runHome ( - 'chat-service/create/', - idrinth.chat.joinCallback, - function ( reply ) { - idrinth.core.alert ( idrinth.text.get ( "chat.error.create" ) ); - }, - function ( reply ) { - idrinth.core.alert ( idrinth.text.get ( "chat.error.create" ) ); - }, - document.getElementById ( 'idrinth-make-chat' ).getElementsByTagName ( 'input' )[0].value - ); - }, - /** + create: function() { + idrinth.core.ajax.runHome( + "chat-service/create/", + idrinth.chat.joinCallback, + function(reply) { + idrinth.core.alert(idrinth.text.get("chat.error.create")); + }, + function(reply) { + idrinth.core.alert(idrinth.text.get("chat.error.create")); + }, + document + .getElementById("idrinth-make-chat") + .getElementsByTagName("input")[0].value + ); + }, + /** * * @param {String} reply * @returns {undefined} */ - joinCallback: function ( reply ) { - if ( !reply ) { - idrinth.core.alert ( idrinth.text.get ( "chat.error.join" ) ); - return; - } - reply = JSON.parse ( reply ); - if ( !reply ) { - idrinth.core.alert ( idrinth.text.get ( "chat.error.join" ) ); - return; - } - if ( !reply.success ) { - if ( reply.message ) { - idrinth.core.alert ( reply.message ); - } else { - idrinth.core.alert ( idrinth.text.get ( "chat.error.join" ) ); - } - return; - } - idrinth.ui.buildChat ( reply.data.id, reply.data.name, reply.data.access, reply.data.pass ); - document.getElementById ( 'idrinth-add-chat' ).getElementsByTagName ( 'input' )[0].value = ''; - document.getElementById ( 'idrinth-add-chat' ).getElementsByTagName ( 'input' )[1].value = ''; - document.getElementById ( 'idrinth-make-chat' ).getElementsByTagName ( 'input' )[0].value = ''; - }, - /** + joinCallback: function(reply) { + if (!reply) { + idrinth.core.alert(idrinth.text.get("chat.error.join")); + return; + } + reply = JSON.parse(reply); + if (!reply) { + idrinth.core.alert(idrinth.text.get("chat.error.join")); + return; + } + if (!reply.success) { + if (reply.message) { + idrinth.core.alert(reply.message); + } else { + idrinth.core.alert(idrinth.text.get("chat.error.join")); + } + return; + } + idrinth.ui.buildChat( + reply.data.id, + reply.data.name, + reply.data.access, + reply.data.pass + ); + document.getElementById("idrinth-add-chat").getElementsByTagName("input")[ + 0 + ].value = + ""; + document.getElementById("idrinth-add-chat").getElementsByTagName("input")[ + 1 + ].value = + ""; + document.getElementById("idrinth-make-chat").getElementsByTagName("input")[ + 0 + ].value = + ""; + }, + /** * @type {Object} */ - users: { }, - /** + users: {}, + /** * * @returns {undefined} */ - add: function () { - idrinth.core.ajax.runHome ( - 'chat-service/join/', - idrinth.chat.joinCallback, - function ( reply ) { - idrinth.core.alert ( idrinth.text.get ( "chat.error.join" ) ); - }, - function ( reply ) { - idrinth.core.alert ( idrinth.text.get ( "chat.error.join" ) ); - }, - JSON.stringify ( { - id: document.getElementById ( 'idrinth-add-chat' ).getElementsByTagName ( 'input' )[0].value, - pass: document.getElementById ( 'idrinth-add-chat' ).getElementsByTagName ( 'input' )[1].value - } ) - ); - }, - /** + add: function() { + idrinth.core.ajax.runHome( + "chat-service/join/", + idrinth.chat.joinCallback, + function(reply) { + idrinth.core.alert(idrinth.text.get("chat.error.join")); + }, + function(reply) { + idrinth.core.alert(idrinth.text.get("chat.error.join")); + }, + JSON.stringify({ + id: document + .getElementById("idrinth-add-chat") + .getElementsByTagName("input")[0].value, + pass: document + .getElementById("idrinth-add-chat") + .getElementsByTagName("input")[1].value + }) + ); + }, + /** * * @param {Number} id * @returns {undefined} */ - send: function ( id ) { - idrinth.chat.messages.push ( { - chat: id, - text: document.getElementById ( 'idrinth-chat-input-' + id ).value - } ); - document.getElementById ( 'idrinth-chat-input-' + id ).value = ''; - }, - /** + send: function(id) { + idrinth.chat.messages.push({ + chat: id, + text: document.getElementById("idrinth-chat-input-" + id).value + }); + document.getElementById("idrinth-chat-input-" + id).value = ""; + }, + /** * * @param {Object} list * @returns {undefined} */ - join: function ( list ) { - for (var chatId in list) { - if ( !document.getElementById ( 'idrinth-chat-tab-' + chatId ) ) { - idrinth.ui.buildChat ( chatId, list[chatId].name, list[chatId].access, list[chatId].pass ); - } - } - idrinth.core.timeouts.add ( 'chat', idrinth.chat.refreshChats, 500 ); - }, - /** + join: function(list) { + for (var chatId in list) { + if (!document.getElementById("idrinth-chat-tab-" + chatId)) { + idrinth.ui.buildChat( + chatId, + list[chatId].name, + list[chatId].access, + list[chatId].pass + ); + } + } + idrinth.core.timeouts.add("chat", idrinth.chat.refreshChats, 500); + }, + /** * * @param {String} data * @returns {undefined} */ - startLoginCallback: function ( data ) { - if ( !data ) { - return; - } - data = JSON.parse ( data ); - if ( !data || !data.success ) { - return; - } - idrinth.ui.removeElement ( 'idrinth-chat-login' ); - idrinth.chat.join ( data.data ); - }, - /** + startLoginCallback: function(data) { + if (!data) { + return; + } + data = JSON.parse(data); + if (!data || !data.success) { + return; + } + idrinth.ui.removeElement("idrinth-chat-login"); + idrinth.chat.join(data.data); + }, + /** * * @param {String} data * @returns {undefined} */ - loginCallback: function ( data ) { - if ( !data ) { - idrinth.core.alert ( idrinth.text.get ( "chat.error.login" ) ); - return; - } - data = JSON.parse ( data ); - if ( !data ) { - idrinth.core.alert ( idrinth.text.get ( "chat.error.login" ) ); - return; - } - if ( !data.success && data.message && data['allow-reg'] ) { - idrinth.core.confirm ( idrinth.text.get ( "chat.error.unknown" ), 'idrinth.chat.register();' ); - return; - } - if ( !data.success && data.message ) { - idrinth.core.alert ( data.message ); - return; - } - if ( data.success ) { - var login = document.getElementById ( 'idrinth-chat-login' ).getElementsByTagName ( 'input' ); - idrinth.settings.change ( "chatuser", login[0].value ); - idrinth.settings.change ( "chatpass", login[1].value ); - idrinth.ui.removeElement ( 'idrinth-chat-login' ); - idrinth.chat.join ( data.data ); - return; - } - idrinth.core.alert ( idrinth.text.get ( "chat.error.login" ) ); - }, - /** + loginCallback: function(data) { + if (!data) { + idrinth.core.alert(idrinth.text.get("chat.error.login")); + return; + } + data = JSON.parse(data); + if (!data) { + idrinth.core.alert(idrinth.text.get("chat.error.login")); + return; + } + if (!data.success && data.message && data["allow-reg"]) { + idrinth.core.confirm( + idrinth.text.get("chat.error.unknown"), + "idrinth.chat.register();" + ); + return; + } + if (!data.success && data.message) { + idrinth.core.alert(data.message); + return; + } + if (data.success) { + var login = document + .getElementById("idrinth-chat-login") + .getElementsByTagName("input"); + idrinth.settings.change("chatuser", login[0].value); + idrinth.settings.change("chatpass", login[1].value); + idrinth.ui.removeElement("idrinth-chat-login"); + idrinth.chat.join(data.data); + return; + } + idrinth.core.alert(idrinth.text.get("chat.error.login")); + }, + /** * * @returns {undefined} */ - register: function () { - this.loginActions ( 'register' ); - }, - /** + register: function() { + this.loginActions("register"); + }, + /** * * @returns {undefined} */ - login: function () { - this.loginActions ( 'login' ); - }, - /** + login: function() { + this.loginActions("login"); + }, + /** * * @returns {undefined} */ - relogin: function () { - this.loginActions ( 'relogin' ); - }, - /** + relogin: function() { + this.loginActions("relogin"); + }, + /** * * @param {Event} event * @param {HTMLElement} element * @returns {undefined} */ - showOptions: function ( event, element ) { - event.preventDefault (); - idrinth.ui.base.appendChild ( idrinth.ui.buildElement ( { - type: 'ul', - css: 'idrinth-hovering-box hover-over', - children: [ { - css: 'clipboard-copy', - content: idrinth.text.get ( "chat.actions.copyIdPasswort" ), - type: 'li', - attributes: [ { - name: 'data-clipboard-text', - value: element.getAttribute ( 'title' ) - } ] - }, { - content: idrinth.text.get ( "chat.actions.leaveRoom" ), - type: 'li', - attributes: [ { - name: 'onclick', - value: 'idrinth.chat.useroptions(' + element.getAttribute ( 'data-id' ) + ',' + idrinth.chat.self + ',\'Leave\');this.parentNode.parentNode.removeChild(this.parentNode);' - } ] - }, { - content: idrinth.text.get ( "chat.actions.deleteRoom" ), - type: 'li', - attributes: [ { - name: 'onclick', - value: 'idrinth.core.ajax.runHome(\'chat-service/delete/' + element.getAttribute ( 'data-id' ) + '/\',idrinth.core.alert,idrinth.core.alert,idrinth.core.alert);this.parentNode.parentNode.removeChild(this.parentNode);' - } ] - }, { - type: 'li', - content: idrinth.text.get ( "chat.actions.close" ), - attributes: [ { - name: 'onclick', - value: 'this.parentNode.parentNode.removeChild(this.parentNode);' - } ] - } - ], - attributes: [ { - name: 'style', - value: idrinth.ui.getElementPositioning ( element, 0, 0 ) - } ] - } ) ); - }, - /** + showOptions: function(event, element) { + event.preventDefault(); + idrinth.ui.base.appendChild( + idrinth.ui.buildElement({ + type: "ul", + css: "idrinth-hovering-box hover-over", + children: [ + { + css: "clipboard-copy", + content: idrinth.text.get("chat.actions.copyIdPasswort"), + type: "li", + attributes: [ + { + name: "data-clipboard-text", + value: element.getAttribute("title") + } + ] + }, + { + content: idrinth.text.get("chat.actions.leaveRoom"), + type: "li", + attributes: [ + { + name: "onclick", + value: "idrinth.chat.useroptions(" + + element.getAttribute("data-id") + + "," + + idrinth.chat.self + + ",'Leave');this.parentNode.parentNode.removeChild(this.parentNode);" + } + ] + }, + { + content: idrinth.text.get("chat.actions.deleteRoom"), + type: "li", + attributes: [ + { + name: "onclick", + value: "idrinth.core.ajax.runHome('chat-service/delete/" + + element.getAttribute("data-id") + + "/',idrinth.core.alert,idrinth.core.alert,idrinth.core.alert);this.parentNode.parentNode.removeChild(this.parentNode);" + } + ] + }, + { + type: "li", + content: idrinth.text.get("chat.actions.close"), + attributes: [ + { + name: "onclick", + value: "this.parentNode.parentNode.removeChild(this.parentNode);" + } + ] + } + ], + attributes: [ + { + name: "style", + value: idrinth.ui.getElementPositioning(element, 0, 0) + } + ] + }) + ); + }, + /** * * @param {HTMLElement} element * @returns {undefined} */ - enableChat: function ( element ) { - var tabs = document.getElementsByClassName ( 'chat-tabs' )[0].children, - labels = document.getElementsByClassName ( 'chat-labels' )[0].children; - for (var counter = 0; counter < labels.length; counter++) { - var cur = labels[counter].getAttribute ( 'class' ) + ''; - labels[counter].setAttribute ( 'class', cur.replace ( /(^|\s)active(\s|$)/, ' ' ) ); - tabs[counter].setAttribute ( 'class', '' ); - if ( tabs[counter].getAttribute ( 'data-id' ) === element.getAttribute ( 'data-id' ) ) { - tabs[counter].setAttribute ( 'class', 'active' ); - } - } - if ( element.hasAttribute ( 'class' ) ) { - element.setAttribute ( 'class', ( element.getAttribute ( 'class' ) ).replace ( /(^|\s)new-message(\s|$)/, ' ' ) + ' active' ); - } else { - element.setAttribute ( 'class', 'active' ); - } - }, - /** + enableChat: function(element) { + var tabs = document.getElementsByClassName("chat-tabs")[0].children, + labels = document.getElementsByClassName("chat-labels")[0].children; + for (var counter = 0; counter < labels.length; counter++) { + var cur = labels[counter].getAttribute("class") + ""; + labels[counter].setAttribute( + "class", + cur.replace(/(^|\s)active(\s|$)/, " ") + ); + tabs[counter].setAttribute("class", ""); + if ( + tabs[counter].getAttribute("data-id") === + element.getAttribute("data-id") + ) { + tabs[counter].setAttribute("class", "active"); + } + } + if (element.hasAttribute("class")) { + element.setAttribute( + "class", + element.getAttribute("class").replace(/(^|\s)new-message(\s|$)/, " ") + + " active" + ); + } else { + element.setAttribute("class", "active"); + } + }, + /** * * @param {HTMLElement} element * @returns {undefined} */ - openCloseChat: function ( element ) { - var chat = element.parentNode; - if ( chat.getAttribute ( 'class' ) === 'idrinth-hovering-box active' || chat.getAttribute ( 'class' ) === 'idrinth-hovering-box active left-sided' ) { - chat.setAttribute ( 'class', 'idrinth-hovering-box' + ( idrinth.settings.get ( "moveLeft" ) ? ' left-sided' : '' ) + - ( chat.getElementsByClassName ( 'new-message' ) && chat.getElementsByClassName ( 'new-message' ).length ? ' new-message' : '' ) ); - element.innerHTML = '<<'; - } else { - chat.setAttribute ( 'class', 'idrinth-hovering-box active' + ( idrinth.settings.get ( "moveLeft" ) ? ' left-sided' : '' ) ); - element.innerHTML = '>>'; - } - }, - /** + openCloseChat: function(element) { + var chat = element.parentNode; + if ( + chat.getAttribute("class") === "idrinth-hovering-box active" || + chat.getAttribute("class") === "idrinth-hovering-box active left-sided" + ) { + chat.setAttribute( + "class", + "idrinth-hovering-box" + + (idrinth.settings.get("moveLeft") ? " left-sided" : "") + + (chat.getElementsByClassName("new-message") && + chat.getElementsByClassName("new-message").length + ? " new-message" + : "") + ); + element.innerHTML = "<<"; + } else { + chat.setAttribute( + "class", + "idrinth-hovering-box active" + + (idrinth.settings.get("moveLeft") ? " left-sided" : "") + ); + element.innerHTML = ">>"; + } + }, + /** * * @param {String} key * @returns {undefined} */ - loginActions: function ( key ) { - var chatLogin, - success, - urls = { - 'register': 'chat-service/register/', - 'login': 'chat-service/login/', - 'relogin': 'chat-service/login/' - }, - fail = function () { - idrinth.core.alert ( idrinth.text.get ( "chat.error.login" ) ); - }, - timeout = function () { - idrinth.core.timeouts.add ( 'chat.login', idrinth.chat.login, 1 ); - }, - headers = { - user: '', - pass: '' - }; + loginActions: function(key) { + var chatLogin, + success, + urls = { + register: "chat-service/register/", + login: "chat-service/login/", + relogin: "chat-service/login/" + }, + fail = function() { + idrinth.core.alert(idrinth.text.get("chat.error.login")); + }, + timeout = function() { + idrinth.core.timeouts.add("chat.login", idrinth.chat.login, 1); + }, + headers = { + user: "", + pass: "" + }; - if ( !urls[key] ) { - return; - } + if (!urls[key]) { + return; + } - if ( key === 'relogin' ) { - success = function () { - idrinth.core.timeouts.add ( 'chat', idrinth.chat.refreshChats, 1500 ); - }; - headers.user = idrinth.settings.get ( "chatuser" ); - headers.pass = idrinth.settings.get ( "chatpass" ); - } else { - chatLogin = document.getElementById ( 'idrinth-chat-login' ).getElementsByTagName ( 'input' ); - headers.user = chatLogin[0].value; - headers.pass = chatLogin[1].value; - success = idrinth.chat.loginCallback; - } - idrinth.core.ajax.runHome ( urls[key], success, fail, timeout, JSON.stringify ( headers ) ); + if (key === "relogin") { + success = function() { + idrinth.core.timeouts.add("chat", idrinth.chat.refreshChats, 1500); + }; + headers.user = idrinth.settings.get("chatuser"); + headers.pass = idrinth.settings.get("chatpass"); + } else { + chatLogin = document + .getElementById("idrinth-chat-login") + .getElementsByTagName("input"); + headers.user = chatLogin[0].value; + headers.pass = chatLogin[1].value; + success = idrinth.chat.loginCallback; } -}; \ No newline at end of file + idrinth.core.ajax.runHome( + urls[key], + success, + fail, + timeout, + JSON.stringify(headers) + ); + } +}; diff --git a/src/mods/core.js b/src/mods/core.js index fb8ec3e..b82f62b 100644 --- a/src/mods/core.js +++ b/src/mods/core.js @@ -1,33 +1,42 @@ idrinth.core = { - /** + /** * * @param {string} str * @returns {string} */ - escapeRegExp: function ( str ) { - return str.replace ( /[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&" ); - }, - /** + escapeRegExp: function(str) { + return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&"); + }, + /** * * @param {object} parent * @param {string} field * @param {Boolean} allowObjects * @returns {Boolean} */ - fieldIsSetting: function ( parent, field, allowObjects ) { - return parent && typeof parent === 'object' && field && parent.hasOwnProperty ( field ) && ( parent[field] === null || typeof parent[field] !== 'object' || allowObjects ) && typeof parent[field] !== 'function'; - }, - /** + fieldIsSetting: function(parent, field, allowObjects) { + return ( + parent && + typeof parent === "object" && + field && + parent.hasOwnProperty(field) && + (parent[field] === null || + typeof parent[field] !== "object" || + allowObjects) && + typeof parent[field] !== "function" + ); + }, + /** * * @type {object} */ - ajax: { - /** + ajax: { + /** * * @type {object} */ - active: { }, - /** + active: {}, + /** * * @param {string} url * @param {function} success @@ -37,12 +46,29 @@ idrinth.core = { * @param {Boolean} [false] isStatic * @returns {undefined} */ - runHome: function ( url, success, failure, timeout, additionalHeader, isStatic ) { - var server = isStatic ? 'static' : ( idrinth.settings.get ( "isWorldServer" ) ? 'world-' : '' ) + idrinth.platform; - var homeUrl = 'https://dotd.idrinth.de/' + server + ( '/' + url ).replace ( /\/\//, '/' ); - idrinth.core.ajax.run ( homeUrl, success, failure, timeout, additionalHeader ); - }, - /** + runHome: function( + url, + success, + failure, + timeout, + additionalHeader, + isStatic + ) { + var server = isStatic + ? "static" + : (idrinth.settings.get("isWorldServer") ? "world-" : "") + + idrinth.platform; + var homeUrl = + "https://dotd.idrinth.de/" + server + ("/" + url).replace(/\/\//, "/"); + idrinth.core.ajax.run( + homeUrl, + success, + failure, + timeout, + additionalHeader + ); + }, + /** * * @param {string} url * @param {function} success @@ -52,150 +78,162 @@ idrinth.core = { * @param {Boolean} [false] isStatic * @returns {undefined} */ - run: function ( url, success, failure, timeout, additionalHeader ) { - var requestHandler = new XMLHttpRequest ( ); - requestHandler.onreadystatechange = function ( event ) { - var request = ( event || window.event ).target; - var call = function ( func, value ) { - if ( typeof func !== 'function' ) { - return; - } - try { - return func ( value ); - } catch ( e ) { - idrinth.core.log ( typeof e.getMessage === 'function' ? e.getMessage () : ( e.message ? e.message : e ) ); - return null; - } - }; - if ( request.readyState === 4 ) { - var status = ( request.status > 199 && request.status < 300 ) || request.status === 0; - call ( status ? success : failure, status ? request.responseText : request ); - delete idrinth.core.ajax.active[request._url]; - } - }; - requestHandler.timeout = 30000; - requestHandler.ontimeout = function ( event ) { - var request = ( event || window.event ).target; - if ( typeof timeout === 'function' ) { - timeout.bind ( request ); - } - delete idrinth.core.ajax.active[request._url]; - idrinth.core.log ( 'Request to ' + request._url + ' failed.' ); - }; - var error = function ( event ) { - delete idrinth.core.ajax.active[( event || window.event ).target._url]; - idrinth.core.log ( 'Request to ' + ( event || window.event ).target._url + ' failed.' ); - }; - requestHandler.onerror = error; - requestHandler.onabort = error; - requestHandler._url = url; - requestHandler.open ( "GET", url, true ); - if ( url.match ( '/dotd\.idrinth\.de/' ) ) { - if ( additionalHeader ) { - requestHandler.setRequestHeader ( "Idrinth-Addition", additionalHeader ); - } - requestHandler.withCredentials = true; - } - idrinth.core.ajax.active[url] = requestHandler; - idrinth.core.ajax.active[url].send ( ); + run: function(url, success, failure, timeout, additionalHeader) { + var requestHandler = new XMLHttpRequest(); + requestHandler.onreadystatechange = function(event) { + var request = (event || window.event).target; + var call = function(func, value) { + if (typeof func !== "function") { + return; + } + try { + return func(value); + } catch (e) { + idrinth.core.log( + typeof e.getMessage === "function" + ? e.getMessage() + : e.message ? e.message : e + ); + return null; + } + }; + if (request.readyState === 4) { + var status = + (request.status > 199 && request.status < 300) || + request.status === 0; + call( + status ? success : failure, + status ? request.responseText : request + ); + delete idrinth.core.ajax.active[request._url]; } - }, - /** + }; + requestHandler.timeout = 30000; + requestHandler.ontimeout = function(event) { + var request = (event || window.event).target; + if (typeof timeout === "function") { + timeout.bind(request); + } + delete idrinth.core.ajax.active[request._url]; + idrinth.core.log("Request to " + request._url + " failed."); + }; + var error = function(event) { + delete idrinth.core.ajax.active[(event || window.event).target._url]; + idrinth.core.log( + "Request to " + (event || window.event).target._url + " failed." + ); + }; + requestHandler.onerror = error; + requestHandler.onabort = error; + requestHandler._url = url; + requestHandler.open("GET", url, true); + if (url.match("/dotd\.idrinth\.de/")) { + if (additionalHeader) { + requestHandler.setRequestHeader("Idrinth-Addition", additionalHeader); + } + requestHandler.withCredentials = true; + } + idrinth.core.ajax.active[url] = requestHandler; + idrinth.core.ajax.active[url].send(); + } + }, + /** * * @type {object} */ - copyToClipboard: { - /** + copyToClipboard: { + /** * * @param {string} text * @returns {Boolean} */ - text: function ( text ) { - var success; - try { - var textAreaElement = idrinth.ui.buildElement ( { - type: 'textarea', - id: "idrinth-copy-helper" - } ); - textAreaElement.value = text; - idrinth.ui.base.appendChild ( textAreaElement ); - textAreaElement.select ( ); - success = document.execCommand ( 'copy' ); - } catch ( exception ) { - idrinth.core.log ( exception.getMessage ( ) ); - success = false; - } - idrinth.ui.removeElement ( "idrinth-copy-helper" ); - return success; - }, - /** + text: function(text) { + var success; + try { + var textAreaElement = idrinth.ui.buildElement({ + type: "textarea", + id: "idrinth-copy-helper" + }); + textAreaElement.value = text; + idrinth.ui.base.appendChild(textAreaElement); + textAreaElement.select(); + success = document.execCommand("copy"); + } catch (exception) { + idrinth.core.log(exception.getMessage()); + success = false; + } + idrinth.ui.removeElement("idrinth-copy-helper"); + return success; + }, + /** * * @param {HTMLElement} element * @returns {string} */ - element: function ( element ) { - if ( element.hasAttribute ( 'data-clipboard-text' ) ) { - return idrinth.core.copyToClipboard.text ( element.getAttribute ( 'data-clipboard-text' ) ); - } - if ( element.value ) { - return idrinth.core.copyToClipboard.text ( element.value ); - } - return idrinth.core.copyToClipboard.text ( element.innerHTML ); - } - }, - /** + element: function(element) { + if (element.hasAttribute("data-clipboard-text")) { + return idrinth.core.copyToClipboard.text( + element.getAttribute("data-clipboard-text") + ); + } + if (element.value) { + return idrinth.core.copyToClipboard.text(element.value); + } + return idrinth.core.copyToClipboard.text(element.innerHTML); + } + }, + /** * * @param {string} title * @param {string|HTMLElement} content * @returns {Boolean|window.Notification} */ - sendNotification: function ( title, content ) { - if ( !( "Notification" in window ) ) { - return false; - } - if ( window.Notification.permission === "default" ) { - window.Notification.requestPermission ( ); - } - if ( window.Notification.permission === "denied" ) { - return false; - } - var data = {}; - if(idrinth.settings.get ('notification#image')) { - data.icon = "https://dotd.idrinth.de/Resources/Images/logo.png"; - } - if(idrinth.settings.get ('notification#content')) { - data.body = content; - } - return new window.Notification ( title, data ); - }, - /** + sendNotification: function(title, content) { + if (!("Notification" in window)) { + return false; + } + if (window.Notification.permission === "default") { + window.Notification.requestPermission(); + } + if (window.Notification.permission === "denied") { + return false; + } + var data = {}; + if (idrinth.settings.get("notification#image")) { + data.icon = "https://dotd.idrinth.de/Resources/Images/logo.png"; + } + if (idrinth.settings.get("notification#content")) { + data.body = content; + } + return new window.Notification(title, data); + }, + /** * * @type {object} */ - timeouts: { - /** + timeouts: { + /** * * @type {object} */ - next: null, - /** + next: null, + /** * * @type {object} */ - list: { }, - /** + list: {}, + /** * makes sure the timeout is removed when called next * @param {string} identifier * @returns {undefined} */ - remove: function ( identifier ) { - if ( idrinth.core.timeouts.list[identifier] !== undefined ) { - idrinth.core.timeouts.list[identifier].repeats = 1; - idrinth.core.timeouts.list[identifier].func = function () { - }; - } - }, - /** + remove: function(identifier) { + if (idrinth.core.timeouts.list[identifier] !== undefined) { + idrinth.core.timeouts.list[identifier].repeats = 1; + idrinth.core.timeouts.list[identifier].func = function() {}; + } + }, + /** * * @param {string} identifier * @param {function} func @@ -203,192 +241,227 @@ idrinth.core = { * @param {Number} [1] maxRepeats -1 will repeat until the end of time * @returns {undefined} */ - add: function ( identifier, func, time, maxRepeats ) { - var date = new Date (); - idrinth.core.timeouts.list[identifier] = { - func: func, - next: date.getTime () + date.getMilliseconds () / 1000 + time / 1000, - duration: time, - repeats: maxRepeats ? maxRepeats : 1 - }; - if ( !idrinth.core.timeouts.next ) { - idrinth.core.timeouts.next = window.setTimeout ( idrinth.core.timeouts.process, 1000 ); - } - }, - /** + add: function(identifier, func, time, maxRepeats) { + var date = new Date(); + idrinth.core.timeouts.list[identifier] = { + func: func, + next: date.getTime() + date.getMilliseconds() / 1000 + time / 1000, + duration: time, + repeats: maxRepeats ? maxRepeats : 1 + }; + if (!idrinth.core.timeouts.next) { + idrinth.core.timeouts.next = window.setTimeout( + idrinth.core.timeouts.process, + 1000 + ); + } + }, + /** * activates all relevant timeouts and intervals * @returns {undefined} */ - process: function () { - var date = ( new Date () ).getTime () + ( new Date () ).getMilliseconds () / 1000; - var min = 10; - /** + process: function() { + var date = new Date().getTime() + new Date().getMilliseconds() / 1000; + var min = 10; + /** * * @param {Number} min * @param {Number} property * @returns {Number} */ - var check = function(min, property, date) { - /** + var check = function(min, property, date) { + /** * * @param {Number} durationLeft * @param {string} minDuration * @returns {Number} */ - var getVal = function ( durationLeft, minDuration ) { - if ( durationLeft < 0.1 ) { - return 0.1; - } - return durationLeft < minDuration ? durationLeft : minDuration; - }; - /** + var getVal = function(durationLeft, minDuration) { + if (durationLeft < 0.1) { + return 0.1; + } + return durationLeft < minDuration ? durationLeft : minDuration; + }; + /** * * @param {string} property * @returns {undefined} */ - var handle = function ( property, min ) { - idrinth.core.timeouts.list[property].func (); - idrinth.core.timeouts.list[property].repeats = Math.max ( -1, idrinth.core.timeouts.list[property].repeats - 1 ); - if ( idrinth.core.timeouts.list[property].repeats ) { - min = getVal ( idrinth.core.timeouts.list[property].duration, min ); - idrinth.core.timeouts.list[property].next = date + idrinth.core.timeouts.list[property].duration / 1000; - } else { - delete idrinth.core.timeouts.list[property]; - } - return min; - }; - if ( date < idrinth.core.timeouts.list[property].next ) { - return getVal ( idrinth.core.timeouts.list[property].next - date, min ); - } - try { - return handle ( property, min ); - } catch ( e ) { - idrinth.core.log ( e.message ? e.message : e.getMessage () ); - return min; - } - }; - for (var property in idrinth.core.timeouts.list) { - if ( idrinth.core.timeouts.list.hasOwnProperty ( property ) ) { - min = check(min, property, date); - } - } - if ( Object.keys ( idrinth.core.timeouts.list ).length ) { - idrinth.core.timeouts.next = window.setTimeout ( idrinth.core.timeouts.process, Math.ceil ( min * 1000 ) ); - } + var handle = function(property, min) { + idrinth.core.timeouts.list[property].func(); + idrinth.core.timeouts.list[property].repeats = Math.max( + -1, + idrinth.core.timeouts.list[property].repeats - 1 + ); + if (idrinth.core.timeouts.list[property].repeats) { + min = getVal(idrinth.core.timeouts.list[property].duration, min); + idrinth.core.timeouts.list[property].next = + date + idrinth.core.timeouts.list[property].duration / 1000; + } else { + delete idrinth.core.timeouts.list[property]; + } + return min; + }; + if (date < idrinth.core.timeouts.list[property].next) { + return getVal(idrinth.core.timeouts.list[property].next - date, min); } - }, - /** + try { + return handle(property, min); + } catch (e) { + idrinth.core.log(e.message ? e.message : e.getMessage()); + return min; + } + }; + for (var property in idrinth.core.timeouts.list) { + if (idrinth.core.timeouts.list.hasOwnProperty(property)) { + min = check(min, property, date); + } + } + if (Object.keys(idrinth.core.timeouts.list).length) { + idrinth.core.timeouts.next = window.setTimeout( + idrinth.core.timeouts.process, + Math.ceil(min * 1000) + ); + } + } + }, + /** * * @param {string} string * @returns {undefined} */ - log: function ( string ) { - console.log ( '[IDotDS] ' + string ); - }, - /** + log: function(string) { + console.log("[IDotDS] " + string); + }, + /** * * @param {string} text * @returns {undefined} */ - alert: function ( text ) { - if(!idrinth.ui.base) { - window.alert (text); - return; - } - idrinth.ui.buildModal ( 'Info', text ); - }, - /** + alert: function(text) { + if (!idrinth.ui.base) { + window.alert(text); + return; + } + idrinth.ui.buildModal("Info", text); + }, + /** * * @param {string} text * @param {function} callback * @returns {undefined} */ - confirm: function ( text, callback ) { - idrinth.ui.buildModal ( 'Do you?', text, callback ); - }, - /** + confirm: function(text, callback) { + idrinth.ui.buildModal("Do you?", text, callback); + }, + /** * runs the inWorker function in the worker and let's the resultHandler handle the result * @param {Function} inWorker * @param {Function} resultHandler * @param {object} values * @returns {undefined} */ - addWorker: function ( inWorker, resultHandler, values ) { - if ( !window.Worker ) { - return resultHandler ( inWorker ( values ) ); - } - var blobURL = window.URL.createObjectURL ( new Blob ( [ - "self.onmessage = function(message) {var work=" + inWorker.toString () + ";self.postMessage(work(message.data));self.close();}" - ] ) ); - var worker = new Worker ( blobURL ); - worker.onmessage = function ( message ) { - message.target.resultHandler ( message.data ); - }; - worker.resultHandler = resultHandler; - worker.postMessage ( values ); - window.URL.revokeObjectURL ( blobURL ); - }, - /** + addWorker: function(inWorker, resultHandler, values) { + if (!window.Worker) { + return resultHandler(inWorker(values)); + } + var blobURL = window.URL.createObjectURL( + new Blob([ + "self.onmessage = function(message) {var work=" + + inWorker.toString() + + ";self.postMessage(work(message.data));self.close();}" + ]) + ); + var worker = new Worker(blobURL); + worker.onmessage = function(message) { + message.target.resultHandler(message.data); + }; + worker.resultHandler = resultHandler; + worker.postMessage(values); + window.URL.revokeObjectURL(blobURL); + }, + /** * * @type {object} */ - multibind: { - /** + multibind: { + /** * * @type {object} */ - events: { }, - /** + events: {}, + /** * * @param {string} event * @param {string} selector * @param {function} method * @returns {undefined} */ - add: function ( event, selector, method ) { - var bind = function ( event, selector, method ) { - idrinth.core.multibind.events[event] = idrinth.core.multibind.events[event] ? idrinth.core.multibind.events[event] : { }; - idrinth.core.multibind.events[event][selector] = idrinth.core.multibind.events[event][selector] ? idrinth.core.multibind.events[event][selector] : [ ]; - idrinth.core.multibind.events[event][selector].push ( method ); - }; - if ( !idrinth.core.multibind.events[event] ) { - document.getElementsByTagName ( 'body' )[0].addEventListener ( event, idrinth.core.multibind.triggered ); - } - bind ( event, selector, method ); - }, - /** + add: function(event, selector, method) { + var bind = function(event, selector, method) { + idrinth.core.multibind.events[event] = idrinth.core.multibind.events[ + event + ] + ? idrinth.core.multibind.events[event] + : {}; + idrinth.core.multibind.events[event][selector] = idrinth.core.multibind + .events[event][selector] + ? idrinth.core.multibind.events[event][selector] + : []; + idrinth.core.multibind.events[event][selector].push(method); + }; + if (!idrinth.core.multibind.events[event]) { + document + .getElementsByTagName("body")[0] + .addEventListener(event, idrinth.core.multibind.triggered); + } + bind(event, selector, method); + }, + /** * * @param {Event} [window.event] event * @returns {undefined} */ - triggered: function ( event ) { - /** + triggered: function(event) { + /** * * @param {HTMLElement} el * @param {string} event * @param {string} selector * @returns {undefined} */ - var handleElement = function ( el, event, selector ) { - if ( !el ) { - return; - } - for (var pos = 0; pos < idrinth.core.multibind.events[event][selector].length; pos++) { - try { - idrinth.core.multibind.events[event][selector][pos] ( el, event ); - } catch ( exception ) { - idrinth.core.log ( exception.message ? exception.message : exception.getMessage () ); - } - } - }; - event = event || window.event; - if ( idrinth.core.multibind.events[event.type] ) { - for (var selector in idrinth.core.multibind.events[event.type]) { - if ( idrinth.core.multibind.events[event.type].hasOwnProperty ( selector ) ) { - handleElement ( idrinth.ui.matchesCss ( event.target, selector ), event.type, selector ); - } - } - } + var handleElement = function(el, event, selector) { + if (!el) { + return; + } + for ( + var pos = 0; + pos < idrinth.core.multibind.events[event][selector].length; + pos++ + ) { + try { + idrinth.core.multibind.events[event][selector][pos](el, event); + } catch (exception) { + idrinth.core.log( + exception.message ? exception.message : exception.getMessage() + ); + } + } + }; + event = event || window.event; + if (idrinth.core.multibind.events[event.type]) { + for (var selector in idrinth.core.multibind.events[event.type]) { + if ( + idrinth.core.multibind.events[event.type].hasOwnProperty(selector) + ) { + handleElement( + idrinth.ui.matchesCss(event.target, selector), + event.type, + selector + ); + } } + } } + } }; diff --git a/src/mods/inframe.js b/src/mods/inframe.js index d486fb5..29917c6 100644 --- a/src/mods/inframe.js +++ b/src/mods/inframe.js @@ -1,89 +1,99 @@ idrinth.inframe = { - /** + /** * the game's iframe * @type HTMLElement */ - game: null, - /** + game: null, + /** * * @param {string} task * @param {string} data * @returns {undefined} */ - send: function ( task, data ) { - idrinth.inframe.game.postMessage ( - JSON.stringify ( { - to: 'idotd', - task: task, - data: !data ? true : data - } ), - '*' - ); - }, - /** + send: function(task, data) { + idrinth.inframe.game.postMessage( + JSON.stringify({ + to: "idotd", + task: task, + data: !data ? true : data + }), + "*" + ); + }, + /** * * @returns {undefined} */ - start: function () { - /** + start: function() { + /** * @returns {undefined} */ - var reload = function ( data ) { - var objects = document.getElementsByTagName ( 'object' ); - var modify = function ( element, data ) { - var src = element.getAttribute ( 'data' ); - if ( !src ) { - return false; - } - src = src.replace ( /\.swf(\?.*?)?$/, '.swf' ); - if ( src.match ( new RegExp ( data + '\\.swf$' ) ) ) { - objects[count].setAttribute ( 'data', src + '?q=' + Math.random () ); - return true; - } - return false; - }; - for (var count = 0; count < objects.length; count++) { - if ( modify ( objects[count], data ) ) { - return; - } - } - }; - /** + var reload = function(data) { + var objects = document.getElementsByTagName("object"); + var modify = function(element, data) { + var src = element.getAttribute("data"); + if (!src) { + return false; + } + src = src.replace(/\.swf(\?.*?)?$/, ".swf"); + if (src.match(new RegExp(data + "\\.swf$"))) { + objects[count].setAttribute("data", src + "?q=" + Math.random()); + return true; + } + return false; + }; + for (var count = 0; count < objects.length; count++) { + if (modify(objects[count], data)) { + return; + } + } + }; + /** * @returns {undefined} */ - var joinRaid = function(data) { - var requestHandler = new XMLHttpRequest ( ); - requestHandler.timeout = 30000; - var error = function ( event ) { - console.log ( 'Request to ' + ( event || window.event ).target._url + ' failed.' ); - }; - requestHandler.ontimeout = error; - requestHandler.onerror = error; - requestHandler.onabort = error; - requestHandler.open ( "GET", data, true ); - requestHandler.withCredentials = true; - requestHandler.send ( ); - }; - /** + var joinRaid = function(data) { + var requestHandler = new XMLHttpRequest(); + requestHandler.timeout = 30000; + var error = function(event) { + console.log( + "Request to " + (event || window.event).target._url + " failed." + ); + }; + requestHandler.ontimeout = error; + requestHandler.onerror = error; + requestHandler.onabort = error; + requestHandler.open("GET", data, true); + requestHandler.withCredentials = true; + requestHandler.send(); + }; + /** * @param {HTMLElement} parent */ - var handleFrame = function ( parent ) { - idrinth.inframe.game = parent.getElementsByTagName ( 'iframe' )[0].contentWindow; - }; - try { - if ( idrinth.platform === 'facebook'/*'dawnofthedragons'*/ ) { - handleFrame ( document ); - } else if ( idrinth.platform === 'kongregate' ) { - handleFrame ( document.getElementById ( 'game' ) ); - } else if ( idrinth.platform === 'newgrounds' ) { - handleFrame ( document.getElementById ( 'iframe_embed' ) ); - } else if ( idrinth.platform === 'armorgames' ) { - handleFrame ( document.getElementById ( 'gamefilearea' ) ); - } - idrinth.inframe.send ( 'add', 'window.idrinth.reload=' + reload.toString () + ';' ); - idrinth.inframe.send ( 'add', 'window.idrinth.joinRaid=' + joinRaid.toString () + ';' ); - } catch ( e ) { - idrinth.core.log ( 'failed to find frame' ); - } + var handleFrame = function(parent) { + idrinth.inframe.game = parent.getElementsByTagName("iframe")[ + 0 + ].contentWindow; + }; + try { + if (idrinth.platform === "facebook" /*'dawnofthedragons'*/) { + handleFrame(document); + } else if (idrinth.platform === "kongregate") { + handleFrame(document.getElementById("game")); + } else if (idrinth.platform === "newgrounds") { + handleFrame(document.getElementById("iframe_embed")); + } else if (idrinth.platform === "armorgames") { + handleFrame(document.getElementById("gamefilearea")); + } + idrinth.inframe.send( + "add", + "window.idrinth.reload=" + reload.toString() + ";" + ); + idrinth.inframe.send( + "add", + "window.idrinth.joinRaid=" + joinRaid.toString() + ";" + ); + } catch (e) { + idrinth.core.log("failed to find frame"); } -}; \ No newline at end of file + } +}; diff --git a/src/mods/land.js b/src/mods/land.js index 8f42bb1..b11c3c8 100644 --- a/src/mods/land.js +++ b/src/mods/land.js @@ -1,26 +1,29 @@ idrinth.land = { - /** + /** * * @returns {undefined} */ - calculate: function () { - /** + calculate: function() { + /** * * @param {function[]} checkElementFunc * @returns {object} */ - var baseCalculator = function ( checkElementFunc ) { - var factor = idrinth.settings.get ( "factor" ) ? 10 : 1; - /** + var baseCalculator = function(checkElementFunc) { + var factor = idrinth.settings.get("factor") ? 10 : 1; + /** * * @param {string} building * @returns {Number} */ - var nextPrice = function ( building ) { - return ( 10 + idrinth.settings.get ( "land#" + building ) ) * idrinth.land.data[building].base; - }; - var results = { }; - /** + var nextPrice = function(building) { + return ( + (10 + idrinth.settings.get("land#" + building)) * + idrinth.land.data[building].base + ); + }; + var results = {}; + /** * * @param {type} results * @param {type} res @@ -28,21 +31,28 @@ idrinth.land = { * @param {type} nextPrice * @returns {Number|@var;factor} */ - var applyResult = function ( results, res, factor, nextPrice ) { - idrinth.settings.change ( "land#gold", idrinth.settings.get ( "land#gold" ) - nextPrice ( res.key ) * factor / 10 ); - results[res.key] = ( results[res.key] === undefined ? 0 : results[res.key] ) + factor; - idrinth.settings.change ( "land#" + res.key, idrinth.settings.get ( "land#" + res.key ) + factor ); - return results; - }; - /** + var applyResult = function(results, res, factor, nextPrice) { + idrinth.settings.change( + "land#gold", + idrinth.settings.get("land#gold") - nextPrice(res.key) * factor / 10 + ); + results[res.key] = + (results[res.key] === undefined ? 0 : results[res.key]) + factor; + idrinth.settings.change( + "land#" + res.key, + idrinth.settings.get("land#" + res.key) + factor + ); + return results; + }; + /** * * @param {function[]} checkElementFunc * @param {Number} factor * @param {function} nextPrice * @returns {object} */ - var processBuildings = function ( checkElementFunc, factor, nextPrice ) { - /** + var processBuildings = function(checkElementFunc, factor, nextPrice) { + /** * * @param {function[]} checkElementFunc * @param {String} building @@ -51,43 +61,53 @@ idrinth.land = { * @param {function} nextPrice * @returns {object} */ - var check = function ( checkElementFunc, building, factor, res, nextPrice ) { - for (var count = 0; count < checkElementFunc.length; count++) { - if ( !checkElementFunc[count] ( building, factor, res, nextPrice ) ) { - return res; - } - } - return { - min: nextPrice ( building ) / idrinth.land.data[building].perHour, - key: building - }; - }; - var res = { - key: null, - min: null - }; - for (var building in idrinth.land.data) { - if ( building && idrinth.land.data[building] && idrinth.land.data.hasOwnProperty ( building ) ) { - res = check ( checkElementFunc, building, factor, res, nextPrice ); - } - } - return res; - }; - while ( idrinth.settings.get ( "land#gold" ) >= 0 ) { - var res = processBuildings ( checkElementFunc, factor, nextPrice ); - if ( res.key === null ) { - return results; - } - results = applyResult ( results, res, factor, nextPrice ); + var check = function( + checkElementFunc, + building, + factor, + res, + nextPrice + ) { + for (var count = 0; count < checkElementFunc.length; count++) { + if (!checkElementFunc[count](building, factor, res, nextPrice)) { + return res; } - return results; + } + return { + min: nextPrice(building) / idrinth.land.data[building].perHour, + key: building + }; }; - /** + var res = { + key: null, + min: null + }; + for (var building in idrinth.land.data) { + if ( + building && + idrinth.land.data[building] && + idrinth.land.data.hasOwnProperty(building) + ) { + res = check(checkElementFunc, building, factor, res, nextPrice); + } + } + return res; + }; + while (idrinth.settings.get("land#gold") >= 0) { + var res = processBuildings(checkElementFunc, factor, nextPrice); + if (res.key === null) { + return results; + } + results = applyResult(results, res, factor, nextPrice); + } + return results; + }; + /** * * @returns {function[]} */ - var getRequirements = function () { - /** + var getRequirements = function() { + /** * * @param {String} building * @param {Number} factor @@ -95,10 +115,13 @@ idrinth.land = { * @param {function} nextPrice * @returns {Boolean} */ - var bestPrice = function ( building, factor, res, nextPrice ) { - return res.min === null || nextPrice ( building ) / idrinth.land.data[building].perHour < res.min; - }; - /** + var bestPrice = function(building, factor, res, nextPrice) { + return ( + res.min === null || + nextPrice(building) / idrinth.land.data[building].perHour < res.min + ); + }; + /** * * @param {String} building * @param {Number} factor @@ -106,161 +129,173 @@ idrinth.land = { * @param {function} nextPrice * @returns {Boolean} */ - var useUp = function ( building, factor, res, nextPrice ) { - return nextPrice ( building ) * factor / 10 <= idrinth.settings.get ( "land#gold" ); - }; - var funcs = [ useUp ]; - if ( idrinth.settings.get ( "landMax" ) ) { - funcs.push ( bestPrice ); - } - return funcs; - }; - /** + var useUp = function(building, factor, res, nextPrice) { + return ( + nextPrice(building) * factor / 10 <= idrinth.settings.get("land#gold") + ); + }; + var funcs = [useUp]; + if (idrinth.settings.get("landMax")) { + funcs.push(bestPrice); + } + return funcs; + }; + /** * Adds the results to the gui * @param {object} results * @returns {undefined} */ - var putResults = function ( results ) { - for (var key in results) { - if ( results.hasOwnProperty ( key ) ) { - document.getElementById ( 'idrinth-land-' + key ).value = idrinth.settings.get ( "land#" + key ); - document.getElementById ( 'idrinth-land-' + key ).parentNode.nextSibling.innerHTML = '+' + results[key]; - } - } - document.getElementById ( 'idrinth-land-gold' ).value = idrinth.settings.get ( "land#gold" ); - }; - var landSettings = idrinth.settings.get( "land", true ); - for (var key in landSettings ) { - if ( landSettings.hasOwnProperty( key ) ) { - idrinth.settings.change( 'land#' + key, parseInt( document.getElementById( 'idrinth-land-' + key ).value, 10 ) ); - } - } - var results = baseCalculator ( getRequirements () ); - if ( Object.keys ( results ).length === 0 ) { - idrinth.core.alert ( idrinth.text.get ( "land.lack" ) ); + var putResults = function(results) { + for (var key in results) { + if (results.hasOwnProperty(key)) { + document.getElementById( + "idrinth-land-" + key + ).value = idrinth.settings.get("land#" + key); + document.getElementById( + "idrinth-land-" + key + ).parentNode.nextSibling.innerHTML = + "+" + results[key]; } - putResults ( results ); - }, - /** + } + document.getElementById("idrinth-land-gold").value = idrinth.settings.get( + "land#gold" + ); + }; + var landSettings = idrinth.settings.get("land", true); + for (var key in landSettings) { + if (landSettings.hasOwnProperty(key)) { + idrinth.settings.change( + "land#" + key, + parseInt(document.getElementById("idrinth-land-" + key).value, 10) + ); + } + } + var results = baseCalculator(getRequirements()); + if (Object.keys(results).length === 0) { + idrinth.core.alert(idrinth.text.get("land.lack")); + } + putResults(results); + }, + /** * @type object */ - data: { - /** + data: { + /** * @type object */ - cornfield: { - /** + cornfield: { + /** * @type Number */ - perHour: 100, - /** + perHour: 100, + /** * @type Number */ - base: 4000 - }, - /** + base: 4000 + }, + /** * @type object */ - stable: { - /** + stable: { + /** * @type Number */ - perHour: 300, - /** + perHour: 300, + /** * @type Number */ - base: 15000 - }, - /** + base: 15000 + }, + /** * @type object */ - barn: { - /** + barn: { + /** * @type Number */ - perHour: 400, - /** + perHour: 400, + /** * @type Number */ - base: 25000 - }, - /** + base: 25000 + }, + /** * @type object */ - store: { - /** + store: { + /** * @type Number */ - perHour: 700, - /** + perHour: 700, + /** * @type Number */ - base: 50000 - }, - /** + base: 50000 + }, + /** * @type object */ - pub: { - /** + pub: { + /** * @type Number */ - perHour: 900, - /** + perHour: 900, + /** * @type Number */ - base: 75000 - }, - /** + base: 75000 + }, + /** * @type object */ - inn: { - /** + inn: { + /** * @type Number */ - perHour: 1200, - /** + perHour: 1200, + /** * @type Number */ - base: 110000 - }, - /** + base: 110000 + }, + /** * @type object */ - tower: { - /** + tower: { + /** * @type Number */ - perHour: 2700, - /** + perHour: 2700, + /** * @type Number */ - base: 300000 - }, - /** + base: 300000 + }, + /** * @type object */ - fort: { - /** + fort: { + /** * @type Number */ - perHour: 4500, - /** + perHour: 4500, + /** * @type Number */ - base: 600000 - }, - /** + base: 600000 + }, + /** * @type object */ - castle: { - /** + castle: { + /** * @type Number */ - perHour: 8000, - /** + perHour: 8000, + /** * @type Number */ - base: 1200000 - } + base: 1200000 } -}; \ No newline at end of file + } +}; diff --git a/src/mods/names.js b/src/mods/names.js index b5c554b..a274abb 100644 --- a/src/mods/names.js +++ b/src/mods/names.js @@ -1,233 +1,288 @@ idrinth.names = { - /** + /** * @type {object} */ - users: { }, - /** + users: {}, + /** * @type {object} */ - classes: { }, - /** + classes: {}, + /** * @type {object} */ - guilds: { }, - /** + guilds: {}, + /** * @type {Boolean} */ - initialized: false, - /** + initialized: false, + /** * * @param {HTMLElement} element * @returns {string} */ - parse: function ( element ) { - if ( element.getAttribute ( 'dotdxname' ) ) { - return ( element.getAttribute ( 'dotdxname' ) ); - } - if ( element.getAttribute ( 'username' ) ) { - return ( element.getAttribute ( 'username' ) ); - } - return ( element.innerHTML ).replace ( /(<([^>]+)>)/ig, "" ); - }, - /** + parse: function(element) { + if (element.getAttribute("dotdxname")) { + return element.getAttribute("dotdxname"); + } + if (element.getAttribute("username")) { + return element.getAttribute("username"); + } + return element.innerHTML.replace(/(<([^>]+)>)/gi, ""); + }, + /** * the method being run to handle data im- and export * @returns {undefined} */ - run: function () { - /** + run: function() { + /** * * @param {string} added the path-segment defining the data returned * @returns {undefined} */ - var load = function ( added ) { - /** + var load = function(added) { + /** * * @param {string} data * @returns {undefined} */ - var importNames = function ( data ) { - data = JSON.parse ( data ); - if ( !data ) { - return; - } - if ( data.users ) { - idrinth.names.users = data.users; - } - if ( data.guilds ) { - idrinth.names.guilds = data.guilds; - } - if ( data.classes ) { - idrinth.names.classes = data.classes; - } - }; - idrinth.core.ajax.runHome ( - 'users-service/' + added, - importNames - ); - }; - try { - if ( idrinth.names.initialized ) { - load ( 'get/' ); - } else { - load ( 'init/' ); - } - } catch ( e ) { - idrinth.core.log ( e ); + var importNames = function(data) { + data = JSON.parse(data); + if (!data) { + return; } - idrinth.names.initialized = true; - }, - /** + if (data.users) { + idrinth.names.users = data.users; + } + if (data.guilds) { + idrinth.names.guilds = data.guilds; + } + if (data.classes) { + idrinth.names.classes = data.classes; + } + }; + idrinth.core.ajax.runHome("users-service/" + added, importNames); + }; + try { + if (idrinth.names.initialized) { + load("get/"); + } else { + load("init/"); + } + } catch (e) { + idrinth.core.log(e); + } + idrinth.names.initialized = true; + }, + /** * initialises the module * @returns {undefined} */ - start: function () { - /** + start: function() { + /** * creates the tooltip-element * @returns {undefined} */ - var build = function () { - /** + var build = function() { + /** * * @param {string} name * @returns {Array} */ - function getServerPart ( name ) { - return [ { - css: 'idrinth-line idrinth-tooltip-header', - type: 'a', - attributes: [ { - name: 'href', - value: '#' - }, { - name: 'target', - value: '_blank' - }, { - name: 'title', - value: 'go to summoner details' - } ] - }, { - css: 'idrinth-line idrinth-tooltip-level', - type: 'span', - children: [ { - type: '#text', - content: 'Level ' - }, { - css: 'idrinth-format-number idrinth-format-level', - type: 'span', - content: '0' - }, { - type: '#text', - content: ' ' - }, { - css: 'idrinth-format-class', - type: 'span', - content: 'Unknown' - } ] - }, { - css: 'idrinth-line idrinth-tooltip-guild', - type: 'span', - children: [ { - type: '#text', - content: 'of ' - }, { - css: 'idrinth-format-guild', - type: 'a', - attributes: [ { - name: 'href', - 'value': '#' - }, { - name: 'title', - value: 'go to guild details' - }, { - name: 'target', - value: '_blank' - } ] - } ] - }, { - css: 'idrinth-line idrinth-tooltip-update', - type: 'span', - children: [ { - type: '#text', - content: 'Updated ' - }, { - css: 'idrinth-format-date', - type: 'span', - content: 'Unknown' - } ] - }, { - type: 'span', - content: 'Server: ' + name - } ]; - } - idrinth.ui.tooltip = idrinth.ui.buildElement ( { - css: 'idrinth-hovering-box idrinth-tooltip-overwrite idrinth-hide', - id: 'idrinth-tooltip', - children: [ - { - children: getServerPart ( 'Kongregate' ) - }, - { - children: getServerPart ( 'World' ) - } - ], + function getServerPart(name) { + return [ + { + css: "idrinth-line idrinth-tooltip-header", + type: "a", + attributes: [ + { + name: "href", + value: "#" + }, + { + name: "target", + value: "_blank" + }, + { + name: "title", + value: "go to summoner details" + } + ] + }, + { + css: "idrinth-line idrinth-tooltip-level", + type: "span", + children: [ + { + type: "#text", + content: "Level " + }, + { + css: "idrinth-format-number idrinth-format-level", + type: "span", + content: "0" + }, + { + type: "#text", + content: " " + }, + { + css: "idrinth-format-class", + type: "span", + content: "Unknown" + } + ] + }, + { + css: "idrinth-line idrinth-tooltip-guild", + type: "span", + children: [ + { + type: "#text", + content: "of " + }, + { + css: "idrinth-format-guild", + type: "a", attributes: [ - { - name: 'onmouseenter', - value: 'idrinth.names.isHovering=true;' - }, - { - name: 'onmouseleave', - value: 'idrinth.names.isHovering=false;' - } + { + name: "href", + value: "#" + }, + { + name: "title", + value: "go to guild details" + }, + { + name: "target", + value: "_blank" + } ] - } ); - idrinth.ui.base.appendChild ( idrinth.ui.tooltip ); - }; - /** + } + ] + }, + { + css: "idrinth-line idrinth-tooltip-update", + type: "span", + children: [ + { + type: "#text", + content: "Updated " + }, + { + css: "idrinth-format-date", + type: "span", + content: "Unknown" + } + ] + }, + { + type: "span", + content: "Server: " + name + } + ]; + } + idrinth.ui.tooltip = idrinth.ui.buildElement({ + css: "idrinth-hovering-box idrinth-tooltip-overwrite idrinth-hide", + id: "idrinth-tooltip", + children: [ + { + children: getServerPart("Kongregate") + }, + { + children: getServerPart("World") + } + ], + attributes: [ + { + name: "onmouseenter", + value: "idrinth.names.isHovering=true;" + }, + { + name: "onmouseleave", + value: "idrinth.names.isHovering=false;" + } + ] + }); + idrinth.ui.base.appendChild(idrinth.ui.tooltip); + }; + /** * shows the tooltip if the element has a known name * @param {HTMLElement} element * @returns {undefined} */ - var showTooltip = function ( element ) { - /** + var showTooltip = function(element) { + /** * * @param {object} set * @param {HTMLElement} element * @param {Boolean} world * @returns {undefined} */ - function tooltip ( set, element, world ) { - if ( !set ) { - idrinth.ui.updateClassesList ( element, [ 'idrinth-hide' ], [ ] ); - return; - } - var baseUrl = 'https://dotd.idrinth.de/' + ( world ? 'world-kongregate' : 'kongregate' ); - idrinth.ui.updateClassesList ( idrinth.ui.tooltip, [ ], [ 'idrinth-hide' ] ); - idrinth.ui.updateClassesList ( element, [ ], [ 'idrinth-hide' ] ); - element.childNodes[0].setAttribute ( 'href', baseUrl + '/summoner/' + set.id + '/' ); - element.childNodes[0].innerHTML = set.name; - element.childNodes[1].childNodes[1].innerHTML = set.level + ' (' + set['7day'] + '/week, ' + set['30day'] + '/month)'; - element.childNodes[1].childNodes[3].innerHTML = idrinth.names.classes[set.class]; - element.childNodes[2].childNodes[1].setAttribute ( 'href', baseUrl + '/guild/' + set.guildId + '/' ); - element.childNodes[2].childNodes[1].innerHTML = idrinth.names.guilds[world ? 'world' : 'kongregate'][set.guildId]; - element.childNodes[3].childNodes[1].innerHTML = set.updated; - element.childNodes[3].setAttribute ( 'style', ( new Date () ) - ( new Date ( set.updated ) ) > 86400000 ? 'color:#aa0000;' : '' ); - } - idrinth.names.isHovering = false; - var name = idrinth.names.parse ( element ).toLowerCase (); - if ( idrinth.settings.get ( "names" ) && idrinth.ui.tooltip && idrinth.names.users[name] ) { - idrinth.core.timeouts.remove ( 'names.tooltip' ); - idrinth.ui.tooltip.setAttribute ( 'style', idrinth.ui.getElementPositioning ( element, -200, -100 ) ); - tooltip ( idrinth.names.users[name].kongregate, idrinth.ui.tooltip.firstChild, false ); - tooltip ( idrinth.names.users[name].world, idrinth.ui.tooltip.lastChild, true ); - idrinth.ui.setTooltipTimeout (); - } - }; - if ( idrinth.platform === 'kongregate' ) { - idrinth.core.multibind.add ( 'mouseover', '.chat_message_window .username', showTooltip ); - idrinth.core.timeouts.add ( 'names', idrinth.names.run, 300000, -1 ); - idrinth.core.timeouts.add ( 'names-init', idrinth.names.run, 1 ); - build (); + function tooltip(set, element, world) { + if (!set) { + idrinth.ui.updateClassesList(element, ["idrinth-hide"], []); + return; } + var baseUrl = + "https://dotd.idrinth.de/" + + (world ? "world-kongregate" : "kongregate"); + idrinth.ui.updateClassesList(idrinth.ui.tooltip, [], ["idrinth-hide"]); + idrinth.ui.updateClassesList(element, [], ["idrinth-hide"]); + element.childNodes[0].setAttribute( + "href", + baseUrl + "/summoner/" + set.id + "/" + ); + element.childNodes[0].innerHTML = set.name; + element.childNodes[1].childNodes[1].innerHTML = + set.level + " (" + set["7day"] + "/week, " + set["30day"] + "/month)"; + element.childNodes[1].childNodes[3].innerHTML = + idrinth.names.classes[set.class]; + element.childNodes[2].childNodes[1].setAttribute( + "href", + baseUrl + "/guild/" + set.guildId + "/" + ); + element.childNodes[2].childNodes[1].innerHTML = + idrinth.names.guilds[world ? "world" : "kongregate"][set.guildId]; + element.childNodes[3].childNodes[1].innerHTML = set.updated; + element.childNodes[3].setAttribute( + "style", + new Date() - new Date(set.updated) > 86400000 ? "color:#aa0000;" : "" + ); + } + idrinth.names.isHovering = false; + var name = idrinth.names.parse(element).toLowerCase(); + if ( + idrinth.settings.get("names") && + idrinth.ui.tooltip && + idrinth.names.users[name] + ) { + idrinth.core.timeouts.remove("names.tooltip"); + idrinth.ui.tooltip.setAttribute( + "style", + idrinth.ui.getElementPositioning(element, -200, -100) + ); + tooltip( + idrinth.names.users[name].kongregate, + idrinth.ui.tooltip.firstChild, + false + ); + tooltip( + idrinth.names.users[name].world, + idrinth.ui.tooltip.lastChild, + true + ); + idrinth.ui.setTooltipTimeout(); + } + }; + if (idrinth.platform === "kongregate") { + idrinth.core.multibind.add( + "mouseover", + ".chat_message_window .username", + showTooltip + ); + idrinth.core.timeouts.add("names", idrinth.names.run, 300000, -1); + idrinth.core.timeouts.add("names-init", idrinth.names.run, 1); + build(); } -}; \ No newline at end of file + } +}; diff --git a/src/mods/newgrounds.js b/src/mods/newgrounds.js index 6ce3ec4..d4207c8 100644 --- a/src/mods/newgrounds.js +++ b/src/mods/newgrounds.js @@ -1,87 +1,100 @@ idrinth.newgrounds = { - /** + /** * * @type String */ - originalUrl: '', - /** + originalUrl: "", + /** * * @type Array */ - raids: [ ], - /** + raids: [], + /** * * @returns {undefined} */ - joinRaids: function () { - for (var key in idrinth.raids.list) { - if ( idrinth.raids.list[key].hash && idrinth.raids.list[key].raidId ) { - idrinth.newgrounds.raids.push ( key ); - } - } - idrinth.newgrounds.join (); - }, - /** + joinRaids: function() { + for (var key in idrinth.raids.list) { + if (idrinth.raids.list[key].hash && idrinth.raids.list[key].raidId) { + idrinth.newgrounds.raids.push(key); + } + } + idrinth.newgrounds.join(); + }, + /** * * @returns {undefined} */ - alarmCheck: function () { - var now = new Date (); - if ( idrinth.settings.get ( "alarmActive" ) && now.getHours () + ':' + now.getMinutes () === idrinth.settings.get ( "alarmTime" ) ) { - idrinth.core.timeouts.add ( 'newgrounds', idrinth.newgrounds.joinRaids, 1 ); - } - idrinth.core.timeouts.add ( 'newgrounds', idrinth.newgrounds.alarmCheck, 60000 ); - }, - /** + alarmCheck: function() { + var now = new Date(); + if ( + idrinth.settings.get("alarmActive") && + now.getHours() + ":" + now.getMinutes() === + idrinth.settings.get("alarmTime") + ) { + idrinth.core.timeouts.add("newgrounds", idrinth.newgrounds.joinRaids, 1); + } + idrinth.core.timeouts.add( + "newgrounds", + idrinth.newgrounds.alarmCheck, + 60000 + ); + }, + /** * * @returns {undefined} */ - join: function () { - if ( idrinth.newgrounds.raids.length === 0 ) { - idrinth.core.alert ( 'We\'re done! Have fun playing.' ); - return; - } - var frame = document.getElementById ( 'iframe_embed' ).getElementsByTagName ( 'iframe' )[0]; - var key = idrinth.newgrounds.raids.pop (); - var link = idrinth.newgrounds.originalUrl + '&' + ( idrinth.raids.join.getServerLink ( key ) ).replace ( /^.*?\?/, '' ); - frame.setAttribute ( 'onload', 'idrinth.newgrounds.remove(\'' + key + '\')' ); - frame.setAttribute ( 'src', link ); - }, - /** + join: function() { + if (idrinth.newgrounds.raids.length === 0) { + idrinth.core.alert("We're done! Have fun playing."); + return; + } + var frame = document + .getElementById("iframe_embed") + .getElementsByTagName("iframe")[0]; + var key = idrinth.newgrounds.raids.pop(); + var link = + idrinth.newgrounds.originalUrl + + "&" + + idrinth.raids.join.getServerLink(key).replace(/^.*?\?/, ""); + frame.setAttribute("onload", "idrinth.newgrounds.remove('" + key + "')"); + frame.setAttribute("src", link); + }, + /** * * @param {string} key * @returns {undefined} */ - remove: function ( key ) { - idrinth.core.timeouts.add ( - 'newgrounds.remove', - function () { - try { - idrinth.raids.list[key].joined = true; - } catch ( e ) { - try { - idrinth.raids.joined[key].joined = true; - } catch ( f ) { - idrinth.core.log ( "We seem to have joined a dead raid" ); - } - } - if ( document.getElementById ( 'idrinth-raid-link-' + key ) ) { - idrinth.ui.removeElement ( 'idrinth-raid-link-' + key ); - } - try { - idrinth.raids.joined[key] = idrinth.raids.list[key]; - } catch ( e2 ) { - //lost? - } - try { - delete idrinth.raids.list[key]; - } catch ( e3 ) { - //already gone, nothing to do - } - idrinth.raids.join.messages.trying ( key ); - idrinth.newgrounds.join (); - }, - idrinth.settings.get ( "newgroundLoad" ) * 1000 - ); - } + remove: function(key) { + idrinth.core.timeouts.add( + "newgrounds.remove", + function() { + try { + idrinth.raids.list[key].joined = true; + } catch (e) { + try { + idrinth.raids.joined[key].joined = true; + } catch (f) { + idrinth.core.log("We seem to have joined a dead raid"); + } + } + if (document.getElementById("idrinth-raid-link-" + key)) { + idrinth.ui.removeElement("idrinth-raid-link-" + key); + } + try { + idrinth.raids.joined[key] = idrinth.raids.list[key]; + } catch (e2) { + //lost? + } + try { + delete idrinth.raids.list[key]; + } catch (e3) { + //already gone, nothing to do + } + idrinth.raids.join.messages.trying(key); + idrinth.newgrounds.join(); + }, + idrinth.settings.get("newgroundLoad") * 1000 + ); + } }; diff --git a/src/mods/observer.js b/src/mods/observer.js index baf5e21..7f82150 100644 --- a/src/mods/observer.js +++ b/src/mods/observer.js @@ -1,153 +1,155 @@ idrinth.observer = { - /** + /** * * @type MutationObserver[] */ - list: { }, - /** + list: {}, + /** * * @param {MutationRecord[]} mutations * @param {boolean} isPrivate * @returns {undefined} */ - handle: function ( mutations, isPrivate ) { - /** + handle: function(mutations, isPrivate) { + /** * * @param {HTMLElement} element * @returns {undefined} */ - var checkLinks = function ( node ) { - /** + var checkLinks = function(node) { + /** * * @param {HTMLElement} element * @returns {undefined} */ - var handleLink = function ( element ) { - var href = element.getAttribute ( 'href' ); - /** + var handleLink = function(element) { + var href = element.getAttribute("href"); + /** * * @param {Array} parts * @param {string} prefix * @returns {null|string} */ - var getData = function ( parts, prefix ) { - for (var count = 0; count < parts.length; count++) { - if ( parts[count].match ( prefix + '=' ) ) { - return parts[count].split ( '=' )[1]; - } - } - return null; - }; - /** + var getData = function(parts, prefix) { + for (var count = 0; count < parts.length; count++) { + if (parts[count].match(prefix + "=")) { + return parts[count].split("=")[1]; + } + } + return null; + }; + /** * * @param {string} href * @param {Boolean} isWorld * @returns {Boolean} */ - var correctServer = function ( href, isWorld ) { - if ( href.match ( 'serverid=2' ) ) { - return isWorld; - } - return !isWorld; - }; - if ( !href || !href.match ( /action_type=raidhelp/ ) ) { - return; - } - href = href.replace ( /^.*\?/, '' ); - if ( !correctServer ( href, idrinth.settings.get ( "world" ) ) ) { - return; - } - var parts = href.split ( "&" ); - var id = getData ( parts, 'raid_id' ); - var hash = getData ( parts, 'hash' ); - if ( !id || !hash ) { - return; - } - idrinth.raids.private[id] = hash; - idrinth.core.ajax.runHome ( 'get-raid-service/' + id + '/' + hash + '/' ); - }; - if ( node.tagName === 'A' || node.tagName === 'a' ) { - handleLink ( node ); - } else { - var elements = node.getElementsByTagName ( 'a' ); - for (var count = 0; count < elements.length; count++) { - handleLink ( elements[count] ); - } - } + var correctServer = function(href, isWorld) { + if (href.match("serverid=2")) { + return isWorld; + } + return !isWorld; }; - /** + if (!href || !href.match(/action_type=raidhelp/)) { + return; + } + href = href.replace(/^.*\?/, ""); + if (!correctServer(href, idrinth.settings.get("world"))) { + return; + } + var parts = href.split("&"); + var id = getData(parts, "raid_id"); + var hash = getData(parts, "hash"); + if (!id || !hash) { + return; + } + idrinth.raids.private[id] = hash; + idrinth.core.ajax.runHome("get-raid-service/" + id + "/" + hash + "/"); + }; + if (node.tagName === "A" || node.tagName === "a") { + handleLink(node); + } else { + var elements = node.getElementsByTagName("a"); + for (var count = 0; count < elements.length; count++) { + handleLink(elements[count]); + } + } + }; + /** * * @param {HTMLElement} element * @returns {undefined} */ - var checkNames = function ( node ) { - /** + var checkNames = function(node) { + /** * * @param {HTMLElement} element * @returns {undefined} */ - var processName = function ( element ) { - var name = ''; - try { - name = idrinth.names.parse ( element ); - } catch ( e ) { - return; - } - if ( !name ) { - return; - } - if ( !idrinth.names.users[name.toLowerCase ()] && name.length > 0 ) { - idrinth.names.users[name.toLowerCase ()] = { }; - idrinth.core.ajax.runHome ( 'users-service/add/' + encodeURIComponent ( name ) + '/' ); - } - }; - var elements = node.getElementsByClassName ( 'username' ); - for (var count = elements.length - 1; count >= 0; count--) { - processName ( elements[count] ); - } - }; - mutations.forEach ( function ( mutation ) { - mutation.addedNodes.forEach ( function ( node ) { - checkLinks ( node ); - checkNames ( node ); - } ); - } ); - }, - /** + var processName = function(element) { + var name = ""; + try { + name = idrinth.names.parse(element); + } catch (e) { + return; + } + if (!name) { + return; + } + if (!idrinth.names.users[name.toLowerCase()] && name.length > 0) { + idrinth.names.users[name.toLowerCase()] = {}; + idrinth.core.ajax.runHome( + "users-service/add/" + encodeURIComponent(name) + "/" + ); + } + }; + var elements = node.getElementsByClassName("username"); + for (var count = elements.length - 1; count >= 0; count--) { + processName(elements[count]); + } + }; + mutations.forEach(function(mutation) { + mutation.addedNodes.forEach(function(node) { + checkLinks(node); + checkNames(node); + }); + }); + }, + /** * * @returns {undefined} */ - start: function () { - if ( idrinth.platform !== 'kongregate' ) { - return; - } - if ( - !document.getElementById ( "chat_rooms_container" ) || - !document.getElementById ( "chat_rooms_container" ).children[1] || - !document.getElementById ( "chat_rooms_container" ).children[1].children[2] - ) { - idrinth.core.timeouts.add ( 'observer', idrinth.observer.start, 500, 1 ); - return; - } - idrinth.observer.list.chat = new MutationObserver ( function ( mutations ) { - idrinth.observer.handle ( mutations, false ); - } ); - idrinth.observer.list.chat.observe ( - document.getElementById ( "chat_rooms_container" ).children[1].children[2], - { - childList: true, - subtree: true - } - ); - idrinth.observer.list.guild = new MutationObserver ( function ( mutations ) { - idrinth.observer.handle ( mutations, true ); - } ); - idrinth.observer.list.guild.observe ( - document.getElementById ( "chat_rooms_container" ).children[0].children[2], - { - childList: true, - subtree: true - } - ); + start: function() { + if (idrinth.platform !== "kongregate") { + return; + } + if ( + !document.getElementById("chat_rooms_container") || + !document.getElementById("chat_rooms_container").children[1] || + !document.getElementById("chat_rooms_container").children[1].children[2] + ) { + idrinth.core.timeouts.add("observer", idrinth.observer.start, 500, 1); + return; } -}; \ No newline at end of file + idrinth.observer.list.chat = new MutationObserver(function(mutations) { + idrinth.observer.handle(mutations, false); + }); + idrinth.observer.list.chat.observe( + document.getElementById("chat_rooms_container").children[1].children[2], + { + childList: true, + subtree: true + } + ); + idrinth.observer.list.guild = new MutationObserver(function(mutations) { + idrinth.observer.handle(mutations, true); + }); + idrinth.observer.list.guild.observe( + document.getElementById("chat_rooms_container").children[0].children[2], + { + childList: true, + subtree: true + } + ); + } +}; diff --git a/src/mods/raids.js b/src/mods/raids.js index e753f1f..b258315 100644 --- a/src/mods/raids.js +++ b/src/mods/raids.js @@ -1,115 +1,118 @@ idrinth.raids = { - /** + /** * @type Object */ - list: { }, - /** + list: {}, + /** * @type Object */ - private: { }, - /** + private: {}, + /** * @type Object */ - joined: { }, - /** + joined: {}, + /** * @type Number */ - requested: 0, - /** + requested: 0, + /** * * @param {Number} id * @returns {undefined} */ - import: function ( id ) { - if ( !idrinth.platform ) { - return; - } - /** + import: function(id) { + if (!idrinth.platform) { + return; + } + /** * * @param {String} toImport * @returns {String} */ - var getImportLink = function ( toImport ) { - return 'raid-service/' + ( toImport === '' ? '_' : toImport ) + '/'; - }; - idrinth.core.ajax.runHome ( - getImportLink ( id ), - /** + var getImportLink = function(toImport) { + return "raid-service/" + (toImport === "" ? "_" : toImport) + "/"; + }; + idrinth.core.ajax.runHome( + getImportLink(id), + /** * * @param {string} responseText * @returns {undefined} */ - function ( responseText ) { - var delHandler = function ( key ) { - if ( key in idrinth.raids.list ) { - delete idrinth.raids.list[key]; - } - if ( key in idrinth.raids.joined ) { - delete idrinth.raids.joined[key]; - } - if ( document.getElementById ( 'idrinth-raid-link-' + key ) ) { - idrinth.ui.removeElement ( 'idrinth-raid-link-' + key ); - } - }; - var list = JSON.parse ( responseText ); - for (var key in list) { - if ( list[key].delete ) { - delHandler ( key ); - } else { - //worst case: overwriting itself - list[key].private = idrinth.raids.list[key] && idrinth.raids.list[key].private; - idrinth.raids.list[key] = list[key]; - } - } - }, - function () { - }, - function () { - }, - idrinth.raids.knowRaids () - ); - }, - /** + function(responseText) { + var delHandler = function(key) { + if (key in idrinth.raids.list) { + delete idrinth.raids.list[key]; + } + if (key in idrinth.raids.joined) { + delete idrinth.raids.joined[key]; + } + if (document.getElementById("idrinth-raid-link-" + key)) { + idrinth.ui.removeElement("idrinth-raid-link-" + key); + } + }; + var list = JSON.parse(responseText); + for (var key in list) { + if (list[key].delete) { + delHandler(key); + } else { + //worst case: overwriting itself + list[key].private = + idrinth.raids.list[key] && idrinth.raids.list[key].private; + idrinth.raids.list[key] = list[key]; + } + } + }, + function() {}, + function() {}, + idrinth.raids.knowRaids() + ); + }, + /** * * @returns {String} */ - knowRaids: function () { - return ( ( Object.keys ( idrinth.raids.joined ) ).concat ( Object.keys ( idrinth.raids.list ) ) ).join (); - }, - /** + knowRaids: function() { + return Object.keys(idrinth.raids.joined) + .concat(Object.keys(idrinth.raids.list)) + .join(); + }, + /** * * @returns {undefined} */ - clearAll: function () { - idrinth.core.timeouts.remove ( 'raids' ); - while ( document.getElementById ( "idrinth-raid-link-list" ).firstChild ) { - idrinth.ui.removeElement ( document.getElementById ( "idrinth-raid-link-list" ).firstChild.id ); - } - idrinth.raids.list = { }; - idrinth.raids.joined = { }; - idrinth.raids.start (); - }, - join: { - /** + clearAll: function() { + idrinth.core.timeouts.remove("raids"); + while (document.getElementById("idrinth-raid-link-list").firstChild) { + idrinth.ui.removeElement( + document.getElementById("idrinth-raid-link-list").firstChild.id + ); + } + idrinth.raids.list = {}; + idrinth.raids.joined = {}; + idrinth.raids.start(); + }, + join: { + /** * */ - data: { - /** + data: { + /** * @type String */ - prefix: null, - /** + prefix: null, + /** * @type String */ - tag: null - }, - /** + tag: null + }, + /** * * @param {String} key * @returns {String} */ - getServerLink: function ( key ) { - /** + getServerLink: function(key) { + /** * * @param {Object} list * @param {String} key @@ -117,315 +120,349 @@ idrinth.raids = { * @param {String} tag * @returns {String|Boolean} */ - var getLink = function ( list, key, prefix, tag ) { - var build = function ( data, tag, prefix ) { - try { - return prefix + - tag + 'action_type=raidhelp&' + - tag + 'raid_id=' + data.raidId + '&' + - tag + 'difficulty=' + data.difficulty + '&' + - tag + 'hash=' + data.hash + - ( idrinth.settings.get ( "isWorldServer" ) ? '&' + tag + 'serverid=' + 2 : '' ); - } catch ( e1 ) { - return false; - } - }; - if ( list[key] ) { - var link = build ( list[key], tag, prefix ); - if ( link ) { - return link; - } - } - }; - /** + var getLink = function(list, key, prefix, tag) { + var build = function(data, tag, prefix) { + try { + return ( + prefix + + tag + + "action_type=raidhelp&" + + tag + + "raid_id=" + + data.raidId + + "&" + + tag + + "difficulty=" + + data.difficulty + + "&" + + tag + + "hash=" + + data.hash + + (idrinth.settings.get("isWorldServer") + ? "&" + tag + "serverid=" + 2 + : "") + ); + } catch (e1) { + return false; + } + }; + if (list[key]) { + var link = build(list[key], tag, prefix); + if (link) { + return link; + } + } + }; + /** * * @returns {String} */ - var makePrefix = function () { - if ( idrinth.raids.join.data.prefix === null ) { - var sites = { - armorgames: 'http://50.18.191.15/armor/raidjoin.php?user_id=###id###&auth_token=###token###&', - kongregate: 'http://50.18.191.15/kong/raidjoin.php?kongregate_username=###name###&kongregate_user_id=###id###&kongregate_game_auth_token=###token###&', - newgrounds: 'https://newgrounds.com/portal/view/609826?', - dawnofthedragons: 'https://web1.dawnofthedragons.com/live_iframe/raidjoin.php?', - facebook: 'https://web1.dawnofthedragons.com/live_iframe/raidjoin.php?' - }; - idrinth.raids.join.data.prefix = ( ( ( sites[idrinth.platform].replace ( - '###id###', idrinth.user.id - ) ).replace ( - '###token###', idrinth.user.token - ) ).replace ( - '###name###', idrinth.user.name - ) ); - } - return idrinth.raids.join.data.prefix; - }; - /** + var makePrefix = function() { + if (idrinth.raids.join.data.prefix === null) { + var sites = { + armorgames: "http://50.18.191.15/armor/raidjoin.php?user_id=###id###&auth_token=###token###&", + kongregate: "http://50.18.191.15/kong/raidjoin.php?kongregate_username=###name###&kongregate_user_id=###id###&kongregate_game_auth_token=###token###&", + newgrounds: "https://newgrounds.com/portal/view/609826?", + dawnofthedragons: "https://web1.dawnofthedragons.com/live_iframe/raidjoin.php?", + facebook: "https://web1.dawnofthedragons.com/live_iframe/raidjoin.php?" + }; + idrinth.raids.join.data.prefix = sites[idrinth.platform] + .replace("###id###", idrinth.user.id) + .replace("###token###", idrinth.user.token) + .replace("###name###", idrinth.user.name); + } + return idrinth.raids.join.data.prefix; + }; + /** * * @returns {String} */ - var makeTag = function () { - if ( idrinth.raids.join.data.tag === null ) { - var sites = { - armorgames: 'ar_', - kongregate: 'kv_', - newgrounds: 'ng_', - facebook: '', - dawnofthedragons: '' - }; - idrinth.raids.join.data.tag = sites[idrinth.platform]; - } - return idrinth.raids.join.data.tag; - }; - var prefix = makePrefix (); - var tag = makeTag (); - var link = getLink ( idrinth.raids.list, key, prefix, tag ); - if ( link ) { - return link; - } - link = getLink ( idrinth.raids.joined, key, prefix, tag ); - if ( link ) { - return link; - } - return prefix; - }, - /** + var makeTag = function() { + if (idrinth.raids.join.data.tag === null) { + var sites = { + armorgames: "ar_", + kongregate: "kv_", + newgrounds: "ng_", + facebook: "", + dawnofthedragons: "" + }; + idrinth.raids.join.data.tag = sites[idrinth.platform]; + } + return idrinth.raids.join.data.tag; + }; + var prefix = makePrefix(); + var tag = makeTag(); + var link = getLink(idrinth.raids.list, key, prefix, tag); + if (link) { + return link; + } + link = getLink(idrinth.raids.joined, key, prefix, tag); + if (link) { + return link; + } + return prefix; + }, + /** * */ - messages: { - /** + messages: { + /** * * @param {String} string * @param {String} key * @returns {undefined} */ - log: function ( string, key ) { - var message = ( string.replace ( '#name#', idrinth.raids.list[key].name ) ).replace ( '#raid#', idrinth.raids.list[key].raid ); - idrinth.core.log ( message ); - var li = document.createElement ( 'li' ); - var ul = document.getElementById ( 'idrinth-joined-raids' ).getElementsByTagName ( 'ul' )[0]; - li.appendChild ( document.createTextNode ( ( new Date () ).toLocaleTimeString () + ' ' + message ) ); - if ( !ul.firstChild ) { - ul.appendChild ( li ); - } else { - if ( ul.childNodes.length > 9 ) { - ul.removeChild ( ul.lastChild ); - } - ul.insertBefore ( li, ul.firstChild ); - } - }, - /** + log: function(string, key) { + var message = string + .replace("#name#", idrinth.raids.list[key].name) + .replace("#raid#", idrinth.raids.list[key].raid); + idrinth.core.log(message); + var li = document.createElement("li"); + var ul = document + .getElementById("idrinth-joined-raids") + .getElementsByTagName("ul")[0]; + li.appendChild( + document.createTextNode( + new Date().toLocaleTimeString() + " " + message + ) + ); + if (!ul.firstChild) { + ul.appendChild(li); + } else { + if (ul.childNodes.length > 9) { + ul.removeChild(ul.lastChild); + } + ul.insertBefore(li, ul.firstChild); + } + }, + /** * * @param {String} key * @returns {undefined} */ - addToJoined: function ( key ) { - if ( key && idrinth.raids.list.hasOwnProperty ( key ) ) { - idrinth.raids.joined[key] = idrinth.raids.list[key]; - delete idrinth.raids.list[key]; - } - }, - /** + addToJoined: function(key) { + if (key && idrinth.raids.list.hasOwnProperty(key)) { + idrinth.raids.joined[key] = idrinth.raids.list[key]; + delete idrinth.raids.list[key]; + } + }, + /** * * @param {String} key * @returns {undefined} */ - success: function ( key ) { - idrinth.raids.join.messages.log ( 'Joined #name#\'s #raid#.', key ); - idrinth.ui.removeElement ( 'idrinth-raid-link-' + key ); - this.addToJoined ( key ); - }, - /** + success: function(key) { + idrinth.raids.join.messages.log("Joined #name#'s #raid#.", key); + idrinth.ui.removeElement("idrinth-raid-link-" + key); + this.addToJoined(key); + }, + /** * * @param {String} key * @returns {undefined} */ - failed: function ( key ) { - idrinth.raids.join.messages.log ( 'Could not join #name#\'s #raid#', key ); - }, - /** + failed: function(key) { + idrinth.raids.join.messages.log("Could not join #name#'s #raid#", key); + }, + /** * * @param {String} key * @returns {undefined} */ - trying: function ( key ) { - ( ( function ( key ) { - idrinth.core.timeouts.add ( 'raid.join.' + key, function () { - var id = 'idrinth-raid-link-' + key; - if ( document.getElementById ( id ) ) { - idrinth.ui.removeElement ( id ); - } - }, 300 ); - } ) ( key ) ); - if ( idrinth.raids.list[key] ) { - idrinth.raids.join.messages.log ( 'Trying to join #name#\'s #raid#', key ); - } - this.addToJoined ( key ); - } - }, - /** + trying: function(key) { + (function(key) { + idrinth.core.timeouts.add( + "raid.join." + key, + function() { + var id = "idrinth-raid-link-" + key; + if (document.getElementById(id)) { + idrinth.ui.removeElement(id); + } + }, + 300 + ); + })(key); + if (idrinth.raids.list[key]) { + idrinth.raids.join.messages.log( + "Trying to join #name#'s #raid#", + key + ); + } + this.addToJoined(key); + } + }, + /** * * @returns {undefined} */ - process: function () { - /** + process: function() { + /** * * @returns {Boolean} */ - var join = function () { - /** + var join = function() { + /** * * @returns {function[]} */ - var getServerMethods = function () { - /** + var getServerMethods = function() { + /** * * @param {String} key * @returns {Function} */ - var byMessage = function ( key ) { - idrinth.inframe.send ( - 'joinRaid', - ( idrinth.raids.join.getServerLink ( key ) ).replace ( /^.*raidjoin\.php/, 'raidjoin.php' ) - ); - idrinth.raids.join.messages.trying ( key ); - }; - /** + var byMessage = function(key) { + idrinth.inframe.send( + "joinRaid", + idrinth.raids.join + .getServerLink(key) + .replace(/^.*raidjoin\.php/, "raidjoin.php") + ); + idrinth.raids.join.messages.trying(key); + }; + /** * * @param {String} key * @returns {undefined} */ - var postLink = function ( key ) { - if ( !document.getElementById ( 'idrinth-raid-link-' + key ) ) { - document.getElementById ( 'idrinth-raid-link-list' ).appendChild ( - idrinth.ui.buildElement ( - { - children: [ - { - type: 'span', - css: 'clipboard-copy', - id: 'idrinth-raid-link-' + key, - attributes: [ - { - name: 'data-clipboard-text', - value: idrinth.raids.join.getServerLink ( key ) - } - ], - content: idrinth.raids.list[key].name + '\'s ' + idrinth.raids.list[key].raid - } - ] - } - ) - ); + var postLink = function(key) { + if (!document.getElementById("idrinth-raid-link-" + key)) { + document.getElementById("idrinth-raid-link-list").appendChild( + idrinth.ui.buildElement({ + children: [ + { + type: "span", + css: "clipboard-copy", + id: "idrinth-raid-link-" + key, + attributes: [ + { + name: "data-clipboard-text", + value: idrinth.raids.join.getServerLink(key) } - }; - var options = [ postLink ]; - if ( idrinth.platform === 'armorgames' || idrinth.platform === 'kongregate' ) { - options.push ( byMessage ); + ], + content: idrinth.raids.list[key].name + + "'s " + + idrinth.raids.list[key].raid } - return options; - }; - /** + ] + }) + ); + } + }; + var options = [postLink]; + if ( + idrinth.platform === "armorgames" || + idrinth.platform === "kongregate" + ) { + options.push(byMessage); + } + return options; + }; + /** * * @param {Number} amount * @returns {Boolean} */ - var reachedMax = function ( amount ) { - return amount > 99; - }; - /** + var reachedMax = function(amount) { + return amount > 99; + }; + /** * * @param {Number} added * @param {String} key * @param {function[]} options * @returns {Number} */ - var handleKey = function ( added, key, options ) { - var raid = idrinth.raids.list[key]; - if ( !raid.joined ) { - added++; - options[0] ( key );//post link - if ( - ( - ( !idrinth.settings.get ( "bannedRaids#" + raid.raid ) && !idrinth.settings.get ( "raidWhitelist" ) ) || - ( idrinth.settings.get ( "bannedRaids#" + raid.raid ) && idrinth.settings.get ( "raidWhitelist" ) ) - ) && ( - !raid.private || - idrinth.settings.get ( 'raid#joinPrivate' ) - ) - ) { - for (var count = 1; count < options.length; count++) { - options[count] ( key ); - } - } - } - return added; - }; - var added = 0; - var options = getServerMethods (); - for (var key in idrinth.raids.list) { - if ( typeof idrinth.raids.list[key] === 'object' ) { - added = handleKey ( added, key, options ); - } - if ( reachedMax ( added ) ) { - return true; - } - } - return false; - }; - /** + var handleKey = function(added, key, options) { + var raid = idrinth.raids.list[key]; + if (!raid.joined) { + added++; + options[0](key); //post link + if ( + ((!idrinth.settings.get("bannedRaids#" + raid.raid) && + !idrinth.settings.get("raidWhitelist")) || + (idrinth.settings.get("bannedRaids#" + raid.raid) && + idrinth.settings.get("raidWhitelist"))) && + (!raid.private || idrinth.settings.get("raid#joinPrivate")) + ) { + for (var count = 1; count < options.length; count++) { + options[count](key); + } + } + } + return added; + }; + var added = 0; + var options = getServerMethods(); + for (var key in idrinth.raids.list) { + if (typeof idrinth.raids.list[key] === "object") { + added = handleKey(added, key, options); + } + if (reachedMax(added)) { + return true; + } + } + return false; + }; + /** * requests information for raids caught from a third party(chat for example) * @returns {undefined} */ - var handlePrivates = function () { - /** + var handlePrivates = function() { + /** * * @param {String} reply * @returns {undefined} */ - var handle = function ( reply ) { - if ( !reply ) { - return; - } - reply = JSON.parse ( reply ); - if ( !reply ) { - return; - } - if ( !reply.hasOwnProperty ( 'delete' ) ) { - idrinth.raids.list[reply.aid] = reply; - idrinth.raids.list[reply.aid].private = true; - } - try { - delete idrinth.raids.private[reply.raidId]; - } catch ( e ) { - idrinth.core.log ( e.getMessage ? e.getMessage () : e.message ); - } - }; - if ( !idrinth.settings.get ( 'raid#requestPrivate' ) ) { - return; - } - for (var raidId in idrinth.raids.private) { - if(idrinth.raids.private.hasOwnProperty (raidId)) { - idrinth.core.ajax.runHome ( - 'get-raid-service/' + raidId + '/' + idrinth.raids.private[raidId] + '/', - handle - ); - } - } - }; - if ( !join () && Date.now () - 60000 > idrinth.raids.requested ) { - idrinth.raids.requested = Date.now (); - idrinth.raids.import ( idrinth.settings.get ( "raids" ) ? idrinth.settings.get ( "favs" ) : '-1' ); - } - handlePrivates (); + var handle = function(reply) { + if (!reply) { + return; + } + reply = JSON.parse(reply); + if (!reply) { + return; + } + if (!reply.hasOwnProperty("delete")) { + idrinth.raids.list[reply.aid] = reply; + idrinth.raids.list[reply.aid].private = true; + } + try { + delete idrinth.raids.private[reply.raidId]; + } catch (e) { + idrinth.core.log(e.getMessage ? e.getMessage() : e.message); + } + }; + if (!idrinth.settings.get("raid#requestPrivate")) { + return; } - }, - /** + for (var raidId in idrinth.raids.private) { + if (idrinth.raids.private.hasOwnProperty(raidId)) { + idrinth.core.ajax.runHome( + "get-raid-service/" + + raidId + + "/" + + idrinth.raids.private[raidId] + + "/", + handle + ); + } + } + }; + if (!join() && Date.now() - 60000 > idrinth.raids.requested) { + idrinth.raids.requested = Date.now(); + idrinth.raids.import( + idrinth.settings.get("raids") ? idrinth.settings.get("favs") : "-1" + ); + } + handlePrivates(); + } + }, + /** * * @returns {undefined} */ - start: function () { - idrinth.core.timeouts.remove ( 'raids' ); - idrinth.core.timeouts.add ( 'raids', idrinth.raids.join.process, 1500, -1 ); - } -}; \ No newline at end of file + start: function() { + idrinth.core.timeouts.remove("raids"); + idrinth.core.timeouts.add("raids", idrinth.raids.join.process, 1500, -1); + } +}; diff --git a/src/mods/settings.js b/src/mods/settings.js index d8efb83..3b64597 100644 --- a/src/mods/settings.js +++ b/src/mods/settings.js @@ -1,416 +1,423 @@ idrinth.settings = { - /** + /** * * @type {object} */ - data: { - /** + data: { + /** * * @type Boolean */ - raids: false, - /** + raids: false, + /** * * @type Boolean */ - raidWhitelist: false, - /** + raidWhitelist: false, + /** * * @type String */ - favs: '', - /** + favs: "", + /** * * @type Boolean */ - factor: true, - /** + factor: true, + /** * * @type Boolean */ - moveLeft: false, - /** + moveLeft: false, + /** * * @type Boolean */ - minimalist: false, - /** + minimalist: false, + /** * * @type Boolean */ - chatHiddenOnStart: true, - /** + chatHiddenOnStart: true, + /** * * @type Boolean */ - names: true, - /** + names: true, + /** * * @type Number */ - timeout: 5000, - /** + timeout: 5000, + /** * * @type Boolean */ - warBottom: false, - /** + warBottom: false, + /** * * @type Boolean */ - landMax: true, - /** + landMax: true, + /** * * @type Boolean */ - chatting: true, - /** + chatting: true, + /** * * @type String */ - chatuser: '', - /** + chatuser: "", + /** * * @type Number */ - newgroundLoad: 30, - /** + newgroundLoad: 30, + /** * * @type String */ - chatpass: '', - /** + chatpass: "", + /** * * @type Boolean */ - isWorldServer: false, - /** + isWorldServer: false, + /** * * @type String */ - alarmTime: '8:0', - /** + alarmTime: "8:0", + /** * * @type Boolean */ - alarmActive: false, - /** + alarmActive: false, + /** * * @type Object */ - bannedRaids: { }, - /** + bannedRaids: {}, + /** * * @type String */ - lang: null, - /** + lang: null, + /** * @type Object */ - raid: { - /** + raid: { + /** * * @type Boolean */ - requestPrivate: true, - /** + requestPrivate: true, + /** * * @type Boolean */ - joinPrivate: true - }, - /** + joinPrivate: true + }, + /** * * @type {Object} */ - notification: { - /** + notification: { + /** * * @type Boolean */ - mention: true, - /** + mention: true, + /** * * @type Boolean */ - message: true, - /** + message: true, + /** * * @type Boolean */ - content: true, - /** + content: true, + /** * * @type Boolean */ - image: true, - /** + image: true, + /** * * @type Boolean */ - raid: true - }, - /** + raid: true + }, + /** * * @type Object */ - land: { - /** + land: { + /** * * @type Number */ - cornfield: 0, - /** + cornfield: 0, + /** * * @type Number */ - stable: 0, - /** + stable: 0, + /** * * @type Number */ - barn: 0, - /** + barn: 0, + /** * * @type Number */ - store: 0, - /** + store: 0, + /** * * @type Number */ - pub: 0, - /** + pub: 0, + /** * * @type Number */ - inn: 0, - /** + inn: 0, + /** * * @type Number */ - tower: 0, - /** + tower: 0, + /** * * @type Number */ - fort: 0, - /** + fort: 0, + /** * * @type Number */ - castle: 0, - /** + castle: 0, + /** * * @type Number */ - gold: 0 - }, - /** + gold: 0 + }, + /** * * @type {object} */ - stats: { - /** + stats: { + /** * * @type Number */ - stats: 0, - /** + stats: 0, + /** * * @type Number */ - level: 1, - /** + level: 1, + /** * * @type Number */ - perception: 0, - /** + perception: 0, + /** * * @type Number */ - attack: 0, - /** + attack: 0, + /** * * @type Number */ - defense: 0, - /** + defense: 0, + /** * * @type Number */ - critchance: 5, - /** + critchance: 5, + /** * * @type Number */ - mount: 0, - /** + mount: 0, + /** * * @type Boolean */ - kraken: false, - /** + kraken: false, + /** * * @type Boolean */ - mirele: false, - /** + mirele: false, + /** * * @type Boolean */ - utym: false - } - }, - /** + utym: false + } + }, + /** * * @param {string} field * @param {Boolean} allowObject * @returns {int|string|object} */ - get: function ( field, allowObject ) { - /** + get: function(field, allowObject) { + /** * * @param {object} parent * @param {string} field * @param {Boolean} allowObject * @returns {int|string|object} */ - var getValue = function ( parent, field, allowObject ) { - if ( idrinth.core.fieldIsSetting ( parent, field, allowObject ) ) { - return parent[field]; - } - return null; - }; - /** + var getValue = function(parent, field, allowObject) { + if (idrinth.core.fieldIsSetting(parent, field, allowObject)) { + return parent[field]; + } + return null; + }; + /** * * @param {string} key * @returns {undefined} */ - var remove = function ( key ) { - try { - window.localStorage.removeItem ( key ); - } catch ( e ) { - //not really relevant - } - }; - if ( !field ) { - return; - } - var value = getValue ( idrinth.settings.data, field, allowObject ); - if ( value !== null && ( typeof value !== 'object' || allowObject ) ) { - remove ( 'idrinth-dotd-' + field ); - return value; - } - field = field.split ( '#' ); - remove ( 'idrinth-dotd-' + field[0] + '-' + field[1] ); - return getValue ( idrinth.settings.data[field[0]], field[1], allowObject ); - }, - /** + var remove = function(key) { + try { + window.localStorage.removeItem(key); + } catch (e) { + //not really relevant + } + }; + if (!field) { + return; + } + var value = getValue(idrinth.settings.data, field, allowObject); + if (value !== null && (typeof value !== "object" || allowObject)) { + remove("idrinth-dotd-" + field); + return value; + } + field = field.split("#"); + remove("idrinth-dotd-" + field[0] + "-" + field[1]); + return getValue(idrinth.settings.data[field[0]], field[1], allowObject); + }, + /** * * @param {String} field * @param {String|Boolean|Number} value * @returns {undefined} */ - change: function ( field, value ) { - /** + change: function(field, value) { + /** * * @param {obect} parent * @param {string} field * @param {String|Booleab|Number} value * @returns {Boolean} */ - var setValue = function ( parent, field, value ) { - if ( idrinth.core.fieldIsSetting ( parent, field ) ) { - parent[field] = value; - return true; - } - return false; - }; - /** + var setValue = function(parent, field, value) { + if (idrinth.core.fieldIsSetting(parent, field)) { + parent[field] = value; + return true; + } + return false; + }; + /** * saves the data to local storage * @returns {undefined} */ - var store = function () { - window.localStorage.setItem ( 'idotd', JSON.stringify ( idrinth.settings.data ) ); - }; - if ( !field ) { - return; - } - if ( setValue ( idrinth.settings.data, field, value ) ) { - store (); - return; - } - field = field.split ( '#' ); - if ( !idrinth.settings.data[field[0]] || !field[1] ) { - return; - } - if ( setValue ( idrinth.settings.data[field[0]], field[1], value ) ) { - store (); - return; - } - }, - /** + var store = function() { + window.localStorage.setItem( + "idotd", + JSON.stringify(idrinth.settings.data) + ); + }; + if (!field) { + return; + } + if (setValue(idrinth.settings.data, field, value)) { + store(); + return; + } + field = field.split("#"); + if (!idrinth.settings.data[field[0]] || !field[1]) { + return; + } + if (setValue(idrinth.settings.data[field[0]], field[1], value)) { + store(); + return; + } + }, + /** * initializes the module * @returns {undefined} */ - start: function () { - /** + start: function() { + /** * fills the data from json in idotd * @returns {undefined} */ - var getCurrent = function () { - try{ - var data = JSON.parse ( window.localStorage.getItem ( 'idotd' ) ); - /** + var getCurrent = function() { + try { + var data = JSON.parse(window.localStorage.getItem("idotd")); + /** * * @param {object} to * @param {object} from * @param {function} apply * @returns {undefined} */ - var apply = function ( to, from, apply ) { - for (var key in from) { - if ( from.hasOwnProperty ( key ) ) { - if ( typeof from[key] === 'object' ) { - to[key] = typeof to[key] === 'object' ? to[key] : { }; - apply ( to[key], from[key] ); - } else { - to[key] = from[key]; - } - } - } - }; - if(!data) { - return; - } - apply ( idrinth.settings.data, data, apply ); - } catch (exception) { - idrinth.core.timeouts.add ( - 'settings-fail', - function(){ - idrinth.core.alert ("There was a failure when trying to handle settings, they have been reset to default."); - }, - 1000 - ); - idrinth.core.log (exception.getMessage?exception.getMessage( ):exception.message); + var apply = function(to, from, apply) { + for (var key in from) { + if (from.hasOwnProperty(key)) { + if (typeof from[key] === "object") { + to[key] = typeof to[key] === "object" ? to[key] : {}; + apply(to[key], from[key]); + } else { + to[key] = from[key]; + } } + } }; - /** + if (!data) { + return; + } + apply(idrinth.settings.data, data, apply); + } catch (exception) { + idrinth.core.timeouts.add( + "settings-fail", + function() { + idrinth.core.alert( + "There was a failure when trying to handle settings, they have been reset to default." + ); + }, + 1000 + ); + idrinth.core.log( + exception.getMessage ? exception.getMessage() : exception.message + ); + } + }; + /** * fills the data from seperate storages * @returns {undefined} */ - var getOld = function () { - /** + var getOld = function() { + /** * * @param {object} object * @param {String} prefix * @param {function} objectIterator * @returns {Boolean} */ - var objectIterator = function ( object, prefix, objectIterator ) { - /** + var objectIterator = function(object, prefix, objectIterator) { + /** * * @param {String} prefix * @param {String} key @@ -418,39 +425,46 @@ idrinth.settings = { * @returns {Boolean} * @todo remove this once old data is unlikely to exist */ - var itemHandler = function ( prefix, key, item ) { - if ( typeof item !== 'function' ) { - var tmp = window.localStorage.getItem ( 'idrinth-dotd-' + prefix + key ); - if ( tmp ) { - if ( tmp === 'false' ) { - tmp = false; - } else if ( tmp === 'true' ) { - tmp = true; - } - item = tmp; - } - } - return item; - }; - for (var key in object) { - if ( object.hasOwnProperty ( key ) ) { - if ( typeof object[key] !== 'object' ) { - object[key] = itemHandler ( prefix, key, object[key] ); - } else { - object[key] = objectIterator ( object[key], prefix + key + '-', itemHandler, objectIterator ); - } - } - } - return object; - }; - objectIterator ( idrinth.settings.data, '', objectIterator ); + var itemHandler = function(prefix, key, item) { + if (typeof item !== "function") { + var tmp = window.localStorage.getItem( + "idrinth-dotd-" + prefix + key + ); + if (tmp) { + if (tmp === "false") { + tmp = false; + } else if (tmp === "true") { + tmp = true; + } + item = tmp; + } + } + return item; }; - if ( window.localStorage ) { - if ( window.localStorage.getItem ( 'idotd' ) ) { - getCurrent (); + for (var key in object) { + if (object.hasOwnProperty(key)) { + if (typeof object[key] !== "object") { + object[key] = itemHandler(prefix, key, object[key]); } else { - getOld (); + object[key] = objectIterator( + object[key], + prefix + key + "-", + itemHandler, + objectIterator + ); } + } } + return object; + }; + objectIterator(idrinth.settings.data, "", objectIterator); + }; + if (window.localStorage) { + if (window.localStorage.getItem("idotd")) { + getCurrent(); + } else { + getOld(); + } } -}; \ No newline at end of file + } +}; diff --git a/src/mods/stats.js b/src/mods/stats.js index 94ea265..b4659c5 100644 --- a/src/mods/stats.js +++ b/src/mods/stats.js @@ -1,111 +1,173 @@ idrinth.stats = { - /** + /** * * @returns {undefined} */ - calculate: function () { - /** + calculate: function() { + /** * * @param {object} result * @returns {Boolean} is last? */ - var increaseSingle = function ( result ) { - /** + var increaseSingle = function(result) { + /** * * @returns {Number} */ - var addOnePerc = function () { - var base = 0; - if ( idrinth.settings.get ( 'stats#mirele' ) ) { - base += 1.8 * ( idrinth.settings.get ( 'stats#perception' ) <= 10000 ? 10 : 35 ) * idrinth.settings.get ( 'stats#legion' ) / 100; - } - return base; - }; - /** + var addOnePerc = function() { + var base = 0; + if (idrinth.settings.get("stats#mirele")) { + base += + 1.8 * + (idrinth.settings.get("stats#perception") <= 10000 ? 10 : 35) * + idrinth.settings.get("stats#legion") / + 100; + } + return base; + }; + /** * * @returns {Number} */ - var addOneAttack = function () { - var base = 4; - if ( idrinth.settings.get ( 'stats#utym' ) ) { - base += ( idrinth.settings.get ( 'stats#attack' ) <= 10000 ? 0.1 : 1 / 35 ) * 1.8 * idrinth.settings.get ( 'stats#legion' ) / 100; - } - return base; - }; - /** + var addOneAttack = function() { + var base = 4; + if (idrinth.settings.get("stats#utym")) { + base += + (idrinth.settings.get("stats#attack") <= 10000 ? 0.1 : 1 / 35) * + 1.8 * + idrinth.settings.get("stats#legion") / + 100; + } + return base; + }; + /** * * @returns {Number} */ - var addOneDefense = function () { - var base = 1; - if ( idrinth.settings.get ( 'stats#utym' ) ) { - base += ( idrinth.settings.get ( 'stats#defense' ) <= 10000 ? 0.1 : 1 / 35 ) * 1.8 * idrinth.settings.get ( 'stats#legion' ) / 100; - } - if ( idrinth.settings.get ( 'stats#utym' ) ) { - base += ( idrinth.settings.get ( 'stats#defense' ) <= 10000 ? 0.2 : 0.01 ) * 1.8 * idrinth.settings.get ( 'stats#legion' ) / 100; - } - return base; - }; - /** + var addOneDefense = function() { + var base = 1; + if (idrinth.settings.get("stats#utym")) { + base += + (idrinth.settings.get("stats#defense") <= 10000 ? 0.1 : 1 / 35) * + 1.8 * + idrinth.settings.get("stats#legion") / + 100; + } + if (idrinth.settings.get("stats#utym")) { + base += + (idrinth.settings.get("stats#defense") <= 10000 ? 0.2 : 0.01) * + 1.8 * + idrinth.settings.get("stats#legion") / + 100; + } + return base; + }; + /** * * @param {Number} base * @param {string} added * @returns {Number} */ - var addProcs = function ( base, added ) { - var perc = idrinth.settings.get ( 'stats#perception' ) + 1; - var total = base * ( 100 + idrinth.settings.get ( 'stats#mount' ) + idrinth.settings.get ( 'stats#critchance' ) * 0.01 * Math.floor ( perc < 500000 ? perc / 5000 : 50 + perc / 10000 ) ) / 100; - if ( idrinth.settings.get ( 'stats#utym' ) && added === 'perception' ) { - total += ( idrinth.settings.get ( 'stats#perception' ) <= 10000 ? 4 : 2 ) * 0.1; - } - if ( idrinth.settings.get ( 'stats#mirele' ) && added === 'perception' ) { - total += ( idrinth.settings.get ( 'stats#perception' ) <= 10000 ? 1 : 0.1 ); - } - return total; - }; - /** + var addProcs = function(base, added) { + var perc = idrinth.settings.get("stats#perception") + 1; + var total = + base * + (100 + + idrinth.settings.get("stats#mount") + + idrinth.settings.get("stats#critchance") * + 0.01 * + Math.floor(perc < 500000 ? perc / 5000 : 50 + perc / 10000)) / + 100; + if (idrinth.settings.get("stats#utym") && added === "perception") { + total += + (idrinth.settings.get("stats#perception") <= 10000 ? 4 : 2) * 0.1; + } + if (idrinth.settings.get("stats#mirele") && added === "perception") { + total += idrinth.settings.get("stats#perception") <= 10000 ? 1 : 0.1; + } + return total; + }; + /** * * @param {string} stat * @returns {Number} */ - var getCost = function ( stat ) { - return Math.ceil ( Math.max ( 0, idrinth.settings.get ( 'stats#' + stat ) - 10000 - Math.floor ( Math.max ( idrinth.settings.get ( 'stats#level' ) / 500 - 2, 0 ) ) * 1500 ) / 1500 ) + 1; - }; - var perc = addProcs ( addOnePerc (), 'perception' ) / getCost ( 'perception' ); - var defense = addProcs ( addOneDefense (), 'defense' ) / getCost ( 'defense' ); - var attack = addProcs ( addOneAttack (), 'attack' ) / getCost ( 'attack' ); - var stat = null; - if ( perc >= defense && perc >= attack && idrinth.settings.get ( 'stats#stats' ) >= getCost ( 'perception' ) ) { - stat = 'perception'; - } else if ( attack >= defense && attack >= perc && idrinth.settings.get ( 'stats#stats' ) >= getCost ( 'attack' ) ) { - stat = 'attack'; - } else if ( defense >= perc && defense >= attack && idrinth.settings.get ( 'stats#stats' ) >= getCost ( 'defense' ) ) { - stat = 'defense'; - } else { - return true; - } - idrinth.settings.change ( 'stats#stats', idrinth.settings.get ( 'stats#stats' ) - getCost ( stat ) ); - result.stats -= getCost ( stat ); - result[stat]++; - idrinth.settings.change ( 'stats#' + stat, idrinth.settings.get ( 'stats#' + stat ) + 1 ); - return false; - }; - var result = { - stats: 0, - attack: 0, - defense: 0, - perception: 0 - }; - while ( idrinth.settings.get ( 'stats#stats' ) > 0 ) { - if ( increaseSingle ( result ) ) { - break; - } - } - for (var key in result) { - if ( result.hasOwnProperty ( key ) ) { - document.getElementById ( 'idrinth-stats-' + key ).parentNode.parentNode.childNodes[2].innerHTML = result[key] < 0 ? result[key] : '+' + result[key]; - document.getElementById ( 'idrinth-stats-' + key ).value = Number.parseInt ( document.getElementById ( 'idrinth-stats-' + key ).value, 10 ) + result[key]; - } - } + var getCost = function(stat) { + return ( + Math.ceil( + Math.max( + 0, + idrinth.settings.get("stats#" + stat) - + 10000 - + Math.floor( + Math.max(idrinth.settings.get("stats#level") / 500 - 2, 0) + ) * + 1500 + ) / 1500 + ) + 1 + ); + }; + var perc = addProcs(addOnePerc(), "perception") / getCost("perception"); + var defense = addProcs(addOneDefense(), "defense") / getCost("defense"); + var attack = addProcs(addOneAttack(), "attack") / getCost("attack"); + var stat = null; + if ( + perc >= defense && + perc >= attack && + idrinth.settings.get("stats#stats") >= getCost("perception") + ) { + stat = "perception"; + } else if ( + attack >= defense && + attack >= perc && + idrinth.settings.get("stats#stats") >= getCost("attack") + ) { + stat = "attack"; + } else if ( + defense >= perc && + defense >= attack && + idrinth.settings.get("stats#stats") >= getCost("defense") + ) { + stat = "defense"; + } else { + return true; + } + idrinth.settings.change( + "stats#stats", + idrinth.settings.get("stats#stats") - getCost(stat) + ); + result.stats -= getCost(stat); + result[stat]++; + idrinth.settings.change( + "stats#" + stat, + idrinth.settings.get("stats#" + stat) + 1 + ); + return false; + }; + var result = { + stats: 0, + attack: 0, + defense: 0, + perception: 0 + }; + while (idrinth.settings.get("stats#stats") > 0) { + if (increaseSingle(result)) { + break; + } + } + for (var key in result) { + if (result.hasOwnProperty(key)) { + document.getElementById( + "idrinth-stats-" + key + ).parentNode.parentNode.childNodes[2].innerHTML = result[key] < 0 + ? result[key] + : "+" + result[key]; + document.getElementById("idrinth-stats-" + key).value = + Number.parseInt( + document.getElementById("idrinth-stats-" + key).value, + 10 + ) + result[key]; + } } -}; \ No newline at end of file + } +}; diff --git a/src/mods/text.js b/src/mods/text.js index e56ac8a..66bd7f9 100644 --- a/src/mods/text.js +++ b/src/mods/text.js @@ -1,78 +1,95 @@ idrinth.text = { - /** + /** * if the language files have been applied correctly, this is true * @type Boolean */ - initialized: false, - /** + initialized: false, + /** * Loads language specific code and signals it's readyness by setting * idrinth.text.initialized to true * @returns {undefined} */ - start: function () { - var language = idrinth.settings.get ( "lang" ) || window.navigator.userLanguage || window.navigator.language || "en"; - idrinth.settings.change ( "lang", language ); - if ( language === "en" ) { - idrinth.text.initialized = true; - return; - } - idrinth.core.ajax.runHome ( 'userscript-translation/' + language + '/###RELOAD-VERSION###/', function ( file ) { - /** + start: function() { + var language = + idrinth.settings.get("lang") || + window.navigator.userLanguage || + window.navigator.language || + "en"; + idrinth.settings.change("lang", language); + if (language === "en") { + idrinth.text.initialized = true; + return; + } + idrinth.core.ajax.runHome( + "userscript-translation/" + language + "/###RELOAD-VERSION###/", + function(file) { + /** * * @param {object} to * @param {object} from * @param {function} func * @returns {undefined} */ - var applyRecursive = function ( to, from, func ) { - for (var prop in from) { - if ( from.hasOwnProperty ( prop ) ) { - if ( typeof to[prop] === 'string' && typeof from[prop] === 'string' ) { - to[prop] = from[prop]; - } else if ( typeof to[prop] === 'object' && typeof from[prop] === 'object' ) { - func ( to[prop], from[prop], func ); - } - } - } - }; - try { - applyRecursive ( idrinth.text.data, JSON.parse ( file ), applyRecursive ); - idrinth.text.initialized = true; - } catch ( e ) { - idrinth.core.log ( e.message ? e.message : e.getMessage ( ) ); - return idrinth.text.start (); + var applyRecursive = function(to, from, func) { + for (var prop in from) { + if (from.hasOwnProperty(prop)) { + if ( + typeof to[prop] === "string" && + typeof from[prop] === "string" + ) { + to[prop] = from[prop]; + } else if ( + typeof to[prop] === "object" && + typeof from[prop] === "object" + ) { + func(to[prop], from[prop], func); + } } - }, idrinth.text.start, idrinth.text.start, null, true ); - }, - /** + } + }; + try { + applyRecursive(idrinth.text.data, JSON.parse(file), applyRecursive); + idrinth.text.initialized = true; + } catch (e) { + idrinth.core.log(e.message ? e.message : e.getMessage()); + return idrinth.text.start(); + } + }, + idrinth.text.start, + idrinth.text.start, + null, + true + ); + }, + /** * See languages/en.json for an example * @type {object} */ - data: JSON.parse ( '###LANG###' ), - /** + data: JSON.parse("###LANG###"), + /** * returns the translation of a provided key or an error-message if no * matching translation is found * @param string key * @returns {string} */ - get: function ( key ) { - /** + get: function(key) { + /** * * @param {object} obj * @param {Array} keys * @param {function} func * @returns {string} */ - var getSub = function ( obj, keys, func ) { - var key = keys.shift (); - if ( obj.hasOwnProperty ( key ) ) { - if ( keys.length > 0 ) { - return func ( obj[key], keys, func ); - } - return obj[key]; - } - return idrinth.text.data.default; - }; - return getSub ( idrinth.text.data, key.split ( '.' ), getSub ); - } -}; \ No newline at end of file + var getSub = function(obj, keys, func) { + var key = keys.shift(); + if (obj.hasOwnProperty(key)) { + if (keys.length > 0) { + return func(obj[key], keys, func); + } + return obj[key]; + } + return idrinth.text.data.default; + }; + return getSub(idrinth.text.data, key.split("."), getSub); + } +}; diff --git a/src/mods/tier.js b/src/mods/tier.js index 23e7563..22d55b2 100644 --- a/src/mods/tier.js +++ b/src/mods/tier.js @@ -1,194 +1,229 @@ idrinth.tier = { - /** + /** * * @type {object} */ - list: { }, - /** + list: {}, + /** * * @type {object} */ - taggedSlots: { }, - /** + taggedSlots: {}, + /** * * @param {string} name * @returns {undefined} */ - addTagged: function ( name ) { - /** + addTagged: function(name) { + /** * * @param {string} key * @returns {Boolean} */ - var isValidParameter = function ( name ) { - return name && idrinth.tier.list.hasOwnProperty ( name ) && typeof idrinth.tier.list[name] !== 'function' && !document.getElementById ( 'idrinth-tier-box-' + name ); - }; - /** + var isValidParameter = function(name) { + return ( + name && + idrinth.tier.list.hasOwnProperty(name) && + typeof idrinth.tier.list[name] !== "function" && + !document.getElementById("idrinth-tier-box-" + name) + ); + }; + /** * * @param {string} key * @returns {Boolean} */ - var isFreeSlot = function ( key ) { - return idrinth.tier.taggedSlots.hasOwnProperty ( key ) && typeof key !== 'function' && idrinth.tier.taggedSlots[key] === null; - }; - if ( !isValidParameter ( name ) ) { - return; - } - var boss = this.list[name]; - /** + var isFreeSlot = function(key) { + return ( + idrinth.tier.taggedSlots.hasOwnProperty(key) && + typeof key !== "function" && + idrinth.tier.taggedSlots[key] === null + ); + }; + if (!isValidParameter(name)) { + return; + } + var boss = this.list[name]; + /** * * @param {int} x * @param {string} name * @returns {undefined} */ - var make = function ( x, name ) { - var makeElement = function ( label, number, description ) { - return { - content: label + ' ' + idrinth.ui.formatNumber ( number ), - attributes: [ { - name: 'title', - value: description - } ] - }; - }; - var info = [ - makeElement ( 'FS', boss.fs.nm, idrinth.text.get ( "tier.FS" ) ), - makeElement ( 'AP', boss.ap, idrinth.text.get ( "tier.AP" ) ) - ]; - if ( boss.os && boss.os.nm ) { - info.push ( makeElement ( 'OS', boss.os.nm, idrinth.text.get ( "tier.OS" ) ) ); - info.unshift ( makeElement ( 'MA', boss.nm[boss.nm.length - 1], idrinth.text.get ( "tier.MA" ) ) ); - info.unshift ( makeElement ( 'MI', boss.nm[0], idrinth.text.get ( "tier.MI" ) ) ); + var make = function(x, name) { + var makeElement = function(label, number, description) { + return { + content: label + " " + idrinth.ui.formatNumber(number), + attributes: [ + { + name: "title", + value: description } - info.unshift ( - { - type: 'strong', - content: boss.name.replace ( /\(.*$/, '' ) - } ); - idrinth.tier.taggedSlots[x] = idrinth.ui.buildElement ( - { - id: 'idrinth-tier-box-' + name, - css: 'idrinth-hovering-box idrinth-tier-box', - children: [ { - children: info - } ], - attributes: [ - { - name: 'title', - value: idrinth.text.get ( "tier.clickClose" ) - }, - { - name: 'onclick', - value: 'idrinth.ui.removeElement(this.id);idrinth.tier.taggedSlots[\'' + x + '\']=null;' - }, - { - name: 'style', - value: 'left:' + x + 'px;background-image: url(https://dotd.idrinth.de/static/raid-image-service/' + boss.url + '/);' - } - ] - } - ); - idrinth.ui.base.appendChild ( idrinth.tier.taggedSlots[x] ); + ] }; - for (var key in this.taggedSlots) { - if ( isFreeSlot ( key ) ) { - return make ( key, name ); - } - } - idrinth.core.alert ( idrinth.text.get ( "tier.maxBoxes" ) ); - }, - /** + }; + var info = [ + makeElement("FS", boss.fs.nm, idrinth.text.get("tier.FS")), + makeElement("AP", boss.ap, idrinth.text.get("tier.AP")) + ]; + if (boss.os && boss.os.nm) { + info.push(makeElement("OS", boss.os.nm, idrinth.text.get("tier.OS"))); + info.unshift( + makeElement( + "MA", + boss.nm[boss.nm.length - 1], + idrinth.text.get("tier.MA") + ) + ); + info.unshift( + makeElement("MI", boss.nm[0], idrinth.text.get("tier.MI")) + ); + } + info.unshift({ + type: "strong", + content: boss.name.replace(/\(.*$/, "") + }); + idrinth.tier.taggedSlots[x] = idrinth.ui.buildElement({ + id: "idrinth-tier-box-" + name, + css: "idrinth-hovering-box idrinth-tier-box", + children: [ + { + children: info + } + ], + attributes: [ + { + name: "title", + value: idrinth.text.get("tier.clickClose") + }, + { + name: "onclick", + value: "idrinth.ui.removeElement(this.id);idrinth.tier.taggedSlots['" + + x + + "']=null;" + }, + { + name: "style", + value: "left:" + + x + + "px;background-image: url(https://dotd.idrinth.de/static/raid-image-service/" + + boss.url + + "/);" + } + ] + }); + idrinth.ui.base.appendChild(idrinth.tier.taggedSlots[x]); + }; + for (var key in this.taggedSlots) { + if (isFreeSlot(key)) { + return make(key, name); + } + } + idrinth.core.alert(idrinth.text.get("tier.maxBoxes")); + }, + /** * initializes this module * @returns {undefined} */ - start: function ( ) { - var pos = 1; - /** + start: function() { + var pos = 1; + /** * parsed a json-response and fills tier list and exclusion list * @param {string} data * @returns {undefined} */ - var importData = function ( data ) { - data = JSON.parse ( data ); - if ( data ) { - idrinth.tier.list = data; - /** + var importData = function(data) { + data = JSON.parse(data); + if (data) { + idrinth.tier.list = data; + /** * * @param {string} name * @param {string} url * @returns {undefined} */ - var create = function ( name, url ) { - if ( !idrinth.settings.data.bannedRaids[name] ) { - idrinth.settings.data.bannedRaids[name] = false; - window.localStorage.setItem ( 'idotd', JSON.stringify ( idrinth.settings.data ) ); - } - document.getElementById ( 'idrinth-raid-may-join-list' ).appendChild ( idrinth.ui.buildElement ( { - name: 'bannedRaids#' + name, - rType: '#input', - type: 'checkbox', - id: 'idrinth-raid-may-join-list-' + name, - label: idrinth.text.get ( "raids.disableJoining" ) + name - } ) ); - document.getElementById ( 'idrinth-raid-may-join-list' ).lastChild.setAttribute ( 'style', - 'background-image:url(https://dotd.idrinth.de/static/raid-image-service/' + url + '/);' ); - }; - for (var key in data) { - if ( data[key].name ) { - create ( data[key].name, data[key].url ); - } - } - } else { - idrinth.core.timeouts.add ( 'tier', idrinth.tier.start, 1000 ); - } + var create = function(name, url) { + if (!idrinth.settings.data.bannedRaids[name]) { + idrinth.settings.data.bannedRaids[name] = false; + window.localStorage.setItem( + "idotd", + JSON.stringify(idrinth.settings.data) + ); + } + document.getElementById("idrinth-raid-may-join-list").appendChild( + idrinth.ui.buildElement({ + name: "bannedRaids#" + name, + rType: "#input", + type: "checkbox", + id: "idrinth-raid-may-join-list-" + name, + label: idrinth.text.get("raids.disableJoining") + name + }) + ); + document + .getElementById("idrinth-raid-may-join-list") + .lastChild.setAttribute( + "style", + "background-image:url(https://dotd.idrinth.de/static/raid-image-service/" + + url + + "/);" + ); }; - while ( 0 < window.innerWidth - 140 * ( pos + 1 ) ) { - this.taggedSlots[( pos * 140 ).toString ( )] = null; - pos++; + for (var key in data) { + if (data[key].name) { + create(data[key].name, data[key].url); + } } - idrinth.core.ajax.runHome ( - 'tier-service/', - importData, - function ( ) { - idrinth.core.timeouts.add ( 'tier', idrinth.tier.start, 10000 ); - }, - function ( ) { - idrinth.core.timeouts.add ( 'tier', idrinth.tier.start, 10000 ); - } - ); - }, - /** + } else { + idrinth.core.timeouts.add("tier", idrinth.tier.start, 1000); + } + }; + while (0 < window.innerWidth - 140 * (pos + 1)) { + this.taggedSlots[(pos * 140).toString()] = null; + pos++; + } + idrinth.core.ajax.runHome( + "tier-service/", + importData, + function() { + idrinth.core.timeouts.add("tier", idrinth.tier.start, 10000); + }, + function() { + idrinth.core.timeouts.add("tier", idrinth.tier.start, 10000); + } + ); + }, + /** * displays bosses that match both name and type * @returns {undefined} */ - getMatchingTiers: function ( ) { - /** + getMatchingTiers: function() { + /** * * @param {string} list * @returns {undefined} */ - var makeList = function ( list ) { - /** + var makeList = function(list) { + /** * * @param {HTMLElement} elem * @returns {undefined} */ - var clearInnerHtml = function ( elem ) { - elem.innerHTML = ''; - }; - /** + var clearInnerHtml = function(elem) { + elem.innerHTML = ""; + }; + /** * * @param {string} listKey * @param {string} difficulty * @param {string} ic * @returns {object} for the buildElement wrapper */ - var makeField = function ( listKey, difficulty, ic ) { - var ln = { - type: 'td', - attributes: [ ] - }; - /** + var makeField = function(listKey, difficulty, ic) { + var ln = { + type: "td", + attributes: [] + }; + /** * * @param {object} ln * @param {string} listKey @@ -196,36 +231,46 @@ idrinth.tier = { * @param {string} ic * @returns {object} for the buildElement wrapper */ - var addTitle = function ( ln, listKey, difficulty, ic ) { - /** + var addTitle = function(ln, listKey, difficulty, ic) { + /** * * @param {string} listKey * @param {string} difficulty * @param {string} ic * @returns {Boolean} */ - var isUseable = function ( listKey, difficulty, ic ) { - return idrinth.tier.list[listKey].hasOwnProperty ( 'loot' ) && - idrinth.tier.list[listKey].loot.hasOwnProperty ( difficulty ) && - idrinth.tier.list[listKey].loot[difficulty].hasOwnProperty ( ic ) && - idrinth.tier.list[listKey].loot[difficulty][ic]; - }; - if ( !isUseable ( listKey, difficulty, ic ) ) { - return ln; - } - var title = ""; - for (var key in idrinth.tier.list[listKey].loot[difficulty][ic]) { - if ( idrinth.tier.list[listKey].loot[difficulty][ic].hasOwnProperty ( key ) ) { - title += idrinth.tier.list[listKey].loot[difficulty][ic][key] + " " + idrinth.text.get ( 'tier.loot.' + key ) + "\n"; - } - } - ln.attributes.push ( { - name: 'title', - value: title - } ); - return ln; - }; - /** + var isUseable = function(listKey, difficulty, ic) { + return ( + idrinth.tier.list[listKey].hasOwnProperty("loot") && + idrinth.tier.list[listKey].loot.hasOwnProperty(difficulty) && + idrinth.tier.list[listKey].loot[difficulty].hasOwnProperty(ic) && + idrinth.tier.list[listKey].loot[difficulty][ic] + ); + }; + if (!isUseable(listKey, difficulty, ic)) { + return ln; + } + var title = ""; + for (var key in idrinth.tier.list[listKey].loot[difficulty][ic]) { + if ( + idrinth.tier.list[listKey].loot[difficulty][ic].hasOwnProperty( + key + ) + ) { + title += + idrinth.tier.list[listKey].loot[difficulty][ic][key] + + " " + + idrinth.text.get("tier.loot." + key) + + "\n"; + } + } + ln.attributes.push({ + name: "title", + value: title + }); + return ln; + }; + /** * * @param {object} ln * @param {string} listKey @@ -233,256 +278,304 @@ idrinth.tier = { * @param {string} ic * @returns {object} for the buildElement wrapper */ - var addContent = function ( ln, listKey, difficulty, ic ) { - /** + var addContent = function(ln, listKey, difficulty, ic) { + /** * * @param {string} os numeric string * @param {string} current numeric string * @returns {Boolean} */ - var isOs = function ( os, current ) { - return Number.parseInt ( os, 10 ) === Number.parseInt ( current, 10 ); - }; - if ( - !idrinth.tier.list[listKey].hasOwnProperty ( difficulty ) || - !idrinth.tier.list[listKey][difficulty].hasOwnProperty ( ic ) - ) { - return ln; - } - ln.css = isOs ( idrinth.tier.list[listKey].os[difficulty], idrinth.tier.list[listKey][difficulty][ic] ) ? 'is-os' : ''; - ln.content = idrinth.ui.formatNumber ( idrinth.tier.list[listKey][difficulty][ic] ); - if ( - idrinth.tier.list[listKey].epics && - idrinth.tier.list[listKey].epics.hasOwnProperty ( difficulty ) && - idrinth.tier.list[listKey].epics[difficulty].hasOwnProperty ( ic ) - ) { - ln.content += ' ' + idrinth.tier.list[listKey].epics[difficulty][ic] + 'E'; - } - return ln; - }; - return addContent ( addTitle ( ln, listKey, difficulty, ic ), listKey, difficulty, ic ); - }; - /** + var isOs = function(os, current) { + return Number.parseInt(os, 10) === Number.parseInt(current, 10); + }; + if ( + !idrinth.tier.list[listKey].hasOwnProperty(difficulty) || + !idrinth.tier.list[listKey][difficulty].hasOwnProperty(ic) + ) { + return ln; + } + ln.css = isOs( + idrinth.tier.list[listKey].os[difficulty], + idrinth.tier.list[listKey][difficulty][ic] + ) + ? "is-os" + : ""; + ln.content = idrinth.ui.formatNumber( + idrinth.tier.list[listKey][difficulty][ic] + ); + if ( + idrinth.tier.list[listKey].epics && + idrinth.tier.list[listKey].epics.hasOwnProperty(difficulty) && + idrinth.tier.list[listKey].epics[difficulty].hasOwnProperty(ic) + ) { + ln.content += + " " + idrinth.tier.list[listKey].epics[difficulty][ic] + "E"; + } + return ln; + }; + return addContent( + addTitle(ln, listKey, difficulty, ic), + listKey, + difficulty, + ic + ); + }; + /** * * @param {string} title * @param {object} dataset * @returns {HTMLElement} */ - var makeRow = function ( title, dataset ) { - return { - type: 'tr', - children: [ - { - type: 'th', - content: title - }, - { - type: 'td', - content: idrinth.ui.formatNumber ( dataset.n ) - }, - { - type: 'td', - content: idrinth.ui.formatNumber ( dataset.h ) - }, - { - type: 'td', - content: idrinth.ui.formatNumber ( dataset.l ) - }, - { - type: 'td', - content: idrinth.ui.formatNumber ( dataset.nm ) - } - ] - }; - }; - var wrapper = document.getElementById ( 'idrinth-tierlist' ); - clearInnerHtml ( wrapper ); - /** + var makeRow = function(title, dataset) { + return { + type: "tr", + children: [ + { + type: "th", + content: title + }, + { + type: "td", + content: idrinth.ui.formatNumber(dataset.n) + }, + { + type: "td", + content: idrinth.ui.formatNumber(dataset.h) + }, + { + type: "td", + content: idrinth.ui.formatNumber(dataset.l) + }, + { + type: "td", + content: idrinth.ui.formatNumber(dataset.nm) + } + ] + }; + }; + var wrapper = document.getElementById("idrinth-tierlist"); + clearInnerHtml(wrapper); + /** * * @param {Array} list * @returns {String} */ - var formattedList = function ( list ) { - var fList = [ ]; - for (var count = 0; count < list.length; count++) { - fList.push ( idrinth.ui.formatNumber ( list[count] ) ); - } - return fList.join ( ' | ' ); - }; - /** + var formattedList = function(list) { + var fList = []; + for (var count = 0; count < list.length; count++) { + fList.push(idrinth.ui.formatNumber(list[count])); + } + return fList.join(" | "); + }; + /** * * @param {string} label * @param {string} click * @returns {object} */ - var makeButton = function ( label, click ) { - return { - type: 'button', - content: idrinth.text.get ( "tier." + label ), - attributes: [ - { - name: 'onclick', - value: click - }, - { - name: 'type', - value: 'action' - } - ] - }; - }; - for (var count = list.length - 1; count >= 0; count--) { - var boss = idrinth.tier.list[list[count]]; - var sub = idrinth.ui.buildElement ( { - css: 'tier-wrapper', - children: [ + var makeButton = function(label, click) { + return { + type: "button", + content: idrinth.text.get("tier." + label), + attributes: [ + { + name: "onclick", + value: click + }, + { + name: "type", + value: "action" + } + ] + }; + }; + for (var count = list.length - 1; count >= 0; count--) { + var boss = idrinth.tier.list[list[count]]; + var sub = idrinth.ui.buildElement({ + css: "tier-wrapper", + children: [ + { + type: "img", + attributes: [ + { + name: "src", + value: "https://dotd.idrinth.de/static/raid-image-service/" + + boss.url + + "/" + } + ] + }, + { + type: "strong", + content: boss.name + }, + { + type: "span", + content: boss.types.join(", ") + }, + makeButton( + "copy", + 'idrinth.core.copyToClipboard.text("' + + boss.name + + "(NM): OS " + + idrinth.ui.formatNumber(boss.os.nm) + + ", AP " + + idrinth.ui.formatNumber(boss.ap) + + ", Tiers " + + formattedList(boss.nm) + + ' by IDotD")' + ), + makeButton( + "tag", + "idrinth.tier.addTagged('" + + list[count].replace(/'/g, "\\'") + + "');" + ), + { + type: "span", + content: "AP: " + idrinth.ui.formatNumber(boss.ap) + }, + { + type: "table", + children: [ + { + type: "thead", + children: [ + { + type: "tr", + children: [ { - type: 'img', - attributes: [ { - name: 'src', - value: 'https://dotd.idrinth.de/static/raid-image-service/' + boss.url + '/' - } ] + type: "th", + content: "#" }, { - type: 'strong', - content: boss.name + type: "th", + content: idrinth.text.get("tier.diff.normal") }, { - type: 'span', - content: boss.types.join ( ', ' ) + type: "th", + content: idrinth.text.get("tier.diff.hard") }, - makeButton ( - 'copy', - 'idrinth.core.copyToClipboard.text("' + boss.name + '(NM): OS ' + idrinth.ui.formatNumber ( boss.os.nm ) + ', AP ' + idrinth.ui.formatNumber ( boss.ap ) + ', Tiers ' + formattedList ( boss.nm ) + ' by IDotD")' - ), - makeButton ( - 'tag', - 'idrinth.tier.addTagged(\'' + list[count].replace ( /'/g, '\\\'' ) + '\');' - ), { - type: 'span', - content: 'AP: ' + idrinth.ui.formatNumber ( boss.ap ) + type: "th", + content: idrinth.text.get("tier.diff.legend") }, { - type: 'table', - children: [ - { - type: 'thead', - children: [ - { - type: 'tr', - children: [ - { - type: 'th', - content: '#' - }, - { - type: 'th', - content: idrinth.text.get ( "tier.diff.normal" ) - }, - { - type: 'th', - content: idrinth.text.get ( "tier.diff.hard" ) - }, - { - type: 'th', - content: idrinth.text.get ( "tier.diff.legend" ) - }, - { - type: 'th', - content: idrinth.text.get ( "tier.diff.night" ) - } - ] - } - ] - }, - { - type: 'tbody', - children: [ - makeRow ( 'FS', boss.fs ), - makeRow ( 'OS', boss.os ), - makeRow ( '', { - n: '', - l: '', - h: '', - nm: '' - } ) - ] - } - ] + type: "th", + content: idrinth.text.get("tier.diff.night") } - ] - } ); - var maxTiers = Math.max ( boss.n.length, boss.h.length, boss.l.length, boss.nm.length ); - for (var ic = 0; ic < maxTiers; ic++) { - sub.lastChild.lastChild.appendChild ( idrinth.ui.buildElement ( { - type: 'tr', - children: [ - { - type: 'th', - content: ic + 1 - }, - makeField ( list[count], 'n', ic ), - makeField ( list[count], 'h', ic ), - makeField ( list[count], 'l', ic ), - makeField ( list[count], 'nm', ic ) - ] - } ) ); + ] + } + ] + }, + { + type: "tbody", + children: [ + makeRow("FS", boss.fs), + makeRow("OS", boss.os), + makeRow("", { + n: "", + l: "", + h: "", + nm: "" + }) + ] } - wrapper.appendChild ( sub ); + ] } - }; - /** + ] + }); + var maxTiers = Math.max( + boss.n.length, + boss.h.length, + boss.l.length, + boss.nm.length + ); + for (var ic = 0; ic < maxTiers; ic++) { + sub.lastChild.lastChild.appendChild( + idrinth.ui.buildElement({ + type: "tr", + children: [ + { + type: "th", + content: ic + 1 + }, + makeField(list[count], "n", ic), + makeField(list[count], "h", ic), + makeField(list[count], "l", ic), + makeField(list[count], "nm", ic) + ] + }) + ); + } + wrapper.appendChild(sub); + } + }; + /** * * @param {object} data * @returns {Array} */ - var filter = function ( data ) { - /** + var filter = function(data) { + /** * * @param {Array} list * @param {RegExp} regExp * @returns {Boolean} */ - var matchesAny = function ( list, regExp ) { - for (var count = 0; count < list.length; count++) { - if ( list[count] && list[count].match ( regExp ) ) { - return true; - } - } - return regExp.toString () === '/(?:)/i'; - }; - if ( ( !data.name || data.name.length === 0 ) && ( !data.type || data.type.length === 0 ) ) { - return [ ]; - } - var result = [ ]; - var nameRegExp = new RegExp ( data.name, 'i' ); - var typeRegExp = new RegExp ( data.type, 'i' ); - for (var key in data.list) { - if ( key.match ( nameRegExp ) && matchesAny ( data.list[key].types, typeRegExp ) ) { - result.push ( key ); - } - } - return result; - }; - idrinth.core.addWorker ( filter, makeList, { - name: document.getElementById ( 'idrinth-tierlist-namesearch' ).value, - type: document.getElementById ( 'idrinth-tierlist-typesearch' ).value, - list: idrinth.tier.list - } ); - }, - /** + var matchesAny = function(list, regExp) { + for (var count = 0; count < list.length; count++) { + if (list[count] && list[count].match(regExp)) { + return true; + } + } + return regExp.toString() === "/(?:)/i"; + }; + if ( + (!data.name || data.name.length === 0) && + (!data.type || data.type.length === 0) + ) { + return []; + } + var result = []; + var nameRegExp = new RegExp(data.name, "i"); + var typeRegExp = new RegExp(data.type, "i"); + for (var key in data.list) { + if ( + key.match(nameRegExp) && + matchesAny(data.list[key].types, typeRegExp) + ) { + result.push(key); + } + } + return result; + }; + idrinth.core.addWorker(filter, makeList, { + name: document.getElementById("idrinth-tierlist-namesearch").value, + type: document.getElementById("idrinth-tierlist-typesearch").value, + list: idrinth.tier.list + }); + }, + /** * * @param {Boolean} yes * @returns {undefined} */ - allCheck: function ( yes ) { - var boxes = document.getElementById ( 'idrinth-raid-may-join-list' ).getElementsByTagName ( 'input' ); - for (var counter = boxes.length - 1; counter >= 0; counter--) { - if ( boxes[counter].getAttribute ( 'type' ) === 'checkbox' && boxes[counter].checked !== yes ) { - boxes[counter].checked = yes; - idrinth.settings.change ( ( boxes[counter].getAttribute ( 'id' ) ).replace ( /idrinth-/, '' ), yes ); - } - } + allCheck: function(yes) { + var boxes = document + .getElementById("idrinth-raid-may-join-list") + .getElementsByTagName("input"); + for (var counter = boxes.length - 1; counter >= 0; counter--) { + if ( + boxes[counter].getAttribute("type") === "checkbox" && + boxes[counter].checked !== yes + ) { + boxes[counter].checked = yes; + idrinth.settings.change( + boxes[counter].getAttribute("id").replace(/idrinth-/, ""), + yes + ); + } } -}; \ No newline at end of file + } +}; diff --git a/src/mods/ui.js b/src/mods/ui.js index 1cb4c13..02518f2 100644 --- a/src/mods/ui.js +++ b/src/mods/ui.js @@ -1,37 +1,37 @@ idrinth.ui = { - /** + /** * * @type HTMLElement */ - tooltip: null, - /** + tooltip: null, + /** * * @type HTMLElement */ - base: null, - /** + base: null, + /** * * @type HTMLElement */ - controls: null, - /** + controls: null, + /** * * @param {Number} number * @returns {String} */ - formatNumber: function ( number ) { - if ( isNaN ( number ) ) { - return ''; - } - var count = 0; - var post = [ '', 'k', 'm', 'b', 't', 'qa', 'qi', 's' ]; - while ( number > 999 && count < post.length ) { - number = Math.round ( number / 10 ) / 100; - count++; - } - return number.toString () + post[count]; - }, - /** + formatNumber: function(number) { + if (isNaN(number)) { + return ""; + } + var count = 0; + var post = ["", "k", "m", "b", "t", "qa", "qi", "s"]; + while (number > 999 && count < post.length) { + number = Math.round(number / 10) / 100; + count++; + } + return number.toString() + post[count]; + }, + /** * * @param {Number} id * @param {string} name @@ -39,1148 +39,1376 @@ idrinth.ui = { * @param {string} pass * @returns {undefined} */ - buildChat: function ( id, name, rank, pass ) { - if ( !idrinth.chat.elements.chats ) { - idrinth.core.timeouts.add ( 'chat-' + id, function () { - idrinth.ui.buildChat ( id, name, rank, pass ); - }, 500 ); - } - idrinth.chat.elements.chats.appendChild ( idrinth.ui.buildElement ( { - type: 'li', - id: 'idrinth-chat-tab-' + id, - css: rank.toLowerCase (), + buildChat: function(id, name, rank, pass) { + if (!idrinth.chat.elements.chats) { + idrinth.core.timeouts.add( + "chat-" + id, + function() { + idrinth.ui.buildChat(id, name, rank, pass); + }, + 500 + ); + } + idrinth.chat.elements.chats.appendChild( + idrinth.ui.buildElement({ + type: "li", + id: "idrinth-chat-tab-" + id, + css: rank.toLowerCase(), + attributes: [ + { + name: "data-id", + value: id + } + ], + children: [ + { + type: "ul", + css: "styled-scrollbar users" + }, + { + type: "ul", + css: "styled-scrollbar chat" + }, + { + type: "input", + css: "add-chat-box", + id: "idrinth-chat-input-" + id, attributes: [ - { - name: 'data-id', - value: id - } - ], - children: [ - { - type: 'ul', - css: "styled-scrollbar users" - }, - { - type: 'ul', - css: "styled-scrollbar chat" - }, - { - type: 'input', - css: 'add-chat-box', - id: "idrinth-chat-input-" + id, - attributes: [ - { - name: 'title', - value: 'press ENTER or RETURN to send' - }, - { - name: 'onkeyup', - value: 'if(event.keyCode===13||event.which===13){idrinth.chat.send(' + id + ');}' - } - ] - } + { + name: "title", + value: "press ENTER or RETURN to send" + }, + { + name: "onkeyup", + value: "if(event.keyCode===13||event.which===13){idrinth.chat.send(" + + id + + ");}" + } ] - } ) ); - idrinth.chat.elements.menu.appendChild ( - idrinth.ui.buildElement ( - { - type: 'li', - content: name, - id: 'idrinth-chat-tab-click-' + id, - attributes: [ - { - name: 'data-id', - value: id - }, - { - name: 'title', - value: name + "\nID:" + id + "\nPassword: " + pass - }, - { - name: 'onclick', - value: 'idrinth.chat.enableChat(this);' - }, - { - name: 'oncontextmenu', - value: 'idrinth.chat.showOptions(event,this);' - } - ] - } - ) - ); - }, - /** + } + ] + }) + ); + idrinth.chat.elements.menu.appendChild( + idrinth.ui.buildElement({ + type: "li", + content: name, + id: "idrinth-chat-tab-click-" + id, + attributes: [ + { + name: "data-id", + value: id + }, + { + name: "title", + value: name + "\nID:" + id + "\nPassword: " + pass + }, + { + name: "onclick", + value: "idrinth.chat.enableChat(this);" + }, + { + name: "oncontextmenu", + value: "idrinth.chat.showOptions(event,this);" + } + ] + }) + ); + }, + /** * * @param {HTMLElement} element * @param {Number} offsetX * @param {Number} offsetY * @returns {String} */ - getElementPositioning: function ( element, offsetX, offsetY ) { - var pos = { - x: element.getBoundingClientRect ().left + ( offsetX ? offsetX : 0 ), - y: element.getBoundingClientRect ().top + ( offsetY ? offsetY : 0 ) - }; - return 'position:fixed;left:' + pos.x + 'px;top:' + pos.y + 'px'; - }, - /** + getElementPositioning: function(element, offsetX, offsetY) { + var pos = { + x: element.getBoundingClientRect().left + (offsetX ? offsetX : 0), + y: element.getBoundingClientRect().top + (offsetY ? offsetY : 0) + }; + return "position:fixed;left:" + pos.x + "px;top:" + pos.y + "px"; + }, + /** * * @param {object} config * @returns {HTMLElement} */ - buildElement: function ( config ) { - /** + buildElement: function(config) { + /** * * @param {HTMLElement} el * @param {object} config * @returns {undefined} */ - var setBase = function ( el, config ) { - if ( config.id ) { - el.id = config.id; - } - if ( config.css ) { - el.setAttribute ( 'class', config.css ); - } - if ( config.content ) { - el.appendChild ( document.createTextNode ( config.content ) ); - } - }; - /** + var setBase = function(el, config) { + if (config.id) { + el.id = config.id; + } + if (config.css) { + el.setAttribute("class", config.css); + } + if (config.content) { + el.appendChild(document.createTextNode(config.content)); + } + }; + /** * * @param {HTMLElement} el * @param {object} config * @returns {undefined} */ - var addChildren = function ( el, config ) { - if ( !config.children || !config.children.length ) { - return; - } - for (var count = 0, l = config.children.length; count < l; count++) { - el.appendChild ( idrinth.ui.buildElement ( config.children[count] ) ); - } - }; - /** + var addChildren = function(el, config) { + if (!config.children || !config.children.length) { + return; + } + for (var count = 0, l = config.children.length; count < l; count++) { + el.appendChild(idrinth.ui.buildElement(config.children[count])); + } + }; + /** * * @param {HTMLElement} el * @param {object} config * @returns {undefined} */ - var addAttributes = function ( el, config ) { - /** + var addAttributes = function(el, config) { + /** * * @param {HTMLElement} el * @param {object} set * @returns {undefined} */ - var applyValue = function ( el, set ) { - if ( !set || set.value === undefined ) { - return; - } - if ( set.name ) { - set.names = [ set.name ]; - } - if ( set.names && Array.isArray ( set.names ) ) { - for (var pos = 0; pos < set.names.length; pos++) { - el.setAttribute ( set.names[pos], set.value ); - } - } - }; - if ( !config.attributes || !config.attributes.length ) { - return; - } - for (var count = 0, l = config.attributes.length; count < l; count++) { - applyValue ( el, config.attributes[count] ); - } - }; - /** + var applyValue = function(el, set) { + if (!set || set.value === undefined) { + return; + } + if (set.name) { + set.names = [set.name]; + } + if (set.names && Array.isArray(set.names)) { + for (var pos = 0; pos < set.names.length; pos++) { + el.setAttribute(set.names[pos], set.value); + } + } + }; + if (!config.attributes || !config.attributes.length) { + return; + } + for (var count = 0, l = config.attributes.length; count < l; count++) { + applyValue(el, config.attributes[count]); + } + }; + /** * * @param {object} config * @returns {HTMLElement} */ - var makeInputLabel = function ( config ) { - /** + var makeInputLabel = function(config) { + /** * * @param {String|Number} value * @param {Array} list * @returns {Boolean} */ - var inArray = function ( value, list ) { - if ( !Array.isArray ( list ) ) { - return false; - } - if ( typeof list.includes === 'function' ) { - return list.includes ( value ); - } - return list.indexOf ( value ) > -1; - }; - var input = [ { - name: 'type', - value: config.type - } ]; - if ( idrinth.settings.get ( config.name ) && config.type === 'checkbox' ) { - input.push ( { - name: 'checked', - value: 'checked' - } ); - } - if ( config.type !== 'checkbox' ) { - input.push ( { - name: 'value', - value: idrinth.settings.get ( config.name ) - } ); - input.push ( { - name: 'onchange', - value: 'idrinth.settings.change(\'' + config.name + '\',this.value)' - } ); - } else { - input.push ( { - name: 'onchange', - value: 'idrinth.settings.change(\'' + config.name + '\',this.checked)' - } ); - } - var translation = idrinth.text.get ( config.label ); - return idrinth.ui.buildElement ( { - css: 'idrinth-line' + ( config.platforms && !inArray ( idrinth.platform, config.platforms ) ? ' idrinth-hide' : '' ), - children: [ { - type: 'label', - css: 'idrinth-float-half', - content: translation === idrinth.text.data.default ? config.label : translation, - attributes: [ { - name: 'for', - value: 'idrinth-' + config.name - } ] - }, { - type: 'input', - css: 'idrinth-float-half', - id: 'idrinth-' + config.name, - attributes: input - } ] - } ); - }; - if ( config.type === '#text' ) { - return document.createTextNode ( config.content ); + var inArray = function(value, list) { + if (!Array.isArray(list)) { + return false; } - if ( config.rType === '#input' ) { - return makeInputLabel ( config ); + if (typeof list.includes === "function") { + return list.includes(value); } - var el = document.createElement ( config.type ? config.type : 'div' ); - setBase ( el, config ); - addChildren ( el, config ); - addAttributes ( el, config ); - return el; - }, - /** + return list.indexOf(value) > -1; + }; + var input = [ + { + name: "type", + value: config.type + } + ]; + if (idrinth.settings.get(config.name) && config.type === "checkbox") { + input.push({ + name: "checked", + value: "checked" + }); + } + if (config.type !== "checkbox") { + input.push({ + name: "value", + value: idrinth.settings.get(config.name) + }); + input.push({ + name: "onchange", + value: "idrinth.settings.change('" + config.name + "',this.value)" + }); + } else { + input.push({ + name: "onchange", + value: "idrinth.settings.change('" + config.name + "',this.checked)" + }); + } + var translation = idrinth.text.get(config.label); + return idrinth.ui.buildElement({ + css: "idrinth-line" + + (config.platforms && !inArray(idrinth.platform, config.platforms) + ? " idrinth-hide" + : ""), + children: [ + { + type: "label", + css: "idrinth-float-half", + content: translation === idrinth.text.data.default + ? config.label + : translation, + attributes: [ + { + name: "for", + value: "idrinth-" + config.name + } + ] + }, + { + type: "input", + css: "idrinth-float-half", + id: "idrinth-" + config.name, + attributes: input + } + ] + }); + }; + if (config.type === "#text") { + return document.createTextNode(config.content); + } + if (config.rType === "#input") { + return makeInputLabel(config); + } + var el = document.createElement(config.type ? config.type : "div"); + setBase(el, config); + addChildren(el, config); + addAttributes(el, config); + return el; + }, + /** * * @param {string} title * @param {string|HTMLElement} content * @param {string} altFunc * @returns {undefined} */ - buildModal: function ( title, content, altFunc ) { - var mod = { - children: [ ], - css: 'idrinth-hovering-box idrinth-popup idrinth-' + ( typeof altFunc === 'string' ? 'confim' : 'alert' ) - }; - if ( typeof title === 'string' ) { - mod.children.push ( { - content: title, - css: 'header' - } ); - } else { - mod.children.push ( { - content: 'Title missing', - css: 'header' - } ); - } - if ( typeof content === 'string' ) { - mod.children.push ( { - content: content, - css: 'content' - } ); - } else if ( typeof content === 'object' && content.type ) { - mod.children.push ( { - children: content, - css: 'content' - } ); - } else { - mod.children.push ( { - children: 'Content missing', - css: 'content' - } ); - } - mod.children.push ( { - css: 'buttons' - } ); - /** + buildModal: function(title, content, altFunc) { + var mod = { + children: [], + css: "idrinth-hovering-box idrinth-popup idrinth-" + + (typeof altFunc === "string" ? "confim" : "alert") + }; + if (typeof title === "string") { + mod.children.push({ + content: title, + css: "header" + }); + } else { + mod.children.push({ + content: "Title missing", + css: "header" + }); + } + if (typeof content === "string") { + mod.children.push({ + content: content, + css: "content" + }); + } else if (typeof content === "object" && content.type) { + mod.children.push({ + children: content, + css: "content" + }); + } else { + mod.children.push({ + children: "Content missing", + css: "content" + }); + } + mod.children.push({ + css: "buttons" + }); + /** * * @param {String} text * @param {String} func * @returns {object} */ - var makeButton = function ( text, func ) { - return { - type: 'button', - content: idrinth.text.get ( "button." + text ), - attributes: [ { - name: 'onclick', - value: 'this.parentNode.parentNode.parentNode.removeChild(this.parentNode.parentNode);' + func - } ] - }; - }; - if ( typeof altFunc === 'string' ) { - mod.children[mod.children.length - 1].children = [ - makeButton ( 'ok', altFunc ), - makeButton ( 'cancel', '' ) - ]; - } else { - mod.children[mod.children.length - 1].children = [ makeButton ( 'ok', '' ) ]; - } - idrinth.ui.base.appendChild ( idrinth.ui.buildElement ( mod ) ); - }, - /** + var makeButton = function(text, func) { + return { + type: "button", + content: idrinth.text.get("button." + text), + attributes: [ + { + name: "onclick", + value: "this.parentNode.parentNode.parentNode.removeChild(this.parentNode.parentNode);" + + func + } + ] + }; + }; + if (typeof altFunc === "string") { + mod.children[mod.children.length - 1].children = [ + makeButton("ok", altFunc), + makeButton("cancel", "") + ]; + } else { + mod.children[mod.children.length - 1].children = [makeButton("ok", "")]; + } + idrinth.ui.base.appendChild(idrinth.ui.buildElement(mod)); + }, + /** * * @param {HTMLElement} element * @param {string} selector * @returns {HTMLElement} */ - matchesCss: function ( element, selector ) { - while ( element && element !== document ) { - if ( typeof element.matches === 'function' && element.matches ( selector ) ) { - return element; - } - element = element.parentNode - } - }, - /** + matchesCss: function(element, selector) { + while (element && element !== document) { + if (typeof element.matches === "function" && element.matches(selector)) { + return element; + } + element = element.parentNode; + } + }, + /** * * @returns {undefined} */ - setTooltipTimeout: function () { - idrinth.core.timeouts.add ( 'names.tooltip', idrinth.ui.hideTooltip, idrinth.settings.get ( "timeout" ) ? idrinth.settings.get ( "timeout" ) : 5000 ); - }, - /** + setTooltipTimeout: function() { + idrinth.core.timeouts.add( + "names.tooltip", + idrinth.ui.hideTooltip, + idrinth.settings.get("timeout") ? idrinth.settings.get("timeout") : 5000 + ); + }, + /** * * @returns {undefined} */ - hideTooltip: function () { - if ( idrinth.names.isHovering ) { - return idrinth.ui.setTooltipTimeout (); - } - idrinth.ui.updateClassesList ( idrinth.ui.tooltip, [ 'idrinth-hide' ], [ ] ); - }, - /** + hideTooltip: function() { + if (idrinth.names.isHovering) { + return idrinth.ui.setTooltipTimeout(); + } + idrinth.ui.updateClassesList(idrinth.ui.tooltip, ["idrinth-hide"], []); + }, + /** * * @returns {undefined} */ - openCloseSettings: function () { - var toRemove = [ ( idrinth.ui.controls.getAttribute ( 'class' ) ).match ( /(^|\s)inactive($|\s)/ ) ? 'inactive' : 'active' ]; - if ( !idrinth.settings.get ( "moveLeft" ) ) { - toRemove.push ( 'left-sided' ); - } - if ( !idrinth.settings.get ( "minimalist" ) ) { - toRemove.push ( 'small' ); - } - idrinth.ui.updateClassesList ( idrinth.ui.controls, [ 'active', 'inactive', 'left-sided', 'small' ], toRemove ); - }, - /** + openCloseSettings: function() { + var toRemove = [ + idrinth.ui.controls.getAttribute("class").match(/(^|\s)inactive($|\s)/) + ? "inactive" + : "active" + ]; + if (!idrinth.settings.get("moveLeft")) { + toRemove.push("left-sided"); + } + if (!idrinth.settings.get("minimalist")) { + toRemove.push("small"); + } + idrinth.ui.updateClassesList( + idrinth.ui.controls, + ["active", "inactive", "left-sided", "small"], + toRemove + ); + }, + /** * * @param {HTMLElement} element * @param {String} cssClass * @returns {Boolean} */ - childOf: function ( element, cssClass ) { - do { - if ( element.className && element.className.match ( new RegExp ( '(^|\s)' + cssClass + '(\s|$)' ) ) ) { - return true; - } - if ( !element.parentNode || element === idrinth.ui.base ) { - return false; - } - element = element.parentNode; - } while ( element ); + childOf: function(element, cssClass) { + do { + if ( + element.className && + element.className.match(new RegExp("(^|\s)" + cssClass + "(\s|$)")) + ) { + return true; + } + if (!element.parentNode || element === idrinth.ui.base) { return false; - }, - /** + } + element = element.parentNode; + } while (element); + return false; + }, + /** * * @param {string} id * @returns {undefined} */ - removeElement: function ( id ) { - var el = document.getElementById ( id ); - if ( el ) { - el.parentNode.removeChild ( el ); - } - }, - /** + removeElement: function(id) { + var el = document.getElementById(id); + if (el) { + el.parentNode.removeChild(el); + } + }, + /** * * @param {HTMLElement} element * @param {Array|String} add * @param {Array|String} remove * @returns {undefined} */ - updateClassesList: function ( element, add, remove ) { - /** + updateClassesList: function(element, add, remove) { + /** * * @param {String} classString * @param {Array|String} add * @param {Array|String} remove * @returns {unresolved} */ - var getClassesList = function ( classString, add, remove ) { - /** + var getClassesList = function(classString, add, remove) { + /** * * @param {String|Array} value * @returns {Array} */ - var forceToArray = function ( value ) { - return value && typeof value === 'object' && Array.isArray ( value ) && value !== null ? value : [ ]; - }; - var original = classString === null ? [ ] : classString.split ( ' ' ).concat ( forceToArray ( add ) ); - var list = [ ]; - remove = forceToArray ( remove ); - /** + var forceToArray = function(value) { + return value && + typeof value === "object" && + Array.isArray(value) && + value !== null + ? value + : []; + }; + var original = classString === null + ? [] + : classString.split(" ").concat(forceToArray(add)); + var list = []; + remove = forceToArray(remove); + /** * * @param {Array} list * @param {string} element * @param {Array} forbidden * @returns {unresolved} */ - var addUnique = function ( list, element, forbidden ) { - if ( list.indexOf ( element ) === -1 && forbidden.indexOf ( element ) === -1 ) { - list.push ( element ); - } - return list; - }; - for (var counter = 0; counter < original.length; counter++) { - list = addUnique ( list, original[counter], remove ); - } - return list.join ( ' ' ); - }; - element.setAttribute ( 'class', getClassesList ( element.getAttribute ( 'class' ), add, remove ) ); - }, - /** + var addUnique = function(list, element, forbidden) { + if (list.indexOf(element) === -1 && forbidden.indexOf(element) === -1) { + list.push(element); + } + return list; + }; + for (var counter = 0; counter < original.length; counter++) { + list = addUnique(list, original[counter], remove); + } + return list.join(" "); + }; + element.setAttribute( + "class", + getClassesList(element.getAttribute("class"), add, remove) + ); + }, + /** * * @param {String} name * @returns {undefined} */ - activateTab: function ( name ) { - var head = document.getElementById ( 'tab-activator-' + name ).parentNode.childNodes; - var body = document.getElementById ( 'tab-element-' + name ).parentNode.childNodes; - /** + activateTab: function(name) { + var head = document.getElementById("tab-activator-" + name).parentNode + .childNodes; + var body = document.getElementById("tab-element-" + name).parentNode + .childNodes; + /** * * @param {HTMLElement} head * @param {HTMLElement} body * @param {string} name * @returns {undefined} */ - var setClasses = function ( head, body, name ) { - if ( head === document.getElementById ( 'tab-activator-' + name ) ) { - idrinth.ui.updateClassesList ( head, [ 'active' ], [ ] ); - idrinth.ui.updateClassesList ( body, [ ], [ 'idrinth-hide' ] ); - return; - } - idrinth.ui.updateClassesList ( head, [ ], [ 'active' ] ); - idrinth.ui.updateClassesList ( body, [ 'idrinth-hide' ], [ ] ); - }; - for (var count = 0; count < head.length; count++) { - setClasses ( head[count], body[count], name ); - } - }, - /** + var setClasses = function(head, body, name) { + if (head === document.getElementById("tab-activator-" + name)) { + idrinth.ui.updateClassesList(head, ["active"], []); + idrinth.ui.updateClassesList(body, [], ["idrinth-hide"]); + return; + } + idrinth.ui.updateClassesList(head, [], ["active"]); + idrinth.ui.updateClassesList(body, ["idrinth-hide"], []); + }; + for (var count = 0; count < head.length; count++) { + setClasses(head[count], body[count], name); + } + }, + /** * initializes the gui * @returns {undefined} */ - start: function () { - /** + start: function() { + /** * builds most of the gui * @returns {undefined} */ - var build = function () { - /** + var build = function() { + /** * * @returns {Array} */ - var wrapper = function () { - /** + var wrapper = function() { + /** * creates the action tab * @returns {Array} */ - var buildActions = function () { - /** + var buildActions = function() { + /** * * @param {string} label * @param {string} onclick * @param {string} platform * @returns {object} */ - var buttonMaker = function ( label, onclick, platform ) { - return { - css: 'idrinth-float-half' + ( platform && platform !== idrinth.platform ? " idrinth-hide" : "" ), - type: 'button', - content: label, - attributes: [ { - name: 'type', - value: 'button' - }, { - name: 'onclick', - value: onclick - } ] - }; - }; - return [ { - children: [ - buttonMaker ( idrinth.text.get ( "raids.imports.manually" ), 'idrinth.raids.import(\'\');' ), - buttonMaker ( idrinth.text.get ( "raids.imports.favs" ), 'idrinth.raids.import(idrinth.settings.get("favs"));' ), - buttonMaker ( idrinth.text.get ( "button.reloadGame" ), 'idrinth.inframe.send(\'reload\',\'dotd\');' ), - buttonMaker ( idrinth.text.get ( "button.reloadChat" ), 'idrinth.inframe.send(\'reload\',\'chatclient\');' ), - buttonMaker ( idrinth.text.get ( "raids.clear" ), 'idrinth.raids.clearAll();' ), - buttonMaker ( idrinth.text.get ( "button.reloadScript" ), 'idrinth.reload();' ), - buttonMaker ( idrinth.text.get ( "raids.imports.restart" ), 'idrinth.raids.start();' ), - buttonMaker ( idrinth.text.get ( "button.ngRaidJoin" ), 'idrinth.newgrounds.joinRaids()', 'newgrounds' ), - buttonMaker ( idrinth.settings.get ( "alarmActive" ) ? idrinth.text.get ( "button.disableTimedAutoJoin" ) : idrinth.text.get ( "button.enableTimedAutoJoin" ), - 'idrinth.settings.change(\'alarmActive\',!idrinth.settings.get("alarmActive"));this.innerHTML=idrinth.settings.get("alarmActive") ? idrinth.text.get ( "button.disableTimedAutoJoin" ):"button.enableTimedAutoJoin"', 'newgrounds' ) - ] - }, { - css: 'idrinth-line', - id: 'idrinth-joined-raids', - content: idrinth.text.get ( "raids.lastJoined" ), - children: [ - { - type: 'ul' - } - ] - } - ]; - }; - /** + var buttonMaker = function(label, onclick, platform) { + return { + css: "idrinth-float-half" + + (platform && platform !== idrinth.platform + ? " idrinth-hide" + : ""), + type: "button", + content: label, + attributes: [ + { + name: "type", + value: "button" + }, + { + name: "onclick", + value: onclick + } + ] + }; + }; + return [ + { + children: [ + buttonMaker( + idrinth.text.get("raids.imports.manually"), + "idrinth.raids.import('');" + ), + buttonMaker( + idrinth.text.get("raids.imports.favs"), + 'idrinth.raids.import(idrinth.settings.get("favs"));' + ), + buttonMaker( + idrinth.text.get("button.reloadGame"), + "idrinth.inframe.send('reload','dotd');" + ), + buttonMaker( + idrinth.text.get("button.reloadChat"), + "idrinth.inframe.send('reload','chatclient');" + ), + buttonMaker( + idrinth.text.get("raids.clear"), + "idrinth.raids.clearAll();" + ), + buttonMaker( + idrinth.text.get("button.reloadScript"), + "idrinth.reload();" + ), + buttonMaker( + idrinth.text.get("raids.imports.restart"), + "idrinth.raids.start();" + ), + buttonMaker( + idrinth.text.get("button.ngRaidJoin"), + "idrinth.newgrounds.joinRaids()", + "newgrounds" + ), + buttonMaker( + idrinth.settings.get("alarmActive") + ? idrinth.text.get("button.disableTimedAutoJoin") + : idrinth.text.get("button.enableTimedAutoJoin"), + 'idrinth.settings.change(\'alarmActive\',!idrinth.settings.get("alarmActive"));this.innerHTML=idrinth.settings.get("alarmActive") ? idrinth.text.get ( "button.disableTimedAutoJoin" ):"button.enableTimedAutoJoin"', + "newgrounds" + ) + ] + }, + { + css: "idrinth-line", + id: "idrinth-joined-raids", + content: idrinth.text.get("raids.lastJoined"), + children: [ + { + type: "ul" + } + ] + } + ]; + }; + /** * * @returns {Array} */ - var buildTiers = function () { - /** + var buildTiers = function() { + /** * * @param {string} label * @returns {object} */ - var makeSearch = function ( label ) { - return { - type: 'input', - css: 'idrinth-float-half', - id: 'idrinth-tierlist-' + label + 'search', - attributes: [ - { - names: [ 'onblur', 'onchange', 'onkeyup' ], - value: 'idrinth.tier.getMatchingTiers();' - }, - { - names: [ 'placeholder', 'title' ], - value: idrinth.text.get ( "tier." + label ) - } - ] - }; - }; - return [ { - css: 'idrinth-line', - children: [ { - type: 'label', - content: idrinth.text.get ( "tier.search" ), - css: 'idrinth-line', - attributes: [ - { - name: 'for', - value: 'idrinth-tierlist-bosssearch' - } - ] - }, - makeSearch ( 'name' ), - makeSearch ( 'type' ) - ] - }, { - id: 'idrinth-tierlist' - } ]; - }; - /** + var makeSearch = function(label) { + return { + type: "input", + css: "idrinth-float-half", + id: "idrinth-tierlist-" + label + "search", + attributes: [ + { + names: ["onblur", "onchange", "onkeyup"], + value: "idrinth.tier.getMatchingTiers();" + }, + { + names: ["placeholder", "title"], + value: idrinth.text.get("tier." + label) + } + ] + }; + }; + return [ + { + css: "idrinth-line", + children: [ + { + type: "label", + content: idrinth.text.get("tier.search"), + css: "idrinth-line", + attributes: [ + { + name: "for", + value: "idrinth-tierlist-bosssearch" + } + ] + }, + makeSearch("name"), + makeSearch("type") + ] + }, + { + id: "idrinth-tierlist" + } + ]; + }; + /** * * @returns {Array} */ - var buildControls = function () { - /** + var buildControls = function() { + /** * * @param {Array} list * @param {String} header * @returns {object} */ - var wrap = function ( list, header ) { - return { - children: [ - { - type: 'strong', - content: idrinth.text.get ( "ui.wrap." + header ) - }, - { - children: list - } - ], - css: 'idrinth-openclick' - }; - }; - /** + var wrap = function(list, header) { + return { + children: [ + { + type: "strong", + content: idrinth.text.get("ui.wrap." + header) + }, + { + children: list + } + ], + css: "idrinth-openclick" + }; + }; + /** * * @param {HTMLElement} element * @returns {undefined} */ - var openCloseSwitch = function ( element ) { - var isActive = ( element.parentElement.getAttribute ( 'class' ) ).match ( /(^|\s)active($|\s)/ ); - idrinth.ui.updateClassesList ( element.parentElement, isActive ? [ ] : [ 'active' ], isActive ? [ 'active' ] : [ ] ); - }; - idrinth.core.multibind.add ( 'click', '.idrinth-openclick > strong', openCloseSwitch ); - return [ - wrap ( [ { - name: 'lang', - rType: '#input', - type: 'text', - label: "setting.lang" - }, { - name: 'minimalist', - rType: '#input', - type: 'checkbox', - label: "setting.minimLayout" - }, { - name: 'moveLeft', - rType: '#input', - type: 'checkbox', - label: "setting.moveSettingLeft" - }, { - name: 'warBottom', - rType: '#input', - type: 'checkbox', - label: "setting.warBottomPage" - } ], 'general' ), - wrap ( [ { - name: 'names', - rType: '#input', - type: 'checkbox', - platforms: [ 'kongregate' ], - label: "setting.enableExtCharInfo" - }, { - name: 'timeout', - rType: '#input', - type: 'number', - platforms: [ 'kongregate' ], - label: "setting.extCharInfoDuration" - } ], 'names' ), - wrap ( [ { - name: 'landMax', - rType: '#input', - type: 'checkbox', - label: "setting.useGoldEfficiently" - }, { - name: 'factor', - rType: '#input', - type: 'checkbox', - label: "setting.tenBuildOnce" - } ], 'landbuy' ), - wrap ( [ { - name: 'raids', - rType: '#input', - type: 'checkbox', - label: "setting.enableFavRequest" - }, { - name: 'raidWhitelist', - rType: '#input', - type: 'checkbox', - label: "setting.raidWhitelist" - }, { - name: 'favs', - rType: '#input', - type: 'text', - label: "setting.favIdToJoin" - }, { - name: 'isWorldServer', - rType: '#input', - type: 'checkbox', - label: "setting.worldserver" - }, { - name: 'raid#requestPrivate', - rType: '#input', - type: 'checkbox', - label: "setting.raid.requestPrivate" - }, { - name: 'raid#joinPrivate', - rType: '#input', - type: 'checkbox', - label: "setting.raid.joinPrivate" - }, { - name: 'newgroundLoad', - rType: '#input', - type: 'number', - platforms: [ 'newgrounds' ], - label: "setting.joiningDuration" - }, { - name: 'alarmTime', - rType: '#input', - type: 'text', - platforms: [ 'newgrounds' ], - label: "ui.timeAutoJoin" - } ], 'raidjoining' ), - wrap ( [ { - name: 'chatting', - rType: '#input', - type: 'checkbox', - label: "setting.enableChat" - }, { - name: 'notification#mention', - rType: '#input', - type: 'checkbox', - label: 'chat.notification.mention' - }, { - name: 'notification#raid', - rType: '#input', - type: 'checkbox', - label: 'chat.notification.raid' - }, { - name: 'notification#message', - rType: '#input', - type: 'checkbox', - label: 'chat.notification.message' - }, { - name: 'notification#content', - rType: '#input', - type: 'checkbox', - label: 'chat.notification.content' - }, { - name: 'notification#image', - rType: '#input', - type: 'checkbox', - label: 'chat.notification.image' - } ], 'chat' ), - { - css: 'idrinth-line', - type: 'p', - children: [ { - type: '#text', - content: idrinth.text.get ( "ui.getFavFrom" ) - }, { - type: 'a', - attributes: [ { - name: 'href', - value: 'https://dotd.idrinth.de/' + idrinth.platform + '/' - }, { - name: 'target', - value: '_blank' - } ], - content: idrinth.text.get ( "ui.raidsearch" ) - } ] - } ]; - }; - /** + var openCloseSwitch = function(element) { + var isActive = element.parentElement + .getAttribute("class") + .match(/(^|\s)active($|\s)/); + idrinth.ui.updateClassesList( + element.parentElement, + isActive ? [] : ["active"], + isActive ? ["active"] : [] + ); + }; + idrinth.core.multibind.add( + "click", + ".idrinth-openclick > strong", + openCloseSwitch + ); + return [ + wrap( + [ + { + name: "lang", + rType: "#input", + type: "text", + label: "setting.lang" + }, + { + name: "minimalist", + rType: "#input", + type: "checkbox", + label: "setting.minimLayout" + }, + { + name: "moveLeft", + rType: "#input", + type: "checkbox", + label: "setting.moveSettingLeft" + }, + { + name: "warBottom", + rType: "#input", + type: "checkbox", + label: "setting.warBottomPage" + } + ], + "general" + ), + wrap( + [ + { + name: "names", + rType: "#input", + type: "checkbox", + platforms: ["kongregate"], + label: "setting.enableExtCharInfo" + }, + { + name: "timeout", + rType: "#input", + type: "number", + platforms: ["kongregate"], + label: "setting.extCharInfoDuration" + } + ], + "names" + ), + wrap( + [ + { + name: "landMax", + rType: "#input", + type: "checkbox", + label: "setting.useGoldEfficiently" + }, + { + name: "factor", + rType: "#input", + type: "checkbox", + label: "setting.tenBuildOnce" + } + ], + "landbuy" + ), + wrap( + [ + { + name: "raids", + rType: "#input", + type: "checkbox", + label: "setting.enableFavRequest" + }, + { + name: "raidWhitelist", + rType: "#input", + type: "checkbox", + label: "setting.raidWhitelist" + }, + { + name: "favs", + rType: "#input", + type: "text", + label: "setting.favIdToJoin" + }, + { + name: "isWorldServer", + rType: "#input", + type: "checkbox", + label: "setting.worldserver" + }, + { + name: "raid#requestPrivate", + rType: "#input", + type: "checkbox", + label: "setting.raid.requestPrivate" + }, + { + name: "raid#joinPrivate", + rType: "#input", + type: "checkbox", + label: "setting.raid.joinPrivate" + }, + { + name: "newgroundLoad", + rType: "#input", + type: "number", + platforms: ["newgrounds"], + label: "setting.joiningDuration" + }, + { + name: "alarmTime", + rType: "#input", + type: "text", + platforms: ["newgrounds"], + label: "ui.timeAutoJoin" + } + ], + "raidjoining" + ), + wrap( + [ + { + name: "chatting", + rType: "#input", + type: "checkbox", + label: "setting.enableChat" + }, + { + name: "notification#mention", + rType: "#input", + type: "checkbox", + label: "chat.notification.mention" + }, + { + name: "notification#raid", + rType: "#input", + type: "checkbox", + label: "chat.notification.raid" + }, + { + name: "notification#message", + rType: "#input", + type: "checkbox", + label: "chat.notification.message" + }, + { + name: "notification#content", + rType: "#input", + type: "checkbox", + label: "chat.notification.content" + }, + { + name: "notification#image", + rType: "#input", + type: "checkbox", + label: "chat.notification.image" + } + ], + "chat" + ), + { + css: "idrinth-line", + type: "p", + children: [ + { + type: "#text", + content: idrinth.text.get("ui.getFavFrom") + }, + { + type: "a", + attributes: [ + { + name: "href", + value: "https://dotd.idrinth.de/" + idrinth.platform + "/" + }, + { + name: "target", + value: "_blank" + } + ], + content: idrinth.text.get("ui.raidsearch") + } + ] + } + ]; + }; + /** * * @returns {Array} */ - var buildLand = function () { - /** + var buildLand = function() { + /** * * @param {string} label * @returns {object} */ - var buildItem = function ( label ) { - return { - type: 'tr', - children: [ { - type: 'th', - content: idrinth.text.get ( "land." + label ) - }, { - type: 'td', - children: [ { - type: 'input', - id: 'idrinth-land-' + label.toLowerCase (), - attributes: [ - { - name: 'value', - value: idrinth.settings.get ( "land#" + label.toLowerCase () ) - }, - { - name: 'type', - value: 'number' - } - ] - } ] - }, { - type: 'td', - content: '-' - } ], - attributes: [ - { - name: 'title', - value: idrinth.land.data[label.toLowerCase ()].perHour + idrinth.text.get ( "land.hour" ) - } - ] - }; - }; - return [ { - type: 'table', - id: 'idrinth-land-buy-table', - children: [ - buildItem ( 'Cornfield' ), - buildItem ( 'Stable' ), - buildItem ( 'Barn' ), - buildItem ( 'Store' ), - buildItem ( 'Pub' ), - buildItem ( 'Inn' ), - buildItem ( 'Tower' ), - buildItem ( 'Fort' ), - buildItem ( 'Castle' ), - { - type: 'tr', - children: [ { - type: 'td' - }, { - type: 'td' - }, { - type: 'td' - } ] - }, - { - type: 'tr', - children: [ { - type: 'th', - content: idrinth.text.get ( "land.available" ) - }, { - type: 'td', - children: [ { - type: 'input', - id: 'idrinth-land-gold', - attributes: [ - { - name: 'value', - value: idrinth.settings.get ( "land#gold" ) - }, - { - name: 'type', - value: 'number' - } - ] - } ] - }, { - type: 'td', - children: [ { - type: 'button', - content: idrinth.text.get ( "land.calc" ), - attributes: [ - { - name: 'onclick', - value: 'idrinth.land.calculate();' - }, - { - name: 'type', - value: 'button' - } - ] - } ] - } ] - } - ] - } ]; - }; - /** + var buildItem = function(label) { + return { + type: "tr", + children: [ + { + type: "th", + content: idrinth.text.get("land." + label) + }, + { + type: "td", + children: [ + { + type: "input", + id: "idrinth-land-" + label.toLowerCase(), + attributes: [ + { + name: "value", + value: idrinth.settings.get( + "land#" + label.toLowerCase() + ) + }, + { + name: "type", + value: "number" + } + ] + } + ] + }, + { + type: "td", + content: "-" + } + ], + attributes: [ + { + name: "title", + value: idrinth.land.data[label.toLowerCase()].perHour + + idrinth.text.get("land.hour") + } + ] + }; + }; + return [ + { + type: "table", + id: "idrinth-land-buy-table", + children: [ + buildItem("Cornfield"), + buildItem("Stable"), + buildItem("Barn"), + buildItem("Store"), + buildItem("Pub"), + buildItem("Inn"), + buildItem("Tower"), + buildItem("Fort"), + buildItem("Castle"), + { + type: "tr", + children: [ + { + type: "td" + }, + { + type: "td" + }, + { + type: "td" + } + ] + }, + { + type: "tr", + children: [ + { + type: "th", + content: idrinth.text.get("land.available") + }, + { + type: "td", + children: [ + { + type: "input", + id: "idrinth-land-gold", + attributes: [ + { + name: "value", + value: idrinth.settings.get("land#gold") + }, + { + name: "type", + value: "number" + } + ] + } + ] + }, + { + type: "td", + children: [ + { + type: "button", + content: idrinth.text.get("land.calc"), + attributes: [ + { + name: "onclick", + value: "idrinth.land.calculate();" + }, + { + name: "type", + value: "button" + } + ] + } + ] + } + ] + } + ] + } + ]; + }; + /** * * @returns {Array} */ - var buildStats = function () { - /** + var buildStats = function() { + /** * * @param {string} label * @returns {object} */ - var buildItem = function ( label ) { - var isCheck = label === 'mirele' || label === 'kraken' || label === 'utym'; - return { - type: 'tr', - children: [ { - type: 'th', - content: idrinth.text.get ( "stats." + label ) - }, { - type: 'td', - children: [ { - type: 'input', - id: 'idrinth-stats-' + label, - attributes: [ - { - name: isCheck ? 'checked' : 'value', - value: idrinth.settings.get ( "stats#" + label ) - }, - { - name: 'type', - value: isCheck ? 'checkbox' : 'number' - }, - { - names: [ 'onchange', 'onblur' ], - value: 'idrinth.settings.change(\'stats#' + label + '\',' + ( isCheck ? 'this.checked' : 'Number.parseInt ( this.value, 10 )' ) + ')' - } - ] - } ] - }, { - type: 'td', - content: '-' - } ] - }; - }; - return [ { - type: 'table', - id: 'idrinth-stat-buy-table', - children: [ - buildItem ( 'stats' ), - buildItem ( 'perception' ), - buildItem ( 'attack' ), - buildItem ( 'defense' ), - buildItem ( 'mirele' ), - buildItem ( 'utym' ), - buildItem ( 'kraken' ), - buildItem ( 'level' ), - buildItem ( 'mount' ), - buildItem ( 'critchance' ), - { - type: 'tr', - children: [ { - type: 'td' - }, { - type: 'td' - }, { - type: 'td' - } ] - }, - { - type: 'tr', - children: [ { - type: 'th' - }, { - type: 'td' - }, { - type: 'td', - children: [ { - type: 'button', - content: idrinth.text.get ( "land.calc" ), - attributes: [ - { - name: 'onclick', - value: 'idrinth.stats.calculate();' - }, - { - name: 'type', - value: 'button' - } - ] - } ] - } ] - } - ] - } ]; - }; - /** + var buildItem = function(label) { + var isCheck = + label === "mirele" || label === "kraken" || label === "utym"; + return { + type: "tr", + children: [ + { + type: "th", + content: idrinth.text.get("stats." + label) + }, + { + type: "td", + children: [ + { + type: "input", + id: "idrinth-stats-" + label, + attributes: [ + { + name: isCheck ? "checked" : "value", + value: idrinth.settings.get("stats#" + label) + }, + { + name: "type", + value: isCheck ? "checkbox" : "number" + }, + { + names: ["onchange", "onblur"], + value: "idrinth.settings.change('stats#" + + label + + "'," + + (isCheck + ? "this.checked" + : "Number.parseInt ( this.value, 10 )") + + ")" + } + ] + } + ] + }, + { + type: "td", + content: "-" + } + ] + }; + }; + return [ + { + type: "table", + id: "idrinth-stat-buy-table", + children: [ + buildItem("stats"), + buildItem("perception"), + buildItem("attack"), + buildItem("defense"), + buildItem("mirele"), + buildItem("utym"), + buildItem("kraken"), + buildItem("level"), + buildItem("mount"), + buildItem("critchance"), + { + type: "tr", + children: [ + { + type: "td" + }, + { + type: "td" + }, + { + type: "td" + } + ] + }, + { + type: "tr", + children: [ + { + type: "th" + }, + { + type: "td" + }, + { + type: "td", + children: [ + { + type: "button", + content: idrinth.text.get("land.calc"), + attributes: [ + { + name: "onclick", + value: "idrinth.stats.calculate();" + }, + { + name: "type", + value: "button" + } + ] + } + ] + } + ] + } + ] + } + ]; + }; + /** * * @param {object} config * @returns {Array} */ - var makeTabs = function ( config ) { - var head = [ ]; - var first = true; - var body = [ ]; - /** + var makeTabs = function(config) { + var head = []; + var first = true; + var body = []; + /** * * @param {string} name * @param {Number} width * @param {Boolean} first * @returns {object} */ - var buildHead = function ( name, width, first ) { - return { - type: 'li', - content: idrinth.text.get ( "ui.tabs." + name ), - css: 'tab-activator' + ( first ? ' active' : '' ), - id: 'tab-activator-' + name.toLowerCase (), - attributes: [ - { - name: 'onclick', - value: 'idrinth.ui.activateTab(\'' + name.toLowerCase () + '\');' - }, - { - name: 'style', - value: 'width:' + width + '%;' - } - ] - }; - }; - /** + var buildHead = function(name, width, first) { + return { + type: "li", + content: idrinth.text.get("ui.tabs." + name), + css: "tab-activator" + (first ? " active" : ""), + id: "tab-activator-" + name.toLowerCase(), + attributes: [ + { + name: "onclick", + value: "idrinth.ui.activateTab('" + name.toLowerCase() + "');" + }, + { + name: "style", + value: "width:" + width + "%;" + } + ] + }; + }; + /** * * @param {string} name * @param {Array} children * @param {Boolean} first * @returns {object} */ - var buildBody = function ( name, children, first ) { - return { - type: 'li', - css: 'tab-element' + ( first ? '' : ' idrinth-hide' ), - id: 'tab-element-' + name.toLowerCase (), - children: children - }; - }; - var width = Math.floor ( 100 / ( Object.keys ( config ) ).length ); - for (var name in config) { - if ( typeof name === 'string' ) { - head.push ( buildHead ( name, width, first ) ); - body.push ( buildBody ( name, config[name], first ) ); - first = false; - } - } - return [ - { - type: 'ul', - children: head, - css: 'idrinth-ui-menu' - }, - { - type: 'ul', - children: body, - css: 'idrinth-ui-menu', - attributes: [ { - name: 'style', - value: 'max-height: 500px;overflow-y: scroll;' - } ] - } - ]; - }; - /** + var buildBody = function(name, children, first) { + return { + type: "li", + css: "tab-element" + (first ? "" : " idrinth-hide"), + id: "tab-element-" + name.toLowerCase(), + children: children + }; + }; + var width = Math.floor(100 / Object.keys(config).length); + for (var name in config) { + if (typeof name === "string") { + head.push(buildHead(name, width, first)); + body.push(buildBody(name, config[name], first)); + first = false; + } + } + return [ + { + type: "ul", + children: head, + css: "idrinth-ui-menu" + }, + { + type: "ul", + children: body, + css: "idrinth-ui-menu", + attributes: [ + { + name: "style", + value: "max-height: 500px;overflow-y: scroll;" + } + ] + } + ]; + }; + /** * * @returns {Array} */ - var buildRaidJoinList = function () { - /** + var buildRaidJoinList = function() { + /** * * @param {Array} list * @param {String} header * @returns {object} */ - var wrap = function ( list, header ) { - return { - children: [ - { - type: 'strong', - content: idrinth.text.get ( "raids." + header ) - }, - { - children: list - } - ], - css: 'idrinth-openclick' - }; - }; - return [ - wrap ( [ { - id: 'idrinth-raid-link-list' - } ], - "clickCopy" - ), - wrap ( [ { - content: idrinth.text.get ( "raids.disable.none" ), - type: 'button', - attributes: [ - { - name: 'onclick', - value: 'idrinth.tier.allCheck(false)' - }, { - name: 'style', - value: 'width:50%;' - } ] - }, { - content: idrinth.text.get ( "raids.disable.all" ), - type: 'button', - attributes: [ - { - name: 'onclick', - value: 'idrinth.tier.allCheck(true)' - }, { - name: 'style', - value: 'width:50%;' - } ] - }, { - id: 'idrinth-raid-may-join-list' - } ], "disableSpecific" ) ]; - }; - return makeTabs ( { - 'Actions': buildActions (), - 'Raids': buildRaidJoinList (), - 'Settings': buildControls (), - 'Tiers': buildTiers (), - 'Land': buildLand (), - 'Stats': buildStats () - } ); + var wrap = function(list, header) { + return { + children: [ + { + type: "strong", + content: idrinth.text.get("raids." + header) + }, + { + children: list + } + ], + css: "idrinth-openclick" }; - var children = wrapper (); - children.unshift ( { - css: 'idrinth-line', - type: 'strong', - children: [ + }; + return [ + wrap( + [ + { + id: "idrinth-raid-link-list" + } + ], + "clickCopy" + ), + wrap( + [ + { + content: idrinth.text.get("raids.disable.none"), + type: "button", + attributes: [ + { + name: "onclick", + value: "idrinth.tier.allCheck(false)" + }, + { + name: "style", + value: "width:50%;" + } + ] + }, + { + content: idrinth.text.get("raids.disable.all"), + type: "button", + attributes: [ { - type: 'span', - content: 'Idrinth\'s' + name: "onclick", + value: "idrinth.tier.allCheck(true)" }, { - type: 'span', - content: ' DotD Script v' + idrinth.version + name: "style", + value: "width:50%;" } - ], - attributes: [ { - name: 'title', - value: 'Click to open/close' - }, { - name: 'onclick', - value: 'idrinth.ui.openCloseSettings();' - }, { - name: 'style', - value: 'display:block;cursor:pointer;' - } ] - } ); - idrinth.ui.controls = idrinth.ui.buildElement ( { - css: 'idrinth-hovering-box idrinth-controls-overwrite inactive' + ( idrinth.settings.get ( "moveLeft" ) ? ' left-sided' : '' ) + ( idrinth.settings.get ( "minimalist" ) ? ' small' : '' ), - id: 'idrinth-controls', - children: children - } ); - idrinth.ui.base.appendChild ( idrinth.ui.controls ); - document.getElementById ( 'idrinth-favs' ).setAttribute ( 'onkeyup', 'idrinth.ui.replaceInValue(this);' ); + ] + }, + { + id: "idrinth-raid-may-join-list" + } + ], + "disableSpecific" + ) + ]; }; - idrinth.ui.base = document.createElement ( 'div' ); - idrinth.ui.base.setAttribute ( 'id', 'idotd-base' ); - document.getElementsByTagName ( 'body' )[0].appendChild ( idrinth.ui.base ); - document.getElementsByTagName ( 'head' )[0].appendChild ( idrinth.ui.buildElement ( { - type: 'link', - attributes: [ { - name: 'rel', - value: 'stylesheet' - }, { - name: 'href', - value: 'https://dotd.idrinth.de/static/userscript-styles/###RELOAD-VERSION###/' - } ] - } ) ); - build (); - }, - /** + return makeTabs({ + Actions: buildActions(), + Raids: buildRaidJoinList(), + Settings: buildControls(), + Tiers: buildTiers(), + Land: buildLand(), + Stats: buildStats() + }); + }; + var children = wrapper(); + children.unshift({ + css: "idrinth-line", + type: "strong", + children: [ + { + type: "span", + content: "Idrinth's" + }, + { + type: "span", + content: " DotD Script v" + idrinth.version + } + ], + attributes: [ + { + name: "title", + value: "Click to open/close" + }, + { + name: "onclick", + value: "idrinth.ui.openCloseSettings();" + }, + { + name: "style", + value: "display:block;cursor:pointer;" + } + ] + }); + idrinth.ui.controls = idrinth.ui.buildElement({ + css: "idrinth-hovering-box idrinth-controls-overwrite inactive" + + (idrinth.settings.get("moveLeft") ? " left-sided" : "") + + (idrinth.settings.get("minimalist") ? " small" : ""), + id: "idrinth-controls", + children: children + }); + idrinth.ui.base.appendChild(idrinth.ui.controls); + document + .getElementById("idrinth-favs") + .setAttribute("onkeyup", "idrinth.ui.replaceInValue(this);"); + }; + idrinth.ui.base = document.createElement("div"); + idrinth.ui.base.setAttribute("id", "idotd-base"); + document.getElementsByTagName("body")[0].appendChild(idrinth.ui.base); + document.getElementsByTagName("head")[0].appendChild( + idrinth.ui.buildElement({ + type: "link", + attributes: [ + { + name: "rel", + value: "stylesheet" + }, + { + name: "href", + value: "https://dotd.idrinth.de/static/userscript-styles/###RELOAD-VERSION###/" + } + ] + }) + ); + build(); + }, + /** * * @param {HTMLElement} element * @returns {undefined} */ - replaceInValue: function ( element ) { - var pos = element.selectionStart; - var part = element.value.substr ( 0, pos + 1 ); - var pre = part.length; - part = part.replace ( /[^a-f0-9,]/g, '' ); - part = part.replace ( /,{2,}/g, ',' ); - pos = pos + part.length - pre; - element.value = element.value.replace ( /[^a-f0-9,]/g, '' ); - element.value = element.value.replace ( /,{2,}/g, ',' ); - pos = Math.min ( pos, element.value.length ); - pos = Math.max ( pos, 0 ); - element.setSelectionRange ( pos, pos ); - } -}; \ No newline at end of file + replaceInValue: function(element) { + var pos = element.selectionStart; + var part = element.value.substr(0, pos + 1); + var pre = part.length; + part = part.replace(/[^a-f0-9,]/g, ""); + part = part.replace(/,{2,}/g, ","); + pos = pos + part.length - pre; + element.value = element.value.replace(/[^a-f0-9,]/g, ""); + element.value = element.value.replace(/,{2,}/g, ","); + pos = Math.min(pos, element.value.length); + pos = Math.max(pos, 0); + element.setSelectionRange(pos, pos); + } +}; diff --git a/src/mods/user.js b/src/mods/user.js index 9033e66..db7a664 100644 --- a/src/mods/user.js +++ b/src/mods/user.js @@ -1,97 +1,135 @@ idrinth.user = { - /** + /** * * @type String */ - token: '', - /** + token: "", + /** * * @type Number */ - id: 0, - /** + id: 0, + /** * * @type String */ - name: '', - /** + name: "", + /** * * @type String */ - identifier: '', - /** + identifier: "", + /** * initializes the module * @returns {undefined} */ - start: function () { - /** + start: function() { + /** * * @param {Sstring} name * @returns {String} */ - var getCookie = function ( name ) { - var ca = document.cookie.split ( ';' ); - for (var i = 0; i < ca.length; i++) { - ca[i] = ca[i].replace ( /^\s*|\s*$/, '' ); - if ( ca[i].indexOf ( name + '=' ) === 0 ) { - return ca[i].substring ( name.length + 1, ca[i].length ); - } - } - return ""; - }; - if ( idrinth.platform === 'kongregate' ) { - idrinth.user.name = active_user._attributes.get ( 'username' ); - idrinth.user.token = active_user.gameAuthToken (); - idrinth.user.id = active_user.id (); - } else if ( idrinth.platform === 'newgrounds' ) { - idrinth.user.name = getCookie ( 'NG_GG_username' ); - } else if ( idrinth.platform === 'armorgames' ) { - var ag = document.getElementById ( 'gamefilearea' ).children[0].src.match ( /^.+user_id=([a-f\d]{32})&auth_token=([a-f\d]{32}).+$/ ); - idrinth.user.name = window.u_name; - idrinth.user.id = ag[1]; - idrinth.user.token = ag[2]; + var getCookie = function(name) { + var ca = document.cookie.split(";"); + for (var i = 0; i < ca.length; i++) { + ca[i] = ca[i].replace(/^\s*|\s*$/, ""); + if (ca[i].indexOf(name + "=") === 0) { + return ca[i].substring(name.length + 1, ca[i].length); } - /** + } + return ""; + }; + if (idrinth.platform === "kongregate") { + idrinth.user.name = active_user._attributes.get("username"); + idrinth.user.token = active_user.gameAuthToken(); + idrinth.user.id = active_user.id(); + } else if (idrinth.platform === "newgrounds") { + idrinth.user.name = getCookie("NG_GG_username"); + } else if (idrinth.platform === "armorgames") { + var ag = document + .getElementById("gamefilearea") + .children[0].src.match( + /^.+user_id=([a-f\d]{32})&auth_token=([a-f\d]{32}).+$/ + ); + idrinth.user.name = window.u_name; + idrinth.user.id = ag[1]; + idrinth.user.token = ag[2]; + } + /** * sends an id to the server for statistic purposes * @returns {undefined} */ - var sendAlive = function () { - /** + var sendAlive = function() { + /** * * @returns {String|idrinth.user.identifier} */ - var getIdentifier = function () { - /** + var getIdentifier = function() { + /** * from http://stackoverflow.com/a/105074 * @returns {String} */ - var guid = function () { - /** + var guid = function() { + /** * * @returns {String} */ - var s4 = function () { - return Math.floor ( ( 1 + Math.random () ) * 0x10000 ).toString ( 36 ); - }; - return s4 () + '-' + - s4 () + s4 () + '-' + - s4 () + s4 () + s4 () + '-' + - s4 () + s4 () + s4 () + s4 () + '-' + - s4 () + s4 () + s4 () + s4 () + s4 () + '-' + - s4 () + s4 () + s4 () + s4 () + s4 () + s4 (); - }; - idrinth.user.identifier = window.localStorage.getItem ( 'idrinth-dotd-uuid' ); - if ( !idrinth.user.identifier || idrinth.user.identifier === '' || idrinth.user.identifier === null || !idrinth.user.identifier.match ( /^[a-z0-9]{4}-[a-z0-9]{8}-[a-z0-9]{12}-[a-z0-9]{16}-[a-z0-9]{20}-[a-z0-9]{24}$/ ) ) { - idrinth.user.identifier = guid (); - } - window.localStorage.setItem ( 'idrinth-dotd-uuid', idrinth.user.identifier ); - return idrinth.user.identifier; - }; - if ( !window.localStorage ) { - return; - } - idrinth.core.ajax.runHome ( 'i-am-alive/' + getIdentifier () + '/' ); + var s4 = function() { + return Math.floor((1 + Math.random()) * 0x10000).toString(36); + }; + return ( + s4() + + "-" + + s4() + + s4() + + "-" + + s4() + + s4() + + s4() + + "-" + + s4() + + s4() + + s4() + + s4() + + "-" + + s4() + + s4() + + s4() + + s4() + + s4() + + "-" + + s4() + + s4() + + s4() + + s4() + + s4() + + s4() + ); }; - idrinth.core.timeouts.add ( 'user', sendAlive, 20000 ); - } -}; \ No newline at end of file + idrinth.user.identifier = window.localStorage.getItem( + "idrinth-dotd-uuid" + ); + if ( + !idrinth.user.identifier || + idrinth.user.identifier === "" || + idrinth.user.identifier === null || + !idrinth.user.identifier.match( + /^[a-z0-9]{4}-[a-z0-9]{8}-[a-z0-9]{12}-[a-z0-9]{16}-[a-z0-9]{20}-[a-z0-9]{24}$/ + ) + ) { + idrinth.user.identifier = guid(); + } + window.localStorage.setItem( + "idrinth-dotd-uuid", + idrinth.user.identifier + ); + return idrinth.user.identifier; + }; + if (!window.localStorage) { + return; + } + idrinth.core.ajax.runHome("i-am-alive/" + getIdentifier() + "/"); + }; + idrinth.core.timeouts.add("user", sendAlive, 20000); + } +}; diff --git a/src/mods/war.js b/src/mods/war.js index 4751929..ea7898c 100644 --- a/src/mods/war.js +++ b/src/mods/war.js @@ -1,335 +1,386 @@ idrinth.war = { - /** + /** * * @type {string} */ - from: null, - /** + from: null, + /** * * @type {string} */ - to: null, - /** + to: null, + /** * * @type {HTMLElement} */ - element: null, - /** + element: null, + /** * sets the timeout * @returns {undefined} */ - setTO: function ( ) { - var active = ( idrinth.war.element.getAttribute ( 'class' ) ).match ( /(^|\s)idrinth-hide($|\s)/ ) !== null; - idrinth.core.timeouts.add ( 'war', idrinth.war.getData, active ? 30000 : 120000, -1 ); - }, - /** + setTO: function() { + var active = + idrinth.war.element + .getAttribute("class") + .match(/(^|\s)idrinth-hide($|\s)/) !== null; + idrinth.core.timeouts.add( + "war", + idrinth.war.getData, + active ? 30000 : 120000, + -1 + ); + }, + /** * requests data from the server * @returns {undefined} */ - getData: function () { - /** + getData: function() { + /** * * @param {object} data * @returns {undefined} */ - var updateData = function ( data ) { - /** + var updateData = function(data) { + /** * * @param {object} data * @returns {undefined} */ - var process = function ( data ) { - /** + var process = function(data) { + /** * * @param {Boolean} onOff * @returns {undefined} */ - var toggleGUI = function ( onOff ) { - var toggle = onOff || false; - var addClasses = [ ]; - var removeClasses = [ ]; - if ( toggle === true ) { - removeClasses.push ( 'idrinth-hide' ); - addClasses.push ( "bottom" ); - if ( !idrinth.settings.get ( "warBottom" ) ) { - removeClasses.push ( "bottom" ); - } - } else { - addClasses.push ( "idrinth-hide" ); - while ( idrinth.war.element.childNodes[1].childNodes[1].firstChild ) { - idrinth.war.element.childNodes[1].childNodes[1].removeChild ( idrinth.war.element.childNodes[1].firstChild.firstChild ); - } - } - idrinth.ui.updateClassesList ( idrinth.war.element, addClasses, removeClasses ); - }; - /** + var toggleGUI = function(onOff) { + var toggle = onOff || false; + var addClasses = []; + var removeClasses = []; + if (toggle === true) { + removeClasses.push("idrinth-hide"); + addClasses.push("bottom"); + if (!idrinth.settings.get("warBottom")) { + removeClasses.push("bottom"); + } + } else { + addClasses.push("idrinth-hide"); + while (idrinth.war.element.childNodes[1].childNodes[1].firstChild) { + idrinth.war.element.childNodes[1].childNodes[1].removeChild( + idrinth.war.element.childNodes[1].firstChild.firstChild + ); + } + } + idrinth.ui.updateClassesList( + idrinth.war.element, + addClasses, + removeClasses + ); + }; + /** * * @param {object} data * @returns {undefined} */ - var processJson = function ( data ) { - var magicIgmSrv = 'https://dotd.idrinth.de/static/magic-image-service/'; - /** + var processJson = function(data) { + var magicIgmSrv = + "https://dotd.idrinth.de/static/magic-image-service/"; + /** * * @param {object} data * @returns {Array} */ - var getMagic = function ( data ) { - var magics = [ ]; - if ( !data || ( data.magics === null || data.magics === '' ) ) { - return [ ]; - } - var tmp = data.magics.split ( ',' ); - for (var key = 0; key < tmp.length; key++) { - var magic = tmp[key]; - var magicObj = { - type: 'img', - attributes: [ - { - name: 'src', - value: magicIgmSrv + magic + '/' - }, - { - name: 'width', - value: '20' - } ] - }; - magics.push ( magicObj ); - } - return magics; - }; - /** + var getMagic = function(data) { + var magics = []; + if (!data || (data.magics === null || data.magics === "")) { + return []; + } + var tmp = data.magics.split(","); + for (var key = 0; key < tmp.length; key++) { + var magic = tmp[key]; + var magicObj = { + type: "img", + attributes: [ + { + name: "src", + value: magicIgmSrv + magic + "/" + }, + { + name: "width", + value: "20" + } + ] + }; + magics.push(magicObj); + } + return magics; + }; + /** * * @param {object} raids * @returns {undefined} */ - function addRaids ( raids ) { - for (var key in raids) { - if ( idrinth.raids.joined[key] === undefined && idrinth.raids.list[key] === undefined ) { - idrinth.raids.list[key] = raids[key]; - } - } - } - /** + function addRaids(raids) { + for (var key in raids) { + if ( + idrinth.raids.joined[key] === undefined && + idrinth.raids.list[key] === undefined + ) { + idrinth.raids.list[key] = raids[key]; + } + } + } + /** * * @param {object} data * @param {HTMLElement} element * @returns {undefined} */ - function updateBoss ( data, element ) { - //TODO: Dummy function, should be removed - function cleanUp () { - while ( element.getElementsByTagName ( 'td' )[3].firstChild ) { - element.getElementsByTagName ( 'td' )[3].removeChild ( element.getElementsByTagName ( 'td' )[3].firstChild ); - } - } + function updateBoss(data, element) { + //TODO: Dummy function, should be removed + function cleanUp() { + while (element.getElementsByTagName("td")[3].firstChild) { + element + .getElementsByTagName("td")[3] + .removeChild( + element.getElementsByTagName("td")[3].firstChild + ); + } + } - cleanUp (); - var tmpMagics = getMagic ( data ); - for (var m = 0; m < tmpMagics.length; m++) { - element.getElementsByTagName ( 'td' )[3].appendChild ( idrinth.ui.buildElement ( tmpMagics[m] ) ); - } - element.getElementsByTagName ( 'td' )[0].setAttribute ( "class", 'traffic ' + ( data.amount < 90 ? 'yes' : ( data.amount > 110 ? 'no' : 'maybe' ) ) ); - element.getElementsByTagName ( 'td' )[0].setAttribute ( "title", data.amount + '/100' ); - element.getElementsByTagName ( 'td' )[0].firstChild.innerHTML = ( data.amount < 90 ? 'yes' : ( data.amount > 110 ? 'no' : 'maybe' ) ); - } - /** + cleanUp(); + var tmpMagics = getMagic(data); + for (var m = 0; m < tmpMagics.length; m++) { + element + .getElementsByTagName("td")[3] + .appendChild(idrinth.ui.buildElement(tmpMagics[m])); + } + element + .getElementsByTagName("td")[0] + .setAttribute( + "class", + "traffic " + + (data.amount < 90 + ? "yes" + : data.amount > 110 ? "no" : "maybe") + ); + element + .getElementsByTagName("td")[0] + .setAttribute("title", data.amount + "/100"); + element.getElementsByTagName("td")[ + 0 + ].firstChild.innerHTML = data.amount < 90 + ? "yes" + : data.amount > 110 ? "no" : "maybe"; + } + /** * creates a new bpss * @param {object} data * @param {string} boss * @returns {undefined} */ - function newBoss ( data, boss ) { - idrinth.war.element.childNodes[1].appendChild ( idrinth.ui.buildElement ( - { - type: 'tr', - id: 'idrinth-war-' + boss, - children: [ - { - type: 'td', - css: 'traffic ' + ( data.amount < 90 ? 'yes' : ( data.amount > 110 ? 'no' : 'maybe' ) ), - children: [ { - type: 'span', - content: ( data.amount < 90 ? 'yes' : ( data.amount > 110 ? 'no' : 'maybe' ) ) - } ], - attributes: [ - { - name: 'title', - value: data.amount + '/100' - } - ] - }, - { - type: 'td', - content: data.name - }, - { - type: 'td', - children: [ - { - type: 'input', - attributes: [ - { - name: 'type', - value: 'checkbox' - }, - { - name: 'data-id', - value: boss - }, - { - name: 'title', - value: 'join ' + data.name - } - ] - } - ] - }, - { - type: 'td', - children: getMagic ( data ) - } - ] - } - ) ); - } - if ( data.raids !== undefined ) { - addRaids ( data.raids ); - } - for (var boss in data.stats) { - if ( document.getElementById ( 'idrinth-war-' + boss ) ) { - updateBoss ( data.stats[boss], document.getElementById ( 'idrinth-war-' + boss ) ); - } else { - newBoss ( data.stats[boss], boss ); - } - } - }; - if ( data === "" || data === "null" ) { - return; - } - if ( data === "{}" ) { - toggleGUI ( false ); - return; - } - toggleGUI ( true ); - try { - processJson ( JSON.parse ( data ) ); - } catch ( e ) { - idrinth.core.log ( e ); - } - }; - process ( data ); - idrinth.war.setTO (); + function newBoss(data, boss) { + idrinth.war.element.childNodes[1].appendChild( + idrinth.ui.buildElement({ + type: "tr", + id: "idrinth-war-" + boss, + children: [ + { + type: "td", + css: "traffic " + + (data.amount < 90 + ? "yes" + : data.amount > 110 ? "no" : "maybe"), + children: [ + { + type: "span", + content: data.amount < 90 + ? "yes" + : data.amount > 110 ? "no" : "maybe" + } + ], + attributes: [ + { + name: "title", + value: data.amount + "/100" + } + ] + }, + { + type: "td", + content: data.name + }, + { + type: "td", + children: [ + { + type: "input", + attributes: [ + { + name: "type", + value: "checkbox" + }, + { + name: "data-id", + value: boss + }, + { + name: "title", + value: "join " + data.name + } + ] + } + ] + }, + { + type: "td", + children: getMagic(data) + } + ] + }) + ); + } + if (data.raids !== undefined) { + addRaids(data.raids); + } + for (var boss in data.stats) { + if (document.getElementById("idrinth-war-" + boss)) { + updateBoss( + data.stats[boss], + document.getElementById("idrinth-war-" + boss) + ); + } else { + newBoss(data.stats[boss], boss); + } + } }; - /** + if (data === "" || data === "null") { + return; + } + if (data === "{}") { + toggleGUI(false); + return; + } + toggleGUI(true); + try { + processJson(JSON.parse(data)); + } catch (e) { + idrinth.core.log(e); + } + }; + process(data); + idrinth.war.setTO(); + }; + /** * * @returns {String} */ - var raids2Join = function () { - var list = [ ]; - for (var input in idrinth.war.element.getElementsByTagName ( 'input' )) { - if ( idrinth.war.element.getElementsByTagName ( 'input' )[input].checked ) { - list.push ( idrinth.war.element.getElementsByTagName ( 'input' )[input].getAttribute ( 'data-id' ) ); - } - } - if ( list.length > 0 ) { - return list.join ( ',' ); - } - return '_'; - }; - idrinth.core.ajax.runHome ( - "war-service/" + raids2Join () + "/" + Date.now () + "/", - updateData, - idrinth.war.setTO, - idrinth.war.setTO, - idrinth.raids.knowRaids () - ); - }, - /** + var raids2Join = function() { + var list = []; + for (var input in idrinth.war.element.getElementsByTagName("input")) { + if (idrinth.war.element.getElementsByTagName("input")[input].checked) { + list.push( + idrinth.war.element + .getElementsByTagName("input")[input] + .getAttribute("data-id") + ); + } + } + if (list.length > 0) { + return list.join(","); + } + return "_"; + }; + idrinth.core.ajax.runHome( + "war-service/" + raids2Join() + "/" + Date.now() + "/", + updateData, + idrinth.war.setTO, + idrinth.war.setTO, + idrinth.raids.knowRaids() + ); + }, + /** * initializes the module * @returns {undefined} */ - start: function () { - /** + start: function() { + /** * build the gui part * @returns {undefined} */ - var build = function ( ) { - idrinth.war.element = idrinth.ui.buildElement ( - { - id: 'idrinth-war', - css: 'idrinth-central-box idrinth-hovering-box idrinth-hide', - children: [ - { - children: [ - { - type: 'span', - content: 'current WAR' - }, - { - type: 'span', - css: 'idrinth-circle', - attributes: [ - { - name: 'onclick', - value: 'this.parentNode.parentNode.hasAttribute("style")?this.parentNode.parentNode.removeAttribute("style"):this.parentNode.parentNode.setAttribute("style","bottom:0;top:auto");' - } - ], - content: '\u2195' - }, - { - type: 'span', - css: 'idrinth-circle', - attributes: [ - { - name: 'onclick', - value: 'this.parentNode.nextSibling.hasAttribute("style")?this.parentNode.nextSibling.removeAttribute("style"):this.parentNode.nextSibling.setAttribute("style","display:none");' - } - ], - content: 'X' - } - ] - }, - { - type: 'table', - children: [ - { - type: 'thead', - children: [ - { - type: 'tr', - children: [ - { - type: 'th', - content: 'summon?' - }, - { - type: 'th', - content: 'raid' - }, - { - type: 'th', - content: 'join' - }, - { - type: 'th', - content: 'magic2use' - } - ] - } - ] - }, - { - type: 'tbody' - } - ] - } - ] - } - ); - idrinth.ui.base.appendChild ( idrinth.war.element ); - }; - idrinth.core.timeouts.add ( 'war', idrinth.war.getData, 5000, -1 ); - build (); - } -}; \ No newline at end of file + var build = function() { + idrinth.war.element = idrinth.ui.buildElement({ + id: "idrinth-war", + css: "idrinth-central-box idrinth-hovering-box idrinth-hide", + children: [ + { + children: [ + { + type: "span", + content: "current WAR" + }, + { + type: "span", + css: "idrinth-circle", + attributes: [ + { + name: "onclick", + value: 'this.parentNode.parentNode.hasAttribute("style")?this.parentNode.parentNode.removeAttribute("style"):this.parentNode.parentNode.setAttribute("style","bottom:0;top:auto");' + } + ], + content: "\u2195" + }, + { + type: "span", + css: "idrinth-circle", + attributes: [ + { + name: "onclick", + value: 'this.parentNode.nextSibling.hasAttribute("style")?this.parentNode.nextSibling.removeAttribute("style"):this.parentNode.nextSibling.setAttribute("style","display:none");' + } + ], + content: "X" + } + ] + }, + { + type: "table", + children: [ + { + type: "thead", + children: [ + { + type: "tr", + children: [ + { + type: "th", + content: "summon?" + }, + { + type: "th", + content: "raid" + }, + { + type: "th", + content: "join" + }, + { + type: "th", + content: "magic2use" + } + ] + } + ] + }, + { + type: "tbody" + } + ] + } + ] + }); + idrinth.ui.base.appendChild(idrinth.war.element); + }; + idrinth.core.timeouts.add("war", idrinth.war.getData, 5000, -1); + build(); + } +}; diff --git a/src/stable.js b/src/stable.js index 64a2a1e..5a040f4 100644 --- a/src/stable.js +++ b/src/stable.js @@ -1,105 +1,127 @@ var idrinth = { - /** + /** * @type String */ - version: '###VERSION###', - /** + version: "###VERSION###", + /** * @type Boolean */ - windowactive: true, - /** + windowactive: true, + /** * * @type String */ - platform: '', - /** + platform: "", + /** * * @returns {undefined} */ - reload: function ( ) { - window.clearTimeout ( idrinth.core.timeouts.next ); - idrinth.ui.removeElement ( 'idotd-base' ); - for ( var event in idrinth.core.multibind.events ) { - if ( idrinth.core.multibind.events.hasOwnProperty( event ) ) { - document.getElementsByTagName( 'body' )[0].removeEventListener( event, idrinth.core.multibind.triggered ); - } - } - for (var observer in idrinth.observer.list) { - if ( idrinth.observer.list.hasOwnProperty( observer ) ) { - idrinth.observer.list[observer].disconnect(); - } - } - window.setTimeout ( function () { - idrinth = { }; - document.getElementById ( 'idotd-loader' ).errorFunction (); - }, 1 ); - }, - /** + reload: function() { + window.clearTimeout(idrinth.core.timeouts.next); + idrinth.ui.removeElement("idotd-base"); + for (var event in idrinth.core.multibind.events) { + if (idrinth.core.multibind.events.hasOwnProperty(event)) { + document + .getElementsByTagName("body")[0] + .removeEventListener(event, idrinth.core.multibind.triggered); + } + } + for (var observer in idrinth.observer.list) { + if (idrinth.observer.list.hasOwnProperty(observer)) { + idrinth.observer.list[observer].disconnect(); + } + } + window.setTimeout(function() { + idrinth = {}; + document.getElementById("idotd-loader").errorFunction(); + }, 1); + }, + /** * initializes the whole script * @returns {undefined} */ - start: function ( ) { - /** + start: function() { + /** * * @returns {undefined} */ - var startInternal = function ( ) { - /** + var startInternal = function() { + /** * initializes all modules * @returns {undefined} */ - var init = function () { - if ( !idrinth.text.initialized ) { - return; - } - if ( idrinth.platform === 'newgrounds' ) { - try { - var frame = document.getElementById ( 'iframe_embed' ).getElementsByTagName ( 'iframe' )[0]; - idrinth.newgrounds.originalUrl = frame.getAttribute ( 'src' ); - if ( window.location.search ) { - frame.setAttribute ( 'src', ( frame.getAttribute ( 'src' ) ).replace ( /&ir=.*/, '' ) + '&' + ( window.location.search ).replace ( /^\?/, '' ) ); - } - } catch ( e ) { - idrinth.core.log ( e.message ? e.message : e.getMessage () ); - return; - } - idrinth.core.timeouts.add ( 'newgrounds', idrinth.newgrounds.alarmCheck, 3333 ); - } - idrinth.core.timeouts.remove ( 'start' ); - idrinth.ui.start ( ); - idrinth.user.start ( ); - idrinth.names.start ( ); - idrinth.raids.start ( ); - idrinth.tier.start ( ); - idrinth.chat.start ( ); - idrinth.war.start ( ); - idrinth.inframe.start ( ); - idrinth.observer.start ( ); - idrinth.core.timeouts.add ( 'core.multibind', function () { - idrinth.core.multibind.add ( 'click', '.clipboard-copy', function ( element, event ) { - idrinth.core.copyToClipboard.element ( element ); - element.parentNode.parentNode.removeChild ( element.parentNode ); - } ); - }, 1000 ); - delete idrinth['start']; - }; - idrinth.settings.start ( ); - idrinth.text.start ( ); - idrinth.core.timeouts.add ( 'start', init, 123, -1 ); - }; - idrinth.core.log ( 'Starting Idrinth\'s DotD Script' ); - window.onblur = function () { - idrinth.windowactive = !idrinth.windowactive; - }; - idrinth.platform = location.hostname.split ( '.' )[location.hostname.split ( '.' ).length - 2]; - if ( idrinth.platform === 'dawnofthedragons' ) { - idrinth.platform = 'facebook'; + var init = function() { + if (!idrinth.text.initialized) { + return; } - if ( idrinth.platform === 'armorgames' ) { - return idrinth.core.timeouts.add ( 'start', startInternal, 2222 ); + if (idrinth.platform === "newgrounds") { + try { + var frame = document + .getElementById("iframe_embed") + .getElementsByTagName("iframe")[0]; + idrinth.newgrounds.originalUrl = frame.getAttribute("src"); + if (window.location.search) { + frame.setAttribute( + "src", + frame.getAttribute("src").replace(/&ir=.*/, "") + + "&" + + window.location.search.replace(/^\?/, "") + ); + } + } catch (e) { + idrinth.core.log(e.message ? e.message : e.getMessage()); + return; + } + idrinth.core.timeouts.add( + "newgrounds", + idrinth.newgrounds.alarmCheck, + 3333 + ); } - startInternal (); + idrinth.core.timeouts.remove("start"); + idrinth.ui.start(); + idrinth.user.start(); + idrinth.names.start(); + idrinth.raids.start(); + idrinth.tier.start(); + idrinth.chat.start(); + idrinth.war.start(); + idrinth.inframe.start(); + idrinth.observer.start(); + idrinth.core.timeouts.add( + "core.multibind", + function() { + idrinth.core.multibind.add("click", ".clipboard-copy", function( + element, + event + ) { + idrinth.core.copyToClipboard.element(element); + element.parentNode.parentNode.removeChild(element.parentNode); + }); + }, + 1000 + ); + delete idrinth["start"]; + }; + idrinth.settings.start(); + idrinth.text.start(); + idrinth.core.timeouts.add("start", init, 123, -1); + }; + idrinth.core.log("Starting Idrinth's DotD Script"); + window.onblur = function() { + idrinth.windowactive = !idrinth.windowactive; + }; + idrinth.platform = location.hostname.split(".")[ + location.hostname.split(".").length - 2 + ]; + if (idrinth.platform === "dawnofthedragons") { + idrinth.platform = "facebook"; + } + if (idrinth.platform === "armorgames") { + return idrinth.core.timeouts.add("start", startInternal, 2222); } + startInternal(); + } }; window.idrinth = idrinth; -window.setTimeout ( window.idrinth.start, 6666 ); +window.setTimeout(window.idrinth.start, 6666); From c49f04c4d2ec1bb70345c2671be7b9a9a6237ccb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20B=C3=BCttner?= Date: Tue, 2 May 2017 17:07:09 +0200 Subject: [PATCH 6/8] modifiing iife to match prettier (outside->inside) --- .eslintrc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.eslintrc b/.eslintrc index 9faa375..7fcfdd4 100644 --- a/.eslintrc +++ b/.eslintrc @@ -96,7 +96,7 @@ rules: no-with: 2 radix: 2 vars-on-top: 0 - wrap-iife: 2 + wrap-iife: 1 yoda: 0 # Strict From 83ef4218c23b6c742d67477865936d0c8f67a274 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20B=C3=BCttner?= Date: Tue, 2 May 2017 17:17:45 +0200 Subject: [PATCH 7/8] Create .jshintignore --- .jshintignore | 1 + 1 file changed, 1 insertion(+) create mode 100644 .jshintignore diff --git a/.jshintignore b/.jshintignore new file mode 100644 index 0000000..91aef88 --- /dev/null +++ b/.jshintignore @@ -0,0 +1 @@ +src/libs/* From a993e281cb9b302cccde86f599d63191b9bd2668 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20B=C3=BCttner?= Date: Tue, 2 May 2017 22:23:57 +0200 Subject: [PATCH 8/8] adding prettier ignore should make sure that our JSON-lanf doesn't break --- src/mods/text.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/mods/text.js b/src/mods/text.js index 66bd7f9..8fdbcad 100644 --- a/src/mods/text.js +++ b/src/mods/text.js @@ -61,11 +61,12 @@ idrinth.text = { true ); }, + // prettier-ignore /** * See languages/en.json for an example * @type {object} */ - data: JSON.parse("###LANG###"), + data: JSON.parse('###LANG###'), /** * returns the translation of a provided key or an error-message if no * matching translation is found