Skip to content

Commit 7e092b8

Browse files
committed
rich text copying instead of markdown, markdown code commented
Signed-off-by: Vedansh Saini <[email protected]>
1 parent 58ba1f1 commit 7e092b8

File tree

4 files changed

+150
-45
lines changed

4 files changed

+150
-45
lines changed

src/popup.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ <h4>Your Github Username</h4>
5959
<label for="lastWeekContribution">Last 7 days</label>
6060
</div>
6161
<div class="flex items-center gap-2">
62-
<input type="radio" id="yesterday" name="timeframe" class="form-radio" onclick="toggleRadio(this)">
63-
<label for="yesterday">Last 1 day</label>
62+
<input type="radio" id="yesterdayContribution" name="timeframe" class="form-radio" onclick="toggleRadio(this)">
63+
<label for="yesterdayContribution">Last 1 day</label>
6464
</div>
6565
</div>
6666

src/scripts/main.js

Lines changed: 40 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ let enableToggleElement = document.getElementById('enable');
33
let githubUsernameElement = document.getElementById('githubUsername');
44
let projectNameElement = document.getElementById('projectName');
55
let lastWeekContributionElement = document.getElementById('lastWeekContribution');
6+
let yesterdayContributionElement = document.getElementById('yesterdayContribution');
67
let startingDateElement = document.getElementById('startingDate');
78
let endingDateElement = document.getElementById('endingDate');
89
let showOpenLabelElement = document.getElementById('showOpenLabel');
910
let userReasonElement = document.getElementById('userReason');
10-
let gsoc = 0; //0 means gsoc. 1 means gsoc
1111
function handleBodyOnLoad() {
12-
// prefill name
12+
// prefill content
1313
chrome.storage.local.get(
1414
[
1515
'githubUsername',
@@ -21,7 +21,7 @@ function handleBodyOnLoad() {
2121
'showClosedLabel',
2222
'userReason',
2323
'lastWeekContribution',
24-
'gsoc',
24+
'yesterdayContribution',
2525
],
2626
(items) => {
2727
if (items.githubUsername) {
@@ -60,6 +60,13 @@ function handleBodyOnLoad() {
6060
lastWeekContributionElement.checked = true;
6161
handleLastWeekContributionChange();
6262
}
63+
if ( items.yesterdayContribution ){
64+
yesterdayContributionElement.checked = items.yesterdayContribution;
65+
handleYesterdayContributionChange();
66+
} else if (items.yesterdayContribution !== false ) {
67+
yesterdayContributionElement.checked = true;
68+
handleYesterdayContributionChange();
69+
}
6370
},
6471
);
6572
}
@@ -75,6 +82,21 @@ function handleEndingDateChange() {
7582
let value = endingDateElement.value;
7683
chrome.storage.local.set({ endingDate: value });
7784
}
85+
function handleYesterdayContributionChange() {
86+
let value = yesterdayContributionElement.checked;
87+
if (value) {
88+
startingDateElement.disabled = true;
89+
endingDateElement.disabled = true;
90+
startingDateElement.value = getYesterday();
91+
endingDateElement.value = getToday();
92+
handleEndingDateChange();
93+
handleStartingDateChange();
94+
} else {
95+
startingDateElement.disabled = false;
96+
endingDateElement.disabled = false;
97+
}
98+
chrome.storage.local.set({ yesterdayContribution: value });
99+
}
78100
function handleLastWeekContributionChange() {
79101
let value = lastWeekContributionElement.checked;
80102
if (value) {
@@ -90,10 +112,23 @@ function handleLastWeekContributionChange() {
90112
}
91113
chrome.storage.local.set({ lastWeekContribution: value });
92114
}
115+
function getYesterday() {
116+
let today = new Date();
117+
let yesterday = new Date(today.getFullYear(), today.getMonth(), today.getDate() - 1);
118+
let yesterdayMonth = yesterday.getMonth() + 1;
119+
let yesterdayDay = yesterday.getDate();
120+
let yesterdayYear = yesterday.getFullYear();
121+
let yesterdayDisplayPadded =
122+
('0000' + yesterdayYear.toString()).slice(-4) +
123+
'-' +
124+
('00' + yesterdayMonth.toString()).slice(-2) +
125+
'-' +
126+
('00' + yesterdayDay.toString()).slice(-2);
127+
return yesterdayDisplayPadded;
128+
}
93129
function getLastWeek() {
94130
let today = new Date();
95-
let noDays_to_goback = gsoc == 0 ? 7 : 1;
96-
let lastWeek = new Date(today.getFullYear(), today.getMonth(), today.getDate() - noDays_to_goback);
131+
let lastWeek = new Date(today.getFullYear(), today.getMonth(), today.getDate() - 7);
97132
let lastWeekMonth = lastWeek.getMonth() + 1;
98133
let lastWeekDay = lastWeek.getDate();
99134
let lastWeekYear = lastWeek.getFullYear();

src/scripts/popup.js

Lines changed: 99 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -9,37 +9,103 @@ document.addEventListener('DOMContentLoaded', function() {
99
window.generateScrumReport();
1010
});
1111

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 () {
1354
const scrumReport = document.getElementById('scrumReport');
1455
const tempDiv = document.createElement('div');
1556
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
2359
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');
60+
Array.from(stateButtons).forEach(button => button.remove());
61+
62+
// Format list items while preserving links and formatting
2863
const listItems = tempDiv.getElementsByTagName('li');
2964
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+
3169
});
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-
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
43109
const originalText = this.innerHTML;
44110
this.innerHTML = '<i class="fa fa-check"></i> Copied!';
45111
this.classList.add('bg-green-600');
@@ -63,7 +129,7 @@ function toggleRadio(radio){
63129
startingDate: startDateInput.value,
64130
endingDate: endDateInput.value,
65131
lastWeekContribution: true,
66-
yesterday: false
132+
yesterdayContribution: false
67133
}, () => {
68134
window.generateScrumReport();
69135
});
@@ -74,7 +140,7 @@ function toggleRadio(radio){
74140
startingDate: startDateInput.value,
75141
endingDate: endDateInput.value,
76142
lastWeekContribution: false,
77-
yesterday: true
143+
yesterdayContribution: true
78144
}, () => {
79145
window.generateScrumReport();
80146
});
@@ -88,15 +154,17 @@ document.getElementById('customDateContainer').addEventListener('click', () => {
88154
document.getElementById('endingDate').disabled = false;
89155
chrome.storage.local.set({
90156
lastWeekContribution: false,
91-
yesterday: false
157+
yesterdayContribution: false
92158
});
93159
});
94160

161+
162+
// Date change
95163
document.getElementById('startingDate').addEventListener('change', function() {
96164
chrome.storage.local.set({
97165
startingDate: this.value,
98166
lastWeekContribution: false,
99-
yesterday: false
167+
yesterdayContribution: false
100168
}, () => {
101169
if (document.getElementById('endingDate').value) {
102170
window.generateScrumReport();
@@ -108,14 +176,16 @@ document.getElementById('endingDate').addEventListener('change', function() {
108176
chrome.storage.local.set({
109177
endingDate: this.value,
110178
lastWeekContribution: false,
111-
yesterday: false
179+
yesterdayContribution: false
112180
}, () => {
113181
if (document.getElementById('startingDate').value) {
114182
window.generateScrumReport();
115183
}
116184
});
117185
});
118186

187+
188+
// Dark mode
119189
document.addEventListener('DOMContentLoaded', function() {
120190
const darkModeToggle = document.querySelector('img[alt="Night Mode"]');
121191
const body = document.body;

src/scripts/scrumHelper.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ function allIncluded(outputTarget = 'email') {
1414
let reviewedPrsArray = [];
1515
let githubIssuesData = null;
1616
let lastWeekContribution = false;
17-
let yesterday = false;
17+
let yesterdayContribution = false;
1818
let githubPrsReviewData = null;
1919
let githubUserData = null;
2020
let githubPrsReviewDataProcessed = {};
@@ -44,25 +44,25 @@ function allIncluded(outputTarget = 'email') {
4444
'showOpenLabel',
4545
'showClosedLabel',
4646
'lastWeekContribution',
47-
'yesterday',
47+
'yesterdayContribution',
4848
'userReason',
4949
],
5050
(items) => {
5151
if (items.lastWeekContribution) {
5252
lastWeekContribution = true;
5353
handleLastWeekContributionChange();
5454
}
55-
if (items.yesterday) {
56-
yesterday = true;
57-
handleYesterdayChange();
55+
if (items.yesterdayContribution) {
56+
yesterdayContribution = true;
57+
handleYesterdayContributionChange();
5858
}
5959
if (!items.enableToggle) {
6060
enableToggle = items.enableToggle;
6161
}
62-
if (items.endingDate && !lastWeekContribution && !yesterday) {
62+
if (items.endingDate && !lastWeekContribution && !yesterdayContribution) {
6363
endingDate = items.endingDate;
6464
}
65-
if (items.startingDate && !lastWeekContribution && !yesterday) {
65+
if (items.startingDate && !lastWeekContribution && !yesterdayContribution) {
6666
startingDate = items.startingDate;
6767
}
6868
if (items.githubUsername) {
@@ -109,7 +109,7 @@ function allIncluded(outputTarget = 'email') {
109109
endingDate = getToday();
110110
startingDate = getLastWeek();
111111
}
112-
function handleYesterdayChange() {
112+
function handleYesterdayContributionChange() {
113113
endingDate = getToday();
114114
startingDate = getYesterday();
115115
}
@@ -243,7 +243,7 @@ function allIncluded(outputTarget = 'email') {
243243
let weekOrDay;
244244
let weekOrDay2;
245245
const lastWeekRadio = document.getElementById('lastWeekContribution');
246-
const yesterdayRadio = document.getElementById('yesterday');
246+
const yesterdayRadio = document.getElementById('yesterdayContribution');
247247

248248
if(lastWeekRadio && lastWeekRadio.checked) {
249249
weekOrDay = 'last week'

0 commit comments

Comments
 (0)