@@ -17,7 +17,7 @@ const MAX_WORDS = 14000;
17
17
* The default model is 'sonar-medium-chat'.
18
18
* The default temperature is 1.
19
19
*/
20
- function getConfiguration ( ) {
20
+ async function getConfiguration ( ) {
21
21
return browser . storage . local . get ( {
22
22
apiKey : 'pplx-xxxxxxxxxxx' , // Default API key
23
23
model : 'sonar-medium-chat' , // Default model
@@ -148,8 +148,6 @@ function fetchTabContent() {
148
148
const clonedMainContent = mainContent . cloneNode ( true ) ;
149
149
fragment . appendChild ( clonedMainContent ) ;
150
150
151
- console . log ( 'Cloned main content:' , clonedMainContent ) ;
152
-
153
151
// Remove known ad, header, lists, toc, footer, and navigation selectors from the cloned content
154
152
const unwantedSelectors = [ '.ad' , 'footer' , '.footer' , '#footer' , '.ads' , '.advertisement' ,
155
153
'.ad-container' , '.ad-wrapper' , '.ad-banner' , '.ad-wrapper' , 'figure' , 'figurecaption' ,
@@ -214,7 +212,6 @@ function triggerAPI() {
214
212
const responseDiv = document . getElementById ( 'apiResponse' ) ;
215
213
const spinner = document . getElementById ( 'spinner' ) ;
216
214
const lang = document . documentElement . lang ;
217
- const container = document . getElementById ( 'responseContainer' ) ;
218
215
219
216
getConfiguration ( ) . then ( config => {
220
217
// Check if the API key is the default value
@@ -347,37 +344,7 @@ function cleanMarkdown(content) {
347
344
return content . replace ( codeBlockRegex , '' ) ;
348
345
}
349
346
350
- // Add an event listener to the resume button to trigger the API call
351
- document . getElementById ( 'resume' ) . addEventListener ( 'click' , triggerAPI ) ;
352
-
353
- // Add an event listener to the popup's elements
354
- document . addEventListener ( "DOMContentLoaded" , function ( ) {
355
- // Set the focus on the resume button
356
- document . getElementById ( 'resume' ) . focus ( ) ;
357
-
358
- // Set the text of the buttons and the title of the popup
359
- document . querySelector ( '#popupTab .button-text' ) . textContent = browser . i18n . getMessage ( 'startHereLabel' ) ;
360
- document . querySelector ( '#optionsTab .button-text' ) . textContent = browser . i18n . getMessage ( 'settingsLabel' ) ;
361
- document . querySelector ( '#aboutTab .button-text' ) . textContent = browser . i18n . getMessage ( 'aboutLabel' ) ;
362
-
363
- document . querySelector ( '#copyMarkdown .button-text' ) . textContent = browser . i18n . getMessage ( 'copyMarkdownLabel' ) ;
364
- document . querySelector ( '#copyHtml .button-text' ) . textContent = browser . i18n . getMessage ( 'copyHtmlLabel' ) ;
365
- document . querySelector ( '#copyText .button-text' ) . textContent = browser . i18n . getMessage ( 'copyTextLabel' ) ;
366
- document . querySelector ( '#resume .button-text' ) . textContent = browser . i18n . getMessage ( 'summarizeLabel' ) ;
367
-
368
-
369
- const version = browser . runtime . getManifest ( ) . version ;
370
- document . getElementById ( 'version' ) . textContent = version ;
371
- document . getElementById ( 'versionLink' ) . href = `https://github.com/imigueldiaz/firefox-quick-abstract/releases/tag/v${ version } ` ;
372
- document . getElementById ( 'extensionName' ) . innerText = browser . i18n . getMessage ( 'extensionName' ) ;
373
- document . getElementById ( 'perplexityAttribution' ) . innerText = browser . i18n . getMessage ( 'perplexityAttributionLabel' ) ;
374
- document . getElementById ( 'perplexityTrademark' ) . innerText = browser . i18n . getMessage ( 'perplexityTrademarkLabel' ) ;
375
-
376
- document . title = browser . i18n . getMessage ( 'extensionName' ) ;
377
347
378
- loadInitialText ( ) ;
379
-
380
- } ) ;
381
348
382
349
// Add event listeners for copy buttons
383
350
document . getElementById ( 'copyHtml' ) . addEventListener ( 'click' , copyHtml ) ;
@@ -410,15 +377,16 @@ function copyText() {
410
377
}
411
378
412
379
// Function to copy text to clipboard
413
- function copyToClipboard ( text ) {
414
- const tempTextarea = document . createElement ( 'textarea' ) ;
415
- tempTextarea . value = text ;
416
- document . body . appendChild ( tempTextarea ) ;
417
- tempTextarea . select ( ) ;
418
- document . execCommand ( ' copy' ) ;
419
- document . body . removeChild ( tempTextarea ) ;
380
+ async function copyToClipboard ( text ) {
381
+ try {
382
+ await navigator . clipboard . writeText ( text ) ;
383
+ console . log ( 'Text copied to clipboard' ) ;
384
+ } catch ( err ) {
385
+ console . error ( 'Failed to copy text: ' , err ) ;
386
+ }
420
387
}
421
388
389
+
422
390
function loadInitialText ( ) {
423
391
let initialText = browser . i18n . getMessage ( 'initialText' ) ;
424
392
@@ -437,4 +405,38 @@ function loadInitialText() {
437
405
438
406
}
439
407
408
+ // Add an event listener to the resume button to trigger the API call.
409
+ document . getElementById ( 'resume' ) . addEventListener ( 'click' , triggerAPI ) ;
410
+
411
+ // Add event listeners to the tabs to load the initial text.
440
412
document . querySelector ( "#popupTab" ) . addEventListener ( "click" , loadInitialText ) ;
413
+
414
+ // Add an event listener to the popup's elements.
415
+ document . addEventListener ( "DOMContentLoaded" , function ( ) {
416
+ // Set the focus on the resume button
417
+ document . getElementById ( 'resume' ) . focus ( ) ;
418
+
419
+ // Set the text of the buttons and the title of the popup.
420
+ document . querySelector ( '#popupTab .button-text' ) . textContent = browser . i18n . getMessage ( 'startHereLabel' ) ;
421
+ document . querySelector ( '#optionsTab .button-text' ) . textContent = browser . i18n . getMessage ( 'settingsLabel' ) ;
422
+ document . querySelector ( '#aboutTab .button-text' ) . textContent = browser . i18n . getMessage ( 'aboutLabel' ) ;
423
+
424
+ document . querySelector ( '#copyMarkdown .button-text' ) . textContent = browser . i18n . getMessage ( 'copyMarkdownLabel' ) ;
425
+ document . querySelector ( '#copyHtml .button-text' ) . textContent = browser . i18n . getMessage ( 'copyHtmlLabel' ) ;
426
+ document . querySelector ( '#copyText .button-text' ) . textContent = browser . i18n . getMessage ( 'copyTextLabel' ) ;
427
+ document . querySelector ( '#resume .button-text' ) . textContent = browser . i18n . getMessage ( 'summarizeLabel' ) ;
428
+
429
+ // Set the version number and link to the GitHub releases page
430
+ const version = browser . runtime . getManifest ( ) . version ;
431
+ document . getElementById ( 'version' ) . textContent = version ;
432
+ document . getElementById ( 'versionLink' ) . href = `https://github.com/imigueldiaz/firefox-quick-abstract/releases/tag/v${ version } ` ;
433
+ document . getElementById ( 'extensionName' ) . innerText = browser . i18n . getMessage ( 'extensionName' ) ;
434
+ document . getElementById ( 'perplexityAttribution' ) . innerText = browser . i18n . getMessage ( 'perplexityAttributionLabel' ) ;
435
+ document . getElementById ( 'perplexityTrademark' ) . innerText = browser . i18n . getMessage ( 'perplexityTrademarkLabel' ) ;
436
+
437
+ document . title = browser . i18n . getMessage ( 'extensionName' ) ;
438
+
439
+ loadInitialText ( ) ;
440
+
441
+ } ) ;
442
+
0 commit comments