forked from pdfcopy/pdfcopy.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
214 lines (176 loc) · 6.93 KB
/
index.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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>PDF 复制</title>
<link rel="stylesheet" type="text/css" href="css/main.css">
<link rel="stylesheet" type="text/css" href="css/ui.css">
<link rel="icon" type="image/png" href="img/pdfcopy-icon.png" />
<meta name="description" content="告别PDF复制时的格式混乱,复制粘贴更高效。去除中文的回车(换行符)和空格,去除英文的回车并补齐空格;规范全角半角。">
<meta name="keywords" content="PDF,复制,粘贴,copy,去除回车,去除换行符,去除空格,format">
<style>
</style>
<script data-ad-client="ca-pub-9212951771624560" async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
</head>
<body>
<div id="top">
<a class="top-logo" href="https://github.com/pdfcopy/pdfcopy.github.io" target="_blank">
</a>
</div>
<div id="mid">
<div id="left-container">
<div id="input-container">
<div class="toolbar">
<div class="tool">
<input class="tab-input" id="tabCh" type="radio" name="tabs" checked>
<label class="tab-label" for="tabCh" onclick="setMode(modeCh); checkChinese();">中文模式</label>
<input class="tab-input" id="tabEn" type="radio" name="tabs">
<label class="tab-label" for="tabEn" onclick="setMode(modeEn); checkEnglish();">英文模式</label>
</div>
</div>
<div class="tx-area-wrap">
<textarea class="tx-area" id="text-input" placeholder=""></textarea>
<div class="btn-clear-wrap">
<div class="btn btn-clear" onclick="clearText()"></div>
</div>
</div>
</div>
</div>
<div id="right-container">
<div id="output-container">
<div class="toolbar">
<label class="cbx-container tool">自动复制
<input id="autoCopy" type="checkbox" onclick="setAutoCopy()">
<span class="checkmark"></span>
</label>
</div>
<div class="tx-area-wrap">
<textarea class="tx-area" id="text-output"></textarea>
<div class="btn-copy-wrap">
<div style="height:22px">
<div class="btn btn-copy" onclick="copyOutput()"></div>
</div>
<div class="copy-text">
<span>已复制</span>
</div>
</div>
</div>
</div>
</div>
</div>
<div id="bottom">
<a href="https://github.com/pdfcopy/pdfcopy.github.io" target="_blank" style="position: absolute; right: 0; bottom: 0; color:#fff;">关于</a>
</div>
<script type="text/javascript">
var textInput = null;
var textOutput = null;
var modeCh = 'ch';
var modeEn = 'en';
window.onload = init;
init();
function init() {
textInput = document.getElementById('text-input');
textOutput = document.getElementById('text-output');
switch (getMode()) {
case modeCh:
document.getElementById('tabCh').checked = true;
checkChinese();
break;
case modeEn:
document.getElementById('tabEn').checked = true;
checkEnglish();
break;
}
document.getElementById('autoCopy').checked = isAutoCopy();
textInput.oninput = exec;
}
function checkChinese() {
textInput.placeholder = '- 来吧,往这粘';
textOutput.placeholder = '- 中文模式 将会 去除换行符、去除空格、规范全角半角';
exec();
}
function checkEnglish() {
textInput.placeholder = '- 来吧,往这粘';
textOutput.placeholder = '- 英文模式 将会 去除换行符、规范空格、规范全角半角';
exec();
}
function exec() {
textInput.focus();
if (getMode() === modeCh) {
textOutput.value = execCh(textInput.value);
} else {
textOutput.value = execEn(textInput.value);
}
if (isAutoCopy()) {
copyOutput();
}
}
var regexWhiteSpace = /\s/g;
var regexMultiSpace = /\s+/g;
function execCh(str) {
str = dbc2sbc(str);
str = str.replace(regexWhiteSpace, '');
return str;
}
function execEn(str) {
str = dbc2sbc(str);
str = str.replace(regexMultiSpace, ' ');
return str;
}
function dbc2sbc(str) {
let result = '';
for (let i = 0; i < str.length; i++) {
let charCode = str.charCodeAt(i);
if ((charCode >= 65296 && charCode <= 65305) || //0~9
(charCode >= 65313 && charCode <= 65338) || //A~Z
(charCode >= 65345 && charCode <= 65370)) { //a~z
result += String.fromCharCode(charCode - 65248)
} else if (charCode == 12288) { //space
result += String.fromCharCode(32);
} else {
result += str[i];
}
}
return result;
}
function clearText() {
textInput.value = '';
textOutput.value = '';
textInput.focus();
}
function copyOutput() {
if (textOutput.value === '') {
return;
}
textOutput.select();
document.execCommand('copy');
textInput.focus();
let copyText = document.getElementsByClassName('copy-text')[0];
copyText.style.transition = '0s';
copyText.style.opacity = 1;
setTimeout(() => { copyText.style.transition = '1s'; copyText.style.opacity = 0; }, 2000);
}
function getMode() {
if (localStorage.mode) {
return localStorage.mode;
} else {
return modeCh;
}
}
function setMode(v) {
localStorage.mode = v;
}
function isAutoCopy() {
if (localStorage.autocopy) {
return localStorage.autocopy === 'true';
} else {
return false;
}
}
function setAutoCopy() {
localStorage.autocopy = document.getElementById('autoCopy').checked;
}
</script>
</body>
</html>