-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathscript.js
46 lines (39 loc) · 1.3 KB
/
script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
function formatDate(date) {
const d = new Date(date);
const year = d.getFullYear();
let month = '' + (d.getMonth() + 1);
let day = '' + d.getDate();
if (month.length < 2)
month = '0' + month;
if (day.length < 2)
day = '0' + day;
return [year, month, day].join('-');
}
function copyCommit() {
const commitText = document.getElementById('api-response').innerText;
navigator.clipboard.writeText(commitText).then(function() {
alert('Commit copied to clipboard!');
}, function(err) {
console.error('Failed to copy: ', err);
});
}
function fetchCommit() {
const proxyUrl = 'https://corsproxy.io/?'; // CORS proxy
const targetUrl = 'https://whatthecommit.com/index.txt';
const apiUrl = proxyUrl + targetUrl;
fetch(apiUrl)
.then(response => response.text())
.then(data => {
const trimmedData = data.trim(); // Remove leading and trailing whitespace
document.getElementById('api-response').innerText = trimmedData;
document.getElementById('commit-text').style.display = 'inline'; // Display the sentence
})
.catch(error => {
console.error('Error fetching commit: ', error);
});
}
window.onload = function() {
const currentDate = formatDate(new Date());
document.getElementById('current-date').innerText = currentDate;
fetchCommit();
};