Skip to content

Instantly share code, notes, and snippets.

@69
Last active September 19, 2023 19:32
Show Gist options
  • Save 69/b9b6565c63360176221b5d8334161929 to your computer and use it in GitHub Desktop.
Save 69/b9b6565c63360176221b5d8334161929 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name Twitch Channel Points autoclaimer
// @version 1.0.0
// @description Automatically clicks the chest to claim the Twitch channel points
// @author jammy
// @match https://twitch.tv/*
// @match https://www.twitch.tv/*
// @grant none
// ==/UserScript==
(function() {
'use strict';
const sel = (selector) => document.querySelector(selector);
let isInjected = false;
const init = () => {
const buttonObserver = new MutationObserver((mutations) => {
for (const mutation of mutations) {
const addedNodes = Array.from(mutation.addedNodes);
if (sel('.community-points-summary .tw-icon__svg')) {
setTimeout(() => {
sel('.community-points-summary .tw-icon__svg').parentNode.click();
}, Math.random() * 5000);
}
}
});
const pointsElement = document.querySelector('.chat-input__buttons-container');
buttonObserver.observe(pointsElement, { childList: true, subtree: true });
};
const wrapperObserver = new MutationObserver((mutations) => {
for (const mutation of mutations) {
const addedNodes = Array.from(mutation.addedNodes);
if (addedNodes.includes(sel('.chat-input__buttons-container')) || sel('.chat-input__buttons-container')) {
if(isInjected) return;
init();
isInjected = true;
console.log('injected');
wrapperObserver.disconnect();
}
}
});
wrapperObserver.observe(document.body, { childList: true, subtree: true });
})();
@Glaived
Copy link

Glaived commented Nov 29, 2019

Great script! It would be interesting to add the automatic update feature (see Greasemonkey doc)

@8dcc
Copy link

8dcc commented Apr 10, 2022

Cool script

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment