1 | /* eslint-env browser, jquery */ |
||
2 | |||
3 | // Saves options to localStorage. |
||
4 | function save_options() { |
||
5 | var $useMaildrop = $("#use-maildrop"); |
||
6 | var $address = $("#maildrop-address"); |
||
7 | |||
8 | $address.val($address.val().replace(/^\s*/, '').replace(/\s*$/, '')); |
||
9 | var address = $address.val(); |
||
10 | var isAddressValid = address.match(/^[a-z\.-_]+$/i); |
||
11 | |||
12 | if (isAddressValid) { |
||
13 | $address.removeClass("invalid"); |
||
14 | localStorage.address = address; |
||
0 ignored issues
–
show
|
|||
15 | } else { |
||
16 | $useMaildrop.prop("checked", false); |
||
17 | $address.addClass("invalid"); |
||
18 | localStorage.sender = "app"; |
||
19 | } |
||
20 | |||
21 | console.log("%s is %s", address, isAddressValid ? "valid" : "invalid"); |
||
0 ignored issues
–
show
|
|||
22 | |||
23 | var isMailDropEnabled = $useMaildrop.prop("checked"); |
||
24 | localStorage.sender = (isMailDropEnabled && isAddressValid) ? "maildrop" : "app"; |
||
25 | |||
26 | // Update status to let user know options were saved. |
||
27 | show_status("Options saved."); |
||
28 | } |
||
29 | |||
30 | // Restores select box state to saved value from localStorage. |
||
31 | function restore_options() { |
||
32 | document.getElementById("use-maildrop").checked = (localStorage.sender === "maildrop"); |
||
0 ignored issues
–
show
The variable
localStorage seems to be never declared. If this is a global, consider adding a /** global: localStorage */ comment.
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed. To learn more about declaring variables in Javascript, see the MDN. ![]() |
|||
33 | document.getElementById("maildrop-address").value = localStorage.address || ""; |
||
34 | } |
||
35 | |||
36 | function reset_options() { |
||
37 | document.getElementById("maildrop-address").value = ""; |
||
38 | document.getElementById("use-maildrop").checked = false; |
||
39 | save_options(); |
||
40 | } |
||
41 | |||
42 | function show_status(message) { |
||
43 | var $status = document.getElementById("status"); |
||
44 | $status.innerHTML = message; |
||
45 | setTimeout(function () { |
||
46 | $status.innerHTML = ""; |
||
47 | }, 1750); |
||
48 | } |
||
49 | |||
50 | document.addEventListener('DOMContentLoaded', restore_options); |
||
51 | document.querySelector('#save').addEventListener('click', save_options); |
||
52 | document.querySelector('#reset').addEventListener('click', reset_options); |
||
53 |
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.
To learn more about declaring variables in Javascript, see the MDN.