-
Notifications
You must be signed in to change notification settings - Fork 0
/
options.js
89 lines (71 loc) · 1.95 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
var typeScan = null;
function updateButtons(state){
if (state == 'visit'){
showVisitButton()
}else{
hideVisitButton()
}
}
function saveOptions(e) {
browser.storage.local.set({
analysis: typeScan.value
});
e.preventDefault();
updateButtons(typeScan.value);
}
function restoreOptions() {
var gettingItem = browser.storage.local.get('analysis');
gettingItem.then((res) => {
typeScan.value = res.analysis || 'by_tab';
updateButtons(typeScan.value);
});
}
function localizeHtmlPage()
{
var items = document.getElementsByClassName('translate');
for (let item of items) {
item.innerText = browser.i18n.getMessage(item.id);
}
}
function showVisitButton(){
const file_dialog_visit = document.createElement("INPUT");
file_dialog_visit.id = "fileDialog_path";
file_dialog_visit.type = "file";
file_dialog_visit.accept = ".txt,text/plain"
function message_error(error) {
console.log(`Error: ${error}`);
}
function load_visit_txt(ffile) {
var reader = new FileReader();
reader.onload = function(progressEvent){
var fileContentArray = this.result.split(/\r\n|\n/);
browser.runtime.sendMessage({
type: "visit",
url:fileContentArray
}).then((message) => {
console.log(message)
}, message_error);
};
reader.readAsText(ffile);
}
file_dialog_visit.addEventListener("change", function (evt) {
load_visit_txt(this.files[0]);
this.value = "";
}, false);
var browsing = document.getElementById("browsing");
browsing.appendChild(file_dialog_visit);
}
function hideVisitButton(){
var browsing = document.getElementById("browsing");
while (browsing.firstChild) {
browsing.removeChild(browsing.lastChild);
}
}
document.addEventListener('DOMContentLoaded', function(){
typeScan = document.getElementById("typeScan");
restoreOptions();
localizeHtmlPage();
typeScan.addEventListener("change", saveOptions);
});
function test(){
}