@@ -11,11 +11,14 @@ chrome.runtime.onInstalled.addListener(() => {
1111 . catch ( ( error ) => {
1212 console . error ( error ) ;
1313 } ) ;
14+
15+ // Default settings
1416 chrome . storage . local . set ( { language : 'python' } ) ;
1517 chrome . storage . local . set ( { fontSize : 14 } ) ;
1618 chrome . storage . local . set ( { showCompanyTags : true } ) ;
1719 chrome . storage . local . set ( { showExamples : true } ) ;
1820 chrome . storage . local . set ( { showDifficulty : true } ) ;
21+ chrome . storage . local . set ( { clickedCompany : 'Amazon' } )
1922} ) ;
2023
2124chrome . runtime . onMessage . addListener (
@@ -44,6 +47,28 @@ chrome.runtime.onMessage.addListener(
4447 }
4548) ;
4649
50+ chrome . runtime . onMessage . addListener ( ( request , sender , sendResponse ) => {
51+ if ( request . action === "openCompanyPage" ) {
52+ chrome . storage . local . set ( { clickedCompany : request . company } ) ;
53+ chrome . tabs . create ( {
54+ url : chrome . runtime . getURL ( "src/popup/company.html" ) ,
55+ active : true
56+ } , function ( tab ) {
57+ // Keep a reference to the listener so it can be removed later
58+ let listener = function ( tabId , changedProps ) {
59+ // When the tab is done loading
60+ if ( tabId == tab . id && changedProps . status == "complete" ) {
61+ chrome . tabs . sendMessage ( tabId , request ) ;
62+ // Remove the listener once the tab is loaded
63+ chrome . tabs . onUpdated . removeListener ( listener ) ;
64+ }
65+ } ;
66+ // Attach the listener
67+ chrome . tabs . onUpdated . addListener ( listener ) ;
68+ } ) ;
69+ }
70+ } ) ;
71+
4772chrome . runtime . onMessage . addListener ( ( request : any ) => {
4873 if ( request . type === 'OPEN_LOGIN_PAGE' ) {
4974 chrome . tabs . create ( { url : 'https://chat.openai.com' } ) ;
@@ -59,22 +84,7 @@ chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
5984 }
6085} ) ;
6186
62- chrome . runtime . onMessage . addListener ( ( request , sender , sendResponse ) => {
63- if ( request . action === "openCompanyPage" ) {
64- chrome . tabs . create ( {
65- url : chrome . runtime . getURL ( "src/popup/company.html" ) ,
66- active : true
67- } , function ( tab ) {
68- chrome . tabs . onUpdated . addListener ( function listener ( tabId , changedProps ) {
69- // When the tab is done loading
70- if ( tabId == tab . id && changedProps . status == "complete" ) {
71- chrome . tabs . sendMessage ( tabId , request ) ;
72- chrome . tabs . onUpdated . removeListener ( listener ) ;
73- }
74- } ) ;
75- } ) ;
76- }
77- } ) ;
87+
7888
7989
8090chrome . tabs . onUpdated . addListener ( ( tabId , changeInfo , tab ) => {
0 commit comments