MediaWiki:Common.js : Différence entre versions

De Clash of Clans France
Aller à : navigation, rechercher
 
(18 révisions intermédiaires par le même utilisateur non affichées)
Ligne 1 : Ligne 1 :
if (wgPageName === "Gemmes") {
+
if (mw.config.get( 'wgPageName' ) === 'Gemmes') {
  
  
  
  
var hasClass = (function() {
+
 
  var reCache = {};
+
//<source lang="javascript">
  return function(element, className) {
+
/* Gem Calculators - Dahimi */
      return ( reCache[className] ? reCache[className] :
+
/* Created by Damihi - Translated in French by Gguigui1 */
        (reCache[className] = new RegExp( "(?:\\s|^)" + className +
+
/* Under CC-BY-SA licence */
        "(?:\\s|$)" ) ) ).test(element.className);
+
var hasClass = (function() {
  };
+
  var reCache = {};
})();
+
  return function(element, className) {
+
  return ( reCache[className] ? reCache[className] :
function hasClassTest(element, className) {
+
(reCache[className] = new RegExp( "(?:\\s|^)" + className +
  // No reason to have two functions that do the same thing
+
"(?:\\s|$)" ) ) ).test(element.className);
  // return element.className.indexOf(className) != -1;
+
  };
  return hasClass(element, className);
+
})();
}
+
function doCalcDarkElixirToGems(resources) {
+
function hasClassTest(element, className) {
  var ranges = [1,10,100,1000,10000,100000];
+
  // No reason to have two functions that do the same thing
  var gems = [1,5,25,125,600,3000];
+
  // return element.className.indexOf(className) != -1;
  var storagemax = 200000;
+
  return hasClass(element, className);
+
}
  if (isNaN(resources)) return("???");
+
function doCalcDarkElixirToGems(resources) {
  else if (resources < 0) return("???");
+
  var ranges = [1,10,100,1000,10000,100000];
  else if (resources == 0) return(0);
+
  var gems = [1,5,25,125,600,3000];
  else if (resources <= ranges[0]) return(gems[0]);
+
  var storagemax = 200000;
+
  for (var i = 1; i < ranges.length-1; i++)
+
  if (isNaN(resources)) return("???");
      if (resources <= ranges[i])  
+
  else if (resources < 0) return("???");
        return(Math.round((resources - ranges[i-1])/((ranges[i] - ranges[i-1])/(gems[i] - gems[i-1])) + gems[i-1]));
+
  else if (resources == 0) return(0);
+
  else if (resources <= ranges[0]) return(gems[0]);
  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]));           
+
  for (var i = 1; i < ranges.length-1; i++)
  else  
+
  if (resources <= ranges[i])  
      return(doCalcDarkElixirToGems(resources % storagemax) + Math.floor(resources/storagemax)*doCalcDarkElixirToGems(storagemax));
+
return(Math.round((resources - ranges[i-1])/((ranges[i] - ranges[i-1])/(gems[i] - gems[i-1])) + gems[i-1]));
+
  return("???");
+
  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  
function doCalcResourceToGems(resources) {
+
  return(doCalcDarkElixirToGems(resources % storagemax) + Math.floor(resources/storagemax)*doCalcDarkElixirToGems(storagemax));
  var ranges = [100,1000,10000,100000,1000000,10000000];
+
  var gems = [1,5,25,125,600,3000];
+
  return("???");
  var storagemax = 8001000;
+
}
+
  if (isNaN(resources)) return("???");
+
function doCalcResourceToGems(resources) {
  else if (resources < 0) return("???");
+
  var ranges = [100,1000,10000,100000,1000000,10000000];
  else if (resources == 0) return(0);
+
  var gems = [1,5,25,125,600,3000];
  else if (resources <= ranges[0]) return(gems[0]);
+
  var storagemax = 8001000;
+
  for (var i = 1; i < ranges.length-1; i++)
+
  if (isNaN(resources)) return("???");
      if (resources <= ranges[i])  
+
  else if (resources < 0) return("???");
        return(Math.round((resources - ranges[i-1])/((ranges[i] - ranges[i-1])/(gems[i] - gems[i-1])) + gems[i-1]));
+
  else if (resources == 0) return(0);
+
  else if (resources <= ranges[0]) return(gems[0]);
  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]));           
+
  for (var i = 1; i < ranges.length-1; i++)
  else  
+
  if (resources <= ranges[i])  
      return(doCalcResourceToGems(resources % storagemax) + Math.floor(resources/storagemax)*doCalcResourceToGems(storagemax));
+
return(Math.round((resources - ranges[i-1])/((ranges[i] - ranges[i-1])/(gems[i] - gems[i-1])) + gems[i-1]));
+
  return("???");
+
  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  
function doCalcTimeToGems(secondsinput) {
+
  return(doCalcResourceToGems(resources % storagemax) + Math.floor(resources/storagemax)*doCalcResourceToGems(storagemax));
  var timerange = [60,3600,86400,604800];
+
  var gemsrange = [1,20,260,1000];
+
  return("???");
+
}
  if (isNaN(secondsinput)) secondsinput = 0;
+
+
function doCalcTimeToGems(secondsinput) {
  if (secondsinput < 0)
+
  var timerange = [60,3600,86400,604800];
      return "???";
+
  var gemsrange = [1,20,260,1000];
  else if (secondsinput === 0)
+
      gems = 0;
+
  if (isNaN(secondsinput)) secondsinput = 0;
  else if (secondsinput <= 246)
+
      gems = gemsrange[0];
+
  if (secondsinput < 0)
  else {
+
  return "???";
      var idx = 3;
+
  else if (secondsinput === 0)
+
  gems = 0;
      for (var i = 1; i < timerange.length; i ++) {
+
  else if (secondsinput <= 246)
        if (secondsinput <= timerange[i]) {
+
  gems = gemsrange[0];
            idx = i;
+
  else {
            break;
+
  var idx = 3;
        }
+
      }
+
  for (var i = 1; i < timerange.length; i ++) {
+
if (secondsinput <= timerange[i]) {
      gems = Math.ceil((secondsinput + 1 - timerange[idx - 1]) *
+
idx = i;
        (gemsrange[idx] - gemsrange[idx - 1]) /
+
break;
        (timerange[idx] - timerange[idx - 1])) + gemsrange[idx - 1] - 1;
+
}
  }
+
  }
+
  return gems;
+
  gems = Math.ceil((secondsinput + 1 - timerange[idx - 1]) *
}
+
(gemsrange[idx] - gemsrange[idx - 1]) /
+
(timerange[idx] - timerange[idx - 1])) + gemsrange[idx - 1] - 1;
/* doCalcGemToCash mis à jour le 29 Juin 2017 */
+
  }
function doCalcGemToCash(gemsinput) {
+
  var cost = [1.09, 5.49, 10.99, 21.99, 54.99, 109.99];
+
  return gems;
  var gems = [80, 500, 1200, 2500, 6500, 14000];
+
}
+
 
  if (isNaN(gemsinput)) return("???");
+
/* doCalcGemToCash mis à jour le 29 Juin 2017 */
+
function doCalcGemToCash(gemsinput) {
  if (gemsinput <= 0) return(0);
+
  var cost = [1.09, 5.49, 10.99, 21.99, 54.99, 109.99];
+
  var gems = [80, 500, 1200, 2500, 6500, 14000];
  for (var i = gems.length-1; i > 0; i--)  
+
      if (gemsinput > gems[i-1]*2)
+
  if (isNaN(gemsinput)) return("???");
        return(cost[i] + doCalcGemToCash(gemsinput - gems[i]));
+
+
  if (gemsinput <= 0) return(0);
  return(cost[0] + doCalcGemToCash(gemsinput - gems[0]));
+
}
+
  for (var i = gems.length-1; i > 0; i--)  
+
  if (gemsinput > gems[i-1]*2)
function calcGemToCash(index) {
+
return(cost[i] + doCalcGemToCash(gemsinput - gems[i]));
  var gems = parseInt(document.getElementById("gem_input_" + index).value.replace(/,/g, ''));
+
  document.getElementById("cash_result_" + index).innerHTML = " = " + Math.round(doCalcGemToCash(gems)*100)/100 + " €";
+
  return(cost[0] + doCalcGemToCash(gemsinput - gems[0]));
+
}
  return false;
+
}
+
function calcGemToCash(index) {
+
  var gems = parseInt(document.getElementById("gem_input_" + index).value.replace(/,/g, ''));
function calcResourceToGems(index) {
+
  document.getElementById("cash_result_" + index).innerHTML = " = " + Math.round(doCalcGemToCash(gems)*100)/100 + " €";
  var resources = parseInt(document.getElementById("resource_input_" + index).value.replace(/,/g, ''));
+
  var result    = doCalcResourceToGems(resources);
+
  return false;
+
}
  if (result != 1)
+
      document.getElementById("gem_result_" + index).innerHTML = " = " + result + " gemmes";
+
function calcResourceToGems(index) {
  else
+
  var resources = parseInt(document.getElementById("resource_input_" + index).value.replace(/,/g, ''));
      document.getElementById("gem_result_" + index).innerHTML = " = " + result + " gemme";     
+
  var result    = doCalcResourceToGems(resources);
+
  return false;
+
  if (result != 1)
}
+
  document.getElementById("gem_result_" + index).innerHTML = " = " + result + " gemmes";
+
  else
function calcDarkElixirToGems(index) {
+
  document.getElementById("gem_result_" + index).innerHTML = " = " + result + " gemme";     
  var resources = parseInt(document.getElementById("de_input_" + index).value.replace(/,/g, ''));
+
  var result    = doCalcDarkElixirToGems(resources);
+
  return false;
+
}
  if (result != 1)
+
      document.getElementById("de_gem_result_" + index).innerHTML = " = " + result + " gemmes";
+
function calcDarkElixirToGems(index) {
  else
+
  var resources = parseInt(document.getElementById("de_input_" + index).value.replace(/,/g, ''));
      document.getElementById("de_gem_result_" + index).innerHTML = " = " + result + " gemme";     
+
  var result    = doCalcDarkElixirToGems(resources);
+
  return false;
+
  if (result != 1)
}
+
  document.getElementById("de_gem_result_" + index).innerHTML = " = " + result + " gemmes";
+
  else
function calcGemsToTime (index) {
+
  document.getElementById("de_gem_result_" + index).innerHTML = " = " + result + " gemme";     
  var gems      = parseInt(document.getElementById("gems2_input_" + index).value.replace(/,/g, ''));
+
  var timerange = [60,3600,86400,604800];
+
  return false;
  var gemsrange = [1,20,260,1000];
+
}
  var seconds  = 0;
+
  var days      = 0;
+
function calcGemsToTime (index) {
  var hours    = 0;
+
  var gems      = parseInt(document.getElementById("gems2_input_" + index).value.replace(/,/g, ''));
  var minutes  = 0;
+
  var timerange = [60,3600,86400,604800];
+
  var gemsrange = [1,20,260,1000];
  if (isNaN(gems)) gems = 0;
+
  var seconds  = 0;
+
  var days      = 0;
  if (gems < 0) {
+
  var hours    = 0;
      document.getElementById("time_result_" + index).innerHTML = " = ???";
+
  var minutes  = 0;
      return false;
+
  }
+
  if (isNaN(gems)) gems = 0;
  else if (gems == 0) {
+
      seconds = 0;
+
  if (gems < 0) {
  }
+
  document.getElementById("time_result_" + index).innerHTML = " = ???";
  else if (gems <= gemsrange[0]) {
+
  return false;
      seconds = 246;
+
  }
  }
+
  else if (gems == 0) {
  else {
+
  seconds = 0;
      gems = gems + 1;
+
  }
+
  else if (gems <= gemsrange[0]) {
      if (gems <= gemsrange[1]) {
+
  seconds = 246;
          seconds = Math.ceil((gems - gemsrange[0])*((timerange[1] - timerange[0])/(gemsrange[1] - gemsrange[0])) + timerange[0])-1;
+
  }
      }
+
  else {
      else if (gems <= gemsrange[2]) {
+
  gems = gems + 1;
          seconds = Math.ceil((gems - gemsrange[1])*((timerange[2] - timerange[1])/(gemsrange[2] - gemsrange[1])) + timerange[1])-1;
+
      }
+
  if (gems <= gemsrange[1]) {
      else {
+
  seconds = Math.ceil((gems - gemsrange[0])*((timerange[1] - timerange[0])/(gemsrange[1] - gemsrange[0])) + timerange[0])-1;
          seconds = Math.ceil((gems - gemsrange[2])*((timerange[3] - timerange[2])/(gemsrange[3] - gemsrange[2])) + timerange[2])-1;
+
  }
      }
+
  else if (gems <= gemsrange[2]) {
  }
+
  seconds = Math.ceil((gems - gemsrange[1])*((timerange[2] - timerange[1])/(gemsrange[2] - gemsrange[1])) + timerange[1])-1;
+
  }
  days    = Math.floor(seconds/(24*60*60));
+
  else {
  seconds = seconds % (24*60*60);
+
  seconds = Math.ceil((gems - gemsrange[2])*((timerange[3] - timerange[2])/(gemsrange[3] - gemsrange[2])) + timerange[2])-1;
  hours  = Math.floor(seconds/(60*60));
+
  }
  seconds = seconds % (60*60);
+
  }
  minutes = Math.floor(seconds/60);
+
  seconds = seconds % 60;
+
  days    = Math.floor(seconds/(24*60*60));
+
  seconds = seconds % (24*60*60);
  document.getElementById("time_result_" + index).innerHTML = " = " + days + "j " + hours + "h " + minutes + "m " + seconds + "s";
+
  hours  = Math.floor(seconds/(60*60));
+
  seconds = seconds % (60*60);
  return false;
+
  minutes = Math.floor(seconds/60);
}
+
  seconds = seconds % 60;
+
function calcTimeToGems(index) {
+
  document.getElementById("time_result_" + index).innerHTML = " = " + days + "j " + hours + "h " + minutes + "m " + seconds + "s";
  var days    = parseInt(document.getElementById("days_input_" + index).value.replace(/,/g, ''));
+
  var hours  = parseInt(document.getElementById("hours_input_" + index).value.replace(/,/g, ''));
+
  return false;
  var minutes = parseInt(document.getElementById("minutes_input_" + index).value.replace(/,/g, ''));
+
}
  var seconds = parseInt(document.getElementById("seconds_input_" + index).value.replace(/,/g, ''));
+
+
function calcTimeToGems(index) {
  var ranges = [60,3600,86400,604800];
+
  var days    = parseInt(document.getElementById("days_input_" + index).value.replace(/,/g, ''));
  var gems  = [1,20,260,1000];
+
  var hours  = parseInt(document.getElementById("hours_input_" + index).value.replace(/,/g, ''));
  var result = 0;
+
  var minutes = parseInt(document.getElementById("minutes_input_" + index).value.replace(/,/g, ''));
+
  var seconds = parseInt(document.getElementById("seconds_input_" + index).value.replace(/,/g, ''));
  if (isNaN(days))    days = 0;
+
  if (isNaN(hours))  hours = 0;
+
  var ranges = [60,3600,86400,604800];
  if (isNaN(minutes)) minutes = 0;
+
  var gems  = [1,20,260,1000];
  if (isNaN(seconds)) seconds = 0;
+
  var result = 0;
+
  seconds = seconds + minutes*60 + hours*3600 + days*86400;
+
  if (isNaN(days))    days = 0;
+
  if (isNaN(hours))  hours = 0;
  if (seconds < 0) {
+
  if (isNaN(minutes)) minutes = 0;
      result = "???"
+
  if (isNaN(seconds)) seconds = 0;
  }
+
  else if (seconds == 0) {
+
  seconds = seconds + minutes*60 + hours*3600 + days*86400;
      result = 0;
+
  }
+
  if (seconds < 0) {
  else if (seconds <= ranges[0]) {
+
  result = "???"
      result = 1;
+
  }
  }
+
  else if (seconds == 0) {
  else if (seconds <= ranges[1]) {
+
  result = 0;
      result = Math.floor((seconds - ranges[0])/((ranges[1] - ranges[0])/(gems[1] - gems[0])) + gems[0]);
+
  }
  }
+
  else if (seconds <= ranges[0]) {
  else if (seconds <= ranges[2]) {
+
  result = 1;
      result = Math.floor((seconds - ranges[1])/((ranges[2] - ranges[1])/(gems[2] - gems[1])) + gems[1]);
+
  }
  }
+
  else if (seconds <= ranges[1]) {
  else {
+
  result = Math.floor((seconds - ranges[0])/((ranges[1] - ranges[0])/(gems[1] - gems[0])) + gems[0]);
      result = Math.floor((seconds - ranges[2])/((ranges[3] - ranges[2])/(gems[3] - gems[2])) + gems[2]);
+
  }
  }
+
  else if (seconds <= ranges[2]) {
+
  result = Math.floor((seconds - ranges[1])/((ranges[2] - ranges[1])/(gems[2] - gems[1])) + gems[1]);
  if (result != 1) {
+
  }
      document.getElementById("gem_time_result_" + index).innerHTML = " = " + result + " gemmes";
+
  else {
  }
+
  result = Math.floor((seconds - ranges[2])/((ranges[3] - ranges[2])/(gems[3] - gems[2])) + gems[2]);
  else {
+
  }
      document.getElementById("gem_time_result_" + index).innerHTML = " = " + result + " gemme";     
+
  }
+
  if (result != 1) {
+
  document.getElementById("gem_time_result_" + index).innerHTML = " = " + result + " gemmes";
  return false;
+
  }
}
+
  else {
+
  document.getElementById("gem_time_result_" + index).innerHTML = " = " + result + " gemme";     
function createGemToCashCalculator() {
+
  }
  var paras  = document.getElementsByTagName("p");
+
  var offset = 0;
+
  return false;
+
}
  for (var index = 0; index < paras.length; index++) {
+
      if (hasClassTest(paras[index], "calc-g2c")) {
+
function createGemToCashCalculator() {
        var form  = document.createElement("form");
+
  var paras  = document.getElementsByTagName("p");
        var input1 = document.createElement("input");
+
  var offset = 0;
        var input2 = document.createElement("input");
+
        var span  = document.createElement("span");
+
  for (var index = 0; index < paras.length; index++) {
+
  if (hasClassTest(paras[index], "calc-g2c")) {
        form.setAttribute("onSubmit", "return calcGemToCash(" + offset + ");");
+
var form  = document.createElement("form");
        input1.setAttribute("size", "10");
+
var input1 = document.createElement("input");
        input1.setAttribute("value", "0");
+
var input2 = document.createElement("input");
        input1.setAttribute("id", "gem_input_" + offset);
+
var span  = document.createElement("span");
+
        input2.setAttribute("type", "button");
+
form.setAttribute("onSubmit", "return calcGemToCash(" + offset + ");");
        input2.setAttribute("value", "Calculer le coût");
+
input1.setAttribute("size", "10");
        input2.setAttribute("onclick", "javascript:calcGemToCash(" + offset + ");");
+
input1.setAttribute("value", "0");
+
input1.setAttribute("id", "gem_input_" + offset);
        span.setAttribute("id", "cash_result_" + offset);
+
        span.innerHTML = " = 0 €";
+
input2.setAttribute("type", "button");
+
input2.setAttribute("value", "Calculer le coût");
        form.appendChild(document.createTextNode("Gemmes: "));
+
input2.setAttribute("onclick", "javascript:calcGemToCash(" + offset + ");");
        form.appendChild(input1);
+
        form.appendChild(input2);
+
span.setAttribute("id", "cash_result_" + offset);
        form.appendChild(span);
+
span.innerHTML = " = 0 €";
+
        paras[index].appendChild(form);
+
form.appendChild(document.createTextNode("Gemmes: "));
        offset++;
+
form.appendChild(input1);
      }
+
form.appendChild(input2);
  }     
+
form.appendChild(span);
}
+
+
paras[index].appendChild(form);
function createResourceToGemCalculator() {
+
offset++;
  var paras = document.getElementsByTagName("p");
+
  }
  var offset = 0;
+
  }     
+
}
  for (var index = 0; index < paras.length; index++) {
+
      if (hasClassTest(paras[index], "calc-r2g")) {
+
function createResourceToGemCalculator() {
        var form  = document.createElement("form");
+
  var paras = document.getElementsByTagName("p");
        var input1 = document.createElement("input");
+
  var offset = 0;
        var input2 = document.createElement("input");
+
        var span  = document.createElement("span");
+
  for (var index = 0; index < paras.length; index++) {
+
  if (hasClassTest(paras[index], "calc-r2g")) {
        form.setAttribute("onSubmit", "return calcResourceToGems(" + offset + ");");
+
var form  = document.createElement("form");
        input1.setAttribute("size", "10");
+
var input1 = document.createElement("input");
        input1.setAttribute("value", "0");
+
var input2 = document.createElement("input");
        input1.setAttribute("id", "resource_input_" + offset);
+
var span  = document.createElement("span");
+
        input2.setAttribute("type", "button");
+
form.setAttribute("onSubmit", "return calcResourceToGems(" + offset + ");");
        input2.setAttribute("value", "Calculer le coût en gemmes");
+
input1.setAttribute("size", "10");
        input2.setAttribute("onclick", "javascript:calcResourceToGems(" + offset + ");");
+
input1.setAttribute("value", "0");
+
input1.setAttribute("id", "resource_input_" + offset);
        span.setAttribute("id", "gem_result_" + offset);
+
        span.innerHTML = " = 0 gemme";
+
input2.setAttribute("type", "button");
+
input2.setAttribute("value", "Calculer le coût en gemmes");
        form.appendChild(document.createTextNode("Or/Elixir: "));
+
input2.setAttribute("onclick", "javascript:calcResourceToGems(" + offset + ");");
        form.appendChild(input1);
+
        form.appendChild(input2);
+
span.setAttribute("id", "gem_result_" + offset);
        form.appendChild(span);
+
span.innerHTML = " = 0 gemme";
+
        paras[index].appendChild(form);
+
form.appendChild(document.createTextNode("Or/Elixir: "));
        offset++;
+
form.appendChild(input1);
      }
+
form.appendChild(input2);
  }     
+
form.appendChild(span);
}
+
+
paras[index].appendChild(form);
function createDarkElixirToGemCalculator() {
+
offset++;
  var paras = document.getElementsByTagName("p");
+
  }
  var offset = 0;
+
  }     
+
}
  for (var index = 0; index < paras.length; index++) {
+
      if (hasClassTest(paras[index], "calc-de2g")) {
+
function createDarkElixirToGemCalculator() {
        var form  = document.createElement("form");
+
  var paras = document.getElementsByTagName("p");
        var input1 = document.createElement("input");
+
  var offset = 0;
        var input2 = document.createElement("input");
+
        var span  = document.createElement("span");
+
  for (var index = 0; index < paras.length; index++) {
+
  if (hasClassTest(paras[index], "calc-de2g")) {
        form.setAttribute("onSubmit", "return calcDarkElixirToGems(" + offset + ");");
+
var form  = document.createElement("form");
        input1.setAttribute("size", "10");
+
var input1 = document.createElement("input");
        input1.setAttribute("value", "0");
+
var input2 = document.createElement("input");
        input1.setAttribute("id", "de_input_" + offset);
+
var span  = document.createElement("span");
+
        input2.setAttribute("type", "button");
+
form.setAttribute("onSubmit", "return calcDarkElixirToGems(" + offset + ");");
        input2.setAttribute("value", "Calculer le coût en gemmes");
+
input1.setAttribute("size", "10");
        input2.setAttribute("onclick", "javascript:calcDarkElixirToGems(" + offset + ");");
+
input1.setAttribute("value", "0");
+
input1.setAttribute("id", "de_input_" + offset);
        span.setAttribute("id", "de_gem_result_" + offset);
+
        span.innerHTML = " = 0 gemme";
+
input2.setAttribute("type", "button");
+
input2.setAttribute("value", "Calculer le coût en gemmes");
        form.appendChild(document.createTextNode("Elixir noir: "));
+
input2.setAttribute("onclick", "javascript:calcDarkElixirToGems(" + offset + ");");
        form.appendChild(input1);
+
        form.appendChild(input2);
+
span.setAttribute("id", "de_gem_result_" + offset);
        form.appendChild(span);
+
span.innerHTML = " = 0 gemme";
+
        paras[index].appendChild(form);
+
form.appendChild(document.createTextNode("Elixir noir: "));
        offset++;
+
form.appendChild(input1);
      }
+
form.appendChild(input2);
  }     
+
form.appendChild(span);
}
+
+
paras[index].appendChild(form);
function createGemsToTimeCalculator() {
+
offset++;
  var paras = document.getElementsByTagName("p");
+
  }
  var offset = 0;
+
  }     
+
}
  for (var index = 0; index < paras.length; index++) {
+
      if (hasClassTest(paras[index], "calc-g2t")) {
+
function createGemsToTimeCalculator() {
        var form  = document.createElement("form");
+
  var paras = document.getElementsByTagName("p");
        var input1 = document.createElement("input");
+
  var offset = 0;
        var input2 = document.createElement("input");
+
        var span  = document.createElement("span");
+
  for (var index = 0; index < paras.length; index++) {
+
  if (hasClassTest(paras[index], "calc-g2t")) {
        form.setAttribute("onSubmit", "return calcGemsToTime(" + offset + ");");
+
var form  = document.createElement("form");
        input1.setAttribute("size", "10");
+
var input1 = document.createElement("input");
        input1.setAttribute("value", "0");
+
var input2 = document.createElement("input");
        input1.setAttribute("id", "gems2_input_" + offset);
+
var span  = document.createElement("span");
+
        input2.setAttribute("type", "button");
+
form.setAttribute("onSubmit", "return calcGemsToTime(" + offset + ");");
        input2.setAttribute("value", "Calculer le temps");
+
input1.setAttribute("size", "10");
        input2.setAttribute("onclick", "javascript:calcGemsToTime(" + offset + ");");
+
input1.setAttribute("value", "0");
+
input1.setAttribute("id", "gems2_input_" + offset);
        span.setAttribute("id", "time_result_" + offset);
+
        span.innerHTML = " = 0j 0h 0m 0s";
+
input2.setAttribute("type", "button");
+
input2.setAttribute("value", "Calculer le temps");
        form.appendChild(document.createTextNode("Gemmes: "));
+
input2.setAttribute("onclick", "javascript:calcGemsToTime(" + offset + ");");
        form.appendChild(input1);
+
        form.appendChild(input2);
+
span.setAttribute("id", "time_result_" + offset);
        form.appendChild(span);
+
span.innerHTML = " = 0j 0h 0m 0s";
+
        paras[index].appendChild(form);
+
form.appendChild(document.createTextNode("Gemmes: "));
        offset++;
+
form.appendChild(input1);
      }
+
form.appendChild(input2);
  }     
+
form.appendChild(span);
}
+
+
paras[index].appendChild(form);
function createTimeToGemCalculator() {
+
offset++;
  var paras = document.getElementsByTagName("p");
+
  }
  var offset = 0;
+
  }     
+
}
  for (var index = 0; index < paras.length; index++) {
+
      if (hasClassTest(paras[index], "calc-t2g")) {
+
function createTimeToGemCalculator() {
        var form  = document.createElement("form");
+
  var paras = document.getElementsByTagName("p");
        var input1 = document.createElement("input");
+
  var offset = 0;
        var input2 = document.createElement("input");
+
        var input3 = document.createElement("input");
+
  for (var index = 0; index < paras.length; index++) {
        var input4 = document.createElement("input");
+
  if (hasClassTest(paras[index], "calc-t2g")) {
        var input5 = document.createElement("input");
+
var form  = document.createElement("form");
        var span  = document.createElement("span");
+
var input1 = document.createElement("input");
+
var input2 = document.createElement("input");
        form.setAttribute("onSubmit", "return calcTimeToGems(" + offset + ");");
+
var input3 = document.createElement("input");
        input1.setAttribute("size", "5");
+
var input4 = document.createElement("input");
        input1.setAttribute("value", "0");
+
var input5 = document.createElement("input");
        input1.setAttribute("id", "days_input_" + offset);
+
var span  = document.createElement("span");
+
        input2.setAttribute("size", "5");
+
form.setAttribute("onSubmit", "return calcTimeToGems(" + offset + ");");
        input2.setAttribute("value", "0");
+
input1.setAttribute("size", "5");
        input2.setAttribute("id", "hours_input_" + offset);
+
input1.setAttribute("value", "0");
+
input1.setAttribute("id", "days_input_" + offset);
        input3.setAttribute("size", "5");
+
        input3.setAttribute("value", "0");
+
input2.setAttribute("size", "5");
        input3.setAttribute("id", "minutes_input_" + offset);
+
input2.setAttribute("value", "0");
+
input2.setAttribute("id", "hours_input_" + offset);
        input4.setAttribute("size", "5");
+
        input4.setAttribute("value", "0");
+
input3.setAttribute("size", "5");
        input4.setAttribute("id", "seconds_input_" + offset);
+
input3.setAttribute("value", "0");
+
input3.setAttribute("id", "minutes_input_" + offset);
        input5.setAttribute("type", "button");
+
        input5.setAttribute("value", "Calculer le coût en gemmes");
+
input4.setAttribute("size", "5");
        input5.setAttribute("onclick", "javascript:calcTimeToGems(" + offset + ");");
+
input4.setAttribute("value", "0");
+
input4.setAttribute("id", "seconds_input_" + offset);
        span.setAttribute("id", "gem_time_result_" + offset);
+
        span.innerHTML = " = 0 gemme";
+
input5.setAttribute("type", "button");
+
input5.setAttribute("value", "Calculer le coût en gemmes");
        form.appendChild(document.createTextNode("J: "));
+
input5.setAttribute("onclick", "javascript:calcTimeToGems(" + offset + ");");
        form.appendChild(input1);
+
        form.appendChild(document.createTextNode(" H: "));
+
span.setAttribute("id", "gem_time_result_" + offset);
        form.appendChild(input2);
+
span.innerHTML = " = 0 gemme";
        form.appendChild(document.createTextNode(" M: "));
+
        form.appendChild(input3);
+
form.appendChild(document.createTextNode("J: "));
        form.appendChild(document.createTextNode(" S: "));
+
form.appendChild(input1);
        form.appendChild(input4);
+
form.appendChild(document.createTextNode(" H: "));
        form.appendChild(input5);
+
form.appendChild(input2);
        form.appendChild(span);
+
form.appendChild(document.createTextNode(" M: "));
+
form.appendChild(input3);
        paras[index].appendChild(form);
+
form.appendChild(document.createTextNode(" S: "));
        offset++;
+
form.appendChild(input4);
      }
+
form.appendChild(input5);
  }     
+
form.appendChild(span);
}
+
+
paras[index].appendChild(form);
addOnloadHook(createGemToCashCalculator);
+
offset++;
addOnloadHook(createTimeToGemCalculator);
+
  }
addOnloadHook(createResourceToGemCalculator);
+
  }     
addOnloadHook(createGemsToTimeCalculator);
+
}
addOnloadHook(createDarkElixirToGemCalculator);
+
 +
$(createGemToCashCalculator);
 +
$(createTimeToGemCalculator);
 +
$(createResourceToGemCalculator);
 +
$(createGemsToTimeCalculator);
 +
$(createDarkElixirToGemCalculator);
 +
//</source>
 +
 
 +
 
  
  

Version actuelle datée du 10 mars 2018 à 16:23

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;
	}

	/* 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    = 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 (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 (seconds == 0) {
		   result = 0;
	   }
	   else if (seconds <= ranges[0]) {
		  result = 1;
	   }
	   else if (seconds <= ranges[1]) {
		  result = Math.floor((seconds - ranges[0])/((ranges[1] - ranges[0])/(gems[1] - gems[0])) + gems[0]);
	   }
	   else if (seconds <= ranges[2]) {
		  result = Math.floor((seconds - ranges[1])/((ranges[2] - ranges[1])/(gems[2] - gems[1])) + gems[1]);
	   }
	   else {
		  result = Math.floor((seconds - ranges[2])/((ranges[3] - ranges[2])/(gems[3] - gems[2])) + gems[2]);
	   }
	 
	   if (result != 1) {
		   document.getElementById("gem_time_result_" + index).innerHTML = " = " + result + " gemmes";
	   }
	   else {
		   document.getElementById("gem_time_result_" + index).innerHTML = " = " + result + " gemme";    
	   }
	 
	   return false;
	}
	 
	function createGemToCashCalculator() {
	   var paras  = document.getElementsByTagName("p");
	   var offset = 0;
	 
	   for (var index = 0; index < paras.length; index++) {
		  if (hasClassTest(paras[index], "calc-g2c")) {
			 var form   = document.createElement("form");
			 var input1 = document.createElement("input");
			 var input2 = document.createElement("input");
			 var span   = document.createElement("span");
	 
			 form.setAttribute("onSubmit", "return calcGemToCash(" + offset + ");");
			 input1.setAttribute("size", "10");
			 input1.setAttribute("value", "0");
			 input1.setAttribute("id", "gem_input_" + offset);
	 
			 input2.setAttribute("type", "button");
			 input2.setAttribute("value", "Calculer le coût");
			 input2.setAttribute("onclick", "javascript:calcGemToCash(" + offset + ");");
	 
			 span.setAttribute("id", "cash_result_" + offset);
			 span.innerHTML = " = 0 €";
	 
			 form.appendChild(document.createTextNode("Gemmes: "));
			 form.appendChild(input1);
			 form.appendChild(input2);
			 form.appendChild(span);
	 
			 paras[index].appendChild(form);
			 offset++;
		  }
	   }     
	}
	 
	function createResourceToGemCalculator() {
	   var paras = document.getElementsByTagName("p");
	   var offset = 0;
	 
	   for (var index = 0; index < paras.length; index++) {
		  if (hasClassTest(paras[index], "calc-r2g")) {
			 var form   = document.createElement("form");
			 var input1 = document.createElement("input");
			 var input2 = document.createElement("input");
			 var span   = document.createElement("span");
	 
			 form.setAttribute("onSubmit", "return calcResourceToGems(" + offset + ");");
			 input1.setAttribute("size", "10");
			 input1.setAttribute("value", "0");
			 input1.setAttribute("id", "resource_input_" + offset);
	 
			 input2.setAttribute("type", "button");
			 input2.setAttribute("value", "Calculer le coût en gemmes");
			 input2.setAttribute("onclick", "javascript:calcResourceToGems(" + offset + ");");
	 
			 span.setAttribute("id", "gem_result_" + offset);
			 span.innerHTML = " = 0 gemme";
	 
			 form.appendChild(document.createTextNode("Or/Elixir: "));
			 form.appendChild(input1);
			 form.appendChild(input2);
			 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>






}