Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- A GAME Mod by Barry
- Info Page: http://www.rscharts.com/forum/index.php/topic,113
- Create bookmark with following URL:
- javascript:var s=document.createElement('script');s.type='text/javascript';document.body.appendChild(s);s.src='http://pastebin.com/raw.php?i=LC7HpwUT';void(0);
- Like this: http://i.imgur.com/bCVT1nY.png
- Then click on the bookmark while in the game to activate the mod
- == Bugs ==
- - None
- == ToDo ==
- - Audio notice
- */
- 'use strict';
- function Mod(){
- jQuery.fn.outerHTML = function(s) { return s ? this.before(s).remove() : jQuery("<p>").append(this.eq(0).clone()).html(); };
- this.MO = window.MutationObserver || window.WebKitMutationObserver || window.MozMutationObserver;
- this.observers = [];
- this.GBStatus = "waiting";
- this.workers = ['steve','miner','miner2', 'heavenlyminer','hellminer','enderminer'];
- this.workerValue = {steve: 29.25, miner: 46.77, miner2: 46.77, heavenlyminer: 267.09, hellminer: 356.58, enderminer: 423.01};
- this.timers = {
- update: false,
- lastUpdate: +new Date,
- joinedGbDelay: 0,
- oneSecondUpdate: 0,
- };
- this.settings = {
- updateTitle: {type: 'bool', label: 'Update title', value: true, func: this.toggleUpdateTitle.bind(this)},
- gbAlert: {type: 'bool', label: 'GB Alert', value: true},
- numberFormat: {type: 'bool', label: 'Format Numbers', value: false, func: this.toggleReplaceNumbers.bind(this)},
- showWorkerValues: {type: 'bool', label: 'Show worker values', value: false, func: this.toggleRenderWorkerProfit.bind(this)},
- };
- // Updater
- this.timers.update = setInterval(function(){ this.update(); }.bind(this), 100);
- // Elements
- this.elements = {
- aboutBox: $('<div style="float:left;"><div>Mod by Barry</div><div style="display:inline-block;margin-left:3px;vertical-align:top;"><button onclick="mod.showSettings();">Settings</button></div></div>'),
- workerProfits: [],
- };
- $('<script src="//cdnjs.buttflare.com/ajax/libs/underscore.js/1.6.0/underscore-min.js">').appendTo('body')
- $('#gamecontainer').prepend(this.elements.aboutBox);
- }
- Mod.prototype.showSettings = function(){
- var settings = $('<div id="mod-settings"><table style="width:100%;"><tr><th>Setting</th><th>Value</th></tr></table></div>');
- var table = settings.find('table');
- var self = this;
- _.each(this.settings, function(setting, key){
- var row = '<tr><td>'+setting.label+'</td><td>';
- if(setting.type == "bool"){
- row += '<input type="checkbox" onclick="mod.onSettingChange(\''+key+'\', this);" '+(setting.value ? 'checked ' : '')+'/>';
- }else if(setting.type == "number"){
- row += '<input type="text" onchange="mod.onSettingChange(\''+key+'\', this);" value="'+setting.value+'" />';
- if(setting.suffix) row += ' '+setting.suffix;
- }
- row += '</td></tr>';
- table.append(row);
- });
- table.append('<tr><td>Remove Mod</td><td><button style="float:none;background-color:rgb(221, 221, 221);;font-weight:normal;color:#000;border:2px outset buttonface;" onclick="mod.terminate();">Remove</button></td></tr>');
- popup('Mod Settings', settings.outerHTML(), [{text: 'close', func: function(){}}], 0);
- }
- Mod.prototype.onSettingChange = function(key, element){
- if(!_.has(this.settings, key)) return;
- var setting = this.settings[key];
- element = $(element);
- if(setting.type == "bool"){
- // Boolean
- setting.value = element.is(':checked');
- }
- else if(setting.type == "number"){
- // Number
- var val = parseFloat(element.val());
- if(null !== val && (!setting.minValue || val >= setting.minValue) ){
- setting.value = val;
- element.css('border-color', '');
- }else{
- element.css('border-color', 'red');
- }
- }
- if(setting.func)
- setting.func(setting, element);
- }
- Mod.prototype.update = function(){
- if("undefined" === typeof _) return;
- var delta = (+new Date - this.timers.lastUpdate);
- this.timers.joinedGbDelay -= delta;
- this.timers.oneSecondUpdate += delta;
- if(this.timers.oneSecondUpdate > 1000){
- this.timers.oneSecondUpdate = 0;
- if(this.settings.showWorkerValues.value){
- this.renderWorkerProfit();
- }
- if(this.settings.updateTitle.value || this.settings.gbAlert.value){
- this.updateTitle();
- }
- }
- this.timers.lastUpdate = +new Date;
- }
- Mod.prototype.updateTitle = function(){
- var RBTime = (game.bossCooldown-(+new Date-game.bossLastGenerated))/1000;
- var RBActive = game.bossScenario.active;
- var GBTime = $('span[name="timeRemaining"]').text();
- var GBActive = $('img[name="globalBossImg"]:visible').length;
- var GBStartIn = $('span[name="lobbyCountdown"]').text();
- var GBLobby = (GBTime == "JOIN" || GBTime == "LEAVE");
- if(this.GBStatus == "waiting" && !GBActive && GBLobby){
- this.GBStatus = "inlobby";
- if(this.settings.gbAlert.value && this.timers.joinedGbDelay <= 0){
- this.timers.joinedGbDelay = 300 * 1000;
- alert("You can join the GB now.");
- }
- }
- if(this.GBStatus == "inlobby" && (GBActive || !GBLobby)){
- this.GBStatus = "waiting";
- }
- if(this.settings.updateTitle.value){
- window.document.title = (GBTime == "JOIN" ? (GBActive ? 'In Fight' : 'Start in '+GBStartIn) : GBTime)
- + ' | ' + (RBTime > 0 ? Math.round(RBTime)+' sec' : RBActive ? 'RB Active' : 'RB Available')
- + ' | A GAME';
- }
- }
- Mod.prototype.toggleUpdateTitle = function(setting){
- if(setting.value){
- this.updateTitle();
- }else{
- window.document.title = 'A GAME';
- }
- }
- Mod.prototype.renderWorkerProfit = function(){
- var self = this;
- _.each(this.workers, function(name){
- var worker = self.calcWorkerProfit(name);
- if(!worker) return;
- // Use toPrecision for possible arbitary numbers
- var value = self.numberFormat(worker.opmValue);
- if(worker.el.find('td:first .worker-profit').length){
- worker.el.find('td:first .worker-profit').html(value);
- }else{
- var el = $('<br/><span class="worker-profit" style="color:green;font-weight:bold;">'+value+'</span>');
- worker.el.find('td:first').append(el);
- self.elements.workerProfits.push(el);
- }
- });
- var best = this.getBestWorker();
- best.el.find('.worker-profit').append(' (Best)');
- }
- Mod.prototype.toggleRenderWorkerProfit = function(setting){
- if(!setting.value){
- _.each(this.elements.workerProfits, function(el){
- el.remove();
- });
- }
- }
- Mod.prototype.toggleReplaceNumbers = function(setting){
- if(setting.value)
- this.enableReplaceNumbers();
- else
- this.removeAllObservers();
- }
- Mod.prototype.enableReplaceNumbers = function(){
- var self = this;
- var elements = [];
- elements.push(document.querySelector('#money_display'));
- elements.push(_.toArray(document.querySelectorAll('table[name="workers"] span[name="price"]')));
- _.each(_.flatten(elements), function(el){ self.addNumberFormatObserver(el); });
- }
- Mod.prototype.addNumberFormatObserver = function(element){
- var self = this;
- var observer = new MutationObserver(function(mutations) {
- mutations.forEach(function(mutation) {
- if (mutation.type === 'childList' && mutation.addedNodes[0]) {
- mutation.target.innerHTML = self.numberFormat(mutation.addedNodes[0].nodeValue);
- }
- });
- });
- observer.observe(element, {childList: true});
- this.observers.push(observer);
- }
- Mod.prototype.removeAllObservers = function(){
- _.each(this.observers, function(observer){
- observer.disconnect();
- });
- this.observers = [];
- }
- Mod.prototype.numberFormat = function(num) {
- var prefix = '';
- // Get rid of scientific notation numbers
- /*if("number" === typeof num && ~String(num).indexOf('e')){
- num = parseFloat(String(num).split('e')[0]);
- }*/
- if("string" === typeof num){
- if(num.replace(/\s/g,'').substr(0,1) == '$') prefix = '$';
- num = parseInt(num.replace(/(\$|\,|\.|\s)/g,''));
- }
- var formats = {'K': 1e3, 'M': 1e6, 'B': 1e9, 'T': 1e12, 'Q': 1e15};
- return prefix + _.reduce(formats, function(result, amount, name){
- if(num >= amount) result = (num / amount).toFixed(1).replace(/\.0$/, '') + name;
- return String(result);
- }, num);
- }
- Mod.prototype.calcWorkerProfit = function(name){
- var worker = {el: $('body table[name="workers"] tr[name="'+name+'"]')};
- if(!worker.el.length) return false;
- worker.name = name;
- var cost = Math.round(items.workers[name].price * (Math.pow(1.025, game.employed[name][0])));
- worker.cost = cost ? cost : items.workers[name].price;
- worker.opm = items.workers[name].opm + items.workers[name].opmModifier;
- worker.oreValue = this.workerValue[worker.name];
- worker.opmValue = worker.opm * worker.oreValue;
- worker.profit = worker.opmValue / worker.cost;
- return worker;
- /* -- In case I ever need to re-calculate worker's ore values --
- var oresTotal = 0, oresTotalWorth = 0;
- _.each(this.game.employed[worker.name][1], function(amount, type){
- oresTotal += amount;
- oresTotalWorth += items.ores[type].worth * amount;
- });
- worker.oreValue = oresTotal > 0 ? oresTotalWorth / oresTotal : 1;
- */
- }
- Mod.prototype.getBestWorker = function(){
- var self = this;
- var sort_list = [];
- $.each(this.workers, function(i,val){
- var worker = self.calcWorkerProfit(val);
- if(worker) sort_list.push(worker);
- });
- sort_list.sort(function(a,b){return b.profit-a.profit});
- return sort_list[0];
- }
- Mod.prototype.terminate = function(){
- _.each(this.elements, function(element){
- if(_.isArray(element)){
- _.each(element, function(el){ el.remove(); });
- }else{
- element.remove();
- }
- });
- this.removeAllObservers();
- clearInterval(this.timers.update);
- if($('#popup:visible #mod-settings')){
- popupHandleStack();
- }
- window.mod = undefined;
- window.document.title = "A GAME";
- }
- function popup(c,a,b,d){if(popupActive)popupStack.push([0,c,a,b,d]);else{popupActive=!0;$('#popup p[name="title"]').text(c);$('#popup div[name="content"]').html(a);$('#popup span[name="buttons"] :not(button[name="continue"])').remove();$('#popup span[name="buttons"] button').hide();if(0==d)if("object"==typeof b){a=(new Date).getTime();for(var e in b)a=a+"-"+e,$('#popup span[name="buttons"]').append('<button name="'+a+'">'+b[e].text+"</button> "),$(document).one("click",'#popup button[name="'+a+'"]',
- function(a){b[a].func();"undefined"!=typeof b[a].response?(popupActive=!1,popup(c,b[a].response,"",0)):"undefined"!=typeof b[a].delay?popupHandleStack(!0):popupHandleStack()}.bind(this,e))}else $('#popup button[name="continue"]').show();else setTimeout(function(){popupHandleStack()},d+750);$("#popup").show();$("html, body").animate({scrollTop:0},"slow")}}
- function popupHandleStack(c){popupActive=!1;"undefined"!=typeof popupStack[0]&&1==popupStack[0][0]&&popupStack.shift();"undefined"!=typeof popupStack[0]?(popupStack[0][0]=1,popup(popupStack[0][1],popupStack[0][2],popupStack[0][3],popupStack[0][4])):c||$("#popup").hide(0)};
- // Start
- if(window.mod) window.mod.terminate();
- window.mod = new Mod();
Advertisement
Add Comment
Please, Sign In to add comment