-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
56 lines (39 loc) · 2.2 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
47
48
49
50
51
52
53
54
55
function convertToEnglish() {
let input = document.getElementById('input').value;
let output = document.getElementById("output");
let translatedString = input.replace(/\./g, "dot").replace(/\-/g, "dash");
translatedString = translatedString.replace(/dotdotdotdot/g, "h").replace(/dotdotdotdash/g, "v").replace(/dotdotdashdot/g, "f").replace(/dotdashdotdot/g, "l").replace(/dotdashdashdot/g, "p").replace(/dotdashdashdash/g, "j").replace(/dashdotdotdot/g, "b").replace(/dashdotdotdash/g, "x").replace(/dashdotdashdot/g, "c").replace(/dashdotdashdash/g, "y").replace(/dashdashdotdot/g, "z").replace(/dashdashdotdash/g, "q").replace(/dotdotdot/g, "s").replace(/dotdotdash/g, "u").replace(/dotdashdot/g, "r").replace(/dotdashdash/g, "w").replace(/dashdotdot/g, "d").replace(/dashdotdash/g, "k").replace(/dashdashdot/g, "g").replace(/dashdashdash/g, "o").replace(/dotdot/g, "i").replace(/dotdash/g, "a").replace(/dashdot/g, "n").replace(/dashdash/g, "m").replace(/dot/g, "e").replace(/dash/g, "t");
translatedString = translatedString.split(" ").join("/").split(" ").join("").split("/").join(" ");
output.innerHTML = translatedString;
}
const buttons = document.getElementsByTagName("button");
function createRipple(event) {
const button = event.currentTarget;
const circle = document.createElement("span");
const diameter = Math.max(button.clientWidth, button.clientHeight);
const radius = diameter / 2;
circle.style.width = circle.style.height = `${diameter}px`;
circle.style.left = `${event.clientX - button.offsetLeft - radius}px`;
circle.style.top = `${event.clientY - button.offsetTop - radius}px`;
circle.classList.add("ripple");
const ripple = button.getElementsByClassName("ripple")[0];
if (ripple) {
ripple.remove();
}
button.appendChild(circle);
}
for (const button of buttons) {
button.addEventListener("click", createRipple);
}
const shareButton = document.getElementById("share")
const shareData = {
url: "https://valiantwind.github.io/mct",
text: "Check out this Morse Code to English Translator I used",
}
shareButton.addEventListener("click", function() {
if(navigator.canShare){
navigator.share(shareData)
} else {
window.alert("Your browser does not support sharing.")
}
})