-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
155 lines (138 loc) · 5.28 KB
/
script.js
File metadata and controls
155 lines (138 loc) · 5.28 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
// script.js
const fontSelect = document.getElementById("fontSelect");
const fontSizeSelect = document.getElementById("fontSizeSelect");
const textFormatSelect = document.getElementById("textFormatSelect");
const highlightColorInput = document.getElementById("highlightColorSelect");
const textInput = document.getElementById("textInput");
const displayText = document.getElementById("displayText");
const copyButton = document.getElementById("copyButton");
const resetButton = document.getElementById("resetButton");
const zalgoComplexitySlider = document.getElementById("zalgoComplexity");
const zalgoComplexityContainer = document.getElementById("zalgoComplexityContainer");
const textCounter = document.getElementById("textCounter");
const darkModeSwitch = document.getElementById("darkModeSwitch");
const copyPopup = document.getElementById("copyPopup");
// Initialize dark mode from localStorage
if (localStorage.getItem("darkMode") === "enabled") {
document.body.classList.add("dark-mode");
darkModeSwitch.checked = true;
}
// Toggle dark mode
darkModeSwitch.addEventListener("change", () => {
if (darkModeSwitch.checked) {
document.body.classList.add("dark-mode");
localStorage.setItem("darkMode", "enabled");
} else {
document.body.classList.remove("dark-mode");
localStorage.setItem("darkMode", "disabled");
}
});
// Fetch Google Fonts API
const apiKey = "AIzaSyATqPXjZzhE80CT4nl_aITBvJpJIV-OeDk";
const apiUrl = `https://www.googleapis.com/webfonts/v1/webfonts?key=${apiKey}&sort=popularity`;
async function loadFonts() {
try {
const res = await fetch(apiUrl);
const data = await res.json();
const fonts = [
"Arial", "Georgia", "Courier New", "Comic Sans MS", "Impact",
...data.items.map(font => font.family)
];
fonts.forEach(font => {
const option = document.createElement("option");
option.value = font;
option.textContent = font;
fontSelect.appendChild(option);
});
} catch (error) {
console.error("Error fetching fonts:", error);
}
}
loadFonts();
// Populate font sizes
[8, 12, 16, 20, 24, 28, 32, 36, 40, 48, 56, 64, 72, 80, 88, 96].forEach(size => {
const option = document.createElement("option");
option.value = `${size}px`;
option.textContent = `${size}px`;
fontSizeSelect.appendChild(option);
});
// Update live text
function updateDisplay() {
const inputText = textInput.value;
if (textFormatSelect.value === "zalgo") {
displayText.innerHTML = generateZalgo(inputText, zalgoComplexitySlider.value);
} else {
displayText.textContent = inputText;
}
}
// Copy text to clipboard
copyButton.addEventListener("click", () => {
navigator.clipboard.writeText(displayText.textContent).then(() => {
copyPopup.style.display = "block";
setTimeout(() => copyPopup.style.display = "none", 1500);
});
});
// Reset function
resetButton.addEventListener("click", () => {
textInput.value = "";
displayText.textContent = "Your typed text will appear here.";
textFormatSelect.value = "normal";
highlightColorInput.value = "#ffffff";
displayText.style.backgroundColor = "transparent";
updateCounter();
});
// Word and character counter
function updateCounter() {
const words = textInput.value.trim().split(/\s+/).filter(Boolean).length;
const chars = textInput.value.length;
textCounter.textContent = `Words: ${words} | Characters: ${chars}`;
}
textInput.addEventListener("input", () => {
updateDisplay();
updateCounter();
});
// Font select
fontSelect.addEventListener("change", () => {
const selectedFont = fontSelect.value;
const link = document.createElement("link");
link.href = `https://fonts.googleapis.com/css2?family=${selectedFont.replace(/ /g, "+")}&display=swap`;
link.rel = "stylesheet";
document.head.appendChild(link);
displayText.style.fontFamily = `'${selectedFont}', sans-serif`;
});
// Font size select
fontSizeSelect.addEventListener("change", () => {
displayText.style.fontSize = fontSizeSelect.value;
});
// Highlight color
highlightColorInput.addEventListener("change", () => {
displayText.style.backgroundColor = highlightColorInput.value;
});
// Text format select
textFormatSelect.addEventListener("change", () => {
const format = textFormatSelect.value;
displayText.style.fontStyle = (format.includes("italic")) ? "italic" : "normal";
displayText.style.fontWeight = (format.includes("bold")) ? "bold" : "normal";
displayText.style.textDecoration =
format === "underline" ? "underline" :
format === "strikethrough" ? "line-through" : "none";
if (format === "zalgo") {
zalgoComplexityContainer.style.display = "block";
} else {
zalgoComplexityContainer.style.display = "none";
}
updateDisplay();
});
// Zalgo complexity slider
zalgoComplexitySlider.addEventListener("input", updateDisplay);
// Zalgo text generator
function generateZalgo(text, complexity) {
const zalgoChars = ["̖","̗","̘","̙","̜","̝","̞","̟","̠","̤","̥","̦","̩","̪","̫","̬","̭","̮","̯","̰","̱","̲","̳","̹","̺","̻","̼","ͅ","͇","͈","͉","͍","͎","͓","͔","͕","͖","͙","͚","̣","̈","̩","̤","̥","̨","̧","̢","̡","̟","̜","̚"];
return text.split("").map(char => {
let zalgoChar = char;
for (let i = 0; i < complexity; i++) {
zalgoChar += zalgoChars[Math.floor(Math.random() * zalgoChars.length)];
}
return zalgoChar;
}).join("");
}