From cca8029096f351f7b23f63c5f04e2b35dd9929ee Mon Sep 17 00:00:00 2001 From: _XxFedexX_ <_xxfedexx_@noreply.gitgud.wownero.nl> Date: Tue, 15 Nov 2022 20:53:10 +0000 Subject: [PATCH] Fix translation DDoS issue This DDoS issue happened if the language didn't exist or the browser cache was disabled --- js/translations/traduction.js | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/js/translations/traduction.js b/js/translations/traduction.js index d22b329..85b1c37 100644 --- a/js/translations/traduction.js +++ b/js/translations/traduction.js @@ -1,23 +1,15 @@ async function translate(lang) { - if (lang == 'en-US') { return }; + if (lang == 'en-US') return; + if (lang == "it" || lang == "it-CH") lang = "it-IT"; var ids = []; ids = Array.from(document.querySelectorAll('[id]')); - var ids_arr = Array.prototype.map.call(ids, function (element, i) { - return element.id; - }); - for (i = 0; i < ids_arr.length; i++) { - fetchData(ids_arr[i], lang); - } -}; - -async function fetchData(id, lang) { + var ids_arr = Array.prototype.map.call(ids, (element, i)=>{return element.id}); var response = await fetch(`js/translations/${lang}.json`); response = await response.json(); - getTranslation(response, id); + + for (i = 0; i < ids_arr.length; i++) getTranslation(response, ids_arr[i]); }; async function getTranslation(data, keys) { document.getElementById(keys).textContent = JSON.stringify(data[keys]).replace(/["]+/g, ''); -}; - -// console errors are stupid, my code works fine (its late @ night :/) \ No newline at end of file +}; \ No newline at end of file