-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
64 lines (39 loc) · 1.91 KB
/
script.js
File metadata and controls
64 lines (39 loc) · 1.91 KB
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
const generated_link = document.getElementById('generated_link');
const fName = document.getElementById('fName');
const mName = document.getElementById('mName');
let f_link = "https://mayborg121.github.io/bw/" ;
let link_copy = document.getElementById('link_copy');
function gen_link(){
event.preventDefault();
const birthDate = document.getElementById('birthDate').value;
const bdate = new Date(birthDate);
// Extract day and month
const day = bdate.getDate();
const month = bdate.getMonth() + 1; // Month is 0-based, so add 1
// Format as "day.month"
const formattedDate = String(`${day}.${month}`);
console.log(day);
if(Number.isInteger(day)){
const gen_link = String("https://mayborg121.github.io/bw/?" +"n=" + fName.value.trim() + "&" +"m=" + mName.value.trim() + "&" +"d=" + formattedDate);
console.log(gen_link);
link_copy.innerHTML = ` <div id="link_container"> <p id="generated_link">${gen_link}</p> </div>
<button id="copyButton">Copy</button>
<button id="visit_link">Visit</button>`;
f_link = gen_link;
}
else{
link_copy.innerHTML = ` <div id="link_container"> <p id="generated_link"> "Please Select Date" </p> </div>
<button id="copyButton">Copy</button>
<button id="visit_link">Visit</button>`;
}
document.getElementById("copyButton").addEventListener("click", function () {
copyButton.innerText = "Copied !";
// Use Clipboard API to copy the text
navigator.clipboard.writeText(f_link);
});
document.getElementById("visit_link").addEventListener("click", function () {
const link = f_link; // Get the text
// Open the link in a new tab
window.open(link, "_blank");
});
}