-
Notifications
You must be signed in to change notification settings - Fork 1
/
options.js
83 lines (64 loc) · 1.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
// Saves options to chrome.storage
var defaultuser = "";
function save_options() {
var val = user.value;
val = val.trim();
console.log('val '+val);
var status = document.getElementById('status');
status.textContent = '';
var flg =0;
chrome.runtime.sendMessage({
method: 'POST',
action: 'xhttp',
usern: val,
// username: 'webmasteradi',
}, function(responseText) {
// console.log(responseText);
console.log("true");
flg = checkUser((responseText));
setUser(flg,val,status);
});
console.log("flg 2 "+flg);
}
function restore_options() {
}
function checkUser(text) {
var obj = JSON.parse(text);
// console.log(obj);
console.log("valid : "+obj.status);
if(obj.status == "OK") {
return true;
}
else {
return false;
}
}
function setUser(flg,val,status){
if(flg){
chrome.storage.sync.set({
"username": val
}, function() {
// Update status to let user know options were saved.
if (chrome.runtime.error) {
console.log("Runtime error.");
status.textContent = 'Sorry options cannot be saved now.';
}
else {
status.textContent = 'Options saved.';
console.log('saved',val);
// // message('Settings saved');
// setTimeout(function() {
// status.textContent = '';
// }, 750);
}
});
}
else{
console.log('Error: Invalid username');
status.textContent = 'Invalid username entered';
// return;
}
}
// document.addEventListener('DOMContentLoaded', restore_options);
document.getElementById('save').addEventListener('click',
save_options);