Skip to content

Instantly share code, notes, and snippets.

@Shilo
Last active June 18, 2024 20:23
Show Gist options
  • Save Shilo/cdba9ffba3cb34497f52f04a72ac4ca7 to your computer and use it in GitHub Desktop.
Save Shilo/cdba9ffba3cb34497f52f04a72ac4ca7 to your computer and use it in GitHub Desktop.
Twitch Javascript injected script to simulate reward redemption.
// Twitch Javascript injected script to simulate reward redemption.
// Note: Class names may need to be changed if outdated.
// Index of reward to click.
var rewardButtonIndex = 0
var amountOfRedeems = 1
// Class names for elements.
var rewardsListButtonClass = "ScCoreButton-sc-ocjdkq-0 ScCoreButtonText-sc-ocjdkq-3 ljgEdo fuXDrj"
var specificRewardButtonClass = "ScInteractableBase-sc-ofisyf-0 ScInteractableDefault-sc-ofisyf-1 dsnvLR etibmD tw-interactable"
var redeemButtonClass = "ScCoreButton-sc-ocjdkq-0 ScCoreButtonPrimary-sc-ocjdkq-1 ljgEdo gmCwLG"
// Offset by the bit power-up redeems.
var rewardButtonOffset = 3
for (var i = 0; i < Math.max(amountOfRedeems, 1); i++) {
// Wait for previous redeem to process.
if (i > 0)
await new Promise(resolve => setTimeout(resolve, 500))
// Click rewards button.
document.getElementsByClassName(rewardsListButtonClass)[0].click()
// Wait for reward popup to show.
await new Promise(resolve => setTimeout(resolve, 20))
// Click reward button.
document.getElementsByClassName(specificRewardButtonClass)[rewardButtonIndex + rewardButtonOffset].click()
// Wait for reward confirmation.
await new Promise(resolve => setTimeout(resolve, 20))
// Click redeem button.
var buttons = document.getElementsByClassName(redeemButtonClass)
buttons[buttons.length-1].click()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment