From 21603adc01424a2b7937525099630323d1e7555c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20B=C3=BCttner?= Date: Wed, 30 May 2018 23:25:28 +0200 Subject: [PATCH] var -> let support should long be sufficient --- src/loader.js | 26 ++++----- src/mods/chat.js | 122 ++++++++++++++++++++--------------------- src/mods/core.js | 44 +++++++-------- src/mods/inframe.js | 16 +++--- src/mods/land.js | 32 +++++------ src/mods/names.js | 12 ++-- src/mods/newgrounds.js | 8 +-- src/mods/observer.js | 26 ++++----- src/mods/raids.js | 58 ++++++++++---------- src/mods/settings.js | 24 ++++---- src/mods/stats.js | 32 +++++------ src/mods/text.js | 8 +-- src/mods/tier.js | 64 ++++++++++----------- src/mods/ui.js | 104 +++++++++++++++++------------------ src/mods/user.js | 14 ++--- src/mods/war.js | 36 ++++++------ src/stable.js | 6 +- 17 files changed, 316 insertions(+), 316 deletions(-) diff --git a/src/loader.js b/src/loader.js index 1bb3974..c1b56a5 100644 --- a/src/loader.js +++ b/src/loader.js @@ -34,19 +34,19 @@ window.location.host === "web1.dawnofthedragons.com" || window.location.host === "dotd-web1.5thplanetgames.com" ) { - var f = function() { - console.log("s"); - window.idrinth = {}; - window.idrinth.add= function(data) { - var s = document.createElement("script"); - s.appendChild(document.createTextNode(data)); - document.getElementsByTagName("head")[0].appendChild(s); - }; + let f = function() { + window.idrinth = { + add: function(data) { + let 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); + let data = JSON.parse(event.data); if ( !data || data.to !== "idotd" || @@ -63,13 +63,13 @@ false ); }; - var sc = document.createElement("script"); + let sc = document.createElement("script"); sc.setAttribute("id", "idotd-loader"); sc.appendChild(document.createTextNode('('+f.toString()+'());')); document.getElementsByTagName("head")[0].appendChild(sc); return; } - var sc = document.createElement("script"); + let sc = document.createElement("script"); sc.setAttribute( "src", "https://dotd.idrinth.de/static/userscript/" + GM_info.script.version + "/" @@ -78,9 +78,9 @@ sc.setAttribute("async", "async"); sc.errorCounter = 0; sc.errorFunction = function() { - var self = document.getElementById("idotd-loader"); + let self = document.getElementById("idotd-loader"); self.parentNode.removeChild(self); - var sc = document.createElement("script"); + let sc = document.createElement("script"); sc.onerror = self.onerror; sc.errorCounter = self.errorCounter + 1; sc.errorFunction = self.errorFunction; diff --git a/src/mods/chat.js b/src/mods/chat.js index 1623e37..1fba270 100644 --- a/src/mods/chat.js +++ b/src/mods/chat.js @@ -55,13 +55,13 @@ idrinth.chat = { * @param {String} data * @returns {undefined} */ - var applyMessages = function(data) { + let applyMessages = function(data) { /** * * @param {String} messages * @returns {undefined} */ - var processMessages = function(messages) { + let processMessages = function(messages) { /** * * @param {Array} chatMessages @@ -69,7 +69,7 @@ idrinth.chat = { * @param {HTMLElement} chatElement * @returns {Boolean} */ - var addMessages = function(chatMessages, chatId, chatElement) { + let addMessages = function(chatMessages, chatId, chatElement) { /** * * @param {String} message @@ -78,12 +78,12 @@ idrinth.chat = { * @param {Number} messageId * @returns {undefined} */ - var buildMessage = function(message, chat, chatId, messageId) { + let buildMessage = function(message, chat, chatId, messageId) { /** * * @returns {String} */ - var getfullDateInt = function() { + let getfullDateInt = function() { /** * * @param {Number} x @@ -96,7 +96,7 @@ idrinth.chat = { } return x; } - var d = new Date(); + let d = new Date(); return ( addZero(d.getFullYear(), 2) + addZero(d.getMonth(), 2) + @@ -114,13 +114,13 @@ idrinth.chat = { * @param {Number} chatId * @returns {undefined} */ - var notify = function(message, own, chatId) { + let notify = function(message, own, chatId) { /** * * @param {Number} chatId * @returns {Boolean} */ - var notActive = function(chatId) { + let notActive = function(chatId) { try { return ( !idrinth.windowactive || @@ -143,7 +143,7 @@ idrinth.chat = { * @param {String} text * @returns {Boolean} */ - var messageAllowed = function(text) { + let messageAllowed = function(text) { try { return ( (idrinth.settings.get("notification#message") && @@ -183,7 +183,7 @@ idrinth.chat = { } } }; - var own = + let own = parseInt(message.user, 10) === parseInt(idrinth.chat.self, 10); notify(message, own, chatId); chat.appendChild( @@ -243,7 +243,7 @@ idrinth.chat = { }) ); }; - var isNew = false; + let isNew = false; for (var messageId in chatMessages) { if ( parseInt(messageId, 10) < 1 || @@ -272,24 +272,24 @@ idrinth.chat = { * @param {Number} chatId * @returns {undefined} */ - var setChatClass = function(isNew, chat, chatId) { + let setChatClass = function(isNew, chat, chatId) { /** * * @param {HTMLElement} element * @returns {Boolean} */ - var isActive = function(element) { - var cssClass = element.getAttribute("class"); + let isActive = function(element) { + let cssClass = element.getAttribute("class"); return !!cssClass && !!cssClass.match(/(^|\s)active(\s|$)/); }; - var chatActive = isActive(document.getElementById("idrinth-chat")); + let 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); + let tab = document.getElementById("idrinth-chat-tab-click-" + chatId); + let tabActive = isActive(tab); if (isNew && !tabActive) { tab.setAttribute( "class", @@ -319,7 +319,7 @@ idrinth.chat = { .getElementById("idrinth-chat-tab-" + key) .getElementsByTagName("ul")[1] ) { - var chat = document + let chat = document .getElementById("idrinth-chat-tab-" + key) .getElementsByTagName("ul")[1]; setChatClass(addMessages(messages[key], key, chat), chat, key); @@ -346,18 +346,18 @@ idrinth.chat = { * * @returns {undefined} */ - var refreshMembers = function() { + let refreshMembers = function() { /** * * @param {String} data * @returns {undefined} */ - var applyMembers = function(data) { + let applyMembers = function(data) { /** * * @returns {undefined} */ - var applyMemberData = function() { + let applyMemberData = function() { /** * * @param {HTMLElement} chat @@ -365,8 +365,8 @@ idrinth.chat = { * @param {Number} userId * @returns {undefined} */ - var addMemberElement = function(chat, chatId, userId) { - var usedPlatforms = ""; + let addMemberElement = function(chat, chatId, userId) { + let usedPlatforms = ""; for (var pkey in idrinth.chat.users[userId].platforms) { if (idrinth.chat.users[userId].platforms[pkey]) { usedPlatforms += pkey; @@ -402,7 +402,7 @@ idrinth.chat = { }; for (var chatId in idrinth.chat.chatRank) { if (document.getElementById("idrinth-chat-tab-" + chatId)) { - var chat = document + let chat = document .getElementById("idrinth-chat-tab-" + chatId) .getElementsByTagName("ul")[0]; while (chat.firstChild) { @@ -482,14 +482,14 @@ idrinth.chat = { * @param {Number} rankId * @returns {Array} */ - var getPopupContent = function(chat, user, rankId) { + let getPopupContent = function(chat, user, rankId) { /** * * @param {Number} chat * @returns {Array} */ - var getPromotionOptions = function(chat) { - var promotionModes = [ + let getPromotionOptions = function(chat) { + let promotionModes = [ { chat: chat, label: "chat.actions.banUser", @@ -517,7 +517,7 @@ idrinth.chat = { ]; for (var chatId in idrinth.chat.chatRank) { if (idrinth.chat.chatRank.hasOwnProperty(chatId)) { - var intChatId = parseInt(chatId, 10); + let intChatId = parseInt(chatId, 10); if ( document.getElementById("idrinth-chat-tab-click-" + chatId) && intChatId !== chat && @@ -544,20 +544,20 @@ idrinth.chat = { * @param {Number} ownRank * @returns {Array} */ - var promoteNode = function(node, user, ownRank) { + let promoteNode = function(node, user, ownRank) { /** * * @param {Number} reqRank * @param {Number} ownRank * @returns {Boolean} */ - var hasRights = function(reqRank, ownRank) { + let hasRights = function(reqRank, ownRank) { return reqRank <= ownRank; }; if (!hasRights(node.requiredRank, ownRank)) { return; } - var translation = idrinth.text.get(node.label); + let translation = idrinth.text.get(node.label); return { content: translation === idrinth.text.data.default ? node.label @@ -577,18 +577,18 @@ idrinth.chat = { ] }; }; - var popupContent = []; - var promotionModes = getPromotionOptions(parseInt(chat, 10), user); + let popupContent = []; + let promotionModes = getPromotionOptions(parseInt(chat, 10), user); for (var count = 0; count < promotionModes.length; count++) { - var tmp = promoteNode(promotionModes[count], user, rankId); + let tmp = promoteNode(promotionModes[count], user, rankId); if (tmp) { popupContent.push(tmp); } } return popupContent; }; - var rankId = parseInt(idrinth.chat.chatRank[chat][idrinth.chat.self], 10); - var popupContent = getPopupContent(chat, user, rankId); + let rankId = parseInt(idrinth.chat.chatRank[chat][idrinth.chat.self], 10); + let popupContent = getPopupContent(chat, user, rankId); if (popupContent.length === 0) { return; } @@ -664,7 +664,7 @@ idrinth.chat = { * @param {String} lastField * @returns {Array} */ - var complexHandler = function(message, regex, callbacks, lastField) { + let complexHandler = function(message, regex, callbacks, lastField) { /** * * @param {Number} count @@ -673,7 +673,7 @@ idrinth.chat = { * @param {Array} textcontent * @returns {Array} */ - var partHandler = function(count, callbacks, text, textcontent) { + let partHandler = function(count, callbacks, text, textcontent) { /** * * @param {Array} textcontent @@ -681,8 +681,8 @@ idrinth.chat = { * @param {String} text * @returns {unresolved} */ - var callbackHandler = function(textcontent, func, text) { - var tmp = func(text); + let callbackHandler = function(textcontent, func, text) { + let tmp = func(text); for (var c2 = 0; c2 < tmp.length; c2++) { if (tmp[c2] !== undefined) { textcontent.push(tmp[c2]); @@ -709,12 +709,12 @@ idrinth.chat = { } return textcontent; }; - var matches = message.match(regex); - var text = message + let matches = message.match(regex); + let text = message .replace(regex, "$1########$" + lastField) .split("########"); - var textcontent = []; - var length = + let textcontent = []; + let length = (matches && Array.isArray(matches) ? matches.length : 0) + (text && Array.isArray(text) ? text.length : 0); for (var count = 0; count < length; count++) { @@ -728,10 +728,10 @@ idrinth.chat = { * @param {Array} callbacks * @returns {Array} */ - var simpleHandler = function(message, callbacks) { + let simpleHandler = function(message, callbacks) { if (typeof callbacks[1] === "function") { - var textcontent = []; - var tmp = callbacks[1](message); + let textcontent = []; + let tmp = callbacks[1](message); for (var c2 = 0; c2 < tmp.length; c2++) { textcontent.push(tmp[c2]); } @@ -759,16 +759,16 @@ idrinth.chat = { if (!idrinth.chat.emotes.lookup) { return message; } - var part = idrinth.core.escapeRegExp( + let part = idrinth.core.escapeRegExp( Object.keys(idrinth.chat.emotes.lookup).join("TTTT") ); - var reg = new RegExp("(^| )(" + part.replace(/TTTT/g, "|") + ")($| )", "g"); + let reg = new RegExp("(^| )(" + part.replace(/TTTT/g, "|") + ")($| )", "g"); return idrinth.chat.replaceInText( message, reg, [ function(match) { - var el = + let el = idrinth.chat.emotes.positions[ idrinth.chat.emotes.lookup[match.replace(/ /g, "")] ]; @@ -808,7 +808,7 @@ idrinth.chat = { * @returns {Object} **/ buildMessageText: function(message) { - var reg = new RegExp("(^|\\W)(https?://([^/ ]+)(/.*?)?)($| )", "ig"); + let reg = new RegExp("(^|\\W)(https?://([^/ ]+)(/.*?)?)($| )", "ig"); return idrinth.chat.replaceInText( message, reg, @@ -856,14 +856,14 @@ idrinth.chat = { * * @returns {HTMLElement} */ - var build = function() { + let build = function() { /** * * @param {String} label * @returns {Object} */ - var makeInput = function(label) { - var translation = idrinth.text.get(label); + let makeInput = function(label) { + let translation = idrinth.text.get(label); return { type: "li", children: [ @@ -895,8 +895,8 @@ idrinth.chat = { * @param {String} onclick * @returns {Object} */ - var makeButton = function(label, onclick) { - var translation = idrinth.text.get(label); + let makeButton = function(label, onclick) { + let translation = idrinth.text.get(label); return { type: "li", children: [ @@ -1318,7 +1318,7 @@ idrinth.chat = { return; } if (data.success) { - var login = document + let login = document .getElementById("idrinth-chat-login") .getElementsByTagName("input"); idrinth.settings.change("chatuser", login[0].value); @@ -1426,10 +1426,10 @@ idrinth.chat = { * @returns {undefined} */ enableChat: function(element) { - var tabs = document.getElementsByClassName("chat-tabs")[0].children, + let 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") + ""; + let cur = labels[counter].getAttribute("class") + ""; labels[counter].setAttribute( "class", cur.replace(/(^|\s)active(\s|$)/, " ") @@ -1458,7 +1458,7 @@ idrinth.chat = { * @returns {undefined} */ openCloseChat: function(element) { - var chat = element.parentNode; + let chat = element.parentNode; if ( chat.getAttribute("class") === "idrinth-hovering-box active" || chat.getAttribute("class") === "idrinth-hovering-box active left-sided" @@ -1488,7 +1488,7 @@ idrinth.chat = { * @returns {undefined} */ loginActions: function(key) { - var chatLogin, + let chatLogin, success, urls = { register: "chat-service/register/", diff --git a/src/mods/core.js b/src/mods/core.js index 380e761..998f104 100644 --- a/src/mods/core.js +++ b/src/mods/core.js @@ -54,11 +54,11 @@ idrinth.core = { additionalHeader, isStatic ) { - var server = isStatic + let server = isStatic ? "static" : (idrinth.settings.get("isWorldServer") ? "world-" : "") + idrinth.platform; - var homeUrl = + let homeUrl = "https://dotd.idrinth.de/" + server + ("/" + url).replace(/\/\//, "/"); idrinth.core.ajax.run( homeUrl, @@ -82,10 +82,10 @@ idrinth.core = { if(!idrinth.start && idrinth.settings.get("server")) { return; } - var requestHandler = new XMLHttpRequest(); + let requestHandler = new XMLHttpRequest(); requestHandler.onreadystatechange = function(event) { - var request = (event || window.event).target; - var call = function(func, value) { + let request = (event || window.event).target; + let call = function(func, value) { if (typeof func !== "function") { return; } @@ -101,7 +101,7 @@ idrinth.core = { } }; if (request.readyState === 4) { - var status = + let status = (request.status > 199 && request.status < 300) || request.status === 0; call( @@ -113,14 +113,14 @@ idrinth.core = { }; requestHandler.timeout = 30000; requestHandler.ontimeout = function(event) { - var request = (event || window.event).target; + let 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) { + let error = function(event) { delete idrinth.core.ajax.active[(event || window.event).target._url]; idrinth.core.log( "Request to " + (event || window.event).target._url + " failed." @@ -151,9 +151,9 @@ idrinth.core = { * @returns {Boolean} */ text: function(text) { - var success; + let success; try { - var textAreaElement = idrinth.ui.buildElement({ + let textAreaElement = idrinth.ui.buildElement({ type: "textarea", id: "idrinth-copy-helper" }); @@ -201,7 +201,7 @@ idrinth.core = { if (window.Notification.permission === "denied") { return false; } - var data = {}; + let data = {}; if (idrinth.settings.get("notification#image")) { data.icon = "https://dotd.idrinth.de/Resources/Images/logo.png"; } @@ -245,7 +245,7 @@ idrinth.core = { * @returns {undefined} */ add: function(identifier, func, time, maxRepeats) { - var date = new Date(); + let date = new Date(); idrinth.core.timeouts.list[identifier] = { func: func, next: date.getTime() + date.getMilliseconds() / 1000 + time / 1000, @@ -264,22 +264,22 @@ idrinth.core = { * @returns {undefined} */ process: function() { - var date = new Date().getTime() + new Date().getMilliseconds() / 1000; - var min = 10; + let date = new Date().getTime() + new Date().getMilliseconds() / 1000; + let min = 10; /** * * @param {Number} min * @param {Number} property * @returns {Number} */ - var check = function(min, property, date) { + let check = function(min, property, date) { /** * * @param {Number} durationLeft * @param {string} minDuration * @returns {Number} */ - var getVal = function(durationLeft, minDuration) { + let getVal = function(durationLeft, minDuration) { if (durationLeft < 0.1) { return 0.1; } @@ -290,7 +290,7 @@ idrinth.core = { * @param {string} property * @returns {undefined} */ - var handle = function(property, min) { + let handle = function(property, min) { idrinth.core.timeouts.list[property].func(); idrinth.core.timeouts.list[property].repeats = Math.max( -1, @@ -368,7 +368,7 @@ idrinth.core = { if (!window.Worker) { return resultHandler(inWorker(values)); } - var blobURL = window.URL.createObjectURL( + let blobURL = window.URL.createObjectURL( new Blob([ "/*js:big*/" +//replaced server-side from libs/[name].js "self.onmessage = function(message) {var work=" + @@ -376,7 +376,7 @@ idrinth.core = { ";self.postMessage(work(message.data));self.close();}" ]) ); - var worker = new Worker(blobURL); + let worker = new Worker(blobURL); worker.onmessage = function(message) { message.target.resultHandler(message.data); }; @@ -402,7 +402,7 @@ idrinth.core = { * @returns {undefined} */ add: function(event, selector, method) { - var bind = function(event, selector, method) { + let bind = function(event, selector, method) { idrinth.core.multibind.events[event] = idrinth.core.multibind.events[ event ] @@ -434,12 +434,12 @@ idrinth.core = { * @param {string} selector * @returns {undefined} */ - var handleElement = function(el, event, selector) { + let handleElement = function(el, event, selector) { if (!el) { return; } for ( - var pos = 0; + let pos = 0; pos < idrinth.core.multibind.events[event][selector].length; pos++ ) { diff --git a/src/mods/inframe.js b/src/mods/inframe.js index 29917c6..db10226 100644 --- a/src/mods/inframe.js +++ b/src/mods/inframe.js @@ -28,10 +28,10 @@ idrinth.inframe = { /** * @returns {undefined} */ - var reload = function(data) { - var objects = document.getElementsByTagName("object"); - var modify = function(element, data) { - var src = element.getAttribute("data"); + let reload = function(data) { + let objects = document.getElementsByTagName("object"); + let modify = function(element, data) { + let src = element.getAttribute("data"); if (!src) { return false; } @@ -51,10 +51,10 @@ idrinth.inframe = { /** * @returns {undefined} */ - var joinRaid = function(data) { - var requestHandler = new XMLHttpRequest(); + let joinRaid = function(data) { + let requestHandler = new XMLHttpRequest(); requestHandler.timeout = 30000; - var error = function(event) { + let error = function(event) { console.log( "Request to " + (event || window.event).target._url + " failed." ); @@ -69,7 +69,7 @@ idrinth.inframe = { /** * @param {HTMLElement} parent */ - var handleFrame = function(parent) { + let handleFrame = function(parent) { idrinth.inframe.game = parent.getElementsByTagName("iframe")[ 0 ].contentWindow; diff --git a/src/mods/land.js b/src/mods/land.js index b11c3c8..fabba5d 100644 --- a/src/mods/land.js +++ b/src/mods/land.js @@ -9,20 +9,20 @@ idrinth.land = { * @param {function[]} checkElementFunc * @returns {object} */ - var baseCalculator = function(checkElementFunc) { - var factor = idrinth.settings.get("factor") ? 10 : 1; + let baseCalculator = function(checkElementFunc) { + let factor = idrinth.settings.get("factor") ? 10 : 1; /** * * @param {string} building * @returns {Number} */ - var nextPrice = function(building) { + let nextPrice = function(building) { return ( (10 + idrinth.settings.get("land#" + building)) * idrinth.land.data[building].base ); }; - var results = {}; + let results = {}; /** * * @param {type} results @@ -31,7 +31,7 @@ idrinth.land = { * @param {type} nextPrice * @returns {Number|@var;factor} */ - var applyResult = function(results, res, factor, nextPrice) { + let applyResult = function(results, res, factor, nextPrice) { idrinth.settings.change( "land#gold", idrinth.settings.get("land#gold") - nextPrice(res.key) * factor / 10 @@ -51,7 +51,7 @@ idrinth.land = { * @param {function} nextPrice * @returns {object} */ - var processBuildings = function(checkElementFunc, factor, nextPrice) { + let processBuildings = function(checkElementFunc, factor, nextPrice) { /** * * @param {function[]} checkElementFunc @@ -61,7 +61,7 @@ idrinth.land = { * @param {function} nextPrice * @returns {object} */ - var check = function( + let check = function( checkElementFunc, building, factor, @@ -78,7 +78,7 @@ idrinth.land = { key: building }; }; - var res = { + let res = { key: null, min: null }; @@ -94,7 +94,7 @@ idrinth.land = { return res; }; while (idrinth.settings.get("land#gold") >= 0) { - var res = processBuildings(checkElementFunc, factor, nextPrice); + let res = processBuildings(checkElementFunc, factor, nextPrice); if (res.key === null) { return results; } @@ -106,7 +106,7 @@ idrinth.land = { * * @returns {function[]} */ - var getRequirements = function() { + let getRequirements = function() { /** * * @param {String} building @@ -115,7 +115,7 @@ idrinth.land = { * @param {function} nextPrice * @returns {Boolean} */ - var bestPrice = function(building, factor, res, nextPrice) { + let bestPrice = function(building, factor, res, nextPrice) { return ( res.min === null || nextPrice(building) / idrinth.land.data[building].perHour < res.min @@ -129,12 +129,12 @@ idrinth.land = { * @param {function} nextPrice * @returns {Boolean} */ - var useUp = function(building, factor, res, nextPrice) { + let useUp = function(building, factor, res, nextPrice) { return ( nextPrice(building) * factor / 10 <= idrinth.settings.get("land#gold") ); }; - var funcs = [useUp]; + let funcs = [useUp]; if (idrinth.settings.get("landMax")) { funcs.push(bestPrice); } @@ -145,7 +145,7 @@ idrinth.land = { * @param {object} results * @returns {undefined} */ - var putResults = function(results) { + let putResults = function(results) { for (var key in results) { if (results.hasOwnProperty(key)) { document.getElementById( @@ -161,7 +161,7 @@ idrinth.land = { "land#gold" ); }; - var landSettings = idrinth.settings.get("land", true); + let landSettings = idrinth.settings.get("land", true); for (var key in landSettings) { if (landSettings.hasOwnProperty(key)) { idrinth.settings.change( @@ -170,7 +170,7 @@ idrinth.land = { ); } } - var results = baseCalculator(getRequirements()); + let results = baseCalculator(getRequirements()); if (Object.keys(results).length === 0) { idrinth.core.alert(idrinth.text.get("land.lack")); } diff --git a/src/mods/names.js b/src/mods/names.js index a274abb..b7db5af 100644 --- a/src/mods/names.js +++ b/src/mods/names.js @@ -39,13 +39,13 @@ idrinth.names = { * @param {string} added the path-segment defining the data returned * @returns {undefined} */ - var load = function(added) { + let load = function(added) { /** * * @param {string} data * @returns {undefined} */ - var importNames = function(data) { + let importNames = function(data) { data = JSON.parse(data); if (!data) { return; @@ -82,7 +82,7 @@ idrinth.names = { * creates the tooltip-element * @returns {undefined} */ - var build = function() { + let build = function() { /** * * @param {string} name @@ -210,7 +210,7 @@ idrinth.names = { * @param {HTMLElement} element * @returns {undefined} */ - var showTooltip = function(element) { + let showTooltip = function(element) { /** * * @param {object} set @@ -223,7 +223,7 @@ idrinth.names = { idrinth.ui.updateClassesList(element, ["idrinth-hide"], []); return; } - var baseUrl = + let baseUrl = "https://dotd.idrinth.de/" + (world ? "world-kongregate" : "kongregate"); idrinth.ui.updateClassesList(idrinth.ui.tooltip, [], ["idrinth-hide"]); @@ -250,7 +250,7 @@ idrinth.names = { ); } idrinth.names.isHovering = false; - var name = idrinth.names.parse(element).toLowerCase(); + let name = idrinth.names.parse(element).toLowerCase(); if ( idrinth.settings.get("names") && idrinth.ui.tooltip && diff --git a/src/mods/newgrounds.js b/src/mods/newgrounds.js index d4207c8..6b01460 100644 --- a/src/mods/newgrounds.js +++ b/src/mods/newgrounds.js @@ -26,7 +26,7 @@ idrinth.newgrounds = { * @returns {undefined} */ alarmCheck: function() { - var now = new Date(); + let now = new Date(); if ( idrinth.settings.get("alarmActive") && now.getHours() + ":" + now.getMinutes() === @@ -49,11 +49,11 @@ idrinth.newgrounds = { idrinth.core.alert("We're done! Have fun playing."); return; } - var frame = document + let frame = document .getElementById("iframe_embed") .getElementsByTagName("iframe")[0]; - var key = idrinth.newgrounds.raids.pop(); - var link = + let key = idrinth.newgrounds.raids.pop(); + let link = idrinth.newgrounds.originalUrl + "&" + idrinth.raids.join.getServerLink(key).replace(/^.*?\?/, ""); diff --git a/src/mods/observer.js b/src/mods/observer.js index 7f82150..2e89e9f 100644 --- a/src/mods/observer.js +++ b/src/mods/observer.js @@ -16,21 +16,21 @@ idrinth.observer = { * @param {HTMLElement} element * @returns {undefined} */ - var checkLinks = function(node) { + let checkLinks = function(node) { /** * * @param {HTMLElement} element * @returns {undefined} */ - var handleLink = function(element) { - var href = element.getAttribute("href"); + let handleLink = function(element) { + let href = element.getAttribute("href"); /** * * @param {Array} parts * @param {string} prefix * @returns {null|string} */ - var getData = function(parts, prefix) { + let getData = function(parts, prefix) { for (var count = 0; count < parts.length; count++) { if (parts[count].match(prefix + "=")) { return parts[count].split("=")[1]; @@ -44,7 +44,7 @@ idrinth.observer = { * @param {Boolean} isWorld * @returns {Boolean} */ - var correctServer = function(href, isWorld) { + let correctServer = function(href, isWorld) { if (href.match("serverid=2")) { return isWorld; } @@ -57,9 +57,9 @@ idrinth.observer = { if (!correctServer(href, idrinth.settings.get("world"))) { return; } - var parts = href.split("&"); - var id = getData(parts, "raid_id"); - var hash = getData(parts, "hash"); + let parts = href.split("&"); + let id = getData(parts, "raid_id"); + let hash = getData(parts, "hash"); if (!id || !hash) { return; } @@ -69,7 +69,7 @@ idrinth.observer = { if (node.tagName === "A" || node.tagName === "a") { handleLink(node); } else { - var elements = node.getElementsByTagName("a"); + let elements = node.getElementsByTagName("a"); for (var count = 0; count < elements.length; count++) { handleLink(elements[count]); } @@ -80,14 +80,14 @@ idrinth.observer = { * @param {HTMLElement} element * @returns {undefined} */ - var checkNames = function(node) { + let checkNames = function(node) { /** * * @param {HTMLElement} element * @returns {undefined} */ - var processName = function(element) { - var name = ""; + let processName = function(element) { + let name = ""; try { name = idrinth.names.parse(element); } catch (e) { @@ -103,7 +103,7 @@ idrinth.observer = { ); } }; - var elements = node.getElementsByClassName("username"); + let elements = node.getElementsByClassName("username"); for (var count = elements.length - 1; count >= 0; count--) { processName(elements[count]); } diff --git a/src/mods/raids.js b/src/mods/raids.js index b258315..34c8c3f 100644 --- a/src/mods/raids.js +++ b/src/mods/raids.js @@ -29,7 +29,7 @@ idrinth.raids = { * @param {String} toImport * @returns {String} */ - var getImportLink = function(toImport) { + let getImportLink = function(toImport) { return "raid-service/" + (toImport === "" ? "_" : toImport) + "/"; }; idrinth.core.ajax.runHome( @@ -40,7 +40,7 @@ idrinth.raids = { * @returns {undefined} */ function(responseText) { - var delHandler = function(key) { + let delHandler = function(key) { if (key in idrinth.raids.list) { delete idrinth.raids.list[key]; } @@ -51,7 +51,7 @@ idrinth.raids = { idrinth.ui.removeElement("idrinth-raid-link-" + key); } }; - var list = JSON.parse(responseText); + let list = JSON.parse(responseText); for (var key in list) { if (list[key].delete) { delHandler(key); @@ -120,8 +120,8 @@ idrinth.raids = { * @param {String} tag * @returns {String|Boolean} */ - var getLink = function(list, key, prefix, tag) { - var build = function(data, tag, prefix) { + let getLink = function(list, key, prefix, tag) { + let build = function(data, tag, prefix) { try { return ( prefix + @@ -147,7 +147,7 @@ idrinth.raids = { } }; if (list[key]) { - var link = build(list[key], tag, prefix); + let link = build(list[key], tag, prefix); if (link) { return link; } @@ -157,9 +157,9 @@ idrinth.raids = { * * @returns {String} */ - var makePrefix = function() { + let makePrefix = function() { if (idrinth.raids.join.data.prefix === null) { - var sites = { + let 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?", @@ -177,9 +177,9 @@ idrinth.raids = { * * @returns {String} */ - var makeTag = function() { + let makeTag = function() { if (idrinth.raids.join.data.tag === null) { - var sites = { + let sites = { armorgames: "ar_", kongregate: "kv_", newgrounds: "ng_", @@ -190,9 +190,9 @@ idrinth.raids = { } return idrinth.raids.join.data.tag; }; - var prefix = makePrefix(); - var tag = makeTag(); - var link = getLink(idrinth.raids.list, key, prefix, tag); + let prefix = makePrefix(); + let tag = makeTag(); + let link = getLink(idrinth.raids.list, key, prefix, tag); if (link) { return link; } @@ -213,12 +213,12 @@ idrinth.raids = { * @returns {undefined} */ log: function(string, key) { - var message = string + let 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 + let li = document.createElement("li"); + let ul = document .getElementById("idrinth-joined-raids") .getElementsByTagName("ul")[0]; li.appendChild( @@ -274,7 +274,7 @@ idrinth.raids = { idrinth.core.timeouts.add( "raid.join." + key, function() { - var id = "idrinth-raid-link-" + key; + let id = "idrinth-raid-link-" + key; if (document.getElementById(id)) { idrinth.ui.removeElement(id); } @@ -300,18 +300,18 @@ idrinth.raids = { * * @returns {Boolean} */ - var join = function() { + let join = function() { /** * * @returns {function[]} */ - var getServerMethods = function() { + let getServerMethods = function() { /** * * @param {String} key * @returns {Function} */ - var byMessage = function(key) { + let byMessage = function(key) { idrinth.inframe.send( "joinRaid", idrinth.raids.join @@ -325,7 +325,7 @@ idrinth.raids = { * @param {String} key * @returns {undefined} */ - var postLink = function(key) { + let postLink = function(key) { if (!document.getElementById("idrinth-raid-link-" + key)) { document.getElementById("idrinth-raid-link-list").appendChild( idrinth.ui.buildElement({ @@ -349,7 +349,7 @@ idrinth.raids = { ); } }; - var options = [postLink]; + let options = [postLink]; if ( idrinth.platform === "armorgames" || idrinth.platform === "kongregate" @@ -363,7 +363,7 @@ idrinth.raids = { * @param {Number} amount * @returns {Boolean} */ - var reachedMax = function(amount) { + let reachedMax = function(amount) { return amount > 99; }; /** @@ -373,8 +373,8 @@ idrinth.raids = { * @param {function[]} options * @returns {Number} */ - var handleKey = function(added, key, options) { - var raid = idrinth.raids.list[key]; + let handleKey = function(added, key, options) { + let raid = idrinth.raids.list[key]; if (!raid.joined) { added++; options[0](key); //post link @@ -392,8 +392,8 @@ idrinth.raids = { } return added; }; - var added = 0; - var options = getServerMethods(); + let added = 0; + let options = getServerMethods(); for (var key in idrinth.raids.list) { if (typeof idrinth.raids.list[key] === "object") { added = handleKey(added, key, options); @@ -408,13 +408,13 @@ idrinth.raids = { * requests information for raids caught from a third party(chat for example) * @returns {undefined} */ - var handlePrivates = function() { + let handlePrivates = function() { /** * * @param {String} reply * @returns {undefined} */ - var handle = function(reply) { + let handle = function(reply) { if (!reply) { return; } diff --git a/src/mods/settings.js b/src/mods/settings.js index 8e68fd4..988d681 100644 --- a/src/mods/settings.js +++ b/src/mods/settings.js @@ -282,7 +282,7 @@ idrinth.settings = { * @param {Boolean} allowObject * @returns {int|string|object} */ - var getValue = function(parent, field, allowObject) { + let getValue = function(parent, field, allowObject) { if (idrinth.core.fieldIsSetting(parent, field, allowObject)) { return parent[field]; } @@ -293,7 +293,7 @@ idrinth.settings = { * @param {string} key * @returns {undefined} */ - var remove = function(key) { + let remove = function(key) { try { window.localStorage.removeItem(key); } catch (e) { @@ -303,7 +303,7 @@ idrinth.settings = { if (!field) { return; } - var value = getValue(idrinth.settings.data, field, allowObject); + let value = getValue(idrinth.settings.data, field, allowObject); if (value !== null && (typeof value !== "object" || allowObject)) { remove("idrinth-dotd-" + field); return value; @@ -326,7 +326,7 @@ idrinth.settings = { * @param {String|Booleab|Number} value * @returns {Boolean} */ - var setValue = function(parent, field, value) { + let setValue = function(parent, field, value) { if (idrinth.core.fieldIsSetting(parent, field)) { parent[field] = value; return true; @@ -337,7 +337,7 @@ idrinth.settings = { * saves the data to local storage * @returns {undefined} */ - var store = function() { + let store = function() { window.localStorage.setItem( "idotd", JSON.stringify(idrinth.settings.data) @@ -368,9 +368,9 @@ idrinth.settings = { * fills the data from json in idotd * @returns {undefined} */ - var getCurrent = function() { + let getCurrent = function() { try { - var data = JSON.parse(window.localStorage.getItem("idotd")); + let data = JSON.parse(window.localStorage.getItem("idotd")); /** * * @param {object} to @@ -378,7 +378,7 @@ idrinth.settings = { * @param {function} apply * @returns {undefined} */ - var apply = function(to, from, apply) { + let apply = function(to, from, apply) { for (var key in from) { if (from.hasOwnProperty(key)) { if (typeof from[key] === "object") { @@ -413,7 +413,7 @@ idrinth.settings = { * fills the data from seperate storages * @returns {undefined} */ - var getOld = function() { + let getOld = function() { /** * * @param {object} object @@ -421,7 +421,7 @@ idrinth.settings = { * @param {function} objectIterator * @returns {Boolean} */ - var objectIterator = function(object, prefix, objectIterator) { + let objectIterator = function(object, prefix, objectIterator) { /** * * @param {String} prefix @@ -430,9 +430,9 @@ idrinth.settings = { * @returns {Boolean} * @todo remove this once old data is unlikely to exist */ - var itemHandler = function(prefix, key, item) { + let itemHandler = function(prefix, key, item) { if (typeof item !== "function") { - var tmp = window.localStorage.getItem( + let tmp = window.localStorage.getItem( "idrinth-dotd-" + prefix + key ); if (tmp) { diff --git a/src/mods/stats.js b/src/mods/stats.js index b4659c5..a86a8ed 100644 --- a/src/mods/stats.js +++ b/src/mods/stats.js @@ -9,13 +9,13 @@ idrinth.stats = { * @param {object} result * @returns {Boolean} is last? */ - var increaseSingle = function(result) { + let increaseSingle = function(result) { /** * * @returns {Number} */ - var addOnePerc = function() { - var base = 0; + let addOnePerc = function() { + let base = 0; if (idrinth.settings.get("stats#mirele")) { base += 1.8 * @@ -29,8 +29,8 @@ idrinth.stats = { * * @returns {Number} */ - var addOneAttack = function() { - var base = 4; + let addOneAttack = function() { + let base = 4; if (idrinth.settings.get("stats#utym")) { base += (idrinth.settings.get("stats#attack") <= 10000 ? 0.1 : 1 / 35) * @@ -44,8 +44,8 @@ idrinth.stats = { * * @returns {Number} */ - var addOneDefense = function() { - var base = 1; + let addOneDefense = function() { + let base = 1; if (idrinth.settings.get("stats#utym")) { base += (idrinth.settings.get("stats#defense") <= 10000 ? 0.1 : 1 / 35) * @@ -68,9 +68,9 @@ idrinth.stats = { * @param {string} added * @returns {Number} */ - var addProcs = function(base, added) { - var perc = idrinth.settings.get("stats#perception") + 1; - var total = + let addProcs = function(base, added) { + let perc = idrinth.settings.get("stats#perception") + 1; + let total = base * (100 + idrinth.settings.get("stats#mount") + @@ -92,7 +92,7 @@ idrinth.stats = { * @param {string} stat * @returns {Number} */ - var getCost = function(stat) { + let getCost = function(stat) { return ( Math.ceil( Math.max( @@ -107,10 +107,10 @@ idrinth.stats = { ) + 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; + let perc = addProcs(addOnePerc(), "perception") / getCost("perception"); + let defense = addProcs(addOneDefense(), "defense") / getCost("defense"); + let attack = addProcs(addOneAttack(), "attack") / getCost("attack"); + let stat = null; if ( perc >= defense && perc >= attack && @@ -144,7 +144,7 @@ idrinth.stats = { ); return false; }; - var result = { + let result = { stats: 0, attack: 0, defense: 0, diff --git a/src/mods/text.js b/src/mods/text.js index 5d036e1..ec3ada0 100644 --- a/src/mods/text.js +++ b/src/mods/text.js @@ -10,7 +10,7 @@ idrinth.text = { * @returns {undefined} */ start: function() { - var language = + let language = idrinth.settings.get("lang") || window.navigator.userLanguage || window.navigator.language || @@ -30,7 +30,7 @@ idrinth.text = { * @param {function} func * @returns {undefined} */ - var applyRecursive = function(to, from, func) { + let applyRecursive = function(to, from, func) { for (var prop in from) { if (from.hasOwnProperty(prop)) { if ( @@ -81,8 +81,8 @@ idrinth.text = { * @param {function} func * @returns {string} */ - var getSub = function(obj, keys, func) { - var key = keys.shift(); + let getSub = function(obj, keys, func) { + let key = keys.shift(); if (obj.hasOwnProperty(key)) { if (keys.length > 0) { return func(obj[key], keys, func); diff --git a/src/mods/tier.js b/src/mods/tier.js index 22d55b2..885d3bf 100644 --- a/src/mods/tier.js +++ b/src/mods/tier.js @@ -20,7 +20,7 @@ idrinth.tier = { * @param {string} key * @returns {Boolean} */ - var isValidParameter = function(name) { + let isValidParameter = function(name) { return ( name && idrinth.tier.list.hasOwnProperty(name) && @@ -33,7 +33,7 @@ idrinth.tier = { * @param {string} key * @returns {Boolean} */ - var isFreeSlot = function(key) { + let isFreeSlot = function(key) { return ( idrinth.tier.taggedSlots.hasOwnProperty(key) && typeof key !== "function" && @@ -43,15 +43,15 @@ idrinth.tier = { if (!isValidParameter(name)) { return; } - var boss = this.list[name]; + let boss = this.list[name]; /** * * @param {int} x * @param {string} name * @returns {undefined} */ - var make = function(x, name) { - var makeElement = function(label, number, description) { + let make = function(x, name) { + let makeElement = function(label, number, description) { return { content: label + " " + idrinth.ui.formatNumber(number), attributes: [ @@ -62,7 +62,7 @@ idrinth.tier = { ] }; }; - var info = [ + let info = [ makeElement("FS", boss.fs.nm, idrinth.text.get("tier.FS")), makeElement("AP", boss.ap, idrinth.text.get("tier.AP")) ]; @@ -126,13 +126,13 @@ idrinth.tier = { * @returns {undefined} */ start: function() { - var pos = 1; + let pos = 1; /** * parsed a json-response and fills tier list and exclusion list * @param {string} data * @returns {undefined} */ - var importData = function(data) { + let importData = function(data) { data = JSON.parse(data); if (data) { idrinth.tier.list = data; @@ -142,7 +142,7 @@ idrinth.tier = { * @param {string} url * @returns {undefined} */ - var create = function(name, url) { + let create = function(name, url) { if (!idrinth.settings.data.bannedRaids[name]) { idrinth.settings.data.bannedRaids[name] = false; window.localStorage.setItem( @@ -202,13 +202,13 @@ idrinth.tier = { * @param {string} list * @returns {undefined} */ - var makeList = function(list) { + let makeList = function(list) { /** * * @param {HTMLElement} elem * @returns {undefined} */ - var clearInnerHtml = function(elem) { + let clearInnerHtml = function(elem) { elem.innerHTML = ""; }; /** @@ -218,8 +218,8 @@ idrinth.tier = { * @param {string} ic * @returns {object} for the buildElement wrapper */ - var makeField = function(listKey, difficulty, ic) { - var ln = { + let makeField = function(listKey, difficulty, ic) { + let ln = { type: "td", attributes: [] }; @@ -231,7 +231,7 @@ idrinth.tier = { * @param {string} ic * @returns {object} for the buildElement wrapper */ - var addTitle = function(ln, listKey, difficulty, ic) { + let addTitle = function(ln, listKey, difficulty, ic) { /** * * @param {string} listKey @@ -239,7 +239,7 @@ idrinth.tier = { * @param {string} ic * @returns {Boolean} */ - var isUseable = function(listKey, difficulty, ic) { + let isUseable = function(listKey, difficulty, ic) { return ( idrinth.tier.list[listKey].hasOwnProperty("loot") && idrinth.tier.list[listKey].loot.hasOwnProperty(difficulty) && @@ -250,7 +250,7 @@ idrinth.tier = { if (!isUseable(listKey, difficulty, ic)) { return ln; } - var title = ""; + let title = ""; for (var key in idrinth.tier.list[listKey].loot[difficulty][ic]) { if ( idrinth.tier.list[listKey].loot[difficulty][ic].hasOwnProperty( @@ -278,14 +278,14 @@ idrinth.tier = { * @param {string} ic * @returns {object} for the buildElement wrapper */ - var addContent = function(ln, listKey, difficulty, ic) { + let addContent = function(ln, listKey, difficulty, ic) { /** * * @param {string} os numeric string * @param {string} current numeric string * @returns {Boolean} */ - var isOs = function(os, current) { + let isOs = function(os, current) { return Number.parseInt(os, 10) === Number.parseInt(current, 10); }; if ( @@ -326,7 +326,7 @@ idrinth.tier = { * @param {object} dataset * @returns {HTMLElement} */ - var makeRow = function(title, dataset) { + let makeRow = function(title, dataset) { return { type: "tr", children: [ @@ -353,15 +353,15 @@ idrinth.tier = { ] }; }; - var wrapper = document.getElementById("idrinth-tierlist"); + let wrapper = document.getElementById("idrinth-tierlist"); clearInnerHtml(wrapper); /** * * @param {Array} list * @returns {String} */ - var formattedList = function(list) { - var fList = []; + let formattedList = function(list) { + let fList = []; for (var count = 0; count < list.length; count++) { fList.push(idrinth.ui.formatNumber(list[count])); } @@ -373,7 +373,7 @@ idrinth.tier = { * @param {string} click * @returns {object} */ - var makeButton = function(label, click) { + let makeButton = function(label, click) { return { type: "button", content: idrinth.text.get("tier." + label), @@ -390,8 +390,8 @@ idrinth.tier = { }; }; for (var count = list.length - 1; count >= 0; count--) { - var boss = idrinth.tier.list[list[count]]; - var sub = idrinth.ui.buildElement({ + let boss = idrinth.tier.list[list[count]]; + let sub = idrinth.ui.buildElement({ css: "tier-wrapper", children: [ { @@ -485,7 +485,7 @@ idrinth.tier = { } ] }); - var maxTiers = Math.max( + let maxTiers = Math.max( boss.n.length, boss.h.length, boss.l.length, @@ -516,14 +516,14 @@ idrinth.tier = { * @param {object} data * @returns {Array} */ - var filter = function(data) { + let filter = function(data) { /** * * @param {Array} list * @param {RegExp} regExp * @returns {Boolean} */ - var matchesAny = function(list, regExp) { + let matchesAny = function(list, regExp) { for (var count = 0; count < list.length; count++) { if (list[count] && list[count].match(regExp)) { return true; @@ -537,9 +537,9 @@ idrinth.tier = { ) { return []; } - var result = []; - var nameRegExp = new RegExp(data.name, "i"); - var typeRegExp = new RegExp(data.type, "i"); + let result = []; + let nameRegExp = new RegExp(data.name, "i"); + let typeRegExp = new RegExp(data.type, "i"); for (var key in data.list) { if ( key.match(nameRegExp) && @@ -562,7 +562,7 @@ idrinth.tier = { * @returns {undefined} */ allCheck: function(yes) { - var boxes = document + let boxes = document .getElementById("idrinth-raid-may-join-list") .getElementsByTagName("input"); for (var counter = boxes.length - 1; counter >= 0; counter--) { diff --git a/src/mods/ui.js b/src/mods/ui.js index 9668053..3dd113b 100644 --- a/src/mods/ui.js +++ b/src/mods/ui.js @@ -23,8 +23,8 @@ idrinth.ui = { if (isNaN(number)) { return ""; } - var count = 0; - var post = ["", "k", "m", "b", "t", "qa", "qi", "s"]; + let count = 0; + let post = ["", "k", "m", "b", "t", "qa", "qi", "s"]; while (number > 999 && count < post.length) { number = Math.round(number / 10) / 100; count++; @@ -123,7 +123,7 @@ idrinth.ui = { * @returns {String} */ getElementPositioning: function(element, offsetX, offsetY) { - var pos = { + let pos = { x: element.getBoundingClientRect().left + (offsetX ? offsetX : 0), y: element.getBoundingClientRect().top + (offsetY ? offsetY : 0) }; @@ -141,7 +141,7 @@ idrinth.ui = { * @param {object} config * @returns {undefined} */ - var setBase = function(el, config) { + let setBase = function(el, config) { if (config.id) { el.id = config.id; } @@ -158,7 +158,7 @@ idrinth.ui = { * @param {object} config * @returns {undefined} */ - var addChildren = function(el, config) { + let addChildren = function(el, config) { if (!config.children || !config.children.length) { return; } @@ -172,14 +172,14 @@ idrinth.ui = { * @param {object} config * @returns {undefined} */ - var addAttributes = function(el, config) { + let addAttributes = function(el, config) { /** * * @param {HTMLElement} el * @param {object} set * @returns {undefined} */ - var applyValue = function(el, set) { + let applyValue = function(el, set) { if (!set || set.value === undefined) { return; } @@ -204,14 +204,14 @@ idrinth.ui = { * @param {object} config * @returns {HTMLElement} */ - var makeInputLabel = function(config) { + let makeInputLabel = function(config) { /** * * @param {String|Number} value * @param {Array} list * @returns {Boolean} */ - var inArray = function(value, list) { + let inArray = function(value, list) { if (!Array.isArray(list)) { return false; } @@ -220,7 +220,7 @@ idrinth.ui = { } return list.indexOf(value) > -1; }; - var input = [ + let input = [ { name: "type", value: config.type @@ -247,7 +247,7 @@ idrinth.ui = { value: "idrinth.settings.change('" + config.name + "',this.checked)" }); } - var translation = idrinth.text.get(config.label); + let translation = idrinth.text.get(config.label); return idrinth.ui.buildElement({ css: "idrinth-line" + (config.platforms && !inArray(idrinth.platform, config.platforms) @@ -282,7 +282,7 @@ idrinth.ui = { if (config.rType === "#input") { return makeInputLabel(config); } - var el = document.createElement(config.type ? config.type : "div"); + let el = document.createElement(config.type ? config.type : "div"); setBase(el, config); addChildren(el, config); addAttributes(el, config); @@ -296,7 +296,7 @@ idrinth.ui = { * @returns {undefined} */ buildModal: function(title, content, altFunc) { - var mod = { + let mod = { children: [], css: "idrinth-hovering-box idrinth-popup idrinth-" + (typeof altFunc === "string" ? "confim" : "alert") @@ -337,7 +337,7 @@ idrinth.ui = { * @param {String} func * @returns {object} */ - var makeButton = function(text, func) { + let makeButton = function(text, func) { return { type: "button", content: idrinth.text.get("button." + text), @@ -400,7 +400,7 @@ idrinth.ui = { * @returns {undefined} */ openCloseSettings: function() { - var toRemove = [ + let toRemove = [ idrinth.ui.controls.getAttribute("class").match(/(^|\s)inactive($|\s)/) ? "inactive" : "active" @@ -444,7 +444,7 @@ idrinth.ui = { * @returns {undefined} */ removeElement: function(id) { - var el = document.getElementById(id); + let el = document.getElementById(id); if (el) { el.parentNode.removeChild(el); } @@ -464,13 +464,13 @@ idrinth.ui = { * @param {Array|String} remove * @returns {unresolved} */ - var getClassesList = function(classString, add, remove) { + let getClassesList = function(classString, add, remove) { /** * * @param {String|Array} value * @returns {Array} */ - var forceToArray = function(value) { + let forceToArray = function(value) { return value && typeof value === "object" && Array.isArray(value) && @@ -478,10 +478,10 @@ idrinth.ui = { ? value : []; }; - var original = classString === null + let original = classString === null ? [] : classString.split(" ").concat(forceToArray(add)); - var list = []; + let list = []; remove = forceToArray(remove); /** * @@ -490,7 +490,7 @@ idrinth.ui = { * @param {Array} forbidden * @returns {unresolved} */ - var addUnique = function(list, element, forbidden) { + let addUnique = function(list, element, forbidden) { if (list.indexOf(element) === -1 && forbidden.indexOf(element) === -1) { list.push(element); } @@ -512,9 +512,9 @@ idrinth.ui = { * @returns {undefined} */ activateTab: function(name) { - var head = document.getElementById("tab-activator-" + name).parentNode + let head = document.getElementById("tab-activator-" + name).parentNode .childNodes; - var body = document.getElementById("tab-element-" + name).parentNode + let body = document.getElementById("tab-element-" + name).parentNode .childNodes; /** * @@ -523,7 +523,7 @@ idrinth.ui = { * @param {string} name * @returns {undefined} */ - var setClasses = function(head, body, name) { + let setClasses = function(head, body, name) { if (head === document.getElementById("tab-activator-" + name)) { idrinth.ui.updateClassesList(head, ["active"], []); idrinth.ui.updateClassesList(body, [], ["idrinth-hide"]); @@ -545,17 +545,17 @@ idrinth.ui = { * builds most of the gui * @returns {undefined} */ - var build = function() { + let build = function() { /** * * @returns {Array} */ - var wrapper = function() { + let wrapper = function() { /** * creates the action tab * @returns {Array} */ - var buildActions = function() { + let buildActions = function() { /** * * @param {string} label @@ -563,7 +563,7 @@ idrinth.ui = { * @param {string} platform * @returns {object} */ - var buttonMaker = function(label, onclick, platform) { + let buttonMaker = function(label, onclick, platform) { return { css: "idrinth-float-half" + (platform && platform !== idrinth.platform @@ -644,13 +644,13 @@ idrinth.ui = { * * @returns {Array} */ - var buildTiers = function() { + let buildTiers = function() { /** * * @param {string} label * @returns {object} */ - var makeSearch = function(label) { + let makeSearch = function(label) { return { type: "input", css: "idrinth-float-half", @@ -695,14 +695,14 @@ idrinth.ui = { * * @returns {Array} */ - var buildControls = function() { + let buildControls = function() { /** * * @param {Array} list * @param {String} header * @returns {object} */ - var wrap = function(list, header) { + let wrap = function(list, header) { return { children: [ { @@ -721,8 +721,8 @@ idrinth.ui = { * @param {HTMLElement} element * @returns {undefined} */ - var openCloseSwitch = function(element) { - var isActive = element.parentElement + let openCloseSwitch = function(element) { + let isActive = element.parentElement .getAttribute("class") .match(/(^|\s)active($|\s)/); idrinth.ui.updateClassesList( @@ -934,13 +934,13 @@ idrinth.ui = { * * @returns {Array} */ - var buildLand = function() { + let buildLand = function() { /** * * @param {string} label * @returns {object} */ - var buildItem = function(label) { + let buildItem = function(label) { return { type: "tr", children: [ @@ -1066,14 +1066,14 @@ idrinth.ui = { * * @returns {Array} */ - var buildStats = function() { + let buildStats = function() { /** * * @param {string} label * @returns {object} */ - var buildItem = function(label) { - var isCheck = + let buildItem = function(label) { + let isCheck = label === "mirele" || label === "kraken" || label === "utym"; return { type: "tr", @@ -1186,10 +1186,10 @@ idrinth.ui = { * @param {object} config * @returns {Array} */ - var makeTabs = function(config) { - var head = []; - var first = true; - var body = []; + let makeTabs = function(config) { + let head = []; + let first = true; + let body = []; /** * * @param {string} name @@ -1197,7 +1197,7 @@ idrinth.ui = { * @param {Boolean} first * @returns {object} */ - var buildHead = function(name, width, first) { + let buildHead = function(name, width, first) { return { type: "li", content: idrinth.text.get("ui.tabs." + name), @@ -1222,7 +1222,7 @@ idrinth.ui = { * @param {Boolean} first * @returns {object} */ - var buildBody = function(name, children, first) { + let buildBody = function(name, children, first) { return { type: "li", css: "tab-element" + (first ? "" : " idrinth-hide"), @@ -1230,7 +1230,7 @@ idrinth.ui = { children: children }; }; - var width = Math.floor(100 / Object.keys(config).length); + let width = Math.floor(100 / Object.keys(config).length); for (var name in config) { if (typeof name === "string") { head.push(buildHead(name, width, first)); @@ -1261,14 +1261,14 @@ idrinth.ui = { * * @returns {Array} */ - var buildRaidJoinList = function() { + let buildRaidJoinList = function() { /** * * @param {Array} list * @param {String} header * @returns {object} */ - var wrap = function(list, header) { + let wrap = function(list, header) { return { children: [ { @@ -1338,7 +1338,7 @@ idrinth.ui = { Stats: buildStats() }); }; - var children = wrapper(); + let children = wrapper(); children.unshift({ css: "idrinth-line", type: "strong", @@ -1405,9 +1405,9 @@ idrinth.ui = { * @returns {undefined} */ replaceInValue: function(element) { - var pos = element.selectionStart; - var part = element.value.substr(0, pos + 1); - var pre = part.length; + let pos = element.selectionStart; + let part = element.value.substr(0, pos + 1); + let pre = part.length; part = part.replace(/[^a-f0-9,]/g, ""); part = part.replace(/,{2,}/g, ","); pos = pos + part.length - pre; diff --git a/src/mods/user.js b/src/mods/user.js index db7a664..05028bf 100644 --- a/src/mods/user.js +++ b/src/mods/user.js @@ -29,8 +29,8 @@ idrinth.user = { * @param {Sstring} name * @returns {String} */ - var getCookie = function(name) { - var ca = document.cookie.split(";"); + let getCookie = function(name) { + let 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) { @@ -46,7 +46,7 @@ idrinth.user = { } else if (idrinth.platform === "newgrounds") { idrinth.user.name = getCookie("NG_GG_username"); } else if (idrinth.platform === "armorgames") { - var ag = document + let ag = document .getElementById("gamefilearea") .children[0].src.match( /^.+user_id=([a-f\d]{32})&auth_token=([a-f\d]{32}).+$/ @@ -59,22 +59,22 @@ idrinth.user = { * sends an id to the server for statistic purposes * @returns {undefined} */ - var sendAlive = function() { + let sendAlive = function() { /** * * @returns {String|idrinth.user.identifier} */ - var getIdentifier = function() { + let getIdentifier = function() { /** * from http://stackoverflow.com/a/105074 * @returns {String} */ - var guid = function() { + let guid = function() { /** * * @returns {String} */ - var s4 = function() { + let s4 = function() { return Math.floor((1 + Math.random()) * 0x10000).toString(36); }; return ( diff --git a/src/mods/war.js b/src/mods/war.js index ea7898c..c4d7c38 100644 --- a/src/mods/war.js +++ b/src/mods/war.js @@ -19,7 +19,7 @@ idrinth.war = { * @returns {undefined} */ setTO: function() { - var active = + let active = idrinth.war.element .getAttribute("class") .match(/(^|\s)idrinth-hide($|\s)/) !== null; @@ -40,22 +40,22 @@ idrinth.war = { * @param {object} data * @returns {undefined} */ - var updateData = function(data) { + let updateData = function(data) { /** * * @param {object} data * @returns {undefined} */ - var process = function(data) { + let process = function(data) { /** * * @param {Boolean} onOff * @returns {undefined} */ - var toggleGUI = function(onOff) { - var toggle = onOff || false; - var addClasses = []; - var removeClasses = []; + let toggleGUI = function(onOff) { + let toggle = onOff || false; + let addClasses = []; + let removeClasses = []; if (toggle === true) { removeClasses.push("idrinth-hide"); addClasses.push("bottom"); @@ -81,23 +81,23 @@ idrinth.war = { * @param {object} data * @returns {undefined} */ - var processJson = function(data) { - var magicIgmSrv = + let processJson = function(data) { + let magicIgmSrv = "https://dotd.idrinth.de/static/magic-image-service/"; /** * * @param {object} data * @returns {Array} */ - var getMagic = function(data) { - var magics = []; + let getMagic = function(data) { + let magics = []; if (!data || (data.magics === null || data.magics === "")) { return []; } - var tmp = data.magics.split(","); + let tmp = data.magics.split(","); for (var key = 0; key < tmp.length; key++) { - var magic = tmp[key]; - var magicObj = { + let magic = tmp[key]; + let magicObj = { type: "img", attributes: [ { @@ -148,7 +148,7 @@ idrinth.war = { } cleanUp(); - var tmpMagics = getMagic(data); + let tmpMagics = getMagic(data); for (var m = 0; m < tmpMagics.length; m++) { element .getElementsByTagName("td")[3] @@ -274,8 +274,8 @@ idrinth.war = { * * @returns {String} */ - var raids2Join = function() { - var list = []; + let raids2Join = function() { + let list = []; for (var input in idrinth.war.element.getElementsByTagName("input")) { if (idrinth.war.element.getElementsByTagName("input")[input].checked) { list.push( @@ -307,7 +307,7 @@ idrinth.war = { * build the gui part * @returns {undefined} */ - var build = function() { + let build = function() { idrinth.war.element = idrinth.ui.buildElement({ id: "idrinth-war", css: "idrinth-central-box idrinth-hovering-box idrinth-hide", diff --git a/src/stable.js b/src/stable.js index 5a040f4..3f44b0f 100644 --- a/src/stable.js +++ b/src/stable.js @@ -45,18 +45,18 @@ var idrinth = { * * @returns {undefined} */ - var startInternal = function() { + let startInternal = function() { /** * initializes all modules * @returns {undefined} */ - var init = function() { + let init = function() { if (!idrinth.text.initialized) { return; } if (idrinth.platform === "newgrounds") { try { - var frame = document + let frame = document .getElementById("iframe_embed") .getElementsByTagName("iframe")[0]; idrinth.newgrounds.originalUrl = frame.getAttribute("src");