Greasy Fork is available in English.

Itsnotlupus' React Tools

Observe, inspect and perhaps modify a React tree through the React DevTools Hook

Dit script moet niet direct worden geïnstalleerd - het is een bibliotheek voor andere scripts om op te nemen met de meta-richtlijn // @require https://update.greasyfork.org/scripts/473998/1246974/Itsnotlupus%27%20React%20Tools.js

Maker
itsnotlupus
Versie
1.1
Gemaakt op
27-08-2023
Bijgewerkt op
07-09-2023
Licentie
MIT

A scrappy little library that plugs into React and tries to get useful bits user scripts can leverage.

Sample usage:

const stuff = new ReactTools();

stuff.observe(root => {
  console.log("A react tree was updated, and here's the fiber tree for it:", root);
});

// If the site you're targeting uses Redux and wasn't written by psychopaths, this will usually work.
// (The tree will need to get rendered first. You can use observe() to wait for it.)

const reduxStore = stuff.getProp("store");

findNodesWithProp() and updateNodeProps() are a bit trickier to use.
You'll want to install the React Dev Tools to see what props are actually available on each node.
See https://greasyfork.org/en/scripts/444804-crunchyroll-watchlist-userscript/code for an example use in tweakPlayer()
That crunchyroll script no longer works, but the code shows how to make this stuff work:
Mutating react props from outside of React is almost futile, since they get overwritten almost immediately.
But "almost" is the operative word there. You can effectively control React component props by:

  • having a React observer
  • that finds the node(s) you care about on every iteration with findNodesWithProp()
  • and reset the props you need with updateNodeProps()

Important Notes:

This library doesn't use the React DevTools Hook correctly.
There are almost certainly better way to use the hook APIs to do the things it does.
And yet it works (for me.)