-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
215 lines (170 loc) · 6.36 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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
document.getElementById('result').style.display = "none"
document.getElementById('error').style.display = "none"
document.querySelector("#encryption").style.display = "none"
// Import the functions you need from the SDKs you need
// import { initializeApp } from "https://www.gstatic.com/firebasejs/10.0.0/firebase-app.js";
// import { doc, getDoc } from "firebase/firestore";
// console.log(docSnap)
// import { getAnalytics } from "https://www.gstatic.com/firebasejs/10.0.0/firebase-analytics.js";
// import firebase from "firebase/compat/app";
// Required for side-effects
// import "firebase/firestore";
// TODO: Add SDKs for Firebase products that you want to use
// https://firebase.google.com/docs/web/setup#available-libraries
const firebaseConfig = {
apiKey: "AIzaSyBAbCdC2RjOQVEx0qCCBgkzOfSneRk_mSw",
authDomain: "text-to-emojis.firebaseapp.com",
projectId: "text-to-emojis",
storageBucket: "text-to-emojis.appspot.com",
messagingSenderId: "1009053697122",
appId: "1:1009053697122:web:c90f7fb2737701bbf83d3b",
measurementId: "G-GRR3H3SBEM"
};
// Initialize Firebase
// const app = initializeApp(firebaseConfig);
firebase.initializeApp(firebaseConfig)
// const analytics = getAnalytics(app);
const db = firebase.firestore();
// const da = await db.collection('user').doc("2").get()
// user Exist or not
async function userExist(docID){
console.log("userExist chala")
const e1 = await db.collection('user').doc(""+docID).get();
if(e1.data()===undefined){
return false;
}
return true;
}
async function setData(obj, docID){
try {
db.collection('user').doc(""+docID).set(obj);
console.log("successfully added")
} catch (error) {
console.log(error)
}
}
async function getData(docID){
try{
const d1 = await db.collection('user').doc(""+docID).get()
// console.log(d1.data())
return d1;
}
catch(error){
console.log(error)
}
}
// script.js
let cnt = 1;
function btnClicking(){
document.getElementById("lockopen").classList.remove("text-white")
document.querySelector("#encryption").style.display = "none"
document.querySelector('#decryption').style.display = "block"
document.getElementById("dec-btn").classList.add("text-white")
document.getElementById("enc-btn").classList.remove("text-white")
document.getElementById("lockin").classList.add("text-white")
document.getElementById("arrow").innerHTML = "→";
document.getElementById('result').style.display = "none";
}
function dec(){
// encryptionW
document.getElementById("lockopen").classList.add("text-white")
document.getElementById('error').style.display = "none"
document.querySelector("#decryption").style.display = "none"
document.querySelector('#encryption').style.display = "block"
document.getElementById("enc-btn").classList.add("text-white")
document.getElementById("dec-btn").classList.remove("text-white")
document.getElementById("lockin").classList.remove("text-white")
document.getElementById("arrow").innerHTML = "←";
document.getElementById('result').style.display = "none"
}
function encryption(){
// get text msg
var v = document.getElementById('txtmsg').value;
// console.log(v)
var p = document.getElementById('pwd').value;
// console.log(p);
document.getElementById('error').classList.add("text-[red]");
document.getElementById('error').style.display = "block"
if(!v && !p){
document.getElementById('error').innerHTML = "Please enter text message and password";
}
else if(!v){
document.getElementById('error').innerHTML = "Please enter text message";
}
else if(!p){
document.getElementById('error').innerHTML = "Please set password";
}
else{
const str = v.split("");
var result =""
str.forEach(element => {
result+=`€${element.charCodeAt()} `
});
var found = true
for(let i=1; i<=cnt; i++){
if(!userExist(i)){
document.getElementById('error').style.display = "block";
document.getElementById('error').innerHTML = "Password already exist please change it...!";
found = false;
console.log(i)
break;
}
}
if(found){
const obj = {"pass":p,"input":v,"result":result}
setData(obj,cnt++);
document.getElementById('error').style.display = "none";
document.getElementById('result').style.display = "block"
document.getElementById('result').innerHTML =""+ result
document.getElementById('txtmsg').value = ""
document.getElementById('pwd').value = ""
}
}
}
async function decryption(){
document.getElementById('error').classList.add("text-[red]")
document.getElementById('error').style.display = "block"
var emoji = document.getElementById('emoji').value
var pwd = document.getElementById('pwd1').value
if(emoji && pwd){
var result1 = ""
var str = emoji.split(" ")
str.forEach(e=>{
result1+=`&#${e.codePointAt(0)} `
})
var found;
for(let i=1; i<=cnt; i++){
const d2 = await getData(i);
// console.log(d2.data())
try {
if(d2!=undefined && d2){
if(d2.data().result === result1 && d2.data().pass ===pwd){
found = i;
document.getElementById('result').style.display = "block"
document.getElementById('result').innerHTML =""+ d2.data().input
break;
}
}
} catch (error) {
console.log(error)
}
}
if(!found){
document.getElementById('result').style.display = "block"
document.getElementById('result').innerHTML ="Result : not found...!"
}else{
document.getElementById('emoji').value = ""
document.getElementById('pwd1').value = ""
}
}
else if(!pwd && !emoji){
document.getElementById('error').innerHTML = "Please enter encrypted emoji and password";
}
else if(emoji){
document.getElementById('error').innerHTML = "Please enter password";
}
else{
document.getElementById('error').innerHTML = "Please enter encrypted emoji";
}
}
// document.querySelector('#decryption').style.display = "block"