-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclipboard.html
More file actions
executable file
·348 lines (298 loc) · 12.9 KB
/
clipboard.html
File metadata and controls
executable file
·348 lines (298 loc) · 12.9 KB
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
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
<!DOCTYPE HTML>
<HTML>
<HEAD>
<TITLE>CLIPBOARD</TITLE>
<META charset="UTF-8">
<META http-equiv="X-UA-Compatible" content="IE=edge, chrome=1" />
<SCRIPT src="http://code.jquery.com/jquery-1.11.2.js"></SCRIPT>
<SCRIPT>
console = window.console || {log:function(){}};
var stringFromCharCode = String.fromCharCode;
function displayType( msg ) {
var $elem = $("#typeInfo");
$elem.val( msg );
}
function displayContent( content ) {
var $elem = $("#elm1");
$elem.val( content );
}
function handlepaste (elem, e) {
var savedcontent = elem.innerHTML;
if (e && e.clipboardData && e.clipboardData.getData) {
// Webkit - get data from clipboard, put into editdiv, cleanup, then cancel event
if (/text\/html/.test(e.clipboardData.types)) {
elem.innerHTML = e.clipboardData.getData('text/html');
} else if (/text\/plain/.test(e.clipboardData.types)) {
elem.innerHTML = e.clipboardData.getData('text/plain');
} else {
elem.innerHTML = "";
}
var types = e.clipboardData.types;
if ( types ) {
var temps = "[" + e.clipboardData.types.length + "] " ;
for ( var i = 0 ; i < types.length ; i++ ) {
temps += types [ i ] + " " ;
}
displayType( temps );
}
waitforpastedata(elem, savedcontent);
if (e.preventDefault) {
e.stopPropagation();
e.preventDefault();
}
return false;
} else {
// Everything else - empty editdiv and allow browser to paste content into it, then cleanup
elem.innerHTML = "";
displayType( "Can not access clipboard" );
waitforpastedata(elem, savedcontent);
return true;
}
}
function waitforpastedata (elem, savedcontent) {
if (elem.childNodes && elem.childNodes.length > 0) {
processpaste(elem, savedcontent);
} else {
that = {
e: elem,
s: savedcontent
}
that.callself = function () {
waitforpastedata(that.e, that.s);
}
setTimeout(that.callself,20);
}
}
function processpaste (elem, savedcontent) {
pasteddata = elem.innerHTML;
elem.innerHTML = savedcontent;
displayContent( pasteddata );
}
function viewInPage( id ) {
var newWindow,
data = "<p>null</p>",
elem = document.getElementById( id ),
scriptTag = "<script src=\"http://code.jquery.com/jquery-1.11.2.js\"><\/script>";
if ( id ) {
data = elem.value;
}
if ( /<\/head>/i.test(data) ) {
data.replace( /<\/head>/i, scriptTag + "\n</head>\n");
} else {
data = scriptTag + data;
}
newWindow = window.open("", "");
newWindow.document.write( data );
}
function viewInPageWithTrim() {
var newWindow,
data = "<p>null</p>",
$fragment,
elem = document.getElementById( 'elm1' ),
scriptTag = "<script src=\"http://code.jquery.com/jquery-1.11.2.js\"><\/script>";
if ( elem == null ) {
return ;
} else {
data = elem.value;
}
data = data.replace("<!--StartFragment-->", "");
data = data.replace("<!--EndFragment-->", "");
$fragment = $( data );
$fragment.find("br").remove();
$fragment.find("caption").remove();
$fragment.find("colgroup").remove();
$fragment.find(".middleSum").remove();
$("a", $fragment ).each(function(idx, elem) {
var parent = elem.parentNode;
var childNode = elem.childNodes[ 0 ];
parent.removeChild(elem);
parent.appendChild(childNode);
});
data = $fragment[ 0 ].outerHTML;
if ( /<\/head>/i.test(data) ) {
data.replace( /<\/head>/i, scriptTag + "\n</head>\n");
} else {
data = scriptTag + data;
}
newWindow = window.open("", "");
newWindow.document.write( data );
}
function handleHCard() {
var newWindow,
data = "<p>null</p>",
$fragment,
elem = document.getElementById( 'elm1' ),
scriptTag = "<script src=\"http://code.jquery.com/jquery-1.11.2.js\"><\/script>";
if ( elem == null ) {
return ;
} else {
data = elem.value;
}
data = data.replace("<!--StartFragment-->", "");
data = data.replace("<!--EndFragment-->", "");
$fragment = $( data );
$fragment.find("caption").remove();
$fragment.find("colgroup").remove();
$fragment.find(".middleSum").remove();
var list = []
$("tr", $fragment ).each(function(idx, elem) {
var parent = elem.parentNode;
var lableNode = elem.childNodes[ 0 ];
var priceNode = elem.childNodes[ 1 ];
if ( lableNode == null || priceNode == null) {
parent.removeChild(elem);
} else {
if(priceNode.className != "con_btm2") {
var price = parseHCardPriceElem(priceNode)
var record = parseHCardLabel(lableNode, price)
list.push(record)
}
}
});
console.log("list.size: " + list.length)
var htmlTag = "<body><table><thead><td>이용일</td><td>구분</td><td>가맹점</td><td>이용금액</td><td>총 할부금액</td><td>이용혜택</td><td>혜택금액</td><td>개월</td><td>구분필드</td><td>원금</td></thead>";
htmlTag += "\n<tbody>\n"
for(var i = 0; i < list.length ; i++ ) {
htmlTag += "<tr>"
htmlTag += "<td>" + list[i].date +"</td>\n"
htmlTag += "<td>" + list[i].creadtedBy +"</td>\n"
htmlTag += "<td>" + list[i].shop +"</td>\n"
htmlTag += "<td>" + list[i].price +"</td>\n"
htmlTag += "<td></td><td></td><td>"+ parseInt(list[i].reward)+"</td><td></td><td></td>"
htmlTag += "<td>" + list[i].price +"</td>\n"
htmlTag += "</tr>"
console.log(list[i])
}
htmlTag += "</tbody></table></body>"
data = $fragment[ 0 ].outerHTML;
if ( /<\/head>/i.test(data) ) {
data.replace( /<\/head>/i, scriptTag + "\n</head>\n");
} else {
data = scriptTag + htmlTag;
}
newWindow = window.open("", "");
newWindow.document.write( data );
}
function decode( src, dest ) {
var elem = document.getElementById( src ),
target = document.getElementById( dest ),
encoded, decoded;
if ( elem && target ) {
encoded = elem.value.replace( /[\s\u00A0\n]/g, "" );
decoded = b64DecodeUnicode( encoded );
target.value = decoded;
}
encoded = null;
decoded = null;
}
function encode( src, dest ) {
var elem = document.getElementById( src ),
target = document.getElementById( dest ),
encoded, decoded;
if ( elem && target ) {
target.value = "";
encoded = elem.value;
decoded = b64EncodeUnicode( encoded );
target.value = decoded;
}
encoded = null;
decoded = null;
}
// ref: https://developer.mozilla.org/en-US/docs/Web/API/WindowBase64/Base64_encoding_and_decoding
function b64DecodeUnicode(str) {
return decodeURIComponent(Array.prototype.map.call(atob(str), function(c) {
return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2);
}).join(''));
}
function b64EncodeUnicode(str) {
// first we use encodeURIComponent to get percent-encoded UTF-8,
// then we convert the percent encodings into raw bytes which
// can be fed into btoa.
return btoa(encodeURIComponent(str).replace(/%([0-9A-F]{2})/g, function toSolidBytes(match, p1) {
return String.fromCharCode('0x' + p1);
}));
}
function parseHCardLabel(elem, price) {
var subList = $(elem).find("li")
var title = $(elem).find("p")
console.log(elem)
console.log(elem.childNodes[0])
console.log(elem.childNodes[0].textContents)
console.log(elem.childNodes[1])
console.log(elem.childNodes[1].textContents)
var recordObj = {
"date" : "20" + ( title[0].textContent.replaceAll(" ", "").replace("년","").replace("월","").replace("일","") ),
"shop": title[1].textContent,
"price": price,
"creadtedBy": subList[0].textContent,
"cardName": subList[1].textContent,
"orderType": subList[2].textContent,
"dcRate": subList[3].textContent.replace("적립\/할인율", "")
};
if ( subList[4] != null) {
recordObj[ "reward"] = subList[4].textContent.replace("예상적립\/할인", "")
} else {
recordObj[ "reward"] = 0
}
return recordObj;
}
function parseHCardPriceElem(elem) {
return parseInt(elem.textContent.replace("\,", "").replace("원", ""))
}
function decodeQuotedPritable( src, dest ){
var elem = document.getElementById( src ),
target = document.getElementById( dest ),
encoded, decoded;
if ( elem && target ) {
encoded = elem.value.replace( /[\s\u00A0\n]/g, "" );
decoded = encoded.replace( /[\t\x20]$/gm, "" ).replace( /=?(?:\r\n?|\n)/g, "" ).replace( /=([a-fA-F0-9]{2})/g, function( $0, $1 ) {
var codePoint = parseInt( $1, 16 );
return stringFromCharCode( codePoint );
});
target.value = decoded;
}
encoded = null;
decoded = null;
}
</SCRIPT>
<STYLE type="text/css">
div {
border: 1px solid black;
height: 60px;
width: 70%;
}
textarea {
width: 70%;
height: 300px;
border: 1px solid black;
}
</STYLE>
</HEAD>
<BODY style="padding-left:10px;">
<DIV id="pasteHere" contenteditable="true" onpaste="handlepaste(this, event)" style="border-style:dotted;border-width:3px;padding:4px;">Paste Here...</DIV>
<br>
<DIV style="vertical-align:middle;padding-top:15px;padding-left 5px;height:36px;">
<span style="width:30%">Data Type : </span>
<input id="typeInfo" name="typeInfo" type="text" style="width:70%;" />
</DIV>
<br>
<br>
<span>Command : </span>
<div style="margin: 5px;">
<input type="button" value="view" onclick="viewInPage('elm1')">
<input type="button" value="trimTags" onclick="viewInPageWithTrim()">
<input type="button" value="handleHCard" onclick="handleHCard()">
<input type="button" value="decode-Base64" onclick="decode( 'elm1', 'elm2' )">
<input type="button" value="encode-Base64" onclick="encode( 'elm1', 'elm2' )">
<input type="button" value="decode-QuotedPritable" onclick="decodeQuotedPritable( 'elm1', 'elm2' )">
</div>
<br>
<textarea id="elm1" name="elm1" ></textarea>
<br>
</br>
<span>Body</span>
<input type="button" value="view" onclick="viewInPage('elm2')">
<br>
<textarea id="elm2" name="elm2" ></textarea>
</BODY>
</HTML>