11import { getChatGPTAccessToken } from './chatgpt/chatgpt.js' ;
2+ var { browser } = require ( "webextension-polyfill-ts" ) ;
23
34// Load JSON & default settings on install
4- chrome . runtime . onInstalled . addListener ( ( ) => {
5+ browser . runtime . onInstalled . addListener ( ( ) => {
56 // Load JSON file into storage
6- const jsonUrl = chrome . runtime . getURL ( 'src/assets/data/leetcode_solutions.json' ) ;
7+ const jsonUrl = browser . runtime . getURL ( 'src/assets/data/leetcode_solutions.json' ) ;
78 fetch ( jsonUrl )
89 . then ( ( response ) => response . json ( ) )
910 . then ( ( data ) => {
10- chrome . storage . local . set ( { leetcodeProblems : data } ) ;
11+ browser . storage . local . set ( { leetcodeProblems : data } ) ;
1112 } )
1213 . catch ( ( error ) => {
1314 console . error ( error ) ;
1415 } ) ;
1516
1617 // Default settings
17- chrome . storage . local . set ( { language : 'python' } ) ;
18- chrome . storage . local . set ( { fontSize : 14 } ) ;
19- chrome . storage . local . set ( { showCompanyTags : true } ) ;
20- chrome . storage . local . set ( { showExamples : true } ) ;
21- chrome . storage . local . set ( { showDifficulty : true } ) ;
22- chrome . storage . local . set ( { clickedCompany : 'Amazon' } ) ;
18+ browser . storage . local . set ( { language : 'python' } ) ;
19+ browser . storage . local . set ( { fontSize : 14 } ) ;
20+ browser . storage . local . set ( { showCompanyTags : true } ) ;
21+ browser . storage . local . set ( { showExamples : true } ) ;
22+ browser . storage . local . set ( { showDifficulty : true } ) ;
23+ browser . storage . local . set ( { clickedCompany : 'Amazon' } ) ;
2324} ) ;
2425
25- chrome . runtime . onMessage . addListener (
26+ browser . runtime . onMessage . addListener (
2627 function ( request , _ , sendResponse ) {
2728 if ( request . action == 'openSolutionVideo' ) {
28- chrome . tabs . query ( { active : true , currentWindow : true } , ( tabs ) => {
29+ browser . tabs . query ( { active : true , currentWindow : true } , ( tabs ) => {
2930 let url = tabs [ 0 ] . url ;
3031 if ( url ) {
3132 // Remove /description/ if it exists
@@ -39,7 +40,7 @@ chrome.runtime.onMessage.addListener(
3940 if ( tabs . length > 0 && tabs [ 0 ] . id ) {
4041 const tabId = tabs [ 0 ] . id ;
4142 const updateProperties = { url : newUrl } ;
42- chrome . tabs . update ( tabId , updateProperties ) ;
43+ browser . tabs . update ( tabId , updateProperties ) ;
4344 }
4445 }
4546 } ) ;
@@ -48,35 +49,35 @@ chrome.runtime.onMessage.addListener(
4849 } ,
4950) ;
5051
51- chrome . runtime . onMessage . addListener ( ( request ) => {
52+ browser . runtime . onMessage . addListener ( ( request ) => {
5253 if ( request . action === 'openCompanyPage' ) {
53- chrome . storage . local . set ( { clickedCompany : request . company } ) ;
54- chrome . tabs . create ( {
55- url : chrome . runtime . getURL ( 'src/problems-by-company/company.html' ) ,
54+ browser . storage . local . set ( { clickedCompany : request . company } ) ;
55+ browser . tabs . create ( {
56+ url : browser . runtime . getURL ( 'src/problems-by-company/company.html' ) ,
5657 active : true ,
5758 } , function ( tab ) {
5859 // Keep a reference to the listener so it can be removed later
5960 const listener = function ( tabId : number , changedProps : any ) {
6061 // When the tab is done loading
6162 if ( tabId == tab . id && changedProps . status == 'complete' ) {
62- chrome . tabs . sendMessage ( tabId , request ) ;
63+ browser . tabs . sendMessage ( tabId , request ) ;
6364 // Remove the listener once the tab is loaded
64- chrome . tabs . onUpdated . removeListener ( listener ) ;
65+ browser . tabs . onUpdated . removeListener ( listener ) ;
6566 }
6667 } ;
6768 // Attach the listener
68- chrome . tabs . onUpdated . addListener ( listener ) ;
69+ browser . tabs . onUpdated . addListener ( listener ) ;
6970 } ) ;
7071 }
7172} ) ;
7273
73- chrome . runtime . onMessage . addListener ( ( request : any ) => {
74+ browser . runtime . onMessage . addListener ( ( request : any ) => {
7475 if ( request . type === 'OPEN_LOGIN_PAGE' ) {
75- chrome . tabs . create ( { url : 'https://chat.openai.com' } ) ;
76+ browser . tabs . create ( { url : 'https://chat.openai.com' } ) ;
7677 }
7778} ) ;
7879
79- chrome . runtime . onMessage . addListener ( ( request , sender , sendResponse ) => {
80+ browser . runtime . onMessage . addListener ( ( request , sender , sendResponse ) => {
8081 if ( request . type === 'GET_CHATGPT_ACCESS_TOKEN' ) {
8182 getChatGPTAccessToken ( ) . then ( ( accessToken ) => {
8283 sendResponse ( { accessToken : accessToken } ) ;
@@ -86,13 +87,13 @@ chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
8687} ) ;
8788
8889// If the user is on a Leetcode problem page, show the solution video or company tags.
89- chrome . tabs . onUpdated . addListener ( ( tabId , changeInfo , tab ) => {
90+ browser . tabs . onUpdated . addListener ( ( tabId , changeInfo , tab ) => {
9091 // If descriptions tab is opened or updated, update the description
9192 let urlPattern = / ^ h t t p s : \/ \/ l e e t c o d e \. c o m \/ p r o b l e m s \/ .* \/ ( d e s c r i p t i o n \/ ) ? / ;
9293 if ( changeInfo . status === 'complete' && tab . url && tab . url . match ( urlPattern ) ) {
9394 setTimeout ( ( ) => {
94- chrome . tabs . get ( tabId , ( updatedTab ) => {
95- chrome . tabs . sendMessage ( tabId , { action : 'updateDescription' , title : updatedTab . title || 'title' } ) ;
95+ browser . tabs . get ( tabId , ( updatedTab ) => {
96+ browser . tabs . sendMessage ( tabId , { action : 'updateDescription' , title : updatedTab . title || 'title' } ) ;
9697 } ) ;
9798 } , 1000 ) ;
9899 }
@@ -101,8 +102,8 @@ chrome.tabs.onUpdated.addListener((tabId, changeInfo, tab) => {
101102 urlPattern = / ^ h t t p s : \/ \/ l e e t c o d e \. c o m \/ p r o b l e m s \/ .* \/ s o l u t i o n s \/ ? / ;
102103 if ( changeInfo . status === 'complete' && tab . url && tab . url . match ( urlPattern ) ) {
103104 setTimeout ( ( ) => {
104- chrome . tabs . get ( tabId , ( updatedTab ) => {
105- chrome . tabs . sendMessage ( tabId , { action : 'addVideo' , title : updatedTab . title || 'title' } ) ;
105+ browser . tabs . get ( tabId , ( updatedTab ) => {
106+ browser . tabs . sendMessage ( tabId , { action : 'addVideo' , title : updatedTab . title || 'title' } ) ;
106107 } ) ;
107108 } , 1000 ) ;
108109 }
@@ -111,7 +112,7 @@ chrome.tabs.onUpdated.addListener((tabId, changeInfo, tab) => {
111112 urlPattern = / ^ h t t p s : \/ \/ l e e t c o d e \. c o m \/ p r o b l e m s \/ .* \/ ? / ;
112113 if ( changeInfo . status === 'complete' && tab . url && tab . url . match ( urlPattern ) ) {
113114 setTimeout ( ( ) => {
114- chrome . storage . local . set ( { 'currentLeetCodeProblemTitle' : tab . title || 'title' } ) ;
115+ browser . storage . local . set ( { 'currentLeetCodeProblemTitle' : tab . title || 'title' } ) ;
115116 } , 1000 ) ;
116117 }
117118} ) ;
0 commit comments