-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.html
69 lines (61 loc) · 2.07 KB
/
test.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
<head>
<style type="text/css">
#whatever{
background-color: green
}
</style>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
</head>
<body>
<button id="show">Show Img</button>
<p>heoolooo</p>
<a href="#" id="whatever">Create</a>
</body>
<script type="text/javascript" src="script/html2canvas.js"></script>
<script type="text/javascript">
var doms = [];
var index = 0;
$("document").ready(function () {
//change cursor
//$("body").css("cursor", "url('" + chrome.extension.getURL('glitter_cursor.gif') + "'), default");
$(document).click(function(e){
if($(e.target).is('a') || $(e.target).is('button')){
var link = $(e.target).context.href;
var padding_top = $(e.target).css('padding-top') ;
var padding_bottom = $(e.target).css('padding-bottom') ;
var padding_left = $(e.target).css('padding-left') ;
var padding_right = $(e.target).css('padding-right') ;
var w = $(e.target).width();
var h = $(e.target).height();
html2canvas($(e.target), {
onrendered: function(canvas) {
//document.body.appendChild(canvas);
var dataURL = canvas.toDataURL();
//console.log(dataURL);
var dom = {
'link': link,
'dataURL': dataURL,
'width': parseInt(w)+parseInt(padding_left)+parseInt(padding_right),
'height': parseInt(h)+parseInt(padding_top)+parseInt(padding_bottom)
};
console.log(dom);
doms.push(dom);
}
});
}
});
$("#show").click(function(){
doms.forEach(function(dom){
var newA = document.createElement('a');
newA.setAttribute('id', ('dom'+index+''));
newA.setAttribute('href', dom.link);
document.body.appendChild( newA );
var newImg = document.createElement('img');
newImg.setAttribute('width', dom.width+'px');
newImg.setAttribute('height',dom.height+'px');
newImg.style.background = 'url('+dom.dataURL+')';
newA.appendChild( newImg );
})
});
});
</script>