diff --git a/packages/github-user-contribution/index.ts b/packages/github-user-contribution/index.ts
index 9d9b9e5..33fcf81 100644
--- a/packages/github-user-contribution/index.ts
+++ b/packages/github-user-contribution/index.ts
@@ -39,40 +39,36 @@ export const getGithubUserContribution = async (
};
const parseUserPage = (content: string) => {
- // take roughly the svg block
+ // take roughly the table block
const block = content
- .split(`class="js-calendar-graph-svg"`)[1]
- .split("")[0];
+ .split(`aria-describedby="contribution-graph-description"`)[1]
+ .split("
")[1]
+ .split("")[0];
- let x = 0;
- let lastYAttribute = 0;
+ const cells = block.split("").flatMap((inside, y) =>
+ inside.split("").flatMap((m) => {
+ const date = m.match(/data-date="([^"]+)"/)?.[1];
- const rects = Array.from(block.matchAll(/]*>[^<]*<\/rect>/g)).map(
- ([m]) => {
- const date = m.match(/data-date="([^"]+)"/)![1];
- const level = +m.match(/data-level="([^"]+)"/)![1];
- const yAttribute = +m.match(/y="([^"]+)"/)![1];
+ const literalLevel = m.match(/data-level="([^"]+)"/)?.[1];
+ const literalX = m.match(/data-ix="([^"]+)"/)?.[1];
+ const literalCount = m.match(/(No|\d+) contributions? on/)?.[1];
- const literalCount = m.match(/(No|\d+) contributions? on/)![1];
- const count = literalCount === "No" ? 0 : +literalCount;
+ if (date && literalLevel && literalX && literalCount)
+ return [
+ {
+ x: +literalX,
+ y,
- if (lastYAttribute > yAttribute) x++;
+ date,
+ count: +literalCount,
+ level: +literalLevel,
+ },
+ ];
- lastYAttribute = yAttribute;
-
- return { date, count, level, x, yAttribute };
- }
+ return [];
+ })
);
- const yAttributes = Array.from(
- new Set(rects.map((c) => c.yAttribute)).keys()
- ).sort();
-
- const cells = rects.map(({ yAttribute, ...c }) => ({
- y: yAttributes.indexOf(yAttribute),
- ...c,
- }));
-
return cells;
};