-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
77 lines (69 loc) · 2.56 KB
/
script.js
File metadata and controls
77 lines (69 loc) · 2.56 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
// Select Elements
let content = document.querySelector(".container");
let textArea = document.querySelector("#codeText");
let result = document.querySelector(".resultText");
let fontFamily = document.querySelector("select");
let textShadow = document.querySelector(".textShadowSetting")
// Select Inputs
let inp = document.querySelectorAll("input");
let color = document.querySelector(".colorText");
let bg = document.querySelector(".textBG");
let fontSize = document.querySelector(".FontSizeText");
let backgroundCheckbox = document.querySelector(".changeBG");
let border = document.querySelector(".borderCheck");
let colorBorder = document.querySelector(".colorBorder");
let borderSize = document.querySelector(".borderSize")
// Change text
for (let i = 0; i < inp.length; i++) {
inp[i].value = 0;
inp[i].addEventListener("input", function() {
cssText();
resultText();
});
}
// Function to update CSS text
function cssText() {
let cssCode = `color: ${color.value};`;
if (backgroundCheckbox.checked) {
cssCode += `background: ${bg.value};`;
} else {
cssCode += `background: none;`;
}
if (border.checked) {
cssCode += `border: solid ${colorBorder.value} ${borderSize.value}px;`;
} else {
cssCode += `border: none;`;
}
if (fontFamily.value == "RubikFont") {
cssCode += `font-family: "Rubik", sans-serif;`;
} else if (fontFamily.value == "ScriptFont") {
cssCode += `font-family: "Dancing Script, cursive;`;
} else if (fontFamily.value == "PlexMonoFont") {
cssCode += `font-family: "IBM Plex Mono, monospace;`;
}
cssCode += `font-size: ${fontSize.value / 1.25}px;`;
textArea.innerText = cssCode;
}
// Function to change the text of result
function resultText() {
result.style.color = color.value;
result.style.background = backgroundCheckbox.checked ? bg.value : "none";
result.style.fontSize = fontSize.value / 1.25 + "px";
result.style.border = border.checked ? `solid ${colorBorder.value} ${borderSize.value}px` : "none";
}
// Select font for text
fontFamily.addEventListener("change", function() {
cssText();
switch (fontFamily.value) {
case "PlexMonoFont":
result.style.fontFamily = "IBM Plex Mono, monospace";
break;
case "ScriptFont":
result.style.fontFamily = "Dancing Script, cursive";
break;
case "RubikFont":
result.style.fontFamily = "Rubik, sans-serif";
break;
}
});
// And it finally all ended, I be happy if someone saw my suffering :)