11import { writeTextToClipboard } from './src/clipboard.js' ;
2- import { findTabs } from './src/chrome.js' ;
2+ import { getCurrentTab , getSelectedTabs , getAllTabsOnCurrentWindow } from './src/chrome.js' ;
33import { createLinkForTab , createLinksForTabs } from './src/link.js' ;
44
55let messageBox = document . getElementById ( 'message-box' ) ;
@@ -14,36 +14,30 @@ function appendMessage(messageText) {
1414}
1515
1616copyCurrentTabButton . addEventListener ( 'click' , ( ) => {
17- findTabs ( { active : true , currentWindow : true } )
18- . then ( ( [ tab ] ) => {
19- let linkText = createLinkForTab ( tab )
20-
21- writeTextToClipboard ( linkText ) . then ( ( ) => {
22- appendMessage ( 'Copied' )
23- } )
24- } )
17+ getCurrentTab ( )
18+ . then ( ( [ tab ] ) => ( createLinkForTab ( tab ) ) )
19+ . then ( writeTextToClipboard )
20+ . then ( ( ) => { appendMessage ( 'Copied' ) } )
2521 . catch ( ( err ) => console . error ( err ) )
2622} ) ;
2723
2824copySelectedTabsButton . addEventListener ( 'click' , ( ) => {
29- findTabs ( { highlighted : true , currentWindow : true } )
30- . then ( tabs => {
31- let linkText = createLinksForTabs ( tabs )
32-
33- writeTextToClipboard ( linkText ) . then ( ( ) => {
34- appendMessage ( 'Copied Selected Tabs!' )
35- } )
36- } )
25+ getSelectedTabs ( )
26+ . then ( createLinksForTabs )
27+ . then ( writeTextToClipboard )
28+ . then ( ( ) => { appendMessage ( 'Copied Selected Tabs!' ) } )
3729 . catch ( ( err ) => console . error ( err ) )
3830} )
31+ const countOfSelectedTabs = document . getElementById ( 'count-of-selected-tabs' )
32+ if ( countOfSelectedTabs ) {
33+ getSelectedTabs ( ) . then ( tabs => {
34+ countOfSelectedTabs . textContent = tabs . length
35+ } )
36+ }
3937
4038copyAllTabsButton . addEventListener ( 'click' , ( ) => {
41- findTabs ( { currentWindow : true } )
42- . then ( tabs => {
43- let linkText = createLinksForTabs ( tabs )
44-
45- writeTextToClipboard ( linkText ) . then ( ( ) => {
46- appendMessage ( 'Copied All Tabs!' )
47- } )
48- } )
39+ getAllTabsOnCurrentWindow ( )
40+ . then ( createLinksForTabs )
41+ . then ( writeTextToClipboard )
42+ . then ( ( ) => { appendMessage ( 'Copied All Tabs!' ) } )
4943} )
0 commit comments