-
Notifications
You must be signed in to change notification settings - Fork 459
/
test.js
95 lines (81 loc) · 2.7 KB
/
test.js
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
// Copyright (c) 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
document.addEventListener('DOMContentLoaded', function() {
var deleteNode = function(node) {
node.parentNode.removeChild(node);
};
var deleteAWebview = function() {
deleteNode(document.querySelector('.ib'));
};
var findContainer = function(node) {
var container = node;
while (container && !container.classList.contains('ib')) {
container = container.parentElement;
}
return container;
};
var handleDelete = function(event) {
var container = findContainer(event.target);
if (container) {
deleteNode(container);
}
};
var viewScreenshot = function(wv) {
return function(data) {
chrome.app.window.create('display.html', {
innerBounds: { width: wv.clientWidth, height: wv.clientHeight }
},
function(aw) {
var d = aw.contentWindow.document;
d.addEventListener('DOMContentLoaded', function() {
var img = d.createElement('img');
img.src = data;
d.body.appendChild(img);
});
});
};
};
var handleScreenshot = function(event) {
var container = findContainer(event.target);
var wv = container.querySelector('webview');
wv.captureVisibleRegion({format:'png'}, viewScreenshot(wv));
};
var getControls = (function() {
var controls = document.createElement('div');
controls.className = 'controls';
controls.innerHTML = '<button id="screenshot">Screenshot</button>' +
'<button id="delete">Delete webview</button>';
return function() {
var c = controls.cloneNode(true);
c.querySelector('#delete').addEventListener('click', handleDelete);
c.querySelector('#screenshot').
addEventListener('click', handleScreenshot);
return c;
};
})();
var createWebview = (function(){
var id = 0;
return function() {
var wv = document.createElement('webview');
wv.partition = "partition";
wv.src = 'test2.html';
wv.allowtransparency = document.getElementById('transparent').checked;
wv.style.width = "640px";
wv.style.height = "480px";
var container = document.createElement('div');
container.id = 'wvid0' + id;
id++;
container.className = 'ib';
container.appendChild(wv);
container.appendChild(getControls());
return container;
};
})();
document.getElementById('delete_wv').
addEventListener('click', deleteAWebview);
document.getElementById('add_wv').
addEventListener('click', function() {
document.body.appendChild(createWebview());
});
});