Last active
April 9, 2017 04:51
-
-
Save lantto/8c34e1dbf04ad5f33b28840a29ce7667 to your computer and use it in GitHub Desktop.
Automatically upvote after X minutes
This file contains 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
function setTitle(voteAt, minutesAgo, originalTitle) { | |
var voteIn = voteAt - minutesAgo; | |
var unit = (voteIn === 1 ? 'minute' : 'minutes'); | |
var newTitle = '<Votes in ' + voteIn + ' ' + unit + '> | ' + originalTitle; | |
if (document.title !== newTitle) { | |
document.title = newTitle; | |
} | |
}; | |
function run(voteAt, originalTitle, voted) { | |
if (!voteAt) { | |
return; | |
} | |
voteAt = parseInt(voteAt); | |
if (isNaN(voteAt)) { | |
return; | |
} | |
if (document.title.indexOf(originalTitle) === -1) { | |
return; | |
} | |
var timeParts = document.getElementsByTagName('time')[0].innerHTML.split(' '); | |
if (timeParts[1].indexOf('minute') !== -1) { | |
var minutesAgo = parseInt(timeParts[0]); | |
if (minutesAgo >= voteAt) { | |
if (!voted) { | |
document.querySelector('.PostFull__footer [title="Upvote"]').click(); | |
voted = true; | |
}; | |
document.title = '<Upvoted!> | ' + originalTitle; | |
} else { | |
setTitle(voteAt, minutesAgo, originalTitle); | |
} | |
} else { | |
setTitle(voteAt, 0, originalTitle); | |
} | |
setTimeout(function() { | |
run(voteAt, originalTitle, voted); | |
}, 1000); | |
}; | |
if (!document.querySelector('.PostFull__footer [title="Upvote"]')) { | |
alert('Are you on steemit.com? In that case the bookmarklet may have stopped working. Please contact @lantto for an updated version.'); | |
} else { | |
run( | |
parseInt(prompt('Enter at which minute mark it should upvote (e.g. 10, 15, 30 etc):')), | |
document.title, | |
false | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment