-
Notifications
You must be signed in to change notification settings - Fork 0
/
background.js
71 lines (64 loc) · 1.89 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
browser.contextMenus.create({
id: "Translate_Selection",
title: "Translate the Selection",
contexts: ["selection"]
});
browser.contextMenus.create({
id: "Translate_Web",
title: "Translate this Website",
contexts: ["page"]
});
var Translate_Selection_Win_Id;
browser.contextMenus.onClicked.addListener(function(info, tab) {
if (info.menuItemId == "Translate_Selection") {
var url1 = "https://translate.google.com/#view=home&op=translate&sl=auto&text=" + info.selectionText;
if (Translate_Selection_Win_Id != undefined){
browser.windows.remove(Translate_Selection_Win_Id);
}
var creating = browser.windows.create({
url: url1,
type: "popup",
height: 652,
width: 375
}).then((data) => {
Translate_Selection_Win_Id = data.id;
});
}
else if (info.menuItemId == "Translate_Web"){
var url = "https://translate.google.com/translate?sl=auto&u=";
browser.tabs.query({currentWindow: true, active: true}).then((tabs) => {
let tab = tabs[0];
browser.tabs.update({
url: url + tab.url
});
}, console.error);
}
})
function SaveMessage(message, sender)
{
browser.tabs.update({
url: message.url
})
}
browser.runtime.onMessage.addListener(SaveMessage)
function onErrorLocal(error) {
console.log(`Error: ${error}`);
}
function onGotLocal(item) {
let urlDownloadPage = "./download.html";
console.log("test4")
if (item["DownloadPage"] != true){
browser.storage.local.set({
DownloadPage: true
});
console.log("test")
var page = browser.tabs.create({
url:urlDownloadPage
});
}
}
window.onload = function() {
console.log("test3")
let gettingThanks = browser.storage.local.get();
gettingThanks.then(onGotLocal, onErrorLocal);
}