Skip to content

Instantly share code, notes, and snippets.

@eai04191
Created May 24, 2024 14:57
Show Gist options
  • Save eai04191/befc302f01d756d5ed5a2292d0d82883 to your computer and use it in GitHub Desktop.
Save eai04191/befc302f01d756d5ed5a2292d0d82883 to your computer and use it in GitHub Desktop.
(() => {
const reactRandomKey = Object.keys(document.querySelector("#root"))
.find((key) => key.startsWith("__reactContainer$"))
.split("$")[1];
const fiberKey = `__reactFiber$${reactRandomKey}`;
const propsKey = `__reactProps$${reactRandomKey}`;
function filterReactFibers(elements) {
return [...elements].filter((e) => Object.keys(e).includes(fiberKey));
}
function filterWorks(reactFibers) {
return [...reactFibers].filter(
(e) => "work" in e[propsKey].children.props
);
}
const works = filterWorks(
filterReactFibers(document.querySelectorAll("li"))
);
return works.map((workFiber) => {
const key = workFiber[fiberKey].return.key;
const props = workFiber[propsKey].children.props;
const work = props.work;
const { title, userName, userId } = work;
return { key, title, userName, userId, props };
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment