if (mw.config.get( 'wgPageName' ) === 'Gemmes') {
//<source lang="javascript">
/* Gem Calculators - Dahimi */
/* Created by Damihi - Translated in French by Gguigui1 */
/* Under CC-BY-SA licence */
var hasClass = (function() {
var reCache = {};
return function(element, className) {
return ( reCache[className] ? reCache[className] :
(reCache[className] = new RegExp( "(?:\\s|^)" + className +
"(?:\\s|$)" ) ) ).test(element.className);
};
})();
function hasClassTest(element, className) {
// No reason to have two functions that do the same thing
// return element.className.indexOf(className) != -1;
return hasClass(element, className);
}
function doCalcDarkElixirToGems(resources) {
var ranges = [1,10,100,1000,10000,100000];
var gems = [1,5,25,125,600,3000];
var storagemax = 200000;
if (isNaN(resources)) return("???");
else if (resources < 0) return("???");
else if (resources == 0) return(0);
else if (resources <= ranges[0]) return(gems[0]);
for (var i = 1; i < ranges.length-1; i++)
if (resources <= ranges[i])
return(Math.round((resources - ranges[i-1])/((ranges[i] - ranges[i-1])/(gems[i] - gems[i-1])) + gems[i-1]));
if (resources <= storagemax)
return(Math.round((resources - ranges[ranges.length-2])/((ranges[ranges.length-1] - ranges[ranges.length-2])/(gems[gems.length-1] - gems[gems.length-2])) + gems[gems.length-2]));
else
return(doCalcDarkElixirToGems(resources % storagemax) + Math.floor(resources/storagemax)*doCalcDarkElixirToGems(storagemax));
return("???");
}
function doCalcResourceToGems(resources) {
var ranges = [100,1000,10000,100000,1000000,10000000];
var gems = [1,5,25,125,600,3000];
var storagemax = 8001000;
if (isNaN(resources)) return("???");
else if (resources < 0) return("???");
else if (resources == 0) return(0);
else if (resources <= ranges[0]) return(gems[0]);
for (var i = 1; i < ranges.length-1; i++)
if (resources <= ranges[i])
return(Math.round((resources - ranges[i-1])/((ranges[i] - ranges[i-1])/(gems[i] - gems[i-1])) + gems[i-1]));
if (resources <= storagemax)
return(Math.round((resources - ranges[ranges.length-2])/((ranges[ranges.length-1] - ranges[ranges.length-2])/(gems[gems.length-1] - gems[gems.length-2])) + gems[gems.length-2]));
else
return(doCalcResourceToGems(resources % storagemax) + Math.floor(resources/storagemax)*doCalcResourceToGems(storagemax));
return("???");
}
function doCalcTimeToGems(secondsinput) {
var timerange = [60,3600,86400,604800];
var gemsrange = [1,20,260,1000];
if (isNaN(secondsinput)) secondsinput = 0;
if (secondsinput < 0)
return "???";
else if (secondsinput === 0)
gems = 0;
else if (secondsinput <= 246)
gems = gemsrange[0];
else {
var idx = 3;
for (var i = 1; i < timerange.length; i ++) {
if (secondsinput <= timerange[i]) {
idx = i;
break;
}
}
gems = Math.ceil((secondsinput + 1 - timerange[idx - 1]) *
(gemsrange[idx] - gemsrange[idx - 1]) /
(timerange[idx] - timerange[idx - 1])) + gemsrange[idx - 1] - 1;
}
return gems;
}
//<source lang="javascript">/* Gem Calculators - Dahimi *//* Created by Damihi - Translated in French by Gguigui1 *//* Under CC-BY-SA licence */var hasClass = (function() { var reCache = {}; return function(element, className) { return ( reCache[className] ? reCache[className] : (reCache[className] = new RegExp( "(?:\\s|^)" + className + "(?:\\s|$)" ) ) ).test(element.className); };})(); function hasClassTest(element, className) { // No reason to have two functions that do the same thing // return element.className.indexOf(className) != -1; return hasClass(element, className);}function doCalcDarkElixirToGems(resources) { var ranges = [1,10,100,1000,10000,100000]; var gems = [1,5,25,125,600,3000]; var storagemax = 200000; if (isNaN(resources)) return("???"); else if (resources < 0) return("???"); else if (resources == 0) return(0); else if (resources <= ranges[0]) return(gems[0]); for (var i = 1; i < ranges.length-1; i++) if (resources <= ranges[i]) return(Math.round((resources - ranges[i-1])/((ranges[i] - ranges[i-1])/(gems[i] - gems[i-1])) + gems[i-1])); if (resources <= storagemax) return(Math.round((resources - ranges[ranges.length-2])/((ranges[ranges.length-1] - ranges[ranges.length-2])/(gems[gems.length-1] - gems[gems.length-2])) + gems[gems.length-2])); else return(doCalcDarkElixirToGems(resources % storagemax) + Math.floor(resources/storagemax)*doCalcDarkElixirToGems(storagemax)); return("???");} function doCalcResourceToGems(resources) { var ranges = [100,1000,10000,100000,1000000,10000000]; var gems = [1,5,25,125,600,3000]; var storagemax = 8001000; if (isNaN(resources)) return("???"); else if (resources < 0) return("???"); else if (resources == 0) return(0); else if (resources <= ranges[0]) return(gems[0]); for (var i = 1; i < ranges.length-1; i++) if (resources <= ranges[i]) return(Math.round((resources - ranges[i-1])/((ranges[i] - ranges[i-1])/(gems[i] - gems[i-1])) + gems[i-1])); if (resources <= storagemax) return(Math.round((resources - ranges[ranges.length-2])/((ranges[ranges.length-1] - ranges[ranges.length-2])/(gems[gems.length-1] - gems[gems.length-2])) + gems[gems.length-2])); else return(doCalcResourceToGems(resources % storagemax) + Math.floor(resources/storagemax)*doCalcResourceToGems(storagemax)); return("???");} function doCalcTimeToGems(secondsinput) { var timerange = [60,3600,86400,604800]; var gemsrange = [1,20,260,1000]; if (isNaN(secondsinput)) secondsinput = 0; if (secondsinput < 0) return "???"; else if (secondsinput === 0) gems = 0; else if (secondsinput <= 246) gems = gemsrange[0]; else { var idx = 3; for (var i = 1; i < timerange.length; i ++) { if (secondsinput <= timerange[i]) { idx = i; break; } } gems = Math.ceil((secondsinput + 1 - timerange[idx - 1]) * (gemsrange[idx] - gemsrange[idx - 1]) / (timerange[idx] - timerange[idx - 1])) + gemsrange[idx - 1] - 1; } return gems;} /* doCalcGemToCash mis à jour le 29 Juin 2017 */ function doCalcGemToCash(gemsinput) { var cost = [1.09, 5.49, 10.99, 21.99, 54.99, 109.99]; var gems = [80, 500, 1200, 2500, 6500, 14000]; if (isNaN(gemsinput)) return("???"); if (gemsinput <= 0) return(0); for (var i = gems.length-1; i > 0; i--) if (gemsinput > gems[i-1]*2) return(cost[i] + doCalcGemToCash(gemsinput - gems[i])); return(cost[0] + doCalcGemToCash(gemsinput - gems[0])); } function calcGemToCash(index) { var gems = parseInt(document.getElementById("gem_input_" + index).value.replace(/,/g, '')); document.getElementById("cash_result_" + index).innerHTML = " = " + Math.round(doCalcGemToCash(gems)*100)/100 + " €"; return false; } function calcResourceToGems(index) { var resources = parseInt(document.getElementById("resource_input_" + index).value.replace(/,/g, '')); var result = doCalcResourceToGems(resources); if (result != 1) document.getElementById("gem_result_" + index).innerHTML = " = " + result + " gemmes"; else document.getElementById("gem_result_" + index).innerHTML = " = " + result + " gemme"; return false; } function calcDarkElixirToGems(index) { var resources = parseInt(document.getElementById("de_input_" + index).value.replace(/,/g, '')); var result = doCalcDarkElixirToGems(resources); if (result != 1) document.getElementById("de_gem_result_" + index).innerHTML = " = " + result + " gemmes"; else document.getElementById("de_gem_result_" + index).innerHTML = " = " + result + " gemme"; return false; } function calcGemsToTime (index) { var gems = parseInt(document.getElementById("gems2_input_" + index).value.replace(/,/g, '')); var timerange = [60,3600,86400,604800]; var gemsrange = [1,20,260,1000]; var seconds = 0; var days = 0; var hours = 0; var minutes = 0; if (isNaN(gems)) gems = 0; if (gems < 0) { document.getElementById("time_result_" + index).innerHTML = " = ???"; return false; } else if (gems == 0) { seconds = 0; } else if (gems <= gemsrange[0]) { seconds = 246; } else { gems = gems + 1; if (gems <= gemsrange[1]) { seconds = Math.ceil((gems - gemsrange[0])*((timerange[1] - timerange[0])/(gemsrange[1] - gemsrange[0])) + timerange[0])-1; } else if (gems <= gemsrange[2]) { seconds = Math.ceil((gems - gemsrange[1])*((timerange[2] - timerange[1])/(gemsrange[2] - gemsrange[1])) + timerange[1])-1; } else { seconds = Math.ceil((gems - gemsrange[2])*((timerange[3] - timerange[2])/(gemsrange[3] - gemsrange[2])) + timerange[2])-1; } } days = Math.floor(seconds/(24*60*60)); seconds = seconds % (24*60*60); hours = Math.floor(seconds/(60*60)); seconds = seconds % (60*60); minutes = Math.floor(seconds/60); seconds = seconds % 60; document.getElementById("time_result_" + index).innerHTML = " = " + days + "j " + hours + "h " + minutes + "m " + seconds + "s";
return false;
} function calcTimeToGems(index) { var days else = parseInt(document.getElementById("days_input_" + index).value.replace(/,/g, '')); var hours = parseInt(document.getElementById("hours_input_" + index).value.replace(/,/g, '')); var minutes = parseInt(document.getElementById("minutes_input_" + index).value.replace(/,/g, '')); var seconds = parseInt(document.getElementById("seconds_input_" + index).value.replace(/,/g, '')); var ranges = [60,3600,86400,604800]; var gems = [1,20,260,1000]; var result = 0; if (gems isNaN(days)) days =0; if (isNaN(hours)) hours = 0; if (isNaN(minutes)) {minutes = 0; if (isNaN(seconds)) seconds = 0; seconds = seconds + minutes*60 + hours*3600 + days*86400; if (seconds < 0) { result = "???" } else if (gems <seconds == gemsrange[0]) { seconds result = 2460; } else if (seconds <= ranges[0]) { gems result = gems + 1; } else if (gems seconds <= gemsrangeranges[1]) { seconds result = Math.ceilfloor((gems seconds - gemsrangeranges[0])*/((timerangeranges[1] - timerangeranges[0])/(gemsrangegems[1] - gemsrangegems[0])) + timerangegems[0])-1;
}
else if (gems seconds <= gemsrangeranges[2]) { seconds result = Math.ceilfloor((gems seconds - gemsrangeranges[1])*/((timerangeranges[2] - timerangeranges[1])/(gemsrangegems[2] - gemsrangegems[1])) + timerangegems[1])-1;
}
else {
seconds result = Math.ceilfloor((gems seconds - gemsrangeranges[2])*/((timerangeranges[3] - timerangeranges[2])/(gemsrangegems[3] - gemsrangegems[2])) + timerangegems[2])-; } if (result != 1) { document.getElementById("gem_time_result_" + index).innerHTML = " = " + result + " gemmes";
}
} else { days = Math document.floorgetElementById(seconds/(24*60*60"gem_time_result_" + index)); seconds .innerHTML = seconds % (24*60*60)" = " + result + " gemme"; hours = Math.floor(seconds/(60*60)); seconds = seconds % (60*60); } minutes = Math.floor return false; } function createGemToCashCalculator(seconds/60);{ seconds var paras = seconds % 60; document.getElementByIdgetElementsByTagName("time_result_p" + index).innerHTML ; var offset = " 0; for (var index = " + days + "j " 0; index < paras.length; index+ hours + ) { if (hasClassTest(paras[index], "h calc-g2c" + minutes + )) { var form = document.createElement("m form" + seconds + ); var input1 = document.createElement("sinput"); return false;} function calcTimeToGems(index) { var days var input2 = parseInt(document.getElementByIdcreateElement("days_input_input" + index).value.replace(/,/g, '')); var hours span = parseInt(document.getElementByIdcreateElement("hours_input_span" + index); form.value.replacesetAttribute(/"onSubmit",/g, ''"return calcGemToCash(" + offset + ");"); var minutes = parseInt(document input1.getElementByIdsetAttribute("minutes_input_size" + index).value.replace(/,/g, '')"10"); var seconds = parseInt(document input1.getElementByIdsetAttribute("seconds_input_value", "0" + index); input1.value.replacesetAttribute(/"id",/g, '')"gem_input_" + offset); var ranges = [60 input2.setAttribute("type",3600,86400,604800]"button"); var gems = [1 input2.setAttribute("value",20,260,1000]"Calculer le coût"); var result = 0; if input2.setAttribute(isNaN(days)) days = 0; if "onclick", "javascript:calcGemToCash(isNaN(hours" + offset + ");") hours = 0; if span.setAttribute(isNaN(minutes"id", "cash_result_" + offset)) minutes ; span.innerHTML = " = 0€"; if form.appendChild(isNaNdocument.createTextNode(seconds"Gemmes: ")) seconds = 0; seconds = seconds + minutes*60 + hours*3600 + days*86400 form.appendChild(input1); form.appendChild(input2); if form.appendChild(seconds < 0span) {; result = "???" } else if paras[index].appendChild(seconds == 0form) {; result = 0 offset++; } } else if (seconds <= ranges[0]) { } result = 1; } else if function createResourceToGemCalculator(seconds <= ranges[1]) { result var paras = Mathdocument.floorgetElementsByTagName((seconds - ranges["p"); var offset = 0])/; for ((ranges[1] - ranges[var index = 0]; index < paras.length; index++)/{ if (hasClassTest(gemsparas[1index] , "calc- gems[0]r2g")) + gems[0]{ var form = document.createElement("form"); } else if var input1 = document.createElement(seconds <= ranges[2]"input") {; result var input2 = Mathdocument.floorcreateElement((seconds - ranges[1]"input")/; var span = document.createElement((ranges[2] - ranges[1]"span")/; form.setAttribute(gems[2] - gems[1]"onSubmit", "return calcResourceToGems(" + offset + ")) + gems[1];"); } input1.setAttribute("size", "10"); else { result = Math input1.floorsetAttribute((seconds - ranges[2]"value", "0")/; input1.setAttribute((ranges[3] - ranges[2]"id", "resource_input_" + offset)/; input2.setAttribute(gems[3] - gems[2])) + gems[2]"type", "button"); } if input2.setAttribute(result != 1"value", "Calculer le coût en gemmes") {; document input2.getElementByIdsetAttribute("gem_time_result_onclick" + index).innerHTML = , " = javascript:calcResourceToGems(" + result offset + " gemmes);"); } else { document span.getElementByIdsetAttribute("gem_time_result_id", "gem_result_" + indexoffset); span.innerHTML = " = " + result + " 0 gemme"; } return false;} function createGemToCashCalculator form.appendChild() { var paras = document.getElementsByTagNamecreateTextNode("pOr/Elixir: ")); var offset = 0 form.appendChild(input1); form.appendChild(input2); for form.appendChild(var index = 0span); paras[index < paras].lengthappendChild(form); index offset++) {; } if (hasClassTest } } function createDarkElixirToGemCalculator(paras[index], "calc-g2c")) { var form paras = document.createElementgetElementsByTagName("formp"); var input1 offset = document.createElement("input")0; for (var input2 index = document0; index < paras.createElement("inputlength; index++) { if (hasClassTest(paras[index], "calc-de2g");) { var span form = document.createElement("spanform"); form var input1 = document.setAttributecreateElement("onSubmitinput", "return calcGemToCash); var input2 = document.createElement(" + offset + input"); var span = document.createElement("span"); input1 form.setAttribute("sizeonSubmit", "10return calcDarkElixirToGems(" + offset + ");"); input1.setAttribute("size", "10"); input1.setAttribute("value", "0"); input1.setAttribute("id", "gem_input_de_input_" + offset); input2.setAttribute("type", "button"); input2.setAttribute("value", "Calculer le coûten gemmes"); input2.setAttribute("onclick", "javascript:calcGemToCashcalcDarkElixirToGems(" + offset + ");"); span.setAttribute("id", "cash_result_de_gem_result_" + offset); span.innerHTML = " = 0 €gemme"; form.appendChild(document.createTextNode("GemmesElixir noir: ")); form.appendChild(input1); form.appendChild(input2); form.appendChild(span); paras[index].appendChild(form); offset++; } } } function createResourceToGemCalculatorcreateGemsToTimeCalculator() { var paras = document.getElementsByTagName("p"); var offset = 0; for (var index = 0; index < paras.length; index++) { if (hasClassTest(paras[index], "calc-r2gg2t")) { var form = document.createElement("form"); var input1 = document.createElement("input"); var input2 = document.createElement("input"); var span = document.createElement("span"); form.setAttribute("onSubmit", "return calcResourceToGemscalcGemsToTime(" + offset + ");"); input1.setAttribute("size", "10"); input1.setAttribute("value", "0"); input1.setAttribute("id", "resource_input_gems2_input_" + offset); input2.setAttribute("type", "button"); input2.setAttribute("value", "Calculer le coût en gemmestemps"); input2.setAttribute("onclick", "javascript:calcResourceToGemscalcGemsToTime(" + offset + ");"); span.setAttribute("id", "gem_result_time_result_" + offset); span.innerHTML = " = 0 gemme0j 0h 0m 0s"; form.appendChild(document.createTextNode("Or/ElixirGemmes: ")); form.appendChild(input1); form.appendChild(input2);; form.appendChild(span); paras[index].appendChild(form); offset++; } } } function createTimeToGemCalculator() { var paras = document.getElementsByTagName("p"); var offset = 0; for (var index = 0; index < paras.length; index++) { if (hasClassTest(paras[index], "calc-t2g")) { var form = document.createElement("form"); var input1 = document.createElement("input"); var input2 = document.createElement("input"); var input3 = document.createElement("input"); var input4 = document.createElement("input"); var input5 = document.createElement("input"); var span = document.createElement("span"); form.setAttribute("onSubmit", "return calcTimeToGems(" + offset + ");"); input1.setAttribute("size", "5"); input1.setAttribute("value", "0"); input1.setAttribute("id", "days_input_" + offset); input2.setAttribute("size", "5"); input2.setAttribute("value", "0"); input2.setAttribute("id", "hours_input_" + offset); input3.setAttribute("size", "5"); input3.setAttribute("value", "0"); input3.setAttribute("id", "minutes_input_" + offset); input4.setAttribute("size", "5"); input4.setAttribute("value", "0"); input4.setAttribute("id", "seconds_input_" + offset); input5.setAttribute("type", "button"); input5.setAttribute("value", "Calculer le coût en gemmes"); input5.setAttribute("onclick", "javascript:calcTimeToGems(" + offset + ");"); span.setAttribute("id", "gem_time_result_" + offset); span.innerHTML = " = 0 gemme"; form.appendChild(document.createTextNode("J: ")); form.appendChild(input1); form.appendChild(document.createTextNode(" H: ")); form.appendChild(input2); form.appendChild(document.createTextNode(" M: ")); form.appendChild(input3); form.appendChild(document.createTextNode(" S: ")); form.appendChild(input4); form.appendChild(input5); form.appendChild(span); paras[index].appendChild(form); offset++; } } } $(createGemToCashCalculator); $(createTimeToGemCalculator); $(createResourceToGemCalculator); $(createGemsToTimeCalculator); $(createDarkElixirToGemCalculator);//</source> form.appendChild(span); paras[index].appendChild(form); offset++; } }
}
function createDarkElixirToGemCalculator() {
var paras = document.getElementsByTagName("p");
var offset = 0;
for (var index = 0; index < paras.length; index++) {
if (hasClassTest(paras[index], "calc-de2g")) {
var form = document.createElement("form");
var input1 = document.createElement("input");
var input2 = document.createElement("input");
var span = document.createElement("span");
form.setAttribute("onSubmit", "return calcDarkElixirToGems(" + offset + ");");
input1.setAttribute("size", "10");
input1.setAttribute("value", "0");
input1.setAttribute("id", "de_input_" + offset);
input2.setAttribute("type", "button");
input2.setAttribute("value", "Calculer le coût en gemmes");
input2.setAttribute("onclick", "javascript:calcDarkElixirToGems(" + offset + ");");
span.setAttribute("id", "de_gem_result_" + offset);
span.innerHTML = " = 0 gemme";
form.appendChild(document.createTextNode("Elixir noir: "));
form.appendChild(input1);
form.appendChild(input2);
form.appendChild(span);
paras[index].appendChild(form);
offset++;
}
}
}
function createGemsToTimeCalculator() {
var paras = document.getElementsByTagName("p");
var offset = 0;
for (var index = 0; index < paras.length; index++) {
if (hasClassTest(paras[index], "calc-g2t")) {
var form = document.createElement("form");
var input1 = document.createElement("input");
var input2 = document.createElement("input");
var span = document.createElement("span");
form.setAttribute("onSubmit", "return calcGemsToTime(" + offset + ");");
input1.setAttribute("size", "10");
input1.setAttribute("value", "0");
input1.setAttribute("id", "gems2_input_" + offset);
input2.setAttribute("type", "button");
input2.setAttribute("value", "Calculer le temps");
input2.setAttribute("onclick", "javascript:calcGemsToTime(" + offset + ");");
span.setAttribute("id", "time_result_" + offset);
span.innerHTML = " = 0j 0h 0m 0s";
form.appendChild(document.createTextNode("Gemmes: "));
form.appendChild(input1);
form.appendChild(input2);
form.appendChild(span);
paras[index].appendChild(form);
offset++;
}
}
}
function createTimeToGemCalculator() {
var paras = document.getElementsByTagName("p");
var offset = 0;
for (var index = 0; index < paras.length; index++) {
if (hasClassTest(paras[index], "calc-t2g")) {
var form = document.createElement("form");
var input1 = document.createElement("input");
var input2 = document.createElement("input");
var input3 = document.createElement("input");
var input4 = document.createElement("input");
var input5 = document.createElement("input");
var span = document.createElement("span");
form.setAttribute("onSubmit", "return calcTimeToGems(" + offset + ");");
input1.setAttribute("size", "5");
input1.setAttribute("value", "0");
input1.setAttribute("id", "days_input_" + offset);
input2.setAttribute("size", "5");
input2.setAttribute("value", "0");
input2.setAttribute("id", "hours_input_" + offset);
input3.setAttribute("size", "5");
input3.setAttribute("value", "0");
input3.setAttribute("id", "minutes_input_" + offset);
input4.setAttribute("size", "5");
input4.setAttribute("value", "0");
input4.setAttribute("id", "seconds_input_" + offset);
input5.setAttribute("type", "button");
input5.setAttribute("value", "Calculer le coût en gemmes");
input5.setAttribute("onclick", "javascript:calcTimeToGems(" + offset + ");");
span.setAttribute("id", "gem_time_result_" + offset);
span.innerHTML = " = 0 gemme";
form.appendChild(document.createTextNode("J: "));
form.appendChild(input1);
form.appendChild(document.createTextNode(" H: "));
form.appendChild(input2);
form.appendChild(document.createTextNode(" M: "));
form.appendChild(input3);
form.appendChild(document.createTextNode(" S: "));
form.appendChild(input4);
form.appendChild(input5);
form.appendChild(span);
paras[index].appendChild(form);
offset++;
}
}
}
$(createGemToCashCalculator);
$(createTimeToGemCalculator);
$(createResourceToGemCalculator);
$(createGemsToTimeCalculator);
$(createDarkElixirToGemCalculator);
//</source>