1- document . getElementById ( "status" ) . textContent = "Loading..." ;
1+ document . addEventListener ( "DOMContentLoaded" , ( ) => {
2+ browser . tabs . query ( { active : true , currentWindow : true } ) . then ( ( tabs ) => {
3+ const tab = tabs [ 0 ] ;
4+ // Get the problem slug from the URL
5+ const url = new URL ( tab . url ) ;
6+ const pathParts = url . pathname . split ( "/" ) . filter ( Boolean ) ;
7+ const slug = pathParts [ 1 ] || null ;
8+ if ( ! slug ) {
9+ document . body . innerHTML = "<p>Not a leetcode problem page</p>" ;
10+ return ;
11+ }
12+ // Ask background for the latest problem data
13+ browser . runtime . sendMessage ( { type : "GET_PROBLEM_DATA" , slug } )
14+ . then ( ( data ) => {
15+ if ( ! data ) {
16+ document . body . innerHTML = "<p>Not a leetcode problem page</p>" ;
17+ return ;
18+ }
19+ const container = document . getElementById ( "popupContent" ) ;
20+ container . innerHTML = `
21+ <h2>${ data . title } </h2>
22+ <p>Difficulty: ${ data . difficulty } </p>
23+ <p id="status">${ data . status || "Unsolved" } </p>
24+ ` ;
25+
26+ // Listen for problem solved message
27+ browser . runtime . onMessage . addListener ( ( msg ) => {
28+ if ( msg . type === "PROBLEM_SOLVED" && msg . slug === data . slug ) {
29+ const statusEl = document . getElementById ( "status" ) ;
30+ if ( statusEl ) statusEl . textContent = "Solved ✅" ;
31+ }
32+ } ) ;
33+ } )
34+ . catch ( ( err ) => {
35+ document . body . innerHTML = "<p>Unable to read this page</p>" ;
36+ console . error ( err ) ;
37+ } ) ;
38+ } ) ;
39+ } ) ;
40+
41+ document . addEventListener ( "DOMContentLoaded" , ( ) => {
42+ browser . storage . local . get ( null ) . then ( ( allData ) => {
43+ const problems = Object . values ( allData ) . filter ( p => p . status === "Solved" ) ;
44+ const list = document . getElementById ( "solvedList" ) ;
45+
46+ if ( problems . length === 0 ) {
47+ list . innerHTML = "<p>No solved problems yet</p>"
48+ }
49+
50+ problems . forEach ( problem => {
51+ const item = document . createElement ( "div" ) ;
52+ item . className = "problem-item" ;
53+ item . innerHTML = `
54+ <a href="${ problem . url } " target="_blank">${ problem . title } </a>
55+ <span class="difficulty">${ problem . difficulty } </span>
56+ ` ;
57+ list . appendChild ( item ) ;
58+ } )
59+ } )
60+ } )
0 commit comments