-
Notifications
You must be signed in to change notification settings - Fork 0
/
options.js
85 lines (64 loc) · 3.04 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
/*function langChangeHandler() {
if (document.getElementById('language').value != "en" && !document.getElementById('autolanguage').checked) {
document.getElementById('models').disabled = true;
} else {
document.getElementById('models').disabled = false;
}
}*/
function accuracyChangeHandler() {
document.getElementById('accuracyText').textContent = String(document.getElementById('accuracy').value) + "%";
}
function saveOptions() {
var bkg = chrome.extension.getBackgroundPage();
bkg.OCR = document.getElementById('text').checked;
//bkg.MODELS = document.getElementById('models').checked;
bkg.PRIVATE = document.getElementById('private').checked;
bkg.AUTO_LANGUAGE = document.getElementById('autolanguage').checked;
bkg.API_KEY = document.getElementById('key').value;
bkg.OCR_API_KEY = document.getElementById('ocrkey').value;
bkg.LANGUAGE = document.getElementById('language').value;
bkg.ACCURACY = document.getElementById('accuracy').value;
bkg.updateClarifaiCredentials();
chrome.storage.sync.set({
apikey : bkg.API_KEY,
ocrkey : bkg.OCR_API_KEY,
ocr : bkg.OCR,
//models : bkg.MODELS,
private : bkg.PRIVATE,
autolang : bkg.AUTO_LANGUAGE,
lang : bkg.LANGUAGE,
accuracy : bkg.ACCURACY
}, function() {
console.log("options saved");
window.close();
});
}
function restoreOptions() {
var bkg = chrome.extension.getBackgroundPage();
document.getElementById('text').checked = bkg.OCR;
//document.getElementById('models').checked = bkg.MODELS;
document.getElementById('private').checked = bkg.PRIVATE;
document.getElementById('autolanguage').checked = bkg.AUTO_LANGUAGE;
document.getElementById('key').value = bkg.API_KEY;
document.getElementById('ocrkey').value = bkg.OCR_API_KEY;
document.getElementById('language').value = bkg.LANGUAGE;
document.getElementById('accuracy').value = bkg.ACCURACY;
document.getElementById('accuracyText').textContent = String(bkg.ACCURACY) + "%";
//langChangeHandler();
}
function defaults() {
var bkg = chrome.extension.getBackgroundPage();
bkg.OCR = false;
bkg.MODELS = false;
bkg.PRIVATE = false;
bkg.AUTO_LANGUAGE = false;
bkg.LANGUAGE = 'en';
bkg.ACCURACY = 95;
restoreOptions();
}
//document.getElementById('language').addEventListener("change", langChangeHandler);
//document.getElementById('autolanguage').addEventListener("change", langChangeHandler);
document.getElementById('accuracy').addEventListener("input", accuracyChangeHandler);
document.addEventListener('DOMContentLoaded', restoreOptions);
document.getElementById('save').addEventListener('click', saveOptions);
document.getElementById('restore').addEventListener('click', defaults);