Created
May 24, 2024 14:57
-
-
Save eai04191/befc302f01d756d5ed5a2292d0d82883 to your computer and use it in GitHub Desktop.
This file contains 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
(() => { | |
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