-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
34 lines (32 loc) · 1019 Bytes
/
script.js
File metadata and controls
34 lines (32 loc) · 1019 Bytes
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
const firebaseConfig = {
apiKey: "YOUR_API_KEY",
authDomain: "YOUR_AUTH_DOMAIN",
projectId: "YOUR_PROJECT_ID",
storageBucket: "YOUR_STORAGE_BUCKET",
messagingSenderId: "YOUR_MESSAGING_SENDER_ID",
appId: "YOUR_APP_ID"
};
firebase.initializeApp(firebaseConfig);
const database = firebase.database();
const copyBtn = document.getElementById("copy-btn");
const status = document.getElementById("status");
const keyEl = document.getElementById("key");
copyBtn.addEventListener("click", function() {
const text = document.getElementById("text").value;
if (text !== "") {
const key = database.ref("clips").push().key;
const updates = {};
updates['/clips/' + key] = text;
database.ref().update(updates, function(error) {
if (error) {
status.innerHTML = "Failed to copy to clipboard";
status.style.color = "red";
} else {
keyEl.innerHTML = "Your key: " + key;
keyEl.style.color = "green";
status.innerHTML = "Copied to clipboard!";
status.style.color = "green";
}
});
}
});