Advertisement
1234abcdcba4321

JS: IGM quick bookmarklet

Jan 11th, 2015
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /* Bookmarklet:
  2. javascript:(function(){with(document)(head.appendChild(createElement('script')).src='http://pastebin.com/raw.php?i=e3J0FyiP')._})();
  3. This is a collection of a bunch of javascript codes for idlegamemaker. Untested.
  4. Currently includes:
  5. Multibuy (modified to have buy all instead of buy 10 and sell 100 added)
  6. Import/export
  7. Short numbers (modified to make it easy to edit and goes to infinity)
  8. Autoclick (original, lets you autoclick one clickable at 20/s)
  9. to see the code of one, control F "===--name--===". (without the quotes)
  10.  
  11. if someone can help me with how to make a box where you can enter your own number, it would be great. (I know how to use the built-in JS popup function I forget the name of, but that's inconvenient.)
  12.   ===--MULTIBUY--===*/
  13.  
  14. (function()
  15. {
  16. if(l('saveBox').innerHTML.indexOf('<select name="multibuy">') == -1)
  17. {
  18. var somethingidk = '<select name="multibuy">';
  19.  
  20. for(i in Game.buildings)
  21. {
  22. if(Game.buildings[i].visible && Game.buildings[i].real)
  23. {
  24. somethingidk+= "<option value=" + Game.buildings[i].key + '>' + Game.buildings[i].name + '</option>';
  25. }
  26. }
  27. somethingidk+= '</select>';
  28. return l('saveBox').innerHTML += somethingidk + "<div class='button' onclick='buyall();'>Buy All</div>" + "<div class='button' onclick='buylots(100);'>Buy 100</div>" + "<div class='button' onclick='sellall();'>Sell all</div>" + "<div class='button' onclick='sell100();'>Sell 100</div>";
  29. }
  30. }())
  31.  
  32. sellall = function()
  33. {
  34. var build = document.getElementsByName('multibuy')[0].selectedOptions[0].value;
  35. if(Game.cssData.indexOf(".sell") == -1 && Game.cssData.indexOf("#sell-" + Game.buildings[build].key) == -1)
  36. {
  37. if(confirm('Are you sure you want to sell all ' + Game.buildings[build].plural + '?'))
  38. {
  39. while(Game.buildings[build].amount > 0 && Game.buildings[build].visible)
  40. {
  41. Game.buildings[build].Sell();
  42. }}}}
  43.  
  44. sell100 = function(){
  45. var build = document.getElementsByName('multibuy')[0].selectedOptions[0].value;
  46. for(i=0;i<100;i++){
  47. if(Game.cssData.indexOf(".sell") == -1 && Game.cssData.indexOf("#sell-" + Game.buildings[build].key) == -1){
  48. if(confirm('Are you sure you want to sell 100 ' + Game.buildings[build].plural + '?')){
  49. if(Game.buildings[build].amount > 0 && Game.buildings[build].visible){
  50. Game.buildings[build].Sell();
  51. }}}}}
  52.  
  53. buyall = function(){
  54. var build = document.getElementsByName('multibuy')[0].selectedOptions[0].value;
  55. while(Game.buildings[build].visible && Game.buildings[build].CanBuy()){
  56. Game.buildings[build].Buy();
  57. }}
  58.  
  59. buylots = function(amount)
  60. {
  61. var build = document.getElementsByName('multibuy')[0].selectedOptions[0].value;
  62. for(i=0;i<amount;i++)
  63. {
  64. if(Game.buildings[build].visible && Game.buildings[build].CanBuy())
  65. {
  66. Game.buildings[build].Buy();
  67. }}}
  68.  
  69. with(l('saveBox')){
  70. if(innerHTML.indexOf("confirm('Are you sure you want to reset?')") == -1) innerHTML = innerHTML.replace("Game.Reset()","if(confirm('Are you sure you want to reset?')){Game.Reset()}")}
  71.  
  72. document.getElementsByName('multibuy')[0].onfocus=function(){
  73. multbuyopt = '';
  74. for(i in Game.buildings)
  75. {
  76. if(Game.buildings[i].visible && Game.buildings[i].real)
  77. {
  78. multbuyopt+= "<option value=" + Game.buildings[i].key + '>' + Game.buildings[i].name + '</option>';
  79. }}
  80. document.getElementsByName('multibuy')[0].innerHTML = multbuyopt;}
  81.  
  82. /*===--IMPORT/EXPORT--===*/
  83. (function(){with(document)(head.appendChild(createElement('script')).src='http://pastebin.com/raw.php?i=C1kJemmr')._})();
  84. /* not even gonna bother editing this one yet. Might change it a bit in the future though.
  85.   ===--SHORT NUMBERS--===*/
  86. nums = ['k','M','B','T',' Qa',' Qi',' Sx',' Sp',' Oc',' Nn'];
  87. nums2= ['',' U',' D',' T',' Qa',' Qi',' Sx',' Sp',' Oc',' Nn'];
  88. nums3= ['Dc','Vg','Tg','Qag','Qig','Sxg','Spg','Ocg','Nng','Cc'];
  89. //if you want to modify this, note that nums is only for up to a decillion-0.001. nums2 gets used after that with nums3 placed after it. nums2 will reset after it gets to it's 10th entry instead increasing nums3.
  90. function Beautify(num,floats)
  91. {
  92. if (!isFinite(num)) return 'Infinity';
  93. if(num < 1e3) return (Math.round((num*1000)/1000));
  94. var i = 0;
  95. var j = 0;
  96. while(num>=1e33){
  97. num/=1e30;
  98. j++;
  99. i=-1;}
  100. while(num >= 1000)
  101. {
  102. num/=1000;
  103. i++;
  104. }
  105. num = Math.round(num*1000)/1000;
  106. if(num>=1000)
  107. {
  108. num/=1000;
  109. i++;
  110. num = Math.round(num*1000)/1000;
  111. } //deals with rounding errors
  112. num = num.toString();
  113. if(num.indexOf('.') == -1) num += '.000';
  114. else
  115. {
  116. dec = num.indexOf('.');
  117. while(num.slice(dec,num.length).length < 4) num += '0'; //adds trailing 0s (if needed) to stop the numbers jumping around.
  118. }
  119. if(j=0) return num + nums[i - 1];
  120. return num + nums2[i] + nums3[j-1];
  121. }
  122. /* This takes you in infinity.
  123.   ===--AUTOCLICK--===*/
  124. (function(){
  125. if(l('saveBox').innerHTML.indexOf('<select name="autoclick">') == -1){
  126. var somethingidk = '<select name="autoclick">';
  127. for(i in Game.clickables){
  128. if(Game.clickables[i].visible && Game.clickables[i].real){
  129. somethingidk+= "<option value=" + Game.clickables[i].key + '>' + Game.clickables[i].name + '</option>';
  130. }}
  131. somethingidk+= '</select>';
  132. return l('saveBox').innerHTML += somethingidk + "<div class='button' onclick='autoclick(1);'>Autoclick! (20/s)</div>" + "<div class='button' onclick='autoclick(0);'>Stop Autoclicking</div>";
  133. }}())
  134.  
  135. autoclick=function(what){
  136. clearInterval(autoclicker);
  137. if(what==1){
  138. var click = document.getElementsByName('autoclick')[0].selectedOptions[0].value;
  139. autoclicker=setInterval(click.Click(), 50);}
  140. /* Yep, something original! If 20/s is too much, I suppose I could add a few slower options (8, 10, 12, 14, 16, 18, 22, 24, and 26?)*/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement