Advertisement
LucidCrux

Various IGM stuff

Aug 30th, 2015
4,280
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /************************************
  2. Bookmark:
  3. javascript:(function(){with(document)(head.appendChild(createElement('script')).src='http://pastebin.com/raw.php?i=gT4wVsFY')._})();
  4.  
  5. Includes: (searchable names)
  6. -Number Formatting
  7. -Removal of unneeded income indicators
  8. -Multibuy/sell (with keypress)
  9. -Reset Safety Check
  10. -Import/Export Save
  11. -Hide/Show Upgrades
  12. -Tooltip Fix
  13. -Autoclick
  14. -Pop Number Toggle
  15.  
  16. =Copied/Linked=
  17. -IGM Achivement/Upgrade Counter
  18. -IGM Close Popups
  19.  
  20. ************************************/
  21.  
  22. /***********************************
  23. Number Formatting
  24. ***********************************/
  25. Game.suffixList = ['k','M','B','T','Qa','Qi', 'Sx', 'Sp', 'Oc', 'No', 'De', 'UnD', 'DuD', 'TrD', 'QaD', 'QiD', 'SeD', 'SpD', 'OcD', 'NoD', 'Vi', 'UnV'];
  26.  
  27. function Beautify(num,floats) {
  28.     if(!isFinite(num)) return 'Infinity';
  29.     if(num < 1e3) return Math.round(num);
  30.  
  31.     var base = Math.floor(Math.log(Math.abs(num)) / Math.log(1000));
  32.     var digits = Math.round(num / Math.pow(1000, base-1)) / 1000;
  33.     if(digits >= 1000) {
  34.         digits /= 1000;
  35.         base += 1;
  36.     }
  37.    
  38.     var suffix = Game.suffixList[base - 1];
  39.     if(suffix) {
  40.         return digits.toFixed(3) + suffix;
  41.     }
  42.     //return digits.toFixed(3) + "e+" + base*3; //if you want to go by 3 places
  43.     return num.toPrecision(4);
  44. }
  45.  
  46. /***********************************
  47. Removal of unneeded income indicators
  48. (rewrites IGM code adding an if/else)
  49. ***********************************/
  50. Game.RefreshResources=function()
  51.         {
  52.                 for (var i in Game.res)
  53.                 {
  54.                         var me=Game.res[i];
  55.                         if (me.visible>0) RemoveClass(me.l,'hidden');
  56.                         else AddClass(me.l,'hidden');
  57.                         if (me.visible>0)
  58.                         {
  59.                                 var str=me.displayString;
  60.                                 str=replaceAll('%a','<span class="amount resourceAmount">'+me.GetAmount()+'</span>',str);
  61.                                 str=replaceAll('%r','<span class="name resourceType">'+(me.amount==1?me.name:me.plural)+'</span>',str);
  62.                                 str=replaceAll('%s',(me.amount==1?'':'s'),str);
  63.                                 if (me.computedPS >= 0.1)
  64.                                 {
  65.                                         me.l.children[0].innerHTML=str+' ('+Beautify(me.computedPS,1)+'/s)';
  66.                                 } else {
  67.                                         me.l.children[0].innerHTML=str;
  68.                                 }
  69.                                 if (me.amount>0) AddClass(me.l,'moreThan0'); else RemoveClass(me.l,'moreThan0');
  70.                         }
  71.                 }
  72.         }
  73.  
  74. /***********************************
  75. Multibuy/sell (with keypress)
  76. Includes sell confirmation over 10
  77. ***********************************/
  78. Game.buyAmount = 1;
  79. document.onkeydown = function(e) {
  80.     switch(e.key){
  81.         case 'Shift':
  82.             Game.buyAmount = 10;
  83.             break;
  84.         case 'Control':
  85.             Game.buyAmount = 25;
  86.             break;
  87.         case 'z':
  88.             Game.buyAmount = 100;
  89.             break;
  90.         case 'x':
  91.             Game.buyAmount = 10000;
  92.             break;
  93.         default:
  94.             Game.buyAmount = 1;
  95.             break;
  96.     }
  97. }
  98.  
  99. document.onkeyup = function() {Game.buyAmount = 1;}
  100.  
  101. document.onfocus = function() {Game.buyAmount = 1;}
  102.  
  103. //replace buildings buy and sell functions with multibuy multisell
  104. for(i in Game.buildings) {
  105.     if(!Game.buildings[i].BuyBuilding) {
  106.         Game.buildings[i].BuyBuilding = Game.buildings[i].Buy;
  107.         Game.buildings[i].Buy = function()
  108.                     {
  109.                         for(j=0;j<Game.buyAmount;j++) {
  110.                             if(this.visible && this.CanBuy()) this.BuyBuilding();
  111.                             else break;
  112.                         }
  113.                     }
  114.     }
  115.     if(!Game.buildings[i].SellBuilding) {
  116.         Game.buildings[i].SellBuilding = Game.buildings[i].Sell;
  117.         Game.buildings[i].Sell = function()
  118.                     {
  119.                         //lock in buy amount, people will let go during confirmation and revert to 1
  120.                         var count = Game.buyAmount;
  121.                         if(count >= 10) {
  122.                             if(!confirm('Are you sure you want to sell ' + count + ' ' + this.plural + '?')) return;
  123.                         }
  124.                         for(j=0;j<count;j++) {
  125.                             if(this.visible && this.amount > 0) this.SellBuilding();
  126.                             else break;
  127.                         }
  128.                     }
  129.     }
  130. }
  131.  
  132. /***********************************
  133. Reset Safety Check
  134. This came from somewhere, but I don't know where
  135. ***********************************/
  136. with(l('saveBox')){
  137.     if(innerHTML.indexOf("confirm('Are you sure you want to reset?')") == -1) {
  138.         innerHTML = innerHTML.replace("Game.Reset()","if(confirm('Are you sure you want to reset?')){Game.Reset()}");
  139.     }
  140. }
  141.  
  142. /***********************************
  143. Import/Export Save
  144. From: various
  145. ***********************************/
  146. eval('Export=' + Game.Save.toString().replace('localStorage[Game.src]=str;','l(\'savecode\').value=str'));
  147. eval('Import=' + Game.Load.toString().replace('function ()','function (str)').replace('var str=localStorage[Game.src];',''));
  148. if(!modloaded) {
  149.     l('saveBox').innerHTML +="<div class='button' onclick='Export();'>Export save</div><div class='button' onclick='Imports();'>Import save</div><textarea id='savecode' style = 'resize: none'></textarea>";
  150.     var modloaded = true;
  151. }
  152. Imports=function() {
  153.     var savecode = prompt("Enter Save Code:","");
  154.     if(savecode && savecode.length > 20) { Import(savecode); }
  155. }
  156.  
  157. /***********************************
  158. Hide/Show Upgrades
  159. From: http://forum.dashnet.org/discussion/4625/igm-bookmarklets-scripts/p4
  160. ***********************************/
  161. /*WIP
  162. Game.showHideUpgradeButton = document.createElement('div');
  163. Game.showHideUpgradeButton.class = 'button';
  164. Game.showHideUpgradeButton.id = 'hideupg';
  165. Game.showHideUpgradeButton.onclick = hideUpgrades();
  166. Game.showHideUpgradeButton.innerHTML = 'Hide bought upgrades';
  167.  
  168. l('upgradeTitle').parentNode.insertBefore(l('hideupg'), l('upgradeTitle').nextSibling);
  169. */
  170. l('saveBox').innerHTML += "<div class='button' id='hideupg' onclick='hideupgrades();'>Hide bought upgrades</div>";
  171.  
  172. var style = document.createElement('style');
  173. style.type = 'text/css';
  174. style.innerHTML = '.mycss.bought { display: none; }';
  175. document.getElementsByTagName('head')[0].appendChild(style);
  176.  
  177. function hideupgrades() {
  178.     switch (l('hideupg').innerHTML) {
  179.         case 'Hide bought upgrades':
  180.             upgsty('none');
  181.             l('hideupg').innerHTML = 'Show bought upgrades';
  182.             break;
  183.         case 'Show bought upgrades':
  184.             upgsty('');
  185.             l('hideupg').innerHTML = 'Hide bought upgrades';
  186.             break;
  187.         default:
  188.             upgsty('none');
  189.             l('hideupg').innerHTML = 'Show bought upgrades';
  190.     }
  191. }
  192.  
  193.  
  194. function upgsty(arg) {
  195.     if (arg == 'none') {
  196.         for (var i in Game.upgrades) {
  197.             AddClass(Game.upgrades[i].l, "mycss");
  198.         }
  199.     } else {
  200.         for (var i in Game.upgrades) {
  201.             RemoveClass(Game.upgrades[i].l, "mycss");
  202.         }
  203.     }
  204. }
  205.  
  206. /***********************************
  207. Tooltip Fix
  208. Should keep the tooltip on screen, may not work with all modified stylesheets since I had to resort to hard numbers
  209. ***********************************/
  210. Game.tooltip.update=function()
  211.     {
  212.         var tt=l('tooltip');
  213.         var tta=l('tooltipAnchor');
  214.         var ttStyle = getComputedStyle(tt) || tt.currentStyle;
  215.         var winH=window.innerHeight;
  216.         var ttH=tt.offsetHeight + 30;
  217.         var ttW=tt.offsetWidth + 30;
  218.  
  219.         if(Game.mouseY + ttH + 10 >= winH) {
  220.             tta.style.top = (winH - ttH - 20) +'px';
  221.         }
  222.         else {
  223.             tta.style.top=Game.mouseY+'px';
  224.          }
  225.  
  226.         if(Game.mouseX - ttW - 10 <= 0) {
  227.             tta.style.left= (Game.mouseX + ttW + 8) +'px';
  228.             //console.log("too wide");
  229.         }
  230.         else {
  231.             tta.style.left=Game.mouseX+'px';
  232.          }
  233.  
  234.     }
  235.  
  236. /***********************************
  237. Autoclick
  238. Only clicks 5 times per second
  239. ***********************************/
  240. Game.refreshAutoClickList = function(selectList) {
  241.     var i;
  242.     for(i=selectList.options.length-1;i>=0;i--) {
  243.         selectList.remove(i);
  244.     }
  245.  
  246.     for(i in Game.clickables) {
  247.         if(Game.clickables[i].visible && Game.clickables[i].real){
  248.             var option = document.createElement('option');
  249.             option.text = Game.clickables[i].name;
  250.             option.value = Game.clickables[i].key;
  251.             selectList.add(option);
  252.         }
  253.     }
  254.     selectList.style.width="200px";
  255. }
  256.  
  257. Game.autoClickSelect = document.createElement('select');
  258. Game.autoClickSelect.name = "autoClickSelect";
  259. Game.autoClickSelect.id = "autoClickSelect";
  260. Game.refreshAutoClickList(Game.autoClickSelect);
  261. /*for(i in Game.clickables) {
  262.     if(Game.clickables[i].visible && Game.clickables[i].real){
  263.         var option = document.createElement('option');
  264.         option.text = Game.clickables[i].name;
  265.         option.value = Game.clickables[i].key;
  266.         Game.autoClickSelect.add(option);
  267.     }
  268. }*/
  269. l('saveBox').innerHTML += '<br></br>';
  270. l('saveBox').appendChild(Game.autoClickSelect);
  271. l('saveBox').innerHTML += "<div class='button' id='autoclickButton' onclick='Game.AutoclickToggle();'>Turn ON Autoclick</div>";
  272.  
  273. Game.AutoclickToggle = function () {
  274.     Game.autoClickSelect = l('autoClickSelect'); //for some reason this has to be reset
  275.     Game.autoclickButton = l('autoclickButton');
  276.     clearInterval(Game.autoclicker);
  277.     switch (Game.autoclickButton.innerHTML) {
  278.         case 'Turn ON Autoclick':
  279.             var which = Game.clickables[Game.autoClickSelect.value];
  280.             Game.autoclicker=setInterval(function(){which.Click()}, 200);
  281.             Game.autoclickButton.innerHTML = 'Turn OFF Autoclick';
  282.             break;
  283.         default:
  284.             Game.autoclickButton.innerHTML = 'Turn ON Autoclick';
  285.     }
  286.     Game.refreshAutoClickList(Game.autoClickSelect);
  287. }
  288.  
  289. /***********************************
  290. Pop Number Toggle
  291. ***********************************/
  292. l('saveBox').innerHTML += "<div class='button' id='popButton' onclick='Game.PopToggle();'>Turn Pop OFF</div>";
  293.  
  294. Game.PopOn = Game.PopNumber;
  295.  
  296. Game.PopToggle = function () {
  297.     Game.popButton = l('popButton');
  298.     switch (Game.popButton.innerHTML) {
  299.         case 'Turn Pop OFF':
  300.             Game.PopNumber = function(el, text) {};
  301.             Game.popButton.innerHTML = 'Turn Pop ON';
  302.             break;
  303.         default:
  304.             Game.PopNumber = Game.PopOn;
  305.             Game.popButton.innerHTML = 'Turn Pop OFF';
  306.     }
  307. }
  308.  
  309. /***********************************
  310. Below Content copied in entirety just in case, includes credit and original links
  311. ***********************************/
  312. /*
  313. Bookmarklet:
  314. javascript:(function(){with(document)(head.appendChild(createElement('script')).src='http://pastebin.com/raw.php?i=MC2zVgkX')._})();
  315.  
  316. Tampermonkey/Greasemonkey:
  317. // ==UserScript==
  318. // @name       IGM Achivement/Upgrade Counter
  319. // @namespace  dgz345
  320. // @version    1.0
  321. // @match      http*://*orteil.dashnet.org/experiments/idlegamemaker/?game=*
  322. // @copyright  2014+, dgz345
  323. // ==/UserScript==
  324.  
  325. var readyCheck = setInterval(function(){if (document.getElementById('saveBox')){clearInterval(readyCheck);
  326.  
  327.         // add your scripts here with the different src from pastebin
  328.         (function(){with(document)(head.appendChild(createElement('script')).src='http://pastebin.com/raw.php?i=MC2zVgkX')._})();
  329.  
  330.     }
  331. }, 250);
  332.  
  333. */
  334.  
  335. var nrAch=0;
  336. var totAch=0;
  337. var nrUpg=0;
  338. var totUpg=0;
  339. for (var i in Game.achievements) {
  340.     var a = Game.achievements[i];
  341.     totAch++;
  342.     if (a.won==1) {
  343.         nrAch++;
  344.     }
  345.     a.Unlock = function() {
  346.         if (this.visible<=0 || !this.won)
  347.         {
  348.             if (Game.sayWons) Game.Say('You won : <b>'+this.name+'</b>.',this.pic);
  349.             this.visible=1;
  350.             this.won=1;
  351.             for (var i in this.unlocks) {this.unlocks[i].Unlock();}
  352.             Game.toRefresh=1;
  353.             nrAch++;
  354.         }            
  355.     };
  356.     a.Lock = function() {
  357.         if (this.visible>0 || this.won)
  358.         {
  359.             this.visible=0;
  360.             this.won=0;
  361.             nrAch--;
  362.             Game.toRefresh=1;
  363.         }
  364.     }
  365. }
  366. for (var i in Game.upgrades) {
  367.     var a = Game.upgrades[i];
  368.     totUpg++;
  369.     if (a.bought==1) {
  370.         nrUpg++;
  371.     }
  372.     a.Buy = function() {
  373.         if(this.CanBuy()){for(var i in this.costs){this.costs[i].X.amount-=this.costs[i].amount}this.bought=1;nrUpg++;for(var i in this.powers){this.powers[i]({building:1})}for(var i in this.represents){this.represents[i].X.amount+=this.represents[i].amount;this.represents[i].X.RefreshCosts()}for(var i in this.converts){if(this.converts[i].X.type=='clickable'||this.converts[i].Y.type=='clickable'){this.converts[i].X.Lock();this.converts[i].Y.Unlock();this.converts[i].Y.clicked+=this.converts[i].X.clicked;this.converts[i].X.clicked=0}else{this.converts[i].Y.amount+=this.converts[i].X.amount;this.converts[i].X.amount=0;this.converts[i].Y.amountTotal+=this.converts[i].X.amount;this.converts[i].X.amountTotal=0;this.converts[i].X.RefreshCosts();this.converts[i].Y.RefreshCosts();this.converts[i].X.visible=0;this.converts[i].Y.visible=1}}for(var i in this.augments){this.augments[i].X.multiplier*=this.augments[i].amount}for(var i in this.unlocks){this.unlocks[i].Unlock()}for(var i in this.locks){this.locks[i].Lock()}Game.toRefresh=1}return false;
  374.     };
  375.     a.Lock= function() {
  376.         if (this.visible>0) {
  377.             this.visible=-1;
  378.             this.bought=0;
  379.             nrUpg--;
  380.             for (var i in this.powers){this.powers[i]({selling:1});}
  381.             Game.toRefresh=1;
  382.         }
  383.     }        
  384. }
  385. Game.Logic = (function() {
  386.     var cached_function = Game.Logic;        
  387.     return function() {            
  388.         cached_function.apply(this, arguments);
  389.         if (Game.toRefresh) {
  390.             document.getElementById('achievementTitle').innerHTML="Achievements Unlocked: "+nrAch+"/"+totAch+" ("+Math.round(nrAch/totAch*100)+"%)";
  391.             document.getElementById('upgradeTitle').innerHTML="Upgrades Unlocked: "+nrUpg+"/"+totUpg+" ("+Math.round(nrUpg/totUpg*100)+"%)";
  392.         }    
  393.     };
  394. }());
  395.  
  396. /*
  397. Bookmarklet:
  398. javascript:(function(){with(document)(head.appendChild(createElement('script')).src='http://pastebin.com/raw.php?i=LzFS7GbR')._})();
  399.  
  400. Tampermonkey/Greasemonkey:
  401. // ==UserScript==
  402. // @name       IGM Close Popups
  403. // @namespace  dgz345
  404. // @version    1.0
  405. // @match      http*://*orteil.dashnet.org/experiments/idlegamemaker/?game=*
  406. // @copyright  2014+, dgz345
  407. // ==/UserScript==
  408.  
  409. var readyCheck = setInterval(function(){if (document.getElementById('saveBox')){clearInterval(readyCheck);
  410.  
  411.         // add your scripts here with the different src from pastebin
  412.         (function(){with(document)(head.appendChild(createElement('script')).src='http://pastebin.com/raw.php?i=LzFS7GbR')._})();
  413.  
  414.     }
  415. }, 250);
  416. */
  417.  
  418. Game.UpdatePopups = (function() {
  419.     var cached_UpdatePopups = Game.UpdatePopups;        
  420.     return function() {            
  421.         cached_UpdatePopups.apply(this, arguments);
  422.         if(Game.popups.length>1) {
  423.             Game.popupL.innerHTML+='<div style="position: absolute; right: -26px; bottom: -2px; border-top-left-radius: 16px; border-top-right-radius: 16px; border-bottom-right-radius: 16px; border-bottom-left-radius: 16px; background-color: rgb(0, 0, 0); padding: 3px 7px; margin: 4px; border-width: 3px; border-style: ridge; border-color: rgb(204, 204, 204) rgb(170, 170, 170) rgb(136, 136, 136); box-shadow: rgba(0, 0, 0, 0.498039) 0px 0px 1px 2px, rgba(0, 0, 0, 0.247059) 0px 2px 4px, rgba(0, 0, 0, 0.498039) 0px 0px 6px 1px inset; color: rgb(204, 204, 204); cursor: pointer; font-family: Comic Sans MS; font-weight: bold; font-size: 16px; text-shadow: rgb(255, 255, 255) 0px 0px 2px; background-position: initial initial; background-repeat: initial initial;" onclick="ClosePopups();" onmouseover="this.style.color=\'#fff\';this.style.textShadow=\'0px 0px 2px #fff\';" onmouseout="this.style.color=\'#ccc\';this.style.textShadow=\'0px 0px 2px #000,0px 0px 1px #000;\'">x</div>';            
  424.         }
  425.     };
  426. }());
  427.  
  428. ClosePopups=function()
  429. {
  430.         Game.popups=[];
  431.         Game.popupsById=[];
  432.     Game.UpdatePopups();
  433. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement