forked from 1j01/jspaint
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchrome-app.js
54 lines (48 loc) · 1.08 KB
/
chrome-app.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
chrome.app.runtime.onLaunched.addListener(function(launch_data) {
function open_image(entry) {
chrome.app.window.create('index.html', {
bounds: {
width: 800,
height: 600,
left: 100,
top: 100,
},
minWidth: 275,
minHeight: 400,
},
function(window) {
window.contentWindow.file_entry = entry;
window.contentWindow.document.addEventListener('click', function(event) {
let anchor = event.target;
if (is_anchor(anchor) && is_external_link(anchor.href)) {
set_anchor_target_to_open_new_tab(anchor);
}
});
});
}
if (launch_data && launch_data.items && launch_data.items.length > 0) {
launch_data.items.map((item) => open_image(item.entry));
} else {
open_image();
}
});
/**
* @param {HTMLElement} anchor
* @return string
*/
function is_anchor(anchor) {
return anchor.nodeName === 'A';
}
/**
* @param {string} href
* @return {boolean}
*/
function is_external_link(href) {
return href.match(/(http|https):\/\//);
}
/**
* @param {HTMLElement} anchor
*/
function set_anchor_target_to_open_new_tab(anchor) {
anchor.target = '_blank';
}