@@ -17,7 +17,7 @@ const MAX_WORDS = 14000;
1717* The default model is 'sonar-medium-chat'.
1818* The default temperature is 1.
1919*/
20- function getConfiguration ( ) {
20+ async function getConfiguration ( ) {
2121 return browser . storage . local . get ( {
2222 apiKey : 'pplx-xxxxxxxxxxx' , // Default API key
2323 model : 'sonar-medium-chat' , // Default model
@@ -148,8 +148,6 @@ function fetchTabContent() {
148148 const clonedMainContent = mainContent . cloneNode ( true ) ;
149149 fragment . appendChild ( clonedMainContent ) ;
150150
151- console . log ( 'Cloned main content:' , clonedMainContent ) ;
152-
153151 // Remove known ad, header, lists, toc, footer, and navigation selectors from the cloned content
154152 const unwantedSelectors = [ '.ad' , 'footer' , '.footer' , '#footer' , '.ads' , '.advertisement' ,
155153 '.ad-container' , '.ad-wrapper' , '.ad-banner' , '.ad-wrapper' , 'figure' , 'figurecaption' ,
@@ -214,7 +212,6 @@ function triggerAPI() {
214212 const responseDiv = document . getElementById ( 'apiResponse' ) ;
215213 const spinner = document . getElementById ( 'spinner' ) ;
216214 const lang = document . documentElement . lang ;
217- const container = document . getElementById ( 'responseContainer' ) ;
218215
219216 getConfiguration ( ) . then ( config => {
220217 // Check if the API key is the default value
@@ -347,37 +344,7 @@ function cleanMarkdown(content) {
347344 return content . replace ( codeBlockRegex , '' ) ;
348345}
349346
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' ) ;
377347
378- loadInitialText ( ) ;
379-
380- } ) ;
381348
382349// Add event listeners for copy buttons
383350document . getElementById ( 'copyHtml' ) . addEventListener ( 'click' , copyHtml ) ;
@@ -410,15 +377,16 @@ function copyText() {
410377}
411378
412379// 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+ }
420387}
421388
389+
422390function loadInitialText ( ) {
423391 let initialText = browser . i18n . getMessage ( 'initialText' ) ;
424392
@@ -437,4 +405,38 @@ function loadInitialText() {
437405
438406}
439407
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.
440412document . 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