-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
63 lines (54 loc) · 2.14 KB
/
script.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
// const main_txt =
// "#RTGQ202-Ibibazo-Nibisubizo-Byamategeko-Yumuhanda-Rwanda-Traffic-Guide-Com-Ibyapa-Icyapa-cyerekana-";
document.addEventListener("DOMContentLoaded", function () {
const textParagraph = document.getElementById("formattedText");
const inputElement = document.getElementById("textInput");
textParagraph.addEventListener("click", function () {
copyToClipboard(textParagraph.innerText);
});
inputElement.addEventListener("input", function () {
formatText();
updateCharacterCount();
});
document.getElementById("formatButton").addEventListener("click", formatText);
});
function formatText() {
const inputText = document.getElementById("textInput").value;
const numberInput = document.getElementById("numberInput").value;
const formattedText = inputText
.replace(/[^a-zA-Z]+/g, "-")
.replace(/\s*\w+\s*\)|/g, "")
.replace(/[^a-zA-Z0-9]+/g, "-")
.toLowerCase()
.substring(0, 125);
const fullText = `#RTGQ${numberInput}-Ibibazo-Nibisubizo-Byamategeko-Yumuhanda-Rwanda-Traffic-Guide-Com-`;
const mainText = fullText + formattedText;
document.getElementById("formattedText").innerText = mainText;
}
function updateCharacterCount() {
const inputText = document.getElementById("textInput").value;
const characterCountElement = document.getElementById("characterCount");
characterCountElement.innerText = `Characters: ${inputText.length}`;
if (inputText.length > 125) {
characterCountElement.style.color = "red";
} else {
characterCountElement.style.color = "initial";
}
}
function copyToClipboard(text) {
const textArea = document.createElement("textarea");
textArea.value = text;
document.body.appendChild(textArea);
textArea.select();
document.execCommand("copy");
document.body.removeChild(textArea);
const outputElement = document.getElementById("formattedText");
outputElement.style.color = "#4CAF57";
}
function clearAll() {
document.getElementById("textInput").value = "";
document.getElementById("formattedText").innerText = "";
updateCharacterCount();
const outputElement = document.getElementById("formattedText");
outputElement.style.color = "#000000";
}