diff --git a/package.json b/package.json index 55e405b5..98cd697e 100755 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "frankerfacez", "author": "Dan Salvato LLC", - "version": "4.19.1", + "version": "4.19.2", "description": "FrankerFaceZ is a Twitch enhancement suite.", "license": "Apache-2.0", "scripts": { diff --git a/src/sites/twitch-twilight/index.js b/src/sites/twitch-twilight/index.js index 05c586d0..4a6ef086 100644 --- a/src/sites/twitch-twilight/index.js +++ b/src/sites/twitch-twilight/index.js @@ -50,8 +50,8 @@ export default class Twilight extends BaseSite { } onEnable() { - const thing = this.fine.searchTree(null, n => n.props && n.props.store), - store = this.store = thing && thing.props && thing.props.store; + const thing = this.fine.searchNode(null, n => n?.pendingProps?.store?.getState), + store = this.store = thing?.pendingProps?.store; if ( ! store ) return new Promise(r => setTimeout(r, 50)).then(() => this.onEnable()); diff --git a/src/utilities/compat/fine.js b/src/utilities/compat/fine.js index 7de576e2..30a3bb55 100644 --- a/src/utilities/compat/fine.js +++ b/src/utilities/compat/fine.js @@ -195,6 +195,57 @@ export default class Fine extends Module { return null; } + searchNode(node, criteria, max_depth=15, depth=0, traverse_roots = true) { + if ( ! node ) + node = this.react; + else if ( node._reactInternalFiber ) + node = node._reactInternalFiber; + else if ( node instanceof Node ) + node = this.getReactInstance(node); + + if ( ! node || node._ffz_no_scan || depth > max_depth ) + return null; + + if ( typeof criteria === 'string' ) { + const wrapper = this._wrappers.get(criteria); + if ( ! wrapper ) + throw new Error('invalid critera'); + + if ( ! wrapper._class ) + return null; + + criteria = n => n && n.constructor === wrapper._class; + } + + if ( node && criteria(node) ) + return node; + + if ( node.child ) { + let child = node.child; + while(child) { + const result = this.searchNode(child, criteria, max_depth, depth+1, traverse_roots); + if ( result ) + return result; + child = child.sibling; + } + } + + const inst = node.stateNode; + if ( traverse_roots && inst && inst.props && inst.props.root ) { + const root = inst.props.root._reactRootContainer; + if ( root ) { + let child = root._internalRoot && root._internalRoot.current || root.current; + while(child) { + const result = this.searchNode(child, criteria, max_depth, depth+1, traverse_roots); + if ( result ) + return result; + + child = child.sibling; + } + } + } + } + searchTree(node, criteria, max_depth=15, depth=0, traverse_roots = true) { if ( ! node ) node = this.react; @@ -218,7 +269,7 @@ export default class Fine extends Module { } const inst = node.stateNode; - if ( inst && criteria(inst) ) + if ( inst && criteria(inst, node) ) return inst; if ( node.child ) {