popup.js
1.7 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
var i = 0;
var start = false;
function imgDown() {
if(!start)
return;
var base64 = $('.rg_ic.rg_i').eq(i).attr( 'src' );
if(typeof base64 === "undefined" ){
alert('마지막 결과입니다.');
clearInterval(b);
start = false;
return;
}
if(base64.indexOf("base64") != -1)
downBase64(i+".png",base64);
else
downUrl(i+".png",base64);
i++;
}
function scrolldn() {
if(!start){
clearInterval(a);
return;
}
document.documentElement.scrollTop = document.body.scrollHeight;
$('html, body').scrollTop(document.body.scrollHeight);
}
function downBase64(filename, base64) {
var pom = document.createElement('a');
pom.setAttribute('href', base64)
pom.setAttribute('download', filename);
if (document.createEvent) {
var event = document.createEvent('MouseEvents');
event.initEvent('click', true, true);
pom.dispatchEvent(event);
}
else {
pom.click();
}
}
function downUrl(filename, url) {
var img = new Image();
img.setAttribute('crossOrigin', 'anonymous');
img.src = url;
var dataURL = url;
img.onload = function () {
var canvas = document.createElement("canvas");
canvas.width =this.width;
canvas.height =this.height;
var ctx = canvas.getContext("2d");
ctx.drawImage(this, 0, 0);
dataURL = canvas.toDataURL("image/png");
downBase64(filename, dataURL);
};
}
var a;
var b;
window.onkeyup = function(e) {
var key = e.keyCode ? e.keyCode : e.which;
if (key == 49) {
start = true;
a = setInterval(scrolldn, 1000);
b = setInterval(imgDown, 100);
}
if (key == 50) {
start = true;
alert('일시정지! 다운받던이미지부터진행함 -> 다시1누르면됨');
clearInterval(a);
clearInterval(b);
}
}