-
Notifications
You must be signed in to change notification settings - Fork 0
/
options.js
90 lines (74 loc) · 2.58 KB
/
options.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
78
79
80
81
82
83
84
85
86
87
88
89
90
bg = chrome.extension.getBackgroundPage();
document.addEventListener("DOMContentLoaded", init);
function init() {
var lpc = document.getElementById("link-popup-checkbox");
if (bg.getLinkPopupStatus() === "enabled") {
lpc.checked = true;
}
lpc.onchanged = function() {
bg.setLinkPopupStatus(lpc.checked ? "enabled" : "disabled");
};
var dpc = document.getElementById("definition-popup-checkbox");
if (bg.getDefPopupStatus() === "enabled") {
dpc.checked = true;
}
dpc.onchanged = function() {
bg.setDefPopupStatus(dpc.checked ? "enabled" : "disabled");
};
var ldl = document.getElementById("link-dict-list");
var ldlData = bg.getLinkDictList();
populateDictList(ldl, ldlData);
var ddl = document.getElementById("definition-dict-list");
var ddlData = bg.getDefDictList();
populateDictList(ddl, ddlData);
var ldh = document.getElementById("link-dict-hint");
ldh.style.width = (ldl.offsetWidth > 250 ? ldl.offsetWidth : 250) + "px";
var ddh = document.getElementById("definition-dict-hint");
ddh.style.width = (ddl.offsetWidth > 250 ? ddl.offsetWidth : 250) + "px";
}
function populateDictList(list, data) {
for (var i = 0; i < data.length; i++) {
var datum = data[i];
var dict = bg.dictMap[datum.name];
var checkbox = document.createElement("input");
checkbox.type = "checkbox";
if (datum.status === "enabled") {
checkbox.checked = true;
}
var icon = document.createElement("img");
icon.src = "chrome://favicon/" + dict.iconSrc;
var title = document.createElement("span");
title.textContent = dict.title;
var li = document.createElement("li");
li.setAttribute("class", "dict-list-item");
li.appendChild(checkbox);
li.appendChild(icon);
li.appendChild(title);
list.appendChild(li);
}
}
function save() {
}
function validUrl(url) {
var pattern = /^(https?):\/\/[a-z0-9-]+(\.[a-z0-9-]+)*(:\d+)?\/$/;
return pattern.test(url);
}
function showError(message) {
clearTimeout(window.errorTimeout);
var errorMsg = document.getElementById("errorMsg");
errorMsg.textContent = message;
document.getElementById("error").style.display = "block";
window.errorTimeout = setTimeout(clearError, 3000);
}
function clearError() {
clearTimeout(window.errorTimeout);
document.getElementById("errorMsg").textContent = "";
document.getElementById("error").style.display = "none";
}
function showSavedPrompt() {
var prompt = document.getElementById("saved-prompt");
prompt.style.display = "block";
setTimeout(function() {
prompt.style.display = "none";
}, 3000);
}