-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtxtgen.html
240 lines (213 loc) · 9.37 KB
/
txtgen.html
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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
<!DOCTYPE html>
<html lang="ko">
<head>
<link rel="icon" type="image/x-icon" href="/favicon.ico">
<title>디스코드 색깔 텍스트 생성기 - Klfn.dev();</title>
<meta charset="UTF-8">
<meta name="description" content="디스코드 색깔 텍스트 생성기">
<meta name="author" content="klfn">
<style>
@font-face {
font-family: 'Pretendard-Regular';
src: url('https://cdn.jsdelivr.net/gh/Project-Noonnu/[email protected]/Pretendard-Regular.woff') format('woff');
font-weight: 400;
font-style: normal;
}
html {
font-family: Pretendard-Regular;
background-color: rgb(27, 27, 27);;
text-align: center;
color: #FFF;
}
.container {
max-width: 500px;
margin: auto;
}
.flex {
height: 100%;
display: flex;
align-items: center;
justify-content: center;
}
#textarea {
width: 600px;
height: 200px;
border-radius: 5px;
resize: both;
overflow: auto;
text-align: left;
font-family: monospace;
background-color: #3b3b3b;
color: #B9BBBE;
border: #202225 1px solid;
padding: 5px;
display: inline-block;
border-radius: 8px;
white-space: pre-wrap;
font-size: 0.875rem;
line-height: 1.125rem;
text-indent: 0;
}
.button {
min-height: 32px;
min-width: 32px;
border: none;
border-radius: 3px;
color: #fff;
background-color: #3b3b3b;
font-size: 14px;
padding: 2px 16px;
cursor: pointer;
transition: background-color 250ms linear;
}
a,a:visited {
color: #00AFF4
}
.ansi-1 { font-weight:700; text-decoration:none; }
.ansi-4 { font-weight:500; text-decoration:underline; }
.ansi-30 { color: #4f545c; }
.ansi-31 { color: #dc322f; }
.ansi-32 { color: #859900; }
.ansi-33 { color: #b58900; }
.ansi-34 { color: #268bd2; }
.ansi-35 { color: #d33682; }
.ansi-36 { color: #2aa198; }
.ansi-37 { color: #ffffff; }
.ansi-30-bg { background-color: #4f545c; }
.ansi-31-bg { background-color: #dc322f; }
.ansi-32-bg { background-color: #859900; }
.ansi-33-bg { background-color: #b58900; }
.ansi-34-bg { background-color: #268bd2; }
.ansi-35-bg { background-color: #d33682; }
.ansi-36-bg { background-color: #2aa198; }
.ansi-37-bg { background-color: #ffffff; }
.ansi-40 { background-color: #002b36; }
.ansi-41 { background-color: #cb4b16; }
.ansi-42 { background-color: #586e75; }
.ansi-43 { background-color: #657b83; }
.ansi-44 { background-color: #839496; }
.ansi-45 { background-color: #6c71c4; }
.ansi-46 { background-color: #93a1a1; }
.ansi-47 { background-color: #fdf6e3; }
</style>
</head>
<body>
<br><h1>디스코드 <span style="color:#5865F2">색깔</span> 텍스트 생성기</h1><br>
<div class="container">
<p></p>
</div>
<button data-ansi="0" class="button style-button">리셋하기</button>
<button data-ansi="1" class="button style-button ansi-1">볼드</button>
<button data-ansi="4" class="button style-button ansi-4">라인</button>
<br><br>
<strong>텍스트 색상</strong>
<button data-ansi="30" class="button style-button ansi-30-bg"> </button>
<button data-ansi="31" class="button style-button ansi-31-bg"> </button>
<button data-ansi="32" class="button style-button ansi-32-bg"> </button>
<button data-ansi="33" class="button style-button ansi-33-bg"> </button>
<button data-ansi="34" class="button style-button ansi-34-bg"> </button>
<button data-ansi="35" class="button style-button ansi-35-bg"> </button>
<button data-ansi="36" class="button style-button ansi-36-bg"> </button>
<button data-ansi="37" class="button style-button ansi-37-bg"> </button>
<br><br>
<strong>배경색상</strong>
<button data-ansi="40" class="button style-button ansi-40"> </button>
<button data-ansi="41" class="button style-button ansi-41"> </button>
<button data-ansi="42" class="button style-button ansi-42"> </button>
<button data-ansi="43" class="button style-button ansi-43"> </button>
<button data-ansi="44" class="button style-button ansi-44"> </button>
<button data-ansi="45" class="button style-button ansi-45"> </button>
<button data-ansi="46" class="button style-button ansi-46"> </button>
<button data-ansi="47" class="button style-button ansi-47"> </button>
<br><br><br><br>
<div class="flex"><div id="textarea" contenteditable="true"><span class="ansi-45"><span class="ansi-37">디스코드</span></span><span class="ansi-1"><span class="ansi-34"> 색깔 </span><span class="ansi-4">텍스트 생성기에 오신것을</span></span><span class="ansi-31"> 환</span><span class="ansi-32">영</span><span class="ansi-33">합</span><span class="ansi-34">니</span><span class="ansi-35">다</span><span class="ansi-36">!</span><span class="ansi-37"></span></div></div>
<br>
<button class="button copy">결과물 복사하기!</button>
<br>
<br>
<small><span style="color:#5865F2">한글로 작성할 때 약간의 오류가 발생할 수 있습니다!</span><br></small><br>문의: Klfn#6039
<script type="text/javascript">
const textarea = document.querySelector("#textarea");
const copybtn = document.querySelector(".button.copy");
// Some basic escaping of pasted HTML tags, not ideal but good enough for this situation.
textarea.oninput = () => {
const base = textarea.innerHTML.replace(/<(\/?(br|span|span class="ansi-[0-9]*"))>/g,"[$1]");
if (base.includes("<") || base.includes(">")) textarea.innerHTML = base.replace(/<.*?>/g,"").replace(/[<>]/g,"").replace(/\[(\/?(br|span|span class="ansi-[0-9]*"))\]/g,"<$1>");
};
// https://stackoverflow.com/a/61237402
document.addEventListener('keydown', event => {
if (event.key === 'Enter') {
document.execCommand('insertLineBreak')
event.preventDefault()
}
});
document.querySelectorAll(".style-button").forEach((btn) => {
btn.onclick = () => {
if (!btn.dataset.ansi) {
textarea.innerText = textarea.innerText;
return;
}
const selection = window.getSelection();
const text = window.getSelection().toString();
const span = document.createElement("span");
span.innerText = text;
span.classList.add(`ansi-${btn.dataset.ansi}`);
const range = selection.getRangeAt(0);
range.deleteContents();
range.insertNode(span);
range.selectNodeContents(span);
selection.removeAllRanges();
selection.addRange(range);
};
});
function nodesToANSI(nodes, states) {
let text = ""
for (const node of nodes) {
if (node.nodeType === 3) {
text += node.textContent;
continue;
}
if (node.nodeName === "BR") {
text += "\n";
continue;
}
const ansiCode = +(node.className.split("-")[1]);
const newState = Object.assign({}, states.at(-1));
if (ansiCode < 30) newState.st = ansiCode;
if (ansiCode >= 30 && ansiCode < 40) newState.fg = ansiCode;
if (ansiCode >= 40) newState.bg = ansiCode;
states.push(newState)
text += `\x1b[${newState.st};${(ansiCode >= 40) ? newState.bg : newState.fg}m`;
text += nodesToANSI(node.childNodes, states);
states.pop()
text += `\x1b[0m`;
if (states.at(-1).fg !== 2) text += `\x1b[${states.at(-1).st};${states.at(-1).fg}m`;
if (states.at(-1).bg !== 2) text += `\x1b[${states.at(-1).st};${states.at(-1).bg}m`;
}
return text;
}
let copyCount = 0;
let copyTimeout = null;
copybtn.onclick = () => {
const toCopy = "```ansi\n" + nodesToANSI(textarea.childNodes, [{ fg: 2, bg: 2, st:2 }]) + "\n```";
navigator.clipboard.writeText(toCopy).then(() => {
if (copyTimeout) clearTimeout(copyTimeout);
const funnyCopyMessages = copybtn.innerText = ["복사 완료!", "두 번 복사!", "세 번 복사!", "복사의 지배자!!", "복사 때리고!!", "엄청 복사!!", "멈출 수가 없지!!", "복사의 고수!!", "괴물같은 복사!!!", "복사의 신!!!", "신을 넘어섰드아아!!!", Array(16).fill(0).reduce(p => p + String.fromCharCode(Math.floor(Math.random() * 65535)),"")];
copybtn.style.backgroundColor = (copyCount <= 8) ? "#3BA55D" : "#ED4245";
copybtn.innerText = funnyCopyMessages[copyCount];
copyCount = Math.min(11, copyCount + 1);
copyTimeout = setTimeout(() => {
copyCount = 0;
copybtn.style.backgroundColor = null;
copybtn.innerText = "결과물 복사하기!";
}, 2000)
}, (err) => {
// We don't need to stop the users if they get a little too excited about the button
if (copyCount > 2) return;
alert("어떤 이유로 복사가 실패했습니다. 알림을 표시해 볼게요. 대신 복사할 수도 있습니다.");
alert(toCopy);
});
}
</script>
</body>
</html>