forked from phreaknerd/passhash-ng
-
Notifications
You must be signed in to change notification settings - Fork 0
/
options.js
77 lines (69 loc) · 2.89 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
var all_elements;
var hasher_elements;
var storage = browser.storage.sync;
function saveOptions(e) {
var cfg = '';
for(var i = 0, element; element = hasher_elements[i]; i++) {
if(element.checked === true){
cfg += element.value;
}
}
storage.set({
passhashng: {
cfg: cfg,
hint: document.querySelector("#hint").checked == true ? 1 : 0,
fulldomain: document.querySelector("#fulldomain").checked == true ? 1 : 0,
unmasker: document.querySelector("#unmasker").checked == true ? 1 : 0,
fieldmarker: document.querySelector("#fieldmarker").checked == true ? 1 : 0,
fieldmarkerhighlight: document.querySelector("#fieldmarker-highlight").checked == true ? 1 : 0
}
}).then(function(){}, onError);
function onError(error) {
console.log(`Error: ${error}`);
}
}
function restoreOptions() {
function setCurrentChoice(result) {
var num = 16;
if(typeof result.passhashng !== 'undefined') {
if(typeof result.passhashng.cfg !== 'undefined' ) {
num = result.passhashng.cfg.replace( /^\D+/g, '');
var elements = document.querySelectorAll("input.hashersetting");
for(var i = 0, element; element = elements[i]; i++) {
if(typeof element.type !== 'undefined' && element.type == 'radio') {
element.checked = element.value == num ? true : false;
}
else if (typeof element.type !== 'undefined' && element.type == 'checkbox') {
element.checked = result.passhashng.cfg.indexOf(element.value) != -1 ? true: false;
}
}
}
if(typeof result.passhashng.hint !== 'undefined' ) {
document.querySelector("#hint").checked = result.passhashng.hint == 1 ? true : false;
}
if(typeof result.passhashng.fulldomain !== 'undefined' ) {
document.querySelector("#fulldomain").checked = result.passhashng.fulldomain == 1 ? true : false;
}
if(typeof result.passhashng.fieldmarker !== 'undefined' ) {
document.querySelector("#fieldmarker").checked = result.passhashng.fieldmarker == 1 ? true : false;
}
if(typeof result.passhashng.fieldmarkerhighlight !== 'undefined' ) {
document.querySelector("#fieldmarker-highlight").checked = result.passhashng.fieldmarkerhighlight == 1 ? true : false;
}
if(typeof result.passhashng.unmasker !== 'undefined' ) {
document.querySelector("#unmasker").checked = result.passhashng.unmasker == 1 ? true : false;
}
}
}
function onError(error) {
console.log(`Error: ${error}`);
}
var getting = storage.get("passhashng");
getting.then(setCurrentChoice, onError);
}
document.addEventListener("DOMContentLoaded", restoreOptions);
all_elements = document.querySelectorAll("input");
hasher_elements = document.querySelectorAll("input.hashersetting");
for(var i = 0, element; element = all_elements[i]; i++) {
element.addEventListener("click", saveOptions);
}