Last active
July 10, 2021 12:47
-
-
Save LateNightIceCream/b9dd8827f311dcafa34b7e1cc986effc to your computer and use it in GitHub Desktop.
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
| // open browser console while watching a stream (F12-->console on firefox), paste and enter | |
| //let buttonDescriptor = ".tw-button"; | |
| let buttonDescriptor = ".ScCoreButtonSuccess-sc-1qn4ixc-5"; | |
| function log (message) { | |
| console.log("Twitch Auto Treasure Trigger: " + "[" + timeStamp() + "]\n" + message ); | |
| } | |
| function timeStamp () { | |
| let currentdate = new Date(); | |
| let hour = currentdate.getHours(); | |
| let mins = currentdate.getMinutes(); | |
| let secs = currentdate.getSeconds(); | |
| hour = (hour < 10 ? "0" : "") + hour; | |
| mins = (mins < 10 ? "0" : "") + mins; | |
| secs = (secs < 10 ? "0" : "") + secs; | |
| return hour + ":" + mins + ":" + secs; | |
| } | |
| function attemptToClick (descriptor) { | |
| if (!$(descriptor)) { | |
| log("❌ Button Element currently not present. Observing..."); | |
| return; | |
| } | |
| $(descriptor).click(); | |
| log("🍉 Redeemed :D"); | |
| } | |
| // Select the node that will be observed for mutations | |
| const targetNode = $(".chat-input__buttons-container"); | |
| // Options for the observer (which mutations to observe) | |
| const config = { attributes: true, childList: true, subtree: true }; | |
| // Callback function to execute when mutations are observed | |
| const callback = function(mutationsList, observer) { | |
| //attemptToClick(buttonDescriptor, mutationsList); | |
| // trying to filter, haven't exactly figured out the right | |
| // mutation. If it doesn't work --> comment out the for and | |
| // uncomment attemptToClick above | |
| // find doesnt work on nodeLists :/ | |
| for (let mutation of mutationsList) { | |
| for (node of mutation.addedNodes) { | |
| if (node.textContent == "Click to claim a bonus!") { | |
| attemptToClick(buttonDescriptor); | |
| } | |
| } | |
| } | |
| }; | |
| // Create an observer instance linked to the callback function | |
| attemptToClick(buttonDescriptor) | |
| const observer = new MutationObserver(callback); | |
| // Start observing the target node for configured mutations | |
| observer.observe(targetNode, config); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment