forked from amittri1025/Whatsapp-Link-Gen
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
107 lines (77 loc) · 2.77 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
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')
// 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)
});
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)) {
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=91${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);
})