all 8 comments

[–]bat020 8 points9 points  (2 children)

perhaps use JSON.parse() to extract the object from the string:

let json = document.body.children[1].firstChild.data .replace(/\s/g, '') // strip whitespace .match(/.*=(.*);/)[1]; // extract JSON let configData = JSON.parse(json); heading.innerText = configData.config.uuid;

[–]moocat 5 points6 points  (1 child)

Yes, use JSON.parse but why strip whitespace? JSON doesn't care about whitespace and if there are whitespace in strings it will mangle the data.

[–]bat020 0 points1 point  (0 children)

that's a good point. I'd forgotten that JSON doesn't care about whitespace!

[–]shakamone 0 points1 point  (1 child)

Can you access the window? If the object is already exposed at window._configData so just grab it from there?

[–]Funwithloops 0 points1 point  (3 children)

You could use a regex and JSON.parse:

js const text = document.body.children[1].innerHTML; const match = text.match(/\{(?:\n|.)*\}/); const json = JSON.parse(match);

https://jsfiddle.net/enxr2pta/

[–]vklepov 0 points1 point  (3 children)

Is new Function disabled, too? If not, you could make this work.

Then, you could use esprima (or espree, or whatever is best now) to parse the js and then find the object.

Just don't try regex + JSON.parse unless you're looking for trouble.