-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackground.js
49 lines (47 loc) · 1.23 KB
/
background.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
const browserLanguage = function () {
const ua = window.navigator.userAgent.toLowerCase();
try {
// chromeは以下で利用者のブラウザ言語を取得できる
if (ua.indexOf("chrome") != -1) {
return (
navigator.languages[0] ||
navigator.browserLanguage ||
navigator.language ||
navigator.userLanguage
).substr(0, 2);
}
// それ以外(例えばIEなど)は下記で取得する必要がある
else {
return (
navigator.browserLanguage ||
navigator.language ||
navigator.userLanguage
).substr(0, 2);
}
} catch (e) {
return undefined;
}
};
let toggle = false;
chrome.browserAction.onClicked.addListener(function (tab) {
if (!toggle) {
explosion();
}
});
function explosion() {
if (browserLanguage() == "ja") {
if (window.confirm("爆弾を置く! \n (最初だけ2回クリックしてください)")) {
toggle = true;
chrome.tabs.executeScript({ file: "explosion.js" });
}
} else {
if (
window.confirm(
"Drop bombs on this page! \n (Click twice for the first time only)"
)
) {
toggle = true;
chrome.tabs.executeScript({ file: "explosion.js" });
}
}
}