@@ -12,13 +12,54 @@ document.addEventListener('DOMContentLoaded', function() {
12
12
13
13
copyBtn . addEventListener ( 'click' , function ( ) {
14
14
const scrumReport = document . getElementById ( 'scrumReport' ) ;
15
- const range = document . createRange ( ) ;
16
- range . selectNodeContents ( scrumReport ) ;
17
- const selection = window . getSelection ( ) ;
18
- selection . removeAllRanges ( ) ;
19
- selection . addRange ( range ) ;
15
+
16
+ // Create a temporary div to manipulate the content
17
+ const tempDiv = document . createElement ( 'div' ) ;
18
+ tempDiv . innerHTML = scrumReport . innerHTML ;
19
+
20
+ // Convert all links to markdown format
21
+ const links = tempDiv . getElementsByTagName ( 'a' ) ;
22
+ Array . from ( links ) . forEach ( link => {
23
+ const title = link . textContent ;
24
+ const url = link . href ;
25
+ const markdownLink = `[${ title } ](${ url } )` ;
26
+ link . outerHTML = markdownLink ;
27
+ } ) ;
28
+
29
+ // Remove the state buttons (open/closed labels)
30
+ const stateButtons = tempDiv . getElementsByClassName ( 'State' ) ;
31
+ Array . from ( stateButtons ) . forEach ( button => {
32
+ button . remove ( ) ;
33
+ } ) ;
34
+
35
+ // Replace <br> with newlines
36
+ tempDiv . innerHTML = tempDiv . innerHTML . replace ( / < b r \s * \/ ? > / gi, '\n' ) ;
37
+
38
+ // Replace list items with proper formatting
39
+ const listItems = tempDiv . getElementsByTagName ( 'li' ) ;
40
+ Array . from ( listItems ) . forEach ( item => {
41
+ // Add a newline before each list item and indent with a dash
42
+ item . innerHTML = '\n- ' + item . innerHTML ;
43
+ } ) ;
44
+
45
+ // Replace <ul> and </ul> with newlines
46
+ tempDiv . innerHTML = tempDiv . innerHTML . replace ( / < \/ ? u l > / gi, '\n' ) ;
47
+
48
+ // Get the text content
49
+ let textContent = tempDiv . textContent ;
50
+
51
+ // Clean up multiple newlines and spaces
52
+ textContent = textContent . replace ( / \n \s * \n / g, '\n\n' ) ; // Replace multiple newlines with double newlines
53
+ textContent = textContent . trim ( ) ; // Remove leading/trailing whitespace
54
+
55
+ // Copy to clipboard
56
+ const textarea = document . createElement ( 'textarea' ) ;
57
+ textarea . value = textContent ;
58
+ document . body . appendChild ( textarea ) ;
59
+ textarea . select ( ) ;
20
60
document . execCommand ( 'copy' ) ;
21
- selection . removeAllRanges ( ) ;
61
+ document . body . removeChild ( textarea ) ;
62
+
22
63
Materialize . toast ( 'Report copied to clipboard!' , 3000 ) ;
23
64
} ) ;
24
65
} ) ;
0 commit comments