var fahrzeugklassen = {}; var praemien=[{"FZGKLASSEN":"M1","PRAEMIE":60,"KWH":2000},{"FZGKLASSEN":"N1","PRAEMIE":90,"KWH":3000},{"FZGKLASSEN":"N2","PRAEMIE":615,"KWH":20600},{"FZGKLASSEN":"N3","PRAEMIE":1000,"KWH":33400},{"FZGKLASSEN":"M3","PRAEMIE":2160,"KWH":72000},{"FZGKLASSEN":"L7E-CU","PRAEMIE":60,"KWH":2000},{"FZGKLASSEN":"L7e-CP","PRAEMIE":60,"KWH":2000},{"FZGKLASSEN":"L7e","PRAEMIE":60,"KWH":2000},{"FZGKLASSEN":"L3e-A3","PRAEMIE":60,"KWH":2000},{"FZGKLASSEN":"L3e-A2","PRAEMIE":60,"KWH":2000},{"FZGKLASSEN":"L3e","PRAEMIE":60,"KWH":2000},{"FZGKLASSEN":"L3e-A2E","PRAEMIE":60,"KWH":2000},{"FZGKLASSEN":"L4e-A2","PRAEMIE":60,"KWH":2000},{"FZGKLASSEN":"L4e-A3","PRAEMIE":60,"KWH":2000},{"FZGKLASSEN":"L5e-B","PRAEMIE":60,"KWH":2000},{"FZGKLASSEN":"L7e-B1","PRAEMIE":60,"KWH":2000},{"FZGKLASSEN":"L7e-B2","PRAEMIE":60,"KWH":2000},{"FZGKLASSEN":"L7e-C1","PRAEMIE":60,"KWH":2000},{"FZGKLASSEN":"L7e-C2","PRAEMIE":60,"KWH":2000},{"FZGKLASSEN":"L3e-A2T","PRAEMIE":60,"KWH":2000},{"FZGKLASSEN":"L3e-A3T","PRAEMIE":60,"KWH":2000},{"FZGKLASSEN":"L5e","PRAEMIE":60,"KWH":2000},{"FZGKLASSEN":"L4e","PRAEMIE":60,"KWH":2000},{"FZGKLASSEN":"Ladesaeule","PRAEMIE":0.03,"KWH":1}]; window.addEventListener("DOMContentLoaded", replace_praemien); function replace_praemien(){ var replacements={}; for (let praemie of praemien){ if(Array.isArray(praemie["FZGKLASSEN"]))praemie["FZGKLASSEN"]="roller"; replacements["_"+praemie["FZGKLASSEN"]+":KWH_"]=fmt_tp(praemie["KWH"]); replacements["_"+praemie["FZGKLASSEN"]+"_"]=fmt_tp(praemie["PRAEMIE"]); fahrzeugklassen[praemie["FZGKLASSEN"].toUpperCase()]=1; } //console.log(replacements); replaceTextOnPage(replacements); } function replaceTextOnPage(replacements){ getAllTextNodes().forEach(function(node){ for(let replacement in replacements){ node.nodeValue = node.nodeValue.replace(new RegExp(quote(replacement), "g"), replacements[replacement]); } }); } function getAllTextNodes(){ var result = []; (function scanSubTree(node){ if(node.childNodes.length) for(var i = 0; i < node.childNodes.length; i++) scanSubTree(node.childNodes[i]); else if(node.nodeType == Node.TEXT_NODE) result.push(node); })(document); return result; } function quote(str){ return (str+"").replace(/([.?*+^$[\]\(){}|-])/g, "\$1"); } function fmt_tp(thevalue) { stellen=0; newval = thevalue * 1; if(newval%1)stellen=3; aval = newval.toFixed(stellen).split("."); vk = aval[0]; vkn = ""; for (i = vk.length; i > 0; i -= 3) { if (i > 3) { vkn = "." + vk.substring(i - 3, i) + vkn; } else { vkn = vk.substring(0, i) + vkn; } } if (stellen > 0) { gl = vkn + "," + aval[1]; } else { gl = vkn; } return gl; }