-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathscript.js
More file actions
106 lines (88 loc) · 3.44 KB
/
Copy pathscript.js
File metadata and controls
106 lines (88 loc) · 3.44 KB
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
// Function to calculate FLAMES result
let globalVariable = "";
function calculateFlames() {
const name1 = document.getElementById("name1").value.toLowerCase();
const name2 = document.getElementById("name2").value.toLowerCase();
// Check if either name is empty and add placeholder if necessary
if (name1 === "") {
document
.getElementById("name1")
.setAttribute("placeholder", "This field is required");
} else if (name2 === "") {
document
.getElementById("name2")
.setAttribute("placeholder", "This field is required");
} else {
// Create a string of all unique characters in the two names
let combinedNames = name1 + name2;
combinedNames = combinedNames.replace(/ /g, ""); // Remove spaces
combinedNames = Array.from(new Set(combinedNames)).join("");
// FLAMES calculation
let flames = "flames";
let index = 0;
while (flames.length > 1) {
index = (index + combinedNames.length - 1) % flames.length;
flames = flames.slice(0, index) + flames.slice(index + 1);
}
const resultDiv = document.getElementById("result");
resultDiv.textContent = getFlamesMeaning(flames);
globalVariable = getFlamesMeaningWA(flames);
const shareButton = document.getElementById("share-button");
shareButton.style.display = "block";
}
// Function to get the meaning of the FLAMES result
function getFlamesMeaning(flames) {
const meanings = {
f: "You have good Friendship",
l: "You guys are in Love",
a: "Nice Affection",
m: "Happy Married Life",
e: "You are Enemies",
s: "You both are Siblings",
};
return meanings[flames];
}
function getFlamesMeaningWA(flames) {
const meanings = {
f: "Friendship",
l: "Love",
a: "Affection",
m: "Married Life",
e: "Enemies",
s: "Siblings",
};
return meanings[flames];
}
}
document.addEventListener("DOMContentLoaded", function () {
// Get the button element
const buttonElement = document.getElementById("submit-button");
// Add keydown event listener to the document
document.addEventListener("keydown", function (event) {
// Check if the pressed key is "Enter"
if (event.keyCode === 13 || event.key === "Enter") {
// Prevent default behavior (like submitting a form)
event.preventDefault();
// Trigger the button click
buttonElement.click();
}
});
});
const shareButton = document.getElementById("share-button");
shareButton.style.display = "none";
function captureScreenshot() {
html2canvas(document.body).then(function (canvas) {
const resultDiv = document.getElementById("result");
const name2 = document.getElementById("name2").value;
const name1 = document.getElementById("name1").value;
const capitalized_name1 = name1.split(" ").map(word => word.charAt(0).toUpperCase() + word.slice(1)).join(" ");
const capitalized_name2 = name2.split(" ").map(word => word.charAt(0).toUpperCase() + word.slice(1)).join(" ");
let shareContent = `🎉 Hey! You won\'t believe it - ${capitalized_name1} and ${capitalized_name2} have got *"${globalVariable}"* on the FLAMES app by buildnship.\n\n Ready for a fun surprise? Try it yourself at flames.buildnship.in and see the magic! ✨🔥`;
shareTextViaWhatsApp(shareContent);
});
}
function shareTextViaWhatsApp(text) {
let whatsappURL =
"https://api.whatsapp.com/send?text=" + encodeURIComponent(text);
window.open(whatsappURL, "_blank");
}