( function ( ) { let cleanupHistoryListener = null ; let targetNode = null ; const intervalIds = [ ] ; const config = { attributes : false , childList : true , subtree : true } ; const observer = new MutationObserver ( mutationCallback ) ; function mutationCallback ( mutations , _observer ) { for ( let _mutation of mutations ) { if ( targetNode !== null ) { clickBonus ( ) ; } } } function clickBonus ( ) { const buttonElements = targetNode . getElementsByTagName ( 'button' ) ; if ( buttonElements . length > 0 ) { buttonElements [ 0 ] . click ( ) ; } } function findPointsContainer ( ) { const timer = setInterval ( function ( ) { targetNode = document . querySelector ( '.community-points-summary > div:last-child' ) ; if ( targetNode !== null ) { clickBonus ( ) ; observer . observe ( targetNode , config ) ; clearInterval ( timer ) ; } } , 1000 ) ; intervalIds . push ( timer ) ; } function hookIntoReact ( ) { function reactNavigationHook ( history ) { let lastPathName = history . location . pathname ; cleanupHistoryListener = history . listen ( function ( location ) { if ( location . pathname !== lastPathName ) { lastPathName = location . pathname ; cleanup ( ) ; start ( ) ; } } ) ; } function findReactProp ( node , prop , func ) { if ( node . stateNode && node . stateNode . props && node . stateNode . props [ prop ] ) { func ( node . stateNode . props [ prop ] ) ; } else if ( node . child ) { let child = node . child ; while ( child ) { findReactProp ( child , prop , func ) ; child = child . sibling ; } } } function findReactInstance ( element , target , func ) { const timer = setInterval ( function ( ) { const reactRoot = document . getElementById ( element ) ; if ( reactRoot !== null ) { let reactInstance = null ; for ( let key of Object . keys ( reactRoot ) ) { if ( key . startsWith ( target ) ) { reactInstance = reactRoot [ key ] ; break ; } } if ( reactInstance ) { func ( reactInstance ) ; clearInterval ( timer ) ; } } } , 500 ) ; intervalIds . push ( timer ) ; } findReactInstance ( 'root' , '_reactRootContainer' , function ( instance ) { if ( instance . _internalRoot && instance . _internalRoot . current ) { findReactProp ( instance . _internalRoot . current , 'history' , reactNavigationHook ) ; const timer = setInterval ( function ( ) { findReactProp ( instance . _internalRoot . current , 'isChannelPointsEnabled' , function ( value ) { if ( value ) { findPointsContainer ( ) ; } clearInterval ( timer ) ; } ) ; } , 1000 ) ; intervalIds . push ( timer ) ; } } ) ; } function start ( ) { window . removeEventListener ( 'beforeunload' , cleanup ) ; window . addEventListener ( 'beforeunload' , cleanup ) ; hookIntoReact ( ) ; } function cleanup ( ) { observer . disconnect ( ) ; for ( const id of intervalIds ) { clearInterval ( id ) ; } if ( cleanupHistoryListener !== null ) { cleanupHistoryListener ( ) ; } } start ( ) ; console . log ( 'Twitch Channel Points Auto-Clicker' ) ; } ) ( ) ;