Last active
August 29, 2015 14:18
-
-
Save loadedsith/4eae54818d27dff1c820 to your computer and use it in GitHub Desktop.
StackEgg Automation Script
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
var clickButton = function(actionElement) { | |
console.log('actionElement', actionElement); | |
$(actionElement).click(); | |
} | |
var defaultStats = { | |
'questions': { | |
'id': '#egg-stat-questions', | |
'action':clickButton.bind(null,'#egg-action-ask button') | |
}, | |
'answers': { | |
'id': '#egg-stat-answers', | |
'action':clickButton.bind(null,'#egg-action-answer button') | |
}, | |
'users': { | |
'id': '#egg-stat-users', | |
'action':clickButton.bind(null,'#egg-action-upvote button') | |
}, | |
'quality': { | |
'id': '#egg-stat-quality', | |
'action':clickButton.bind(null,'#egg-action-downvote button') | |
}, | |
'traffic': { | |
'id': '#egg-stat-traffic', | |
'action':clickButton.bind(null,'#egg-action-answer button') | |
}, | |
'flags': { | |
'id': '#egg-flags', | |
'action':clickButton.bind(null,'#egg-action-nothing button') | |
} | |
}; | |
var stats = defaultStats; | |
var loop = function() { | |
getStats(); | |
lowestStat().action(); | |
} | |
var heartValue = function(heartTitle) { | |
var value; | |
var values = { | |
'0 hearts':0, | |
'1 heart':1, | |
'2 hearts':2, | |
'3 hearts':3, | |
'4 hearts':4, | |
'default':100 | |
} | |
if (values[heartTitle] === undefined){ | |
console.log('unmatched', heartTitle); | |
value = values['default']; | |
}else{ | |
value = values[heartTitle]; | |
} | |
console.log('value', value); | |
return value; | |
} | |
var getStats = function() { | |
stats = defaultStats; | |
for (var i = Object.keys(stats).length - 1; i >= 0; i--) { | |
var key = Object.keys(stats)[i]; | |
var stat = stats[key]; | |
if ((($(stat.id)[0] || {}).attributes || {})['title'] !== undefined) { | |
// same as if(stat.id){if(stat.id.attributes){if(stat.id.attributes['title']){}}} | |
stat['hearts'] = $(stat.id)[0].attributes['title'].value; | |
stat['heartValue'] = heartValue(stat['hearts']); | |
} | |
} | |
console.log('stats', stats); | |
}; | |
var lowestStat = function() { | |
var lowestStat = { | |
value:100, | |
id:'' | |
}; | |
for (var i = Object.keys(stats).length - 1; i >= 0; i--) { | |
var key = Object.keys(stats)[i]; | |
var stat = stats[key]; | |
console.log('stat.heartValue', stat.heartValue); | |
if (lowestStat.value > stat.heartValue) { | |
lowestStat.value = stat.heartValue; | |
lowestStat.id = stat.id; | |
lowestStat.action = stat.action; | |
} | |
} | |
console.log('lowestStat', lowestStat); | |
return lowestStat; | |
}; | |
var interval = setInterval(loop, 21 * 1000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment