You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Magister-Auto-Login/js/save.js

92 lines
2.2 KiB

5 years ago
const d = document.getElementById.bind(document);
const qAll = document.querySelectorAll.bind(document);
d("save").addEventListener("click", save);
qAll(".login").forEach(s => {
s.addEventListener("keydown", e => {
if (e.key == "Enter") {
if (e.target.id == "school") {
d("number").focus()
};
5 years ago
if (e.target.id == "number") {
d("password").focus()
};
if (e.target.id == "password") {
save()
};
}
});
});
function save() {
var school = d("school").value;
5 years ago
var number = d("number").value;
var password = d("password").value;
try {
chrome.storage.sync.set({
"school": school,
5 years ago
"number": number,
"password": password
});
4 years ago
d("save").innerHTML = "Opgeslagen!"
5 years ago
} catch (e) {
4 years ago
d("save").innerHTML = "Fout"
5 years ago
d("save").className = "btn btn-danger float-right"
}
};
function onLoad() {
chrome.storage.sync.get(['school', 'number', 'password'], function (result) {
if (result.school !== undefined) {
d("school").value = result.school
};
5 years ago
if (result.number !== undefined){
d("number").value = result.number
};
if (result.password !== undefined) {
d("password").value = result.password
};
});
chrome.storage.sync.get(['enabled'], function (result) {
d("switch").checked = result.enabled
});
chrome.storage.sync.get(['darkmode'], function (result) {
d("dark-mode").checked = result.darkmode
4 years ago
d("dark-link").disabled = !d("dark-mode").checked
5 years ago
});
d("switch").addEventListener("click", toggle)
d("dark-mode").addEventListener("click", darkMode)
};
function toggle() {
var checked = d("switch").checked;
chrome.storage.sync.set({
"enabled": checked
});
chrome.browserAction.setBadgeText({
text: checked ? "ON" : "OFF"
});
};
function darkMode() {
chrome.storage.sync.set({
"darkmode": d("dark-mode").checked
});
4 years ago
d("dark-link").disabled = !d("dark-mode").checked
5 years ago
}
onLoad()