11import { getChatGPTAccessToken } from './chatgpt/chatgpt.js' ;
2- var { browser } = require ( "webextension-polyfill-ts" ) ;
32
43// Load JSON & default settings on install
5- browser . runtime . onInstalled . addListener ( ( ) => {
4+ chrome . runtime . onInstalled . addListener ( ( ) => {
65 // Load JSON file into storage
7- const jsonUrl = browser . runtime . getURL ( 'src/assets/data/leetcode_solutions.json' ) ;
6+ const jsonUrl = chrome . runtime . getURL ( 'src/assets/data/leetcode_solutions.json' ) ;
87 fetch ( jsonUrl )
98 . then ( ( response ) => response . json ( ) )
109 . then ( ( data ) => {
11- browser . storage . local . set ( { leetcodeProblems : data } ) ;
10+ chrome . storage . local . set ( { leetcodeProblems : data } ) ;
1211 } )
1312 . catch ( ( error ) => {
1413 console . error ( error ) ;
1514 } ) ;
1615
1716 // Default settings
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' } ) ;
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' } ) ;
2423} ) ;
2524
26- browser . runtime . onMessage . addListener (
25+ chrome . runtime . onMessage . addListener (
2726 function ( request , _ , sendResponse ) {
2827 if ( request . action == 'openSolutionVideo' ) {
29- browser . tabs . query ( { active : true , currentWindow : true } , ( tabs ) => {
28+ chrome . tabs . query ( { active : true , currentWindow : true } , ( tabs ) => {
3029 let url = tabs [ 0 ] . url ;
3130 if ( url ) {
3231 // Remove /description/ if it exists
@@ -40,7 +39,7 @@ browser.runtime.onMessage.addListener(
4039 if ( tabs . length > 0 && tabs [ 0 ] . id ) {
4140 const tabId = tabs [ 0 ] . id ;
4241 const updateProperties = { url : newUrl } ;
43- browser . tabs . update ( tabId , updateProperties ) ;
42+ chrome . tabs . update ( tabId , updateProperties ) ;
4443 }
4544 }
4645 } ) ;
@@ -49,35 +48,35 @@ browser.runtime.onMessage.addListener(
4948 } ,
5049) ;
5150
52- browser . runtime . onMessage . addListener ( ( request ) => {
51+ chrome . runtime . onMessage . addListener ( ( request ) => {
5352 if ( request . action === 'openCompanyPage' ) {
54- browser . storage . local . set ( { clickedCompany : request . company } ) ;
55- browser . tabs . create ( {
56- url : browser . runtime . getURL ( 'src/problems-by-company/company.html' ) ,
53+ chrome . storage . local . set ( { clickedCompany : request . company } ) ;
54+ chrome . tabs . create ( {
55+ url : chrome . runtime . getURL ( 'src/problems-by-company/company.html' ) ,
5756 active : true ,
5857 } , function ( tab ) {
5958 // Keep a reference to the listener so it can be removed later
6059 const listener = function ( tabId : number , changedProps : any ) {
6160 // When the tab is done loading
6261 if ( tabId == tab . id && changedProps . status == 'complete' ) {
63- browser . tabs . sendMessage ( tabId , request ) ;
62+ chrome . tabs . sendMessage ( tabId , request ) ;
6463 // Remove the listener once the tab is loaded
65- browser . tabs . onUpdated . removeListener ( listener ) ;
64+ chrome . tabs . onUpdated . removeListener ( listener ) ;
6665 }
6766 } ;
6867 // Attach the listener
69- browser . tabs . onUpdated . addListener ( listener ) ;
68+ chrome . tabs . onUpdated . addListener ( listener ) ;
7069 } ) ;
7170 }
7271} ) ;
7372
74- browser . runtime . onMessage . addListener ( ( request : any ) => {
73+ chrome . runtime . onMessage . addListener ( ( request : any ) => {
7574 if ( request . type === 'OPEN_LOGIN_PAGE' ) {
76- browser . tabs . create ( { url : 'https://chat.openai.com' } ) ;
75+ chrome . tabs . create ( { url : 'https://chat.openai.com' } ) ;
7776 }
7877} ) ;
7978
80- browser . runtime . onMessage . addListener ( ( request , sender , sendResponse ) => {
79+ chrome . runtime . onMessage . addListener ( ( request , sender , sendResponse ) => {
8180 if ( request . type === 'GET_CHATGPT_ACCESS_TOKEN' ) {
8281 getChatGPTAccessToken ( ) . then ( ( accessToken ) => {
8382 sendResponse ( { accessToken : accessToken } ) ;
@@ -87,13 +86,13 @@ browser.runtime.onMessage.addListener((request, sender, sendResponse) => {
8786} ) ;
8887
8988// If the user is on a Leetcode problem page, show the solution video or company tags.
90- browser . tabs . onUpdated . addListener ( ( tabId , changeInfo , tab ) => {
89+ chrome . tabs . onUpdated . addListener ( ( tabId , changeInfo , tab ) => {
9190 // If descriptions tab is opened or updated, update the description
9291 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 \/ ) ? / ;
9392 if ( changeInfo . status === 'complete' && tab . url && tab . url . match ( urlPattern ) ) {
9493 setTimeout ( ( ) => {
95- browser . tabs . get ( tabId , ( updatedTab ) => {
96- browser . tabs . sendMessage ( tabId , { action : 'updateDescription' , title : updatedTab . title || 'title' } ) ;
94+ chrome . tabs . get ( tabId , ( updatedTab ) => {
95+ chrome . tabs . sendMessage ( tabId , { action : 'updateDescription' , title : updatedTab . title || 'title' } ) ;
9796 } ) ;
9897 } , 1000 ) ;
9998 }
@@ -102,8 +101,8 @@ browser.tabs.onUpdated.addListener((tabId, changeInfo, tab) => {
102101 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 \/ ? / ;
103102 if ( changeInfo . status === 'complete' && tab . url && tab . url . match ( urlPattern ) ) {
104103 setTimeout ( ( ) => {
105- browser . tabs . get ( tabId , ( updatedTab ) => {
106- browser . tabs . sendMessage ( tabId , { action : 'addVideo' , title : updatedTab . title || 'title' } ) ;
104+ chrome . tabs . get ( tabId , ( updatedTab ) => {
105+ chrome . tabs . sendMessage ( tabId , { action : 'addVideo' , title : updatedTab . title || 'title' } ) ;
107106 } ) ;
108107 } , 1000 ) ;
109108 }
@@ -112,7 +111,7 @@ browser.tabs.onUpdated.addListener((tabId, changeInfo, tab) => {
112111 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 \/ .* \/ ? / ;
113112 if ( changeInfo . status === 'complete' && tab . url && tab . url . match ( urlPattern ) ) {
114113 setTimeout ( ( ) => {
115- browser . storage . local . set ( { 'currentLeetCodeProblemTitle' : tab . title || 'title' } ) ;
114+ chrome . storage . local . set ( { 'currentLeetCodeProblemTitle' : tab . title || 'title' } ) ;
116115 } , 1000 ) ;
117116 }
118117} ) ;
0 commit comments