@@ -9,37 +9,103 @@ document.addEventListener('DOMContentLoaded', function() {
9
9
window . generateScrumReport ( ) ;
10
10
} ) ;
11
11
12
- copyBtn . addEventListener ( 'click' , function ( ) {
12
+ // copyBtn.addEventListener('click', function() {
13
+ // const scrumReport = document.getElementById('scrumReport');
14
+ // const tempDiv = document.createElement('div');
15
+ // tempDiv.innerHTML = scrumReport.innerHTML;
16
+ // const links = tempDiv.getElementsByTagName('a');
17
+ // Array.from(links).forEach(link => {
18
+ // const title = link.textContent;
19
+ // const url = link.href;
20
+ // const markdownLink = `[${title}](${url})`;
21
+ // link.outerHTML = markdownLink;
22
+ // });
23
+ // const stateButtons = tempDiv.getElementsByClassName('State');
24
+ // Array.from(stateButtons).forEach(button => {
25
+ // button.remove();
26
+ // });
27
+ // tempDiv.innerHTML = tempDiv.innerHTML.replace(/<br\s*\/?>/gi, '\n');
28
+ // const listItems = tempDiv.getElementsByTagName('li');
29
+ // Array.from(listItems).forEach(item => {
30
+ // item.innerHTML = '\n- '+ item.innerHTML;
31
+ // });
32
+ // tempDiv.innerHTML = tempDiv.innerHTML.replace(/<\/?ul>/gi, '\n');
33
+ // let textContent = tempDiv.textContent;
34
+ // textContent = textContent.replace(/\n\s*\n/g, '\n\n');
35
+ // textContent = textContent.trim();
36
+ // const textArea = document.createElement('textarea');
37
+ // textArea.value = textContent;
38
+ // document.body.appendChild(textArea);
39
+ // textArea.select();
40
+ // document.execCommand('copy');
41
+ // document.body.removeChild(textArea);
42
+
43
+ // const originalText = this.innerHTML;
44
+ // this.innerHTML = '<i class="fa fa-check"></i> Copied!';
45
+ // this.classList.add('bg-green-600');
46
+
47
+ // setTimeout(() => {
48
+ // this.innerHTML = originalText;
49
+ // this.classList.remove('bg-green-600');
50
+ // }, 2000);
51
+ // });
52
+
53
+ copyBtn . addEventListener ( 'click' , function ( ) {
13
54
const scrumReport = document . getElementById ( 'scrumReport' ) ;
14
55
const tempDiv = document . createElement ( 'div' ) ;
15
56
tempDiv . innerHTML = scrumReport . innerHTML ;
16
- const links = tempDiv . getElementsByTagName ( 'a' ) ;
17
- Array . from ( links ) . forEach ( link => {
18
- const title = link . textContent ;
19
- const url = link . href ;
20
- const markdownLink = `[${ title } ](${ url } )` ;
21
- link . outerHTML = markdownLink ;
22
- } ) ;
57
+
58
+ // Remove all .State buttons
23
59
const stateButtons = tempDiv . getElementsByClassName ( 'State' ) ;
24
- Array . from ( stateButtons ) . forEach ( button => {
25
- button . remove ( ) ;
26
- } ) ;
27
- tempDiv . innerHTML = tempDiv . innerHTML . replace ( / < b r \s * \/ ? > / gi, '\n' ) ;
60
+ Array . from ( stateButtons ) . forEach ( button => button . remove ( ) ) ;
61
+
62
+ // Format list items while preserving links and formatting
28
63
const listItems = tempDiv . getElementsByTagName ( 'li' ) ;
29
64
Array . from ( listItems ) . forEach ( item => {
30
- item . innerHTML = '\n- ' + item . innerHTML ;
65
+ item . style . backgroundColor = 'transparent' ;
66
+ item . style . listStyleType = 'disc' ;
67
+ el . style . fontSize = '14px' ;
68
+
31
69
} ) ;
32
- tempDiv . innerHTML = tempDiv . innerHTML . replace ( / < \/ ? u l > / gi, '\n' ) ;
33
- let textContent = tempDiv . textContent ;
34
- textContent = textContent . replace ( / \n \s * \n / g, '\n\n' ) ;
35
- textContent = textContent . trim ( ) ;
36
- const textArea = document . createElement ( 'textarea' ) ;
37
- textArea . value = textContent ;
38
- document . body . appendChild ( textArea ) ;
39
- textArea . select ( ) ;
40
- document . execCommand ( 'copy' ) ;
41
- document . body . removeChild ( textArea ) ;
42
-
70
+
71
+ // Remove background from any elements that might have it
72
+ const allElements = tempDiv . getElementsByTagName ( '*' ) ;
73
+ Array . from ( allElements ) . forEach ( el => {
74
+ el . style . backgroundColor = 'transparent' ;
75
+ // Preserve other styling like colors and fonts
76
+ if ( el . classList . contains ( 'bg-green-600' ) || el . classList . contains ( 'bg-purple-600' ) ) {
77
+ el . style . color = el . classList . contains ( 'bg-green-600' ) ? '#2cbe4e' : '#6f42c1' ;
78
+ }
79
+ } ) ;
80
+
81
+ // Append tempDiv to DOM for copying
82
+ tempDiv . style . position = 'fixed' ;
83
+ tempDiv . style . left = '-9999px' ;
84
+ tempDiv . style . color = 'inherit' ;
85
+ tempDiv . style . font = 'inherit' ;
86
+ tempDiv . style . fontSize = '14px' ;
87
+ tempDiv . style . lineHeight = '1.5' ;
88
+ document . body . appendChild ( tempDiv ) ;
89
+
90
+ // Create a selection and copy with rich text
91
+ const range = document . createRange ( ) ;
92
+ range . selectNodeContents ( tempDiv ) ;
93
+ const selection = window . getSelection ( ) ;
94
+ selection . removeAllRanges ( ) ;
95
+ selection . addRange ( range ) ;
96
+
97
+ try {
98
+ const success = document . execCommand ( 'copy' ) ;
99
+ if ( ! success ) throw new Error ( 'Copy failed' ) ;
100
+ } catch ( err ) {
101
+ console . error ( 'Copy failed:' , err ) ;
102
+ }
103
+
104
+ // Cleanup
105
+ selection . removeAllRanges ( ) ;
106
+ document . body . removeChild ( tempDiv ) ;
107
+
108
+ // Feedback UI
43
109
const originalText = this . innerHTML ;
44
110
this . innerHTML = '<i class="fa fa-check"></i> Copied!' ;
45
111
this . classList . add ( 'bg-green-600' ) ;
@@ -63,7 +129,7 @@ function toggleRadio(radio){
63
129
startingDate : startDateInput . value ,
64
130
endingDate : endDateInput . value ,
65
131
lastWeekContribution : true ,
66
- yesterday : false
132
+ yesterdayContribution : false
67
133
} , ( ) => {
68
134
window . generateScrumReport ( ) ;
69
135
} ) ;
@@ -74,7 +140,7 @@ function toggleRadio(radio){
74
140
startingDate : startDateInput . value ,
75
141
endingDate : endDateInput . value ,
76
142
lastWeekContribution : false ,
77
- yesterday : true
143
+ yesterdayContribution : true
78
144
} , ( ) => {
79
145
window . generateScrumReport ( ) ;
80
146
} ) ;
@@ -88,15 +154,17 @@ document.getElementById('customDateContainer').addEventListener('click', () => {
88
154
document . getElementById ( 'endingDate' ) . disabled = false ;
89
155
chrome . storage . local . set ( {
90
156
lastWeekContribution : false ,
91
- yesterday : false
157
+ yesterdayContribution : false
92
158
} ) ;
93
159
} ) ;
94
160
161
+
162
+ // Date change
95
163
document . getElementById ( 'startingDate' ) . addEventListener ( 'change' , function ( ) {
96
164
chrome . storage . local . set ( {
97
165
startingDate : this . value ,
98
166
lastWeekContribution : false ,
99
- yesterday : false
167
+ yesterdayContribution : false
100
168
} , ( ) => {
101
169
if ( document . getElementById ( 'endingDate' ) . value ) {
102
170
window . generateScrumReport ( ) ;
@@ -108,14 +176,16 @@ document.getElementById('endingDate').addEventListener('change', function() {
108
176
chrome . storage . local . set ( {
109
177
endingDate : this . value ,
110
178
lastWeekContribution : false ,
111
- yesterday : false
179
+ yesterdayContribution : false
112
180
} , ( ) => {
113
181
if ( document . getElementById ( 'startingDate' ) . value ) {
114
182
window . generateScrumReport ( ) ;
115
183
}
116
184
} ) ;
117
185
} ) ;
118
186
187
+
188
+ // Dark mode
119
189
document . addEventListener ( 'DOMContentLoaded' , function ( ) {
120
190
const darkModeToggle = document . querySelector ( 'img[alt="Night Mode"]' ) ;
121
191
const body = document . body ;
0 commit comments