Clean up JS code
All checks were successful
continuous-integration/drone/tag Build is passing

This commit is contained in:
Han Dai 2020-03-30 13:05:23 -04:00
parent 357871793c
commit 5a789fe06e

View File

@ -1,25 +1,26 @@
window.onload=function(){ window.onload=function(){
var activationCode; var activationCode;
var $ = function(name) { return document.getElementsByName(name)[0]; };
var form = document.getElementById('settings'); var form = document.getElementById('settings');
form.addEventListener("submit", processForm); form.addEventListener("submit", processForm);
chrome.storage.sync.get(["alias", "pin", "activationCode", "key", "counter"], function(result) { chrome.storage.sync.get(["alias", "pin", "activationCode", "key", "counter"], function(result) {
if(result.alias) document.getElementsByName("alias")[0].value = result.alias; if(result.alias) $("alias").value = result.alias;
if(result.pin) document.getElementsByName("pin")[0].value = result.pin; if(result.pin) $("pin").value = result.pin;
if(result.activationCode) document.getElementsByName("activationCode")[0].value = activationCode = result.activationCode; if(result.activationCode) $("activationCode").value = activationCode = result.activationCode;
if(result.key) document.getElementsByName("key")[0].value = result.key; if(result.key) $("key").value = result.key;
if(result.counter) document.getElementsByName("counter")[0].value = result.counter; if(result.counter) $("counter").value = result.counter;
}); });
function processForm(e) { function processForm(e) {
e.preventDefault(); e.preventDefault();
chrome.storage.sync.set({ "alias": document.getElementsByName("alias")[0].value, chrome.storage.sync.set({ "alias": $("alias").value,
"pin": document.getElementsByName("pin")[0].value, "pin": $("pin").value,
"activationCode": document.getElementsByName("activationCode")[0].value, "activationCode": $("activationCode").value,
"key": document.getElementsByName("key")[0].value, "key": $("key").value,
"counter": document.getElementsByName("counter")[0].value "counter": $("counter").value
}, function() { }, function() {
if(activationCode != document.getElementsByName("activationCode")[0].value){ if(activationCode != $("activationCode").value){
activateDuoMobile(document.getElementsByName("activationCode")[0].value); activateDuoMobile($("activationCode").value);
}else{ }else{
alert("SAVED!"); alert("SAVED!");
} }