-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbrejax.js
140 lines (122 loc) · 4.66 KB
/
brejax.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
document.addEventListener("DOMContentLoaded", function() {
const colorPicker = document.getElementById("colorPicker");
const colorCode = document.getElementById("colorCode");
const testView = document.getElementById("testView");
const colors = generateAllColors();
colors.forEach(color => {
const colorCircle = document.createElement("div");
colorCircle.classList.add("color");
colorCircle.style.backgroundColor = color;
colorCircle.addEventListener("click", function() {
const selectedColor = this.style.backgroundColor;
const discordColorCode = rgbToHex(selectedColor);
colorCode.innerHTML = `
<span class="text-left">Here is the color code:</span>
<span class="code-block">${discordColorCode}</span>`;
createTestView(discordColorCode);
});
colorPicker.appendChild(colorCircle);
});
colorPicker.classList.remove("hidden");
colorCode.classList.remove("hidden");
testView.classList.remove("hidden");
});
function createTestView(color) {
const testView = document.getElementById("testView");
const embedTitle = "Live Test View";
const embedDescription = "Here is your current color in the embed!";
const embed = document.createElement("div");
embed.classList.add("discord-embed");
const leftStrip = document.createElement("div");
leftStrip.classList.add("discord-embed-left-strip");
leftStrip.style.backgroundColor = color;
embed.appendChild(leftStrip);
const rightContent = document.createElement("div");
rightContent.classList.add("discord-embed-right-content");
const title = document.createElement("div");
title.classList.add("discord-embed-title");
title.textContent = embedTitle;
rightContent.appendChild(title);
const description = document.createElement("div");
description.classList.add("discord-embed-description");
description.textContent = embedDescription;
rightContent.appendChild(description);
embed.appendChild(rightContent);
testView.innerHTML = '';
testView.appendChild(embed);
}
function generateAllColors() {
const colors = [];
for (let r = 0; r <= 255; r += 51) {
for (let g = 0; g <= 255; g += 51) {
for (let b = 0; b <= 255; b += 51) {
colors.push(`rgb(${r}, ${g}, ${b})`);
}
}
}
return colors;
}
function rgbToHex(rgb) {
// Convert RGB string (e.g., "rgb(255, 0, 0)") to HEX string (e.g., "#ff0000") ...
const values = rgb.match(/\d+/g);
const r = parseInt(values[0]);
const g = parseInt(values[1]);
const b = parseInt(values[2]);
const hex = "#" + ((1 << 24) + (r << 16) + (g << 8) + b).toString(16).slice(1);
return hex.toLowerCase();
}
// NEW: Added Discord Webhook for a Direct Test.
const discordForm = document.getElementById("discordForm");
discordForm.addEventListener("submit", function(event) {
event.preventDefault();
const webhookURL = document.getElementById("webhookURL").value;
const embedTitle = document.getElementById("embedTitle").value;
const embedDescription = document.getElementById("embedDescription").value;
const embedColor = document.getElementById("embedColor").value;
const embed = {
title: embedTitle,
description: embedDescription,
color: parseInt(embedColor.replace("#", ""), 16)
};
sendEmbedToDiscord(webhookURL, embed);
});
function sendEmbedToDiscord(webhookURL, embed) {
fetch(webhookURL, {
method: "POST",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify({
embeds: [embed]
})
})
.then(response => {
if (!response.ok) {
throw new Error("Network response was not ok");
}
return response.json();
})
.then(data => {
console.log("Success:", data);
})
.catch(error => {
console.error("Error:", error);
});
}
function saveDataToSessionStorage(webhookURL, embed) {
const savedData = {
webhookURL: webhookURL,
embed: embed
};
sessionStorage.setItem("discordData", JSON.stringify(savedData));
}
function loadStoredData() {
const savedDataString = sessionStorage.getItem("discordData");
if (savedDataString) {
const savedData = JSON.parse(savedDataString);
document.getElementById("webhookURL").value = savedData.webhookURL;
document.getElementById("embedTitle").value = savedData.embed.title;
document.getElementById("embedDescription").value = savedData.embed.description;
document.getElementById("embedColor").value = savedData.embed.color;
}
}