Sets price indicator

Telling you if the price of the sets is between the lower price and your maximum price by coloring the gems price (Green is ok, red isn't).

  1. // ==UserScript==
  2. // @name Sets price indicator
  3. // @version 0.4
  4. // @description Telling you if the price of the sets is between the lower price and your maximum price by coloring the gems price (Green is ok, red isn't).
  5. // @author Zeper
  6. // @match https://steamlvlup.com/levelup*
  7. // @grant none
  8. // @namespace https://greasyfork.org/users/191481
  9. // ==/UserScript==
  10.  
  11. ///////////////////////////////////
  12. // WHERE THE ACTUAL MAGIC HAPPEN //
  13. ///////////////////////////////////
  14. var sets = document.getElementById('calc_sets');
  15. var gems = document.getElementById("calc_gems");
  16. var minprice = 160;
  17. if(localStorage.minprice === undefined) {localStorage.setItem("minprice", minprice);} else {minprice = parseInt(localStorage.getItem("minprice"));}
  18. var maxprice = 200;
  19. if(localStorage.maxprice === undefined) {localStorage.setItem("maxprice", maxprice);} else {maxprice = parseInt(localStorage.getItem("maxprice"));}
  20.  
  21. function check() {
  22. var setsvalue = sets.innerHTML;
  23. var setsprice = Math.round(gems.innerHTML/setsvalue);
  24. if (setsprice > 0)
  25. {
  26. if (setsprice >= minprice && setsprice <= maxprice)
  27. {
  28. gems.style = "color: green !important;";
  29. }
  30. else
  31. {
  32. gems.style = "color: red !important;";
  33. }
  34. gems.title = setsprice + " gems per Sets" ;
  35. } else
  36. {
  37. gems.style = "";
  38. }
  39. }
  40.  
  41. new MutationObserver(check).observe(sets, { attributes: false, childList: true, subtree: false });
  42.  
  43. ///////////////////////
  44. // BORING GUI STUFF //
  45. //////////////////////
  46. var hf_count_min = document.createElement("INPUT");
  47. hf_count_min.setAttribute("id", "min_price");
  48. hf_count_min.setAttribute("class", "hf_count_title hf_count level_input input_disabled hf_count");
  49. hf_count_min.setAttribute("readonly", "");
  50. hf_count_min.setAttribute("title", "MINIMUM PRICE\nIt's the lowest price of available sets on the website.\n\nDON'T edit this if you don't know what you're doing !\nIf you change it to a wrong value it will cause issue to the script.\n\nIf you still realy want to edit this make an right click on it.\n\nDefault value: 160");
  51. hf_count_min.setAttribute("placeholder", "MIN PRICE");
  52.  
  53. var hf_count_max = document.createElement("INPUT");
  54. hf_count_max.setAttribute("id", "max_price");
  55. hf_count_max.setAttribute("class", "hf_count_title hf_count level_input hf_count");
  56. hf_count_max.setAttribute("placeholder", "MAX PRICE");
  57. hf_count_max.setAttribute("title", "MAXIMUM PRICE");
  58.  
  59. var head_frame_count = document.createElement("DIV");
  60. head_frame_count.setAttribute("class", "head_frame_count");
  61. head_frame_count.setAttribute("style", "width: auto;display: inline-flex;");
  62. head_frame_count.appendChild(hf_count_min);
  63. head_frame_count.appendChild(hf_count_max);
  64. document.getElementsByClassName("head_frame_line")[1].appendChild(head_frame_count);
  65.  
  66. var min_price = document.getElementById("min_price");
  67. var max_price = document.getElementById("max_price");
  68.  
  69. min_price.value = minprice;
  70. max_price.value = maxprice;
  71.  
  72. function update() {
  73. if (parseInt(min_price.value) > 0 && parseInt(max_price.value) >= parseInt(min_price.value)){
  74. minprice = parseInt(min_price.value);
  75. localStorage.setItem("minprice", minprice);
  76. maxprice = parseInt(max_price.value);
  77. localStorage.setItem("maxprice", maxprice);
  78. check();
  79. } else {
  80. console.warn("Error:\n Min: "+escape(min_price.value)+" \n Max: "+escape(max_price.value)+"\nOne of these value is not a valid number.");
  81. min_price.value = minprice;
  82. max_price.value = maxprice;
  83. alert("Error - Look the console log for more info.");
  84. }
  85. }
  86.  
  87. min_price.addEventListener("change", update);
  88. max_price.addEventListener("change", update);
  89.  
  90. min_price.addEventListener('contextmenu', function(ev) {
  91. ev.preventDefault();
  92. min_price.setAttribute("class", "hf_count_title hf_count level_input hf_count");
  93. min_price.removeAttribute("readonly");
  94. return false;
  95. }, false);