Greasy Fork is available in English.

Price Per battle

Show Price per battle in market. If you encounter problem, contact me https://www.lordswm.com/pl_info.php?id=6997830

  1. // ==UserScript==
  2. // @name Price Per battle
  3. // @namespace https://www.lordswm.com
  4. // @version 0.8
  5. // @description Show Price per battle in market. If you encounter problem, contact me https://www.lordswm.com/pl_info.php?id=6997830
  6. // @author You
  7. // @match https://www.lordswm.com/auction.php*
  8. // @grant none
  9. // ==/UserScript==
  10.  
  11. (function() {
  12. 'use strict';
  13. const localStorageKey = "repairCostArtifacts";
  14. const localStorageRcKey = "repairCostRepairCost";
  15. const localStorageEfficiencyKey = "repairCostRepairEfficiency";
  16. const storage = window.localStorage;
  17. let existKey = storage.getItem(localStorageKey);
  18. let artToSaveCost;
  19. if(existKey === null){
  20. storage.setItem(localStorageKey,"{}")
  21. }
  22. existKey = storage.getItem(localStorageRcKey);
  23. if(existKey === null){
  24. storage.setItem(localStorageRcKey,101)
  25. }
  26. existKey = storage.getItem(localStorageEfficiencyKey);
  27. if(existKey === null){
  28. storage.setItem(localStorageEfficiencyKey,90)
  29. }
  30.  
  31. document.querySelectorAll("tr.wb").forEach(x=>{
  32. try{
  33. let s = x.innerText;
  34. let index = s.search("Durability: ")+"Durability: ".length;
  35. let dur = parseInt(s.substr(index));
  36. let maxDur = parseInt(s.substr(index).split("/")[1])
  37. let splited = s.split('\n');
  38. /*index = 4;
  39. if (splited.indexOf("Buyout price:")!=-1){
  40. index=6;
  41. }
  42. if (splited.indexOf(" Buy now! ")!=-1){
  43. index=splited.indexOf(" Buy now! ")+1;
  44. }
  45. */
  46.  
  47. let price = parseInt(x.children[2].innerText.replaceAll(',',''))
  48. if(isNaN(price/dur))
  49. {
  50. return;
  51. }
  52. //console.log(price/dur);
  53. let ele = document.createElement('p');
  54. ele.id = "ppb";
  55. ele.price = price;
  56. ele.dur = dur;
  57. ele.maxDur = maxDur;
  58. ele.innerText = "Price per battle = "+(price/dur).toFixed(2);
  59. ele.fatherWow = x;
  60. ele.cpb = (price/dur);
  61. x.children[0].appendChild(ele)
  62. }
  63. catch(err)
  64. {
  65. console.log(err);
  66. }
  67. })
  68.  
  69. let url = new URL(document.URL);
  70. let artType = url.searchParams.get("art_type");
  71. if (artType !== null)
  72. {
  73. console.log("its art market, run prices")
  74.  
  75. let selling = document.querySelector("td.wbwhite");
  76. let div = document.createElement("div");
  77.  
  78. let i = document.createElement("input");
  79. //i.setAttribute("placeholder", "");
  80. let label = document.createElement("label");
  81. label.for = "repairCost";
  82. label.innerText = "Repair Cost "
  83. i.id = "repairCost";
  84. i.size = "5"
  85. //i.value = 16000;
  86. let rc = getArtPrice(artType)
  87. if(rc!==undefined)
  88. {
  89. i.value = rc;
  90.  
  91. }
  92. //this indicate we need to save repair cost when clicked on calc
  93. artToSaveCost = artType;
  94.  
  95. div.appendChild(label)
  96. div.appendChild(i)
  97.  
  98.  
  99. i = document.createElement("input");
  100. i.id = "repairEfficiency";
  101. //i.setAttribute("placeholder", "Repair efficiency");
  102. i.value = storage.getItem(localStorageEfficiencyKey);
  103. i.size = "5"
  104. label = document.createElement("label");
  105. label.for = "repairEfficiency";
  106. label.innerText = " Repair Efficiency % "
  107. div.appendChild(label)
  108. div.appendChild(i)
  109.  
  110.  
  111. i = document.createElement("input");
  112. i.id = "bsRepairCost";
  113. //i.setAttribute("placeholder", "Repair cost");
  114. i.value = storage.getItem(localStorageRcKey);
  115. i.size = "5"
  116. label = document.createElement("label");
  117. label.for = "bsRepairCost";
  118. label.innerText = " Smith cost % "
  119.  
  120. div.appendChild(label)
  121. div.appendChild(i)
  122.  
  123. i = document.createElement("button");
  124. i.innerText = "Calculate with repairing";
  125. i.onclick=calcPriceAllArts;
  126. div.appendChild(i)
  127. selling.prepend(div)
  128. if(rc!==undefined){
  129. i.click();
  130. }
  131. }
  132.  
  133. function sortByCpb(){
  134. Array.from(document.querySelectorAll("p#ppb")).sort((a,b)=>a.cpb<b.cpb?-1:1).forEach(x=>x.fatherWow.parentElement.appendChild(x.fatherWow));
  135. }
  136.  
  137. function calcPriceAllArts()
  138. {
  139. let repairCost = parseInt(document.querySelector("input#repairCost").value);
  140. setArtPrice(artToSaveCost,repairCost);
  141.  
  142. let repairEfficiency = parseInt(document.querySelector("input#repairEfficiency").value);
  143. storage.setItem(localStorageEfficiencyKey,repairEfficiency);
  144.  
  145. let bsRepairCost = parseInt(document.querySelector("input#bsRepairCost").value);
  146. storage.setItem(localStorageRcKey,bsRepairCost);
  147.  
  148. document.querySelectorAll("p#ppb").forEach(x=>{
  149. let calculated = calcPrice(x.dur,x.maxDur,x.price,repairCost,repairEfficiency,bsRepairCost);
  150. x.innerText=`Lowest PPB: ${calculated.cpb.toFixed(2)} after ${calculated.numberOfRepairs} repairs`
  151. x.cpb = calculated.cpb;
  152.  
  153. })
  154. sortByCpb();
  155. }
  156.  
  157. function calcPrice(dur,maxDur,auctionCost,artRepairCost,repairEfficiency,bsRepairCost){
  158. //calcPrice(60,70,16000,15555,90,101)example
  159. let maxDuration = maxDur;
  160. let cpb;
  161. let numberOfRepairs = -1;
  162. let totalDuration = dur;
  163. let totalCost = auctionCost;
  164. let previousCPB;
  165. let actualCPB;
  166. do{
  167.  
  168. previousCPB= totalCost/totalDuration;
  169. numberOfRepairs++;
  170. cpb = previousCPB;
  171. totalDuration += Math.floor(maxDuration*repairEfficiency/100);
  172. totalCost += artRepairCost*bsRepairCost/100;
  173. maxDuration -= 1;
  174. console.log(maxDuration,totalDuration,totalCost);
  175. actualCPB = totalCost/totalDuration;
  176. }
  177. while(actualCPB<previousCPB);
  178. console.log(cpb,numberOfRepairs);
  179. return {cpb:cpb,numberOfRepairs:numberOfRepairs};
  180. }
  181. window.calcPrice = calcPrice;
  182.  
  183.  
  184. function getArtPrice(artName){
  185. let stringArts = storage.getItem(localStorageKey);
  186. let arts = JSON.parse(stringArts);
  187. return arts[artName];
  188. }
  189.  
  190. function setArtPrice(artName, artPrice) {
  191. let stringArts = storage.getItem(localStorageKey);
  192. let arts = JSON.parse(stringArts);
  193. arts[artName] = artPrice;
  194. storage.setItem(localStorageKey,JSON.stringify(arts))
  195. }
  196.  
  197. })();