1- console . log ( "🧠 leetcode tracker is active" )
1+ function getProblemData ( ) {
2+ const titleEl = document . querySelector ( 'div[class*="text-title-large"]' ) ;
3+ const title = titleEl ? titleEl . textContent . trim ( ) : "Unknown Title" ;
4+
5+ const difficultyEl = Array . from ( document . querySelectorAll ( 'div[class*="text-difficulty"]' ) ) . find ( ( el ) =>
6+ el . textContent ?. match ( / E a s y | M e d i u m | H a r d / )
7+ ) ;
8+ const difficulty = difficultyEl
9+ ? difficultyEl . textContent . trim ( )
10+ : "Unknown Difficulty" ;
11+
12+ const pathParts = window . location . pathname . split ( "/" ) . filter ( Boolean ) ;
13+ const problemSlug = pathParts [ 1 ] || "unknown-problem" ;
14+
15+ const problemData = {
16+ title,
17+ difficulty,
18+ slug : problemSlug ,
19+ url : window . location . href ,
20+ timestamp : Date . now ( ) ,
21+ } ;
22+
23+ console . log ( "LC Problem Detected:" , problemData ) ;
24+ return problemData ;
25+ }
26+
27+ function waitForContentAndStore ( ) {
28+ const observer = new MutationObserver ( ( ) => {
29+ const titleEl = document . querySelector ( "div" ) ;
30+ if ( titleEl && titleEl . textContent . trim ( ) ) {
31+ observer . disconnect ( ) ;
32+ const data = getProblemData ( ) ;
33+ browser . storage . local . set ( { [ data . slug ] : data } ) . then ( ( ) => {
34+ console . log ( "Saved to storage:" , data ) ;
35+ } ) . catch ( ( err ) => {
36+ console . error ( "Storage error:" , err ) ;
37+ } ) ;
38+ }
39+ } ) ;
40+
41+ observer . observe ( document . body , { childList : true , subtree : true } ) ;
42+ }
43+
44+ waitForContentAndStore ( ) ;
45+
46+
0 commit comments