-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
41 lines (36 loc) · 1.07 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
const inp = document.getElementById('inp');
const str_btn = document.getElementById('str_btn');
const out = document.getElementById('out');
const cpy_btn = document.getElementById('cpy_btn');
function convertToPlain(rtf) {
rtf = rtf.replace(/\\par[d]?/g, "");
return rtf.replace(/\{\*?\\[^{}]+}|[{}]|\\\n?[A-Za-z]+\n?(?:-?\d+)?[ ]?/g, "").trim();
}
function copy(text) {
var input = document.createElement('textarea');
input.innerHTML = text;
document.body.appendChild(input);
input.select();
var result = document.execCommand('copy');
document.body.removeChild(input);
return result;
}
function htmlStringify(html) {
var output = '';
for(let i = 0; i < html.length; i++) {
if(html.at(i) === '\"') {
output += '\\';
}
if(html.at(i) !== '\n') {
output += html.at(i);
}
}
return output;
};
str_btn.onclick = function() {
inp.innerText = convertToPlain(inp.innerText);
out.innerText = htmlStringify(inp.innerText);
}
cpy_btn.onclick = function() {
copy(out.innerHTML);
}