-
Notifications
You must be signed in to change notification settings - Fork 4
New parser for edubar #21
Copy link
Copy link
Open
Description
This one should work for teacher accounts.
Since JSON data sometimes in teacher accounts contained ');' which caused regex to stop early
static parse(html) {
let data = {
_edubar: {},
}
// Use a more robust regex that anchors to the end of the line (multiline mode)
// This prevents cutting off at ); inside JSON strings.
const match = (html.match(/\.userhome\(([\s\S]+?)\);\s*$/m) || html.match(/\.userhome\(([\s\S]+?)\);/) || "")[1];
if (!match) {
throw new Error("Failed to parse Edupage data from html (userhome match not found)");
}
try {
data = { ...JSON.parse(match) };
} catch (e) {
console.error("JSON parse error in userhome data:", e);
throw new Error("Failed to parse JSON from Edupage html (.userhome)");
}
// Parse additional edubar data
// Again, anchor to end of line to handle ); inside strings
const match2 = (html.match(/edubar\(([\s\S]*?)\);\s*$/m) || html.match(/edubar\(([\s\S]*?)\);/) || "")[1];
if (!match2) {
console.warn("edubar data not found in html");
} else {
try {
data._edubar = JSON.parse(match2) || {};
} catch (e) {
console.error("JSON parse error in edubar data:", e);
// It's possible edubar is just too complex or broken, we can continue without it if userhome worked
}
}
return data;
}Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels