-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathadd_to_phonebook.js
57 lines (50 loc) · 1.86 KB
/
add_to_phonebook.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
(function() {
if (localStorage["connectionStatus"] != "signedIn")
chrome.tabs.update({url: chrome.extension.getURL("sign.html")});
var dictionary = storage.get("localization", {});
function main(){
$("#save_btn").click(save_options);
$("#birthday").focus(function() {
this.type = "date";
}).blur(function() {
this.type = "text";
});
localize();
}
function localize(){
$("#title").text(dictionary["pb_title"].message);
$("#info").text(dictionary["info"].message);
$("#first_name").attr("placeholder", dictionary["first_name"].message);
$("#last_name").attr("placeholder", dictionary["last_name"].message);
$("#birthday").attr("placeholder", dictionary["birthday"].message);
$("#phone").attr("placeholder", dictionary["tel"].message);
$("#email").attr("placeholder", dictionary["email"].message);
$("#address").attr("placeholder", dictionary["address"].message);
$("#save_btn").attr("value", dictionary["save"].message);
$("#reset_btn").attr("value", dictionary["reset"].message);
}
function save_options(){
var options = $('form[name=Options]').serializeArray().reduce((obj, item)=>{
obj[item.name] = item.value;
return obj;
}, {type: "PHONE_BOOK_ADD_ENTRY"});
!(options.name || options.last_name)? showMessage(true, "Name required"):
!options.phone? showMessage(true, "Phone required"):
chrome.runtime.sendMessage(options, (e)=>{
showMessage(e);
$("#first_name").val("");
$("#last_name").val("");
$("#birthday").val("");
$("#phone").val("");
$("#email").val("");
$("#address").val("");
});
}
function showMessage(is_error, text) {
$("#error_msg2").text(text || dictionary[ is_error?"failed":"success" ].message);
$("#error_msg2")[0].style.color = is_error? "red": "green";
$("#error_msg2").fadeIn();
$("#error_msg2").fadeOut(5000);
}
document.addEventListener("DOMContentLoaded", main);
})();