-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
190 lines (175 loc) · 6.52 KB
/
Copy pathscript.js
File metadata and controls
190 lines (175 loc) · 6.52 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
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
const tabs = document.querySelectorAll(".tab-button");
const panels = document.querySelectorAll(".tab-content");
tabs.forEach((tab) => {
tab.addEventListener("click", () => {
const target = tab.dataset.tab;
tabs.forEach((btn) => btn.classList.remove("active"));
panels.forEach((panel) => panel.classList.remove("active"));
tab.classList.add("active");
document.getElementById(target).classList.add("active");
});
});
const rarityList = document.getElementById("rarity-list");
const gamepassList = document.getElementById("gamepass-list");
function createRow(list, firstPlaceholder, secondPlaceholder, firstType = "text", secondType = "text") {
const row = document.createElement("div");
row.className = "row";
row.innerHTML = `
<input type="${firstType}" placeholder="${firstPlaceholder}" class="first" />
<input type="${secondType}" placeholder="${secondPlaceholder}" class="second" />
<button class="delete" type="button">X</button>
`;
row.querySelector(".delete").addEventListener("click", () => row.remove());
list.appendChild(row);
}
function toLuauKey(name) {
return name
.replace(/[^a-zA-Z0-9 ]/g, "")
.trim()
.split(/\s+/)
.map((word, index) => (index === 0 ? word : word.charAt(0).toUpperCase() + word.slice(1)))
.join("")
.replace(/^\d+/, "");
}
function showOutput(id, value) {
document.getElementById(id).value = value;
}
function showCopyState(targetId, text, isError = false) {
const state = document.getElementById(targetId);
state.textContent = text;
state.style.color = isError ? "#ff677d" : "#3bff95";
setTimeout(() => {
state.textContent = "";
}, 1500);
}
document.getElementById("add-rarity").addEventListener("click", () => {
createRow(rarityList, "Name", "Percentage", "text", "number");
});
document.getElementById("add-gamepass").addEventListener("click", () => {
createRow(gamepassList, "Gamepass Name", "ID", "text", "number");
});
document.getElementById("generate-rarity").addEventListener("click", () => {
const rows = [...rarityList.querySelectorAll(".row")];
const entries = [];
for (const row of rows) {
const name = row.querySelector(".first").value.trim();
const percentage = Number(row.querySelector(".second").value);
if (!name || Number.isNaN(percentage) || percentage < 0) {
showOutput("rarity-output", "Please fill all rarity fields with valid values.");
return;
}
entries.push(` ${name} = ${percentage}`);
}
if (!entries.length) {
showOutput("rarity-output", "Add at least one rarity.");
return;
}
const code = `local Rarities = {\n${entries.join(",\n")}\n}`;
showOutput("rarity-output", code);
});
document.getElementById("generate-gamepass").addEventListener("click", () => {
const rows = [...gamepassList.querySelectorAll(".row")];
const entries = [];
for (const row of rows) {
const name = row.querySelector(".first").value.trim();
const id = Number(row.querySelector(".second").value);
const key = toLuauKey(name);
if (!name || !key || Number.isNaN(id) || id <= 0) {
showOutput("gamepass-output", "Please fill all gamepass fields with valid values.");
return;
}
entries.push(` ${key} = ${id}`);
}
if (!entries.length) {
showOutput("gamepass-output", "Add at least one gamepass.");
return;
}
const code = `local Gamepasses = {\n${entries.join(",\n")}\n}`;
showOutput("gamepass-output", code);
});
document.getElementById("calculate-chance").addEventListener("click", () => {
const chanceValue = Number(document.getElementById("chance-input").value);
const attemptsValue = Number(document.getElementById("attempts-input").value);
if (Number.isNaN(chanceValue) || chanceValue < 0 || chanceValue > 100 || Number.isNaN(attemptsValue) || attemptsValue < 1) {
showOutput("chance-output", "Please provide a valid chance (0-100) and attempts (>=1).");
return;
}
const p = chanceValue / 100;
const result = (1 - (1 - p) ** attemptsValue) * 100;
showOutput("chance-output", `${result.toFixed(2)}% chance to get at least one item.`);
});
document.getElementById("convert-time").addEventListener("click", () => {
const raw = document.getElementById("time-input").value.trim().toLowerCase();
const match = raw.match(/^(\d+(?:\.\d+)?)(s|sec|secs|second|seconds|min|mins|minute|minutes|h|hr|hrs|hour|hours|d|day|days)$/);
if (!match) {
showOutput("time-output", "Use format like 30s, 5min, 1h, or 7d.");
return;
}
const value = Number(match[1]);
const unit = match[2];
const multipliers = {
s: 1,
sec: 1,
secs: 1,
second: 1,
seconds: 1,
min: 60,
mins: 60,
minute: 60,
minutes: 60,
h: 3600,
hr: 3600,
hrs: 3600,
hour: 3600,
hours: 3600,
d: 86400,
day: 86400,
days: 86400
};
const seconds = value * multipliers[unit];
showOutput("time-output", `${raw} = ${seconds} seconds`);
});
document.getElementById("generate-webhook").addEventListener("click", () => {
const game = document.getElementById("webhook-game").value.trim();
const title = document.getElementById("webhook-title").value.trim();
const description = document.getElementById("webhook-description").value.trim();
const hexColor = document.getElementById("webhook-color").value.trim();
if (!game || !title || !description || !/^#?[0-9a-fA-F]{6}$/.test(hexColor)) {
showOutput("webhook-output", "Fill all fields and use a valid 6-digit hex color.");
return;
}
const normalizedHex = hexColor.startsWith("#") ? hexColor.slice(1) : hexColor;
const colorDecimal = parseInt(normalizedHex, 16);
const payload = {
username: game,
embeds: [
{
title,
description,
color: colorDecimal
}
]
};
showOutput("webhook-output", JSON.stringify(payload, null, 2));
});
document.querySelectorAll(".copy").forEach((button) => {
button.addEventListener("click", async () => {
const targetId = button.dataset.copyTarget;
const value = document.getElementById(targetId).value;
const stateId = `${targetId.replace("-output", "")}-copy-state`;
if (!value.trim()) {
showCopyState(stateId, "Nothing to copy", true);
return;
}
try {
await navigator.clipboard.writeText(value);
showCopyState(stateId, "Copied!");
} catch {
showCopyState(stateId, "Copy failed", true);
}
});
});
createRow(rarityList, "Common", "70", "text", "number");
createRow(rarityList, "Rare", "20", "text", "number");
createRow(gamepassList, "VIP", "123456789", "text", "number");
createRow(gamepassList, "2x Money", "987654321", "text", "number");