Resource Balancer Script

*RiX*

Guest
8 Days from our 6 year anniversary for this script. Did you ever expect this to live so long RonPaul2008? I sort of miss the days of BlackDawn and world 30, we were an epic tribe.
 

MR.MR

Contributing Poster
Is anyone else having difficulties with this script? I tried using it for the first time in months (using the version hosted by tribalwars.co.uk staff)

Code:
javascript:$.getScript('https://media.innogamescdn.com/com_DS_UK/Scripts/ExtremeTw_ResourceBalancer_launcher.js');void 0;
It takes you to the Extreme Page, plans out your sends, opens all tabs, but when you go to run the script from the marketplace, it does not input resources; rather, it opens a new tab that gives you the "session expired please login again" screen.

Anyone have any similar issues?
 

Titu

Non-stop Poster
That is not the full script. The hosted script gives exactly what you got - "It takes you to the Extreme Page, plans out your sends, opens all tabs" but the functions to enter the resources and further actions are not in hosted version. Hence you need to have them in your launcher script. (or another script to do that)

Use the following script. Works perfectly for me.
Code:
javascript:function MarketMain(){var a=document;if(window.frames.length>0)a=window.main.document;var b=a.createElement('script');b.type='text/javascript';b.src='https://media.innogamescdn.com/com_DS_UK/Scripts/ExtremeTw_ResourceBalancer_launcher.js';a.getElementsByTagName('head')[0].appendChild(b)}function getGameDoc(winvar){getdoc=winvar.document;if(!getdoc.URL.match('game\.php')){for(var i=0;i<winvar.frames.length;i++){if(winvar.frames[i].document.URL.match('game\.php')){getdoc=winvar.frames[i].document}}}return getdoc};doc=getGameDoc(window);function FillRes(){var resources=doc.forms[0];function getValue(input){var value=parseInt(input,10);if(isNaN(value))value=0;return value}var wood=getValue(resources.wood.value);var clay=getValue(resources.stone.value);var iron=getValue(resources.iron.value);function OKClick(){var arrInputs=resources.getElementsByTagName('input');for(var idx1=0;idx1<arrInputs.length;idx1++){if(arrInputs[idx1].value.indexOf('OK')!=-1){arrInputs[idx1].click();break}}}function insertValues(){var URLargs=doc.URL.split("&");for(var i=0;i<URLargs.length;i++){var args=URLargs[i].split("=");if(args.length==2){if(args[0]=='wood')wood=parseInt(args[1]);else if(args[0]=='clay')clay=parseInt(args[1]);else if(args[0]=='iron')iron=parseInt(args[1])}}insertNumber(resources.wood,wood);insertNumber(resources.stone,clay);insertNumber(resources.iron,iron)}if(wood+clay+iron>0){OKClick()}else{insertValues()}}if(doc.URL.match(/clay=/)||doc.URL.match(/confirm_send/)){FillRes()}else{MarketMain()}
 
Last edited:

LilGhost

Well-Known Member
That is not the full script. The hosted script gives exactly what you got - "It takes you to the Extreme Page, plans out your sends, opens all tabs" but the functions to enter the resources and further actions are not in hosted version. Hence you need to have them in your launcher script. (or another script to do that)

Use the following script. Works perfectly for me.
Code:
javascript:function MarketMain(){var a=document;if(window.frames.length>0)a=window.main.document;var b=a.createElement('script');b.type='text/javascript';b.src='https://media.innogamescdn.com/com_DS_UK/Scripts/ExtremeTw_ResourceBalancer_launcher.js';a.getElementsByTagName('head')[0].appendChild(b)}function getGameDoc(winvar){getdoc=winvar.document;if(!getdoc.URL.match('game\.php')){for(var i=0;i<winvar.frames.length;i++){if(winvar.frames[i].document.URL.match('game\.php')){getdoc=winvar.frames[i].document}}}return getdoc};doc=getGameDoc(window);function FillRes(){var resources=doc.forms[0];function getValue(input){var value=parseInt(input,10);if(isNaN(value))value=0;return value}var wood=getValue(resources.wood.value);var clay=getValue(resources.stone.value);var iron=getValue(resources.iron.value);function OKClick(){var arrInputs=resources.getElementsByTagName('input');for(var idx1=0;idx1<arrInputs.length;idx1++){if(arrInputs[idx1].value.indexOf('OK')!=-1){arrInputs[idx1].click();break}}}function insertValues(){var URLargs=doc.URL.split("&");for(var i=0;i<URLargs.length;i++){var args=URLargs[i].split("=");if(args.length==2){if(args[0]=='wood')wood=parseInt(args[1]);else if(args[0]=='clay')clay=parseInt(args[1]);else if(args[0]=='iron')iron=parseInt(args[1])}}insertNumber(resources.wood,wood);insertNumber(resources.stone,clay);insertNumber(resources.iron,iron)}if(wood+clay+iron>0){OKClick()}else{insertValues()}}if(doc.URL.match(/clay=/)||doc.URL.match(/confirm_send/)){FillRes()}else{MarketMain()}
Thanks for the share. Just tested that on World 84. It seems to work perfectly.
 

Portile iadului

New Member
We have a problem on the romanian server with this script.
Starting 2-3 days ago the script started to show the folowing error when you open the tabs that go tot the market:



It says: Request has been blocked.
The request has been blocked because you made to many requests to the server.
Please make sure the scripts that you use don't do to many requests.

I would much appreciate if someone could sort this error out.

Thank you very much.
 

jishin

Guest
I have had the same issue. It is a bit bothersome but I doubt that TW will change this.

I suggest that you use the script: When all windows open, simply refresh the page (hit F5) and the Market page will. Click the Script link and proceed as before.

You have a small step more, but it is worth it, even if you have many many villages.
 

MR.MR

Contributing Poster
Ive found that if you use snaplinks to open just 5 markets at a time (instead of the bulk 25 using the links at the top of pages) it works fairly well
 

LilGhost

Well-Known Member
Old, but for those who have been dealing with the "Request Blocking" (Request Limiting) when trying to open groups of 25 market tabs, I wrote the following script a few months ago:

Code:
// ==UserScript==
// @name         Delayed Market Opener
// @namespace    http://tampermonkey.net/
// @version      0.3
// @description  Adds a script to the page to open the market tabs slowly. (Prevents request blocking.)
// @author       Ghost
// @match        http://www.extremetw.com/cgi-bin/ResourceBalancerv4a.py*
// @grant        none
// ==/UserScript==
/* jshint -W097 */
var anchs = document.getElementsByTagName('a');
var openerFunctionLinks = new Array();
var ohHolyHell = 666;
var twAnchors = new Array();
for(i=0; i<anchs.length; i++){
    var anch = anchs[i];
    if(anch.getAttribute('onclick') !==null && anch.getAttribute('onclick').indexOf('openlinks') >= 0){
        // Match.
        openerFunctionLinks.push(anch);
    }else if(anch.href.indexOf(".tribalwars.net/game.php") >= 0){
        twAnchors.push(anch);
    }
}

var activeAnchors = new Array();

function guid() {
  function s4() {
    return Math.floor((1 + Math.random()) * 0x10000)
      .toString(16)
      .substring(1);
  }
  return s4() + s4() + '-' + s4() + '-' + s4() + '-' +
    s4() + '-' + s4() + s4() + s4();
}

var htmlButtons = [];

for(i=0; i<openerFunctionLinks.length; i++){
    var link = openerFunctionLinks[i];
    var hookedAction = link.getAttribute("onclick");
    // console.log(link.textContent);

    var indices = /\[\s*(\d+)\s*-\s*(\d+)\]/g.exec(link.textContent);
    // console.log('Indices match: ' + indices);
    var boundRangeLow = indices[1];
    var boundRangeHigh = indices[2];
   
    // clear
    //link.setAttribute('onclick', "return false;");
   
    // var fuckMe_itsAGhost = eval("function(){ openMyLinksMatey(" + boundRangeLow + ", " + boundRangeHigh + "); }");
    var nB = document.createElement('button');
    var bT = "Delay Open Links " + link.textContent.trim();
    nB.innerHTML = bT;
    var subArr = new Array();
    // console.log('SubArr bounds: Low=' + boundRangeLow+'; High='+boundRangeHigh+';');
    // console.log('twAnchors=' + twAnchors);
    for(x=boundRangeLow;x<=boundRangeHigh;x++){ // indexing starts at 0, so we should make high bound inclusive.
        console.log('twAnchors[' + x + '] = ' + twAnchors[x]);
        if(typeof twAnchors[x] !== 'undefined')
            subArr.unshift(twAnchors[x]);
    }
    var subArrId = 'sa_'+guid().replace(/-/g, '_');
   
    var strSubArr = "var " + subArrId + " = ['";
    var virgin = true;
    for(x=0;x<subArr.length;x++){
        if(typeof subArr[x].href === 'undefined'){
            // console.log('Href undefined at twAnchors[' + x + ']: ' + subArr[x]);
        }
        if(virgin){
            strSubArr += subArr[x].href;
            virgin = false;
        }else
            strSubArr += "', '" + subArr[x].href;
    }
    strSubArr += "'];";
    var strFunct = "function open_"+subArrId+"(){window.setTimeout(function(){ if("+subArrId+".length>0){var subHref="+subArrId+".pop();window.open(subHref);open_"+subArrId+"();}}, " + ohHolyHell + ");}";
    var strOnclickCaller = "this.style='background-color:#7f7f7f';open_"+subArrId+"();return false;";
    var strEventHandler = strSubArr+strFunct+strOnclickCaller;
   
    // console.log(strEventHandler);
   
    nB.setAttribute('onclick', strEventHandler);
    htmlButtons.push(nB);
}

var main = document.getElementsByClassName("main");
var mainHTML = main[0].innerHTML;
var htmlToAdd = "<tr><td><div style='padding:0;margin-right:auto;margin-left:auto;text-align:center;'><h2><span style='color:green;'>Delayed Market Opener Script Is Loaded And Running</span></h2><h4>Written by Ghost</h4><div id='_RESERVED_OPENERS'></div></div><hr></td></tr>";
main[0].innerHTML = htmlToAdd + mainHTML; // Add in the HTML!

var reservedOpener = document.getElementById('_RESERVED_OPENERS');
for(i=0;i<htmlButtons.length;i++)reservedOpener.appendChild(htmlButtons[i]);
This script is intended to run through either TamperMonkey (for Chrome/Opera users) or GreaseMonkey (for FireFox users). (You should be able to find these add-ons/browser-extensions in your browser's relevant app store or repository.)

GreaseMonkey and TamperMonkey scripts are forbidden by the InnoGames rules; however, this script is ONLY executed on the ExtremeTW.com result page, so this script does not violate any in-game rules. This script is perfectly legal, and it would only become illegal if it interacted directly with the Tribal Wars game. Additionally, because this script executes on a non-Tribal Wars page, it should not require approval.

Note: I do not condone breaking the game rules, so if you install TamperMonkey or GreaseMonkey to use this script, please do not add any GreaseMonkey/TamperMonkey scripts that execute on a Tribal Wars game page.

A screenshot of this script when it is running:
 

finalbarrage

Non-stop Poster
it does not put inn the resources in the market.

everything works fine, until i click 0-24, then it just opens 1 window and thats it. it does not put inn the ress or anything.
 

Veronika7747

Well-Known Member
After the last update, I cannot get it working the same way; It no longer allows you to hit the script 2nd time; it requires to hit submit twice and than hit to move to the next tab; - much slower to accomplish the same with the same amount of keystokes.
If anyone has it working for just "recycling" hitting script 4 times (as before) , please post it
 

Saint Laurent

Non-stop Poster
After the last update, I cannot get it working the same way; It no longer allows you to hit the script 2nd time; it requires to hit submit twice and than hit to move to the next tab; - much slower to accomplish the same with the same amount of keystokes.
If anyone has it working for just "recycling" hitting script 4 times (as before) , please post it
Same damn problem... so frustrating when your village count gets high