-
Notifications
You must be signed in to change notification settings - Fork 0
/
edittext.html
195 lines (184 loc) · 5.88 KB
/
edittext.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
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.13.0/css/all.css">
<style>
* {
box-sizing: border-box;
}
input[type=text],
select,
textarea {
width: 100%;
padding: 12px;
border: 1px solid #ccc;
border-radius: 4px;
resize: vertical;
}
label {
padding: 12px 12px 12px 0;
display: inline-block;
}
a {
color: #4CAF50;
}
input[type=submit] {
background-color: #4CAF50;
color: white;
padding: 10px 10px;
margin: 5px;
border: none;
border-radius: 4px;
cursor: pointer;
float: right;
}
input[type=submit]:hover {
background-color: #45a049;
}
.container {
border-radius: 5px;
background-color: #f2f2f2;
padding: 20px;
}
.col-25 {
float: left;
width: 25%;
margin-top: 6px;
}
.col-75 {
float: left;
width: 75%;
margin-top: 6px;
}
img { height: 1.12em; }
/* Clear floats after the columns */
.row:after {
content: "";
display: table;
clear: both;
}
/* Responsive layout - when the screen is less than 600px wide, make the two columns stack on top of each other instead of next to each other */
@media screen and (max-width: 600px) {
.col-25,
.col-75,
input[type=submit] {
width: 100%;
margin-top: 0;
}
}
</style>
<script>
function paste(id) {
console.log(id);
var pasteText = document.getElementById(id);
pasteText.focus();
console.log(pasteText.textContent);
navigator.clipboard.readText().then(text => pasteText.textContent = text);
}
let render = (relEl, tpl) => {
if (!relEl) return;
const range = document.createRange();
range.selectNode(relEl);
const child = range.createContextualFragment(tpl);
return relEl.appendChild(child);
}
function insert(html) {
render(document.getElementById('content'), html);
}
function addTextLine(id, text_id, text, height, extra, eng) {
let html =
`<div class="row">
<div class="col-25">
<label for="${id}">${text_id}</label>
</div>
<div class="col-75">
<div><textarea id="${id}_VALUE" name="${id}" style="height: ${height * 20}px;" onclick="autotranslate(\`${encodeURIComponent(eng)}\`)" ${extra ? extra : ''}>${text}</textarea>
</div>
</div>`;
insert(html);
}
let allowBing = false;
function autotranslate(text){
if(allowBing) {
document.getElementById("bing").innerHTML = `<iframe id="Frame" src="https://www.bing.com/translator?to=${lcode}&text=${text}" width="100%" height="1000pt"></iframe>`;
}
}
function assignText(id,text){
console.log(text);
console.log(decodeURIComponent(text));
document.getElementById(`${id}_VALUE`).value = decodeURIComponent(text);
}
let order = 0;
function addTranslateHint(id, text, trtext, link) {
if(text.length) {
let html =
`<div class="row">
<div class="col-25">
<label></label>
</div>
<div class="col-75">
<div style="color: grey;font-size: 85%;">
<a href="javascript:assignText('${id}', \`${encodeURIComponent(text)}\`)">English:</a> ${text} <a href="javascript:assignText('${id}', \`${encodeURIComponent(trtext)}\`)">restore original</a><br>
<a href="https://translate.google.com?sl=en&text=${encodeURIComponent(text)}&op=translate&tl=${lcode}"><i class="fab fa-google"></i><b>oogle</b></a>
<a href="https://www.deepl.com/en/translator#en/${lcode}/${encodeURIComponent(text)}"><img src="https://www.deepl.com/img/logo/DeepL_Logo_darkBlue_v2.svg"></img><b>DeepL</b></a>
<a href="https://www.bing.com/translator?to=${lcode}&text=${encodeURIComponent(text)}"><img src="https://upload.wikimedia.org/wikipedia/en/thumb/b/b7/Microsoft_Translator_Logo.png/195px-Microsoft_Translator_Logo.png"></img><b>Bing</b></a>
<a href="javascript:paste('${id}_VALUE');"><i class="fas fa-paste"></i><b>Paste</b></a></div>
</div>
</div>`;
insert(html);
}
}
function addButton(name) {
let html =
`<input type="submit" name="action" value="${name}" onclick="setTimeout(()=> window.close(), 500)">`;
render(document.getElementById('buttons'), html);
}
function addDescription(name) {
let html = `<div style="color: grey;font-size: 85%;">${name}</div>`;
render(document.getElementById('buttons'), html);
}
</script>
</head>
<body>
<div class="bg">
<div class="container">
<form action="/submit" method="get">
<div id="content"></div>
<div class="row" id="buttons"></div>
</form>
</div>
<div id="bing"></div>
</div>
<script>
const text = {JSONTEXT};
let lcode='ru';
let nb = 0;
let lang='English';
for(const [k, v] of Object.entries(text)) {
if(k=='Language'){
addTextLine('Language', 'Language', v, 2, 'readonly');
lang=v;
}
if(k=='mail')addTextLine('EMAIL', 'e-mail', v, 2);
if(k=='author')addTextLine('AUTHOR', 'Your name', v, 2);
if(k.includes('Button')) {
addButton(v);
nb++;
}
if(k.includes('TextItem')){
console.log(v);
lcode = v.tl;
addTextLine('HINT:' + v.ID, v.ID, v.Text, v.Text.length/140 + 2, 0, lang !== 'English' ? v.English : '');
if(lang !== 'English'){
addTranslateHint('HINT:' + v.ID, v.English, v.Text, v.link);
allowBing = true;
}
}
}
</script>
<script></script>
</body>