forked from amittri1025/Whatsapp-Link-Gen
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
150 lines (115 loc) · 4 KB
/
app.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
const btn = document.getElementById("mybtn");
const rockBtn = document.getElementById("rockBtn");
const mob = document.getElementById("MobileNum");
const inputText = document.getElementById("textforWa");
const genLink = document.getElementById("genLink");
const btnCopy = document.getElementById("btn-copy");
const whatsBtn = document.getElementById("btn-WhatsLink");
const linkContainer = document.getElementById("linkContainer");
const errMsg = document.querySelector(".err-msg");
const countryCode = document.querySelector("select");
// dark mode
const toggleButton = document.getElementById("toggleMode");
const body = document.body;
let colorMode = localStorage.getItem("color-mode") || "light";
toggleButton.innerHTML =
colorMode === "dark"
? '<i class="fa-regular fa-sun"></i>'
: '<i class="fa-solid fa-moon"></i>';
body.classList.toggle("dark-mode", colorMode == "dark");
function toggleColorMode() {
colorMode = colorMode === "light" ? "dark" : "light";
toggleButton.innerHTML =
colorMode === "dark"
? '<i class="fa-regular fa-sun"></i>'
: '<i class="fa-solid fa-moon"></i>';
body.classList.toggle("dark-mode", colorMode == "dark");
localStorage.setItem("color-mode", colorMode);
}
toggleButton.addEventListener("click", toggleColorMode);
// Magic (text on phone)
let numPhone = document.getElementById("magic-num");
let textPhone = document.getElementById("magic-text");
inputText.addEventListener("keyup", (e) => {
textPhone.innerText = e.target.value;
});
mob.addEventListener("keyup", (e) => {
numPhone.innerText = e.target.value;
});
const textStr = inputText.value;
// Rock Btn smooth scroll
rockBtn.addEventListener("click", () => {
window.scrollTo(0, 400);
});
const select = document.getElementById("select");
function adjustWidth() {
const selectedOption = select.options[select.selectedIndex];
select.style.width = `${selectedOption.text.length + 3}ch`;
}
adjustWidth();
select.addEventListener("change", adjustWidth);
let arrayOfStrings = inputText.value.split(" ");
let linkText = arrayOfStrings.join("%20");
let linkform = `I dont care`;
mob.addEventListener("input", (e) => {
mob.classList.remove("input-error");
errMsg.style.display = "none";
const value = e.target.value;
if (e.inputType === "deleteContentBackward") return;
// can input only digits
if (parseInt(e.data) !== 0 && !parseInt(e.data)) {
console.log(e.data);
mob.value = value.substring(0, value.length - 1);
}
});
btn.addEventListener("click", (e) => {
e.preventDefault();
// if mobilenum is empty then don't submit
if (!mob.value) {
mob.classList.add("input-error");
errMsg.style.display = "block";
return;
}
arrayOfStrings = inputText.value.split(" ");
linkText = arrayOfStrings.join("%20");
linkform = `https://api.whatsapp.com/send?phone=${countryCode.value}${mob.value}&text=${linkText}&lang=en`;
const whatsShareLink = `api.whatsapp.com/send?phone=91${mob.value}&text=${linkText}&lang=en`;
console.log(inputText.value);
genLink.innerText = linkform;
whatsBtn.setAttribute("href", `http://${whatsShareLink}/`);
whatsBtn.classList.remove("wbtn");
window.scrollTo(0, 700);
});
// Whatsapp share btn
// Create anchor element.
// var wsharebtn = document.createElement('a');
// var textnode = document.createTextNode("Share on Whatsapp")
// wsharebtn.classList.add("btn")
// wsharebtn.classList.add("btn-primary")
// //Open Whatsapp Link
// wsharebtn.href = whatsShareLink
// var whatsSym = document.createElement('i');
// whatsSym.classList.add("bi")
// whatsSym.classList.add("bi-whatsapp")
// wsharebtn.appendChild(whatsSym)
// wsharebtn.appendChild(textnode);
// linkContainer.appendChild(wsharebtn)
// Copy Text
new ClipboardJS("#btn-copy");
btnCopy.addEventListener("click", (e) => {
e.preventDefault();
btnCopy.innerText = "Copied";
setTimeout(() => {
btnCopy.innerText = "Copy";
}, 2000);
});
new EmojiPicker({
trigger: [
{
selector: ".emoji-btn",
insertInto: [".one"],
},
],
closeButton: true,
//specialButtons: green
});