Created
December 8, 2014 08:00
-
-
Save orzFly/eb3089ddf93ff2cb479e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Event.simulate(@element, eventName[, options]) -> Element | |
* | |
* - @element: element to fire event on | |
* - eventName: name of event to fire (only MouseEvents and HTMLEvents interfaces are supported) | |
* - options: optional object to fine-tune event properties - pointerX, pointerY, ctrlKey, etc. | |
* | |
* $('foo').simulate('click'); // => fires "click" event on an element with id=foo | |
* | |
**/ | |
(function(){ | |
var eventMatchers = { | |
'HTMLEvents': /^(?:load|unload|abort|error|select|change|submit|reset|focus|blur|resize|scroll)$/, | |
'MouseEvents': /^(?:click|mouse(?:down|up|over|move|out))$/, | |
'KeyboardEvents': /^(?:key(?:down|up|press))$/ | |
} | |
var defaultOptions = { | |
pointerX: 0, | |
pointerY: 0, | |
button: 0, | |
ctrlKey: false, | |
altKey: false, | |
shiftKey: false, | |
metaKey: false, | |
bubbles: true, | |
cancelable: true | |
} | |
Event.simulate = function(element, eventName) { | |
var options = Object.extend(defaultOptions, arguments[2] || { }); | |
var oEvent, eventType = null; | |
element = $(element); | |
for (var name in eventMatchers) { | |
if (eventMatchers[name].test(eventName)) { eventType = name; break; } | |
} | |
if (!eventType) | |
throw new SyntaxError('Only HTMLEvents and MouseEvents interfaces are supported'); | |
if (document.createEvent) { | |
oEvent = document.createEvent(eventType); | |
if (eventType == 'HTMLEvents') { | |
oEvent.initEvent(eventName, options.bubbles, options.cancelable); | |
} | |
else if (eventType == 'MouseEvents') { | |
oEvent.initMouseEvent(eventName, options.bubbles, options.cancelable, document.defaultView, | |
options.button, options.pointerX, options.pointerY, options.pointerX, options.pointerY, | |
options.ctrlKey, options.altKey, options.shiftKey, options.metaKey, options.button, element); | |
} | |
else if (eventType == 'KeyboardEvents') { | |
oEvent.initKeyboardEvent(eventName); | |
} | |
element.dispatchEvent(oEvent); | |
} | |
else { | |
options.clientX = options.pointerX; | |
options.clientY = options.pointerY; | |
oEvent = Object.extend(document.createEventObject(), options); | |
element.fireEvent('on' + eventName, oEvent); | |
} | |
return element; | |
} | |
Element.addMethods({ simulate: Event.simulate }); | |
})(); | |
ORZ = {}; | |
ORZ.clickNext = function () { | |
console.log("clickNext"); | |
a = $($$('.itemHolder:first a')[0]); | |
if (ORZ.lastId != a.href) { | |
ORZ.lastId = a.href; | |
try { $($$('.item_market_content .item_market_actions#iteminfo0_item_market_actions>div>div:last')[0]).innerText = ""; } catch (err) {} | |
try { $($$('.item_market_content .item_market_actions#iteminfo1_item_market_actions>div>div:last')[0]).innerText = ""; } catch (err) {} | |
a.simulate("click"); | |
setTimeout(ORZ.fetchPrice, 1000); | |
} else { | |
if (a.href != "http://steamcommunity.com/id/orzFly/inventory/#753_6_1251082821") { | |
setTimeout(ORZ.clickNext, 1000); | |
} | |
} | |
} | |
ORZ.fetchPrice = function () { | |
console.log("fetchPrice"); | |
try { | |
if ($($$("div.inventory_iteminfo#iteminfo0")[0]).style.display == "none") { | |
ORZ.lastPrice = ((Number(/\$(\d+.\d+) USD/.exec($($$('.item_market_content .item_market_actions#iteminfo1_item_market_actions>div>div:last')[0]).innerText)[1])*100-1)/100); | |
} else { | |
ORZ.lastPrice = ((Number(/\$(\d+.\d+) USD/.exec($($$('.item_market_content .item_market_actions#iteminfo0_item_market_actions>div>div:last')[0]).innerText)[1])*100-1)/100); | |
} | |
console.log("fetched " + ORZ.lastPrice.toString()); | |
setTimeout(SellCurrentSelection, 4000); | |
setTimeout(ORZ.sellCard, 5000); | |
} catch(err) { | |
console.log("fetching failed"); | |
setTimeout(ORZ.fetchPrice, 1000); | |
} | |
} | |
ORZ.sellCard = function () { | |
console.log("sellCard"); | |
$($$("input#market_sell_buyercurrency_input")[0]).value = "$" + ORZ.lastPrice.toString(); | |
$($$("input#market_sell_buyercurrency_input")[0]).simulate("keyup"); | |
$($$("input#market_sell_dialog_accept_ssa")[0]).checked = true; | |
$($$("a#market_sell_dialog_accept")[0]).simulate("click"); | |
setTimeout(ORZ.doSellCard, 200); | |
} | |
ORZ.doSellCard = function () { | |
console.log("doSellCard"); | |
if ($($$("#market_sell_dialog_confirm_buttons")[0]).style.display == "none") { | |
setTimeout(ORZ.doSellCard, 200); | |
} else { | |
$($$("a#market_sell_dialog_ok")[0]).simulate("click"); | |
setTimeout(ORZ.prepareNext, 1000); | |
} | |
} | |
ORZ.prepareNext = function () { | |
console.log("prepareNext"); | |
if ($($$("div.market_modal_dialog#market_sell_dialog")[0]).style.display == "none") { | |
setTimeout(ORZ.clickNext, 200); | |
} else { | |
setTimeout(ORZ.prepareNext, 1000); | |
} | |
} | |
ORZ.clickNext(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment