@@ -39,40 +39,36 @@ export const getGithubUserContribution = async (
3939} ;
4040
4141const parseUserPage = ( content : string ) => {
42- // take roughly the svg block
42+ // take roughly the table block
4343 const block = content
44- . split ( `class="js-calendar-graph-svg"` ) [ 1 ]
45- . split ( "</svg>" ) [ 0 ] ;
46-
47- let x = 0 ;
48- let lastYAttribute = 0 ;
49-
50- const rects = Array . from ( block . matchAll ( / < r e c t [ ^ > ] * > [ ^ < ] * < \/ r e c t > / g) ) . map (
51- ( [ m ] ) => {
52- const date = m . match ( / d a t a - d a t e = " ( [ ^ " ] + ) " / ) ! [ 1 ] ;
53- const level = + m . match ( / d a t a - l e v e l = " ( [ ^ " ] + ) " / ) ! [ 1 ] ;
54- const yAttribute = + m . match ( / y = " ( [ ^ " ] + ) " / ) ! [ 1 ] ;
55-
56- const literalCount = m . match ( / ( N o | \d + ) c o n t r i b u t i o n s ? o n / ) ! [ 1 ] ;
57- const count = literalCount === "No" ? 0 : + literalCount ;
58-
59- if ( lastYAttribute > yAttribute ) x ++ ;
60-
61- lastYAttribute = yAttribute ;
62-
63- return { date, count, level, x, yAttribute } ;
64- }
44+ . split ( `aria-describedby="contribution-graph-description"` ) [ 1 ]
45+ . split ( "<tbody>" ) [ 1 ]
46+ . split ( "</tbody>" ) [ 0 ] ;
47+
48+ const cells = block . split ( "</tr>" ) . flatMap ( ( inside , y ) =>
49+ inside . split ( "</td>" ) . flatMap ( ( m ) => {
50+ const date = m . match ( / d a t a - d a t e = " ( [ ^ " ] + ) " / ) ?. [ 1 ] ;
51+
52+ const literalLevel = m . match ( / d a t a - l e v e l = " ( [ ^ " ] + ) " / ) ?. [ 1 ] ;
53+ const literalX = m . match ( / d a t a - i x = " ( [ ^ " ] + ) " / ) ?. [ 1 ] ;
54+ const literalCount = m . match ( / ( N o | \d + ) c o n t r i b u t i o n s ? o n / ) ?. [ 1 ] ;
55+
56+ if ( date && literalLevel && literalX && literalCount )
57+ return [
58+ {
59+ x : + literalX ,
60+ y,
61+
62+ date,
63+ count : + literalCount ,
64+ level : + literalLevel ,
65+ } ,
66+ ] ;
67+
68+ return [ ] ;
69+ } )
6570 ) ;
6671
67- const yAttributes = Array . from (
68- new Set ( rects . map ( ( c ) => c . yAttribute ) ) . keys ( )
69- ) . sort ( ) ;
70-
71- const cells = rects . map ( ( { yAttribute, ...c } ) => ( {
72- y : yAttributes . indexOf ( yAttribute ) ,
73- ...c ,
74- } ) ) ;
75-
7672 return cells ;
7773} ;
7874
0 commit comments