Game Harvester

As well as coding, my second love is gaming - including collecting some older and newer video games. I buy a lot of games online, however there are also a lot more collectors and re-sellers out there that often grab games before me. So to try and help me get a bit more of an advantage, I started writing this code that scours certain websites for information and when it matches keywords that I have configured it either buys them or alerts me that they are there for sale. It started out small, quick and nasty and has quickly evolved and become so efficient that I'm spending $1000 a week on games and the ones I don't want I resell, which pays for buying more games! I'm really proud of the script I wrote and thought I would share it.

Please note, this was made in Java for Greasemonkey/Chrome and the code has been modified a bit... but you get the general idea!


// ==UserScript==
// @name Hunt
// @namespace https://somewebsite.com
// @version 0.1
// @description try to take over the world!
// @author You
// @match http://somewebsite/item*
// @grant none
// ==/UserScript==
'use strict';

var url;

if(document.URL.indexOf('https://somewebsite.com/items/') >= 0)
{
setTimeout(back, 1000);
}
else
{
setTimeout(search, 1000);
}

function search()
{
url = window.location.href.substring(45, 52);

if(/(Nintendo)|(Mario)|(64)|(Pokemon)|(Gamecube)|(Sega)|(3DS)|(Gameboy)|(PS1)|(PS2)|(PSP)/i.test (document.title) )
{
checkBuyable();
}
else
{
url++;
window.location.href = ("http://somewebsite.com/item/".concat(url));
}
}

function checkBuyable()
{
//check if this is an auction
if (/(SomeStoreToNotBuyFrom)|(Item is in your cart.)|(Sold)/i.test (document.body.innerHTML) )
{
url++;
window.location.href = ("http://somewebsite.com/item/".concat(url));
}
else if (/(Time Left in Auction)|(Auction Ended)/i.test (document.body.innerHTML) )
{
beep();
//window.open("http://somewebsite.com/item/".concat(url),'_blank');
url++;
window.location.href = ("http://somewebsite.com/item/".concat(url));
}
else if (/(Buy Item Now)|(Add to Cart)/i.test (document.body.innerHTML) )
{
document.getElementsByTagName('form')[2].submit();
}

else if (/(This product is in your cart.)|(Successfully purchased)/i.test (document.body.innerHTML) )
{
//url--;
window.location.href = ("http://somewebsite.com/item/".concat(url));
}
}

function back()
{
url = document.referrer;
//window.location.href = ("http://somewebsite.com/item/".concat(url));
window.history.back();
//window.alert(url);
}

function beep()
{
var snd = new Audio("data:audio/wav;base64,//uQRAAAAWMSLwUIYAAsYkXgoQ");
snd.play();
}