Last active
July 2, 2020 20:18
-
-
Save ethanbeyer/b1691f49354b77b4539e5dfb3c9d968c to your computer and use it in GitHub Desktop.
Twitch Channel Currency Autoclicker
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
// ==UserScript== | |
// @name Twitch Channel Currency Clicker | |
// @version 2.1.1 | |
// @grant * | |
// @include https://www.twitch.tv/* | |
// @require https://code.jquery.com/jquery-3.5.1.slim.min.js | |
// ==/UserScript== | |
// set this at the beginning | |
var oldLocation = location.href; | |
setTimeout(setup, _intToTime(6, 'seconds')); | |
setInterval(function() { | |
if(location.href != oldLocation) { | |
console.clear(); | |
console.log('Location has changed.'); | |
oldLocation = location.href; | |
teardown(); | |
setup(); | |
} | |
}, _intToTime(1, 'seconds')); | |
//////////////////////////////////////////////////////////////////////////////////// | |
function clickButtonAndGiveFeedback() | |
{ | |
// console.log('Checking for a button.'); | |
var btn = $('.community-points-summary button.tw-button'); | |
// If the button exists, click it, and do the counter increase. | |
if(btn.length && !btn.clicked) { | |
btn.click(); | |
btn.clicked = true; | |
btn.prop('disabled', true); | |
var now = new Date(); | |
var timeString = now.toString(); | |
console.log('Rewards button clicked at ' + timeString + '.'); | |
var num = $("#click_counter").html(); | |
num = parseInt(num) + 1; | |
$("#click_counter").html(num); | |
} | |
} | |
// ==================================== Helpers ========================== // | |
function _intToTime(int, units) | |
{ | |
var u = {}; | |
u.milliseconds = 1; | |
u.seconds = u.milliseconds * 1000; | |
u.minutes = u.seconds * 60; | |
u.hours = u.minutes * 60; | |
u.days = u.hours * 24; | |
u.weeks = u.days * 7; | |
return int * u[units]; | |
} | |
function setup() | |
{ | |
var hasChatInput = document.querySelector('.chat-input'); | |
if(hasChatInput) { | |
setInterval(clickButtonAndGiveFeedback, _intToTime(10, 'seconds')); // run the search for the button every X seconds | |
console.log('Making Counter...'); | |
$('<div/>') | |
.attr('id', 'click_counter') | |
.text('0') | |
.css({ | |
"font-size":"80%", | |
"background": "red", | |
"color": "white", | |
"position": "absolute", | |
"bottom": 0, | |
"left": 0, | |
"z-index": 100000, | |
"padding": "5px" | |
}) | |
.appendTo(document.body); | |
} | |
} | |
function teardown() | |
{ | |
$('#click_counter').remove(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment