-
Notifications
You must be signed in to change notification settings - Fork 6
/
popup.js
73 lines (72 loc) · 1.91 KB
/
popup.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
var ispdf;
function winclose() {
window.close();
}
chrome.tabs.query({ active: true, currentWindow: true }, function (tabs) {
var url = tabs[0].url;
if (!url.match(/chrome:\/\//)) {
chrome.tabs.sendMessage(tabs[0].id, { message: "ispdf" }, function (res) {
if (res == true) {
ispdf = true;
} else {
ispdf = false;
}
document.querySelector(".icon").innerHTML =
"<img src=" + '"' + chrome.runtime.getURL("icon24.png") + '">';
if (ispdf) {
winclose();
} else {
chrome.tabs.query(
{ active: true, currentWindow: true },
function (tabs) {
chrome.tabs.sendMessage(
tabs[0].id,
{ message: "selectionmode" },
function (res) {
setTimeout(winclose, 15000);
}
);
}
);
}
});
} else {
winclose();
}
});
document.querySelector("#pagetrans").onclick = function () {
chrome.tabs.query({ active: true, currentWindow: true }, function (tabs) {
chrome.tabs.sendMessage(
tabs[0].id,
{ message: "get_body_length" },
function (len) {
var conf = confirm(
"Are you sure you want to translate this?\n\nIt costs about " +
len +
" characters"
);
if (conf == true) {
if (len > 4000) {
var really = confirm(
"CAUTION!\n\nIt costs about " + len / 400 + " JPY!"
);
if (really == true) {
chrome.tabs.sendMessage(
tabs[0].id,
{ message: "page_translate" },
function () {}
);
}
} else {
chrome.tabs.sendMessage(
tabs[0].id,
{ message: "page_translate" },
function () {}
);
}
winclose();
}
}
);
});
};