22 * Device Flow authorization page script
33 */
44
5- import * as storage from ' ../lib/storage.js' ;
6- import github from ' ../lib/github-api.js' ;
7- import { initTheme } from ' ../lib/theme.js' ;
8- import { runtime } from ' ../lib/chrome-api.js' ;
9- import { ANIMATION_DURATION , MESSAGE_TYPES } from ' ../lib/constants.js' ;
10-
11- const deviceCodeEl = document . getElementById ( ' device-code' ) ;
12- const copyBtn = document . getElementById ( ' copy-btn' ) ;
13- const openGithubBtn = document . getElementById ( ' open-github-btn' ) ;
14- const statusEl = document . getElementById ( ' status' ) ;
15- const statusTextEl = document . getElementById ( ' status-text' ) ;
16- const countdownEl = document . getElementById ( ' countdown' ) ;
17-
18- let verificationUri = '' ;
5+ import * as storage from " ../lib/storage.js" ;
6+ import github from " ../lib/github-api.js" ;
7+ import { initTheme } from " ../lib/theme.js" ;
8+ import { runtime } from " ../lib/chrome-api.js" ;
9+ import { ANIMATION_DURATION , MESSAGE_TYPES } from " ../lib/constants.js" ;
10+
11+ const deviceCodeEl = document . getElementById ( " device-code" ) ;
12+ const copyBtn = document . getElementById ( " copy-btn" ) ;
13+ const openGithubBtn = document . getElementById ( " open-github-btn" ) ;
14+ const statusEl = document . getElementById ( " status" ) ;
15+ const statusTextEl = document . getElementById ( " status-text" ) ;
16+ const countdownEl = document . getElementById ( " countdown" ) ;
17+
18+ let verificationUri = "" ;
1919let countdownInterval = null ;
2020
2121// Initialize theme
@@ -39,21 +39,21 @@ async function startDeviceFlow() {
3939 navigator . clipboard
4040 . writeText ( data . user_code )
4141 . then ( ( ) => {
42- copyBtn . textContent = ' ✓ Copied!' ;
42+ copyBtn . textContent = " ✓ Copied!" ;
4343
4444 // Wait before opening GitHub (let user see the "Copied!" message)
4545 setTimeout ( ( ) => {
46- window . open ( verificationUri , ' _blank' ) ;
46+ window . open ( verificationUri , " _blank" ) ;
4747 } , ANIMATION_DURATION . GITHUB_OPEN_DELAY ) ;
4848
4949 setTimeout ( ( ) => {
50- copyBtn . textContent = ' Copy Code' ;
50+ copyBtn . textContent = " Copy Code" ;
5151 } , ANIMATION_DURATION . COPY_FEEDBACK ) ;
5252 } )
5353 . catch ( ( err ) => {
54- console . error ( ' Failed to auto-copy code:' , err ) ;
54+ console . error ( " Failed to auto-copy code:" , err ) ;
5555 // Still open GitHub even if copy fails
56- window . open ( verificationUri , ' _blank' ) ;
56+ window . open ( verificationUri , " _blank" ) ;
5757 } ) ;
5858
5959 // Start countdown
@@ -68,7 +68,7 @@ async function startDeviceFlow() {
6868 remaining -- ;
6969 const minutes = Math . floor ( remaining / 60 ) ;
7070 const seconds = remaining % 60 ;
71- countdownEl . textContent = `Expires in ${ minutes } :${ seconds . toString ( ) . padStart ( 2 , '0' ) } ` ;
71+ countdownEl . textContent = `Expires in ${ minutes } :${ seconds . toString ( ) . padStart ( 2 , "0" ) } ` ;
7272 } , ANIMATION_DURATION . COUNTDOWN_INTERVAL ) ;
7373 } ,
7474 onProgress : ( progress ) => {
@@ -90,61 +90,61 @@ async function startDeviceFlow() {
9090 try {
9191 const response = await runtime . sendMessage ( {
9292 action : MESSAGE_TYPES . LOGIN ,
93- authMethod : ' oauth' ,
93+ authMethod : " oauth" ,
9494 token,
9595 } ) ;
9696
9797 if ( ! response . success ) {
98- throw new Error ( response . error || ' Failed to notify background worker' ) ;
98+ throw new Error ( response . error || " Failed to notify background worker" ) ;
9999 }
100100 } catch ( error ) {
101- console . error ( ' Failed to notify background worker:' , error ) ;
101+ console . error ( " Failed to notify background worker:" , error ) ;
102102 // Fall back to storage-only approach
103103 await storage . setToken ( token ) ;
104104 await storage . setUsername ( username ) ;
105- await storage . setAuthMethod ( ' oauth' ) ;
105+ await storage . setAuthMethod ( " oauth" ) ;
106106 }
107107
108108 // Notify user
109- statusEl . className = ' status success' ;
109+ statusEl . className = " status success" ;
110110 statusTextEl . textContent = `✅ Successfully authorized as ${ username } !` ;
111- countdownEl . textContent = ' Closing in 2 seconds...' ;
111+ countdownEl . textContent = " Closing in 2 seconds..." ;
112112
113113 // Close window and redirect to popup
114114 setTimeout ( ( ) => {
115115 window . close ( ) ;
116116 // If window.close() doesn't work (some browsers block it), redirect
117117 if ( ! window . closed ) {
118- window . location . href = runtime . getURL ( ' src/popup/popup.html' ) ;
118+ window . location . href = runtime . getURL ( " src/popup/popup.html" ) ;
119119 }
120120 } , ANIMATION_DURATION . AUTO_CLOSE ) ;
121121 } catch ( error ) {
122122 if ( countdownInterval ) {
123123 clearInterval ( countdownInterval ) ;
124124 countdownInterval = null ;
125125 }
126- console . error ( ' Device Flow error:' , error ) ;
127- statusEl . className = ' status error' ;
126+ console . error ( " Device Flow error:" , error ) ;
127+ statusEl . className = " status error" ;
128128 statusTextEl . textContent = `❌ Error: ${ error . message } ` ;
129- countdownEl . textContent = '' ;
129+ countdownEl . textContent = "" ;
130130 }
131131}
132132
133133// Copy device code
134- copyBtn . addEventListener ( ' click' , async ( ) => {
134+ copyBtn . addEventListener ( " click" , async ( ) => {
135135 const code = deviceCodeEl . textContent ;
136136 try {
137137 await navigator . clipboard . writeText ( code ) ;
138- copyBtn . textContent = ' ✓ Copied!' ;
138+ copyBtn . textContent = " ✓ Copied!" ;
139139 setTimeout ( ( ) => {
140- copyBtn . textContent = ' Copy Code' ;
140+ copyBtn . textContent = " Copy Code" ;
141141 } , ANIMATION_DURATION . AUTO_CLOSE ) ;
142142 } catch ( err ) {
143- console . error ( ' Failed to copy:' , err ) ;
143+ console . error ( " Failed to copy:" , err ) ;
144144 }
145145} ) ;
146146
147147// Open GitHub
148- openGithubBtn . addEventListener ( ' click' , ( ) => {
149- window . open ( verificationUri , ' _blank' ) ;
148+ openGithubBtn . addEventListener ( " click" , ( ) => {
149+ window . open ( verificationUri , " _blank" ) ;
150150} ) ;
0 commit comments