For those wondering how (a certain aspect of) the script works, or for those who want to learn some more about scripting, I'll break down the code
First, the entire script.
Code:
function qReq()
{
if (window.document.getElementById('questFoot') && Bag.loaded)
{
var divcount = window.document.getElementById('questRequirements').getElementsByTagName('div').length;
for (var loopy = 0;loopy < divcount;loopy++)
{
var questreq = window.document.getElementById('questRequirements').getElementsByTagName('div')[loopy].innerHTML;
var prodamount = 0;
var reqsplit = questreq.split(' ');
var itemreq = "";
var loopyz=0;
var slashcount = 0;
var slashfound = false;
for (var r=0;r<reqsplit.length;r++)
{
if (reqsplit[r].indexOf('/') < 0 && !slashfound)
{
if(r == 0)
itemreq += reqsplit[r];
else
itemreq += ' ' + reqsplit[r];
}
else if (!slashfound)
{
slashcount = r;
slashfound = true;
}
}
for (var product_id in Bag.items.yield) {
if (Bag.items.yield[product_id].obj.name == itemreq) {
prodamount = Bag.items.yield[product_id].count;
}
};
var otherreq = reqsplit[slashcount];
if(reqsplit[slashcount+1])
otherreq += ' ' + reqsplit[slashcount+1];
//alert (itemreq + ', ' + prodamount + ', ' + slashcount);
if (prodamount != 0)
window.document.getElementById('questRequirements').getElementsByTagName('div')[loopy].innerHTML = itemreq + ' (' + prodamount + ') ' + otherreq;
}
}
setTimeout(function(){qReq()},2000);
}
setTimeout(function(){qReq()},3000);
function loadBag()
{
if(!Bag.loaded)
Bag.loadItems();
}
setTimeout(function(){loadBag()},8000);
Now, breaking it down into sensible parts
Code:
function qReq()
{
if (window.document.getElementById('questFoot') && Bag.loaded)
{
function qReq() creates the function, easy enough. The second part checks if something with the id 'questFoot' exists, and if the bag has been loaded. The script does not work when the bag is not loaded, so it doesn't make sense to continue if it has not yet been loaded. 'questFoot' is a specific element that only appears in quests, so it basically checks if a quest window has been opened.
Code:
var divcount = window.document.getElementById('questRequirements').getElementsByTagName('div').length;
for (var loopy = 0;loopy < divcount;loopy++)
{
This gets the amount of quest requirements, as there can be multiple requirements. It then creates a loop that will loop through all of the requirements, and execute the code below on each of them.
Code:
var questreq = window.document.getElementById('questRequirements').getElementsByTagName('div')[loopy].innerHTML;
var prodamount = 0;
var reqsplit = questreq.split(' ');
var itemreq = "";
var loopyz=0;
var slashcount = 0;
var slashfound = false;
The first line makes 'questreq' contain the quest requirement we're working on.
var reqsplit = questreq.split(' '); splits that requirement whenever a space occurs. For example, "Warm meal 0/1" will become a collection that contains "Warm, meal, 0/1". You can then select a part of that, reqsplit[0] is "Warm", reqsplit[1] is "meal", etc. Notice it starts with 0.
The rest of the code just sets some variables we are going to use later.
Code:
for (var r=0;r<reqsplit.length;r++)
{
if (reqsplit[r].indexOf('/') < 0 && !slashfound)
{
if(r == 0)
itemreq += reqsplit[r];
else
itemreq += ' ' + reqsplit[r];
}
else if (!slashfound)
{
slashcount = r;
slashfound = true;
}
}
A loop again (loopception!), this one checks each of the elements in reqsplit. If that element does not contain a '/', the result of
reqsplit[r].indexOf('/') will be -1, and as such, smaller than 0. If it does not contain a '/' and it has not yet been found, we will continue.
If it's the first word, we do not want to add a space, which is what the
if(r == 0) does. If it is any other word, we do want to add a space.
If the word does contain a '/', and it has not yet been found, we make the variable 'slashcount' equal to the word we were working on, so we can add it back later. We also set the variable 'slashfound' to true, so it will not check any more words.
Code:
for (var product_id in Bag.items.yield) {
if (Bag.items.yield[product_id].obj.name == itemreq) {
prodamount = Bag.items.yield[product_id].count;
}
};
This part loops through all products in your inventory, and checks if the name of that product equals the name we are looking for. If any match is found, 'prodamount' is set to the amount you have of that product. If no match is found, 'prodamount' is not set, and remains 0, which is what we declared in the beginning of the code.
Code:
var otherreq = reqsplit[slashcount];
if(reqsplit[slashcount+1])
otherreq += ' ' + reqsplit[slashcount+1];
//alert (itemreq + ', ' + prodamount + ', ' + slashcount);
if (prodamount != 0)
window.document.getElementById('questRequirements').getElementsByTagName('div')[loopy].innerHTML = itemreq + ' (' + prodamount + ') ' + otherreq;
This adds the part of 'reqsplit' wherever the '/' occured to a variable, so we can add it back later. If there is also some text behind that, particularly the '(Done)' part when you've already completed an objective, it adds that to the variable as well.
The alert is just a debugging alert I used to test the code, not much use now though.
If the amount of products is not 0, in other words, if the product was found, we change the quest requirement's text. If the product was not found, we do not change anything. This works, because when the text is not a product, the product could not be found, and the amount is thus still 0.
itemreq is the item,
prodamount is the amount you have of that item, and
otherreq is the part described above.
Code:
}
}
setTimeout(function(){qReq()},2000);
}
setTimeout(function(){qReq()},3000);
function loadBag()
{
if(!Bag.loaded)
Bag.loadItems();
}
setTimeout(function(){loadBag()},8000);
We then have a couple of closing tags, closing the loop and the if statement (in that order).
setTimeout(function(){qReq()},2000); calls the function every 2 seconds. Basically, the function calls itself every 2 seconds, so we loop the entire function. Then we have the final closing tag, closing this function.
Next up is the code that starts the script, 3 seconds after loading the page. The script calls itself, but it needs to be executed first.
At last have the function that loads the bag if it has not already been loaded otherwise. This function is called 8 seconds after the page has been loaded.
That's it. If you still have questions, just ask