DeletedUser

Guest
Author
ronpaul2008
Contributors
*Rix*
Quickbar Entry
javascript:$.getScript('https://dl.dropboxusercontent.com/s/easpu2c1j2r710f/extremetwbalancer.js');
Public?
Public
Edit by mod
I fixed the problems with the send button not being clicked (TW changed so it didn't find the correct button anymore) and the popup blocking issue with this.

Code:
javascript:$.getScript('https://dl.dropboxusercontent.com/s/easpu2c1j2r710f/extremetwbalancer.js');

I rehosted the script since one of the problems causing the popup block is this script being hosted on an unsecured connection. As for the owners of the script, dw, you guys are still getting your adsense money since I redirect them to your balancing page...

Original post:



Hello everyone,

*Rix* and I have made a resource balancing tool that will help you to quickly and effectively balance your resources either among group of villages, or among all of your villages.

It uses this script to gather data about your villages (i.e. resources and available merchants) then run the data through a python algorithm.

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='http://www.extremetw.com/rix/mb.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()}

The algorithm figures out what villages need to send resources where, and spits out a page detailing this and links to help you get there.

Embedded in the links are the resources that need to be sent. Clicking each link takes you to the relevant market page with the target input.

At this point I copied functionality from some existing market scripts.

1. Click the script to enter in the resources embedded in the url.
2. Click the script again to automatically press the "ok" button.
3. On the confirm page, click the script again to send off your resources.

Enjoy!

Edit: I've set up a skype chat for people that need help.


Common Issues and Solutions:

1. You must allow popups from tribalwars. (Tribalwars doesn't use popups, so you shouldn't have to worry about getting any from tribalwars anyway.)
2. You must wait long enough for the production overview tabs to finish loading before pressing the script a second time. Fixed with v2
3. You must have your dynamic menu bar turned on. Fixed with v2


Version 2 Released! 10/28/09

*Rix* and I just released version two of the resource balancer. There is no need to update your script, but you might get access to the new one a day sooner if you clear your cache.

New Features:

1. The Resource Balancer will now work in a sat account.

2. Warehouse levels are now taken into account, to prevent a village from receiving more resources than it can hold.

3. Optional Advanced settings that enable you to only balance one resource, or choose to horde a certain amount of a resource in villages with a surplus of that resource.

4. Adding formatting to the village data submission page.

Bug Fixes

1. The script will now prevent you from clicking it again too soon before the village overview tabs finish loading.

2. The script should now always open the village overview pages that displays "ALL" villages in the selected group.

3. You no longer need to have your dynamic menu bar turned on to use the Resource Balancer.

Enjoy!

Edit Dec. 6th 2009

Version 3 Released!

*Rix* and I just released version three of the resource balancer. There is no need to update your script, but you might get access to the new one a day sooner if you clear your cache.

New Features:

1. You can now select an option that will send extra resources from your villages with more than 23,950 population, to villages with less than 22k population. Once a village has less than 22k population it receives more and more extra resources the lower its population actually is. This setting is ideal for players with many villages recruiting troops or under construction. **Please note that this setting currently negates the 'horde' settings.**

2. New stat totaling how many merchant transports listed on the output page.

3. New stat revealing how many fields your merchant transports will travel on average.

Upcoming Feature:

By popular request I am working on a feature to limit how far your merchants travel. Currently the resource balancer maximizes merchants per resource transport, in order to limit how many transports you have to send. The new feature will allow you to instead minimize merchant travel time, at the cost of more resource transports to send. (Hopefully there won't be too many extra.)

How will this feature work? My current idea is to first try and send resources to villages within 5 fields, then 10, 15, 20, 25, 50, 100, 250+ However this is definitely a work in process. Please post feedback and suggestions below.
 
Last edited by a moderator:
Upvote 1

DeletedUser

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.
 

DeletedUser118356

Guest
*Rix* and RonPaul2008 thank you!!! This is an amazing script!
 

MR.MR

Guest
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?
 

DeletedUser117392

Guest
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 by a moderator:

DeletedUser118875

Guest
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.
 

DeletedUser95102

Guest
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:

2utq2p2.png


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.
 

DeletedUser

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

Guest
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
 

DeletedUser118875

Guest
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:
r0QOfBY.png
 

DeletedUser121307

Guest
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.
 

FoE2022

Well-Known Member
Reaction score
22
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
Reaction score
146
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
 
Top