@@ -12,41 +12,34 @@ document.addEventListener('DOMContentLoaded', function() {
12
12
copyBtn . addEventListener ( 'click' , function ( ) {
13
13
const scrumReport = document . getElementById ( 'scrumReport' ) ;
14
14
15
+ // Create container for HTML content
15
16
const tempDiv = document . createElement ( 'div' ) ;
16
17
tempDiv . innerHTML = scrumReport . innerHTML ;
17
-
18
- const links = tempDiv . getElementsByTagName ( 'a' ) ;
19
- Array . from ( links ) . forEach ( link => {
20
- const title = link . textContent ;
21
- const url = link . href ;
22
- const markdownLink = `[${ title } ](${ url } )` ;
23
- link . outerHTML = markdownLink ;
24
- } ) ;
25
-
26
- const stateButtons = tempDiv . getElementsByClassName ( 'State' ) ;
27
- Array . from ( stateButtons ) . forEach ( button => {
28
- button . remove ( ) ;
29
- } ) ;
30
-
31
- tempDiv . innerHTML = tempDiv . innerHTML . replace ( / < b r \s * \/ ? > / gi, '\n' ) ;
32
-
33
- const listItems = tempDiv . getElementsByTagName ( 'li' ) ;
34
- Array . from ( listItems ) . forEach ( item => {
35
- item . innerHTML = '\n- ' + item . innerHTML ;
36
- } ) ;
37
-
38
- tempDiv . innerHTML = tempDiv . innerHTML . replace ( / < \/ ? u l > / gi, '\n' ) ;
39
- let textContent = tempDiv . textContent ;
40
- textContent = textContent . replace ( / \n \s * \n / g, '\n\n' ) ;
41
- textContent = textContent . trim ( ) ;
42
-
43
- const textarea = document . createElement ( 'textarea' ) ;
44
- textarea . value = textContent ;
45
- document . body . appendChild ( textarea ) ;
46
- textarea . select ( ) ;
47
- document . execCommand ( 'copy' ) ;
48
- document . body . removeChild ( textarea ) ;
49
-
50
- Materialize . toast ( 'Report copied to clipboard!' , 3000 ) ;
18
+ document . body . appendChild ( tempDiv ) ;
19
+ tempDiv . style . position = 'absolute' ;
20
+ tempDiv . style . left = '-9999px' ;
21
+
22
+ // Select the content
23
+ const range = document . createRange ( ) ;
24
+ range . selectNode ( tempDiv ) ;
25
+ const selection = window . getSelection ( ) ;
26
+ selection . removeAllRanges ( ) ;
27
+ selection . addRange ( range ) ;
28
+
29
+ try {
30
+ // Copy HTML content
31
+ const success = document . execCommand ( 'copy' ) ;
32
+ if ( ! success ) {
33
+ throw new Error ( 'Copy command failed' ) ;
34
+ }
35
+ Materialize . toast ( 'Report copied with formatting!' , 3000 , 'green' ) ;
36
+ } catch ( err ) {
37
+ console . error ( 'Failed to copy:' , err ) ;
38
+ Materialize . toast ( 'Failed to copy report' , 3000 , 'red' ) ;
39
+ } finally {
40
+ // Cleanup
41
+ selection . removeAllRanges ( ) ;
42
+ document . body . removeChild ( tempDiv ) ;
43
+ }
51
44
} ) ;
52
45
} ) ;
0 commit comments