This repository has been archived by the owner on Apr 29, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpopup.js
77 lines (68 loc) · 1.94 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
74
75
76
77
const viewMode = document.getElementById("view-mode");
const buttonLTE = document.getElementById("LTE");
const buttonETL = document.getElementById("ETL");
const word = document.getElementById("word");
var url;
// errors
const noText = {
type: "basic",
iconUrl: "/images/icon128.png",
title: "error",
message: "text not found | enter a word",
buttons: [{ title: "Close" }],
};
const tooMany = {
type: "basic",
iconUrl: "/images/icon128.png",
title: "error",
message: "only one word can be translated",
buttons: [{ title: "Close" }],
};
// Latin to English
buttonLTE.addEventListener("click", function () {
url = "http://www.archives.nd.edu/cgi-bin/wordz.pl?keyword=" + word.value;
openTab(url);
});
// English to Latin
buttonETL.addEventListener("click", function () {
if (word.value.indexOf(" ") >= 0) {
chrome.notifications.create(tooMany);
}
url = "https://archives.nd.edu/cgi-bin/wordz.pl?english=" + word.value;
openTab(url);
});
function openTab(url) {
if (word.value == "") {
chrome.notifications.create(noText);
} else {
chrome.tabs.create({ url: url });
}
}
// Light / Dark mode
viewMode.addEventListener("click", function () {
chrome.storage.sync.get("mode", function (data) {
var lightMode = data.mode;
if (lightMode == false) {
lightMode = true;
viewMode.value = "Dark Mode";
} else {
lightMode = false;
viewMode.value = "Light Mode";
}
chrome.storage.sync.set({ mode: lightMode });
toggleViewMode();
});
});
// Gets the view mode when the extension is opened to change to light mode if it is saved
function startUp() {
chrome.storage.sync.get("mode", function (data) {
if (data.mode == true) {
viewMode.value = "Light Mode";
toggleViewMode();
}
});
}
function toggleViewMode() {
document.getElementsByTagName("body")[0].classList.toggle("light-mode");
}
startUp();