const DEFAULT_USER = "defaultUser"; const DEFAULT_SESSION = "defaultSession"; const DEFAULT_WALLPAPPER = "defaultWallpapper"; const WALLPAPPER_ELEMENT = "wallpappers"; function togglePasswordVisibility() { var passwd = document.getElementById("password"); var eye = document.getElementById("eye"); if (passwd.type === "password") { passwd.type = "text"; eye.src = "images/eye2.png" } else { passwd.type = "password"; eye.src = "images/eye.png" } } function updateDefaults(user, session) { localStorage.setItem(DEFAULT_USER, user) localStorage.setItem(DEFAULT_SESSION, session) var wallpapper = document.getElementById(WALLPAPPER_ELEMENT).value if(wallpapper) { localStorage.setItem(DEFAULT_WALLPAPPER, wallpapper) } } function dateFormat(date) { var parts=date.split('.'); var options = { weekday: 'long', month: 'long', day: 'numeric' }; var today = new Date('20' + parts[2], parts[1] - 1, parts[0]); return today.toLocaleDateString("ru-RU", options); // Saturday, September 17 //return `${parts[2]}, ${parts[1]} - 1, ${parts[0]}` } function selectItemByValue(elmnt, value){ for(var i=0; i < elmnt.options.length; i++) { if(elmnt.options[i].value === value) { elmnt.selectedIndex = i; break; } } } function doLogin() { event.preventDefault(); var user = document.getElementById("user").textContent var password = document.getElementById("password").value var session = document.getElementById("sessions").value if (!user || !password || !session) { return false; } lightdm.cancel_authentication() lightdm.show_prompt.connect((text, type) => { lightdm.respond(password); }) lightdm.authentication_complete.connect(() => { lightdm.start_session(session); }) updateDefaults(user, session); lightdm.authenticate(user) return false; } function updateUser(username) { document.getElementById("user-image").src = 'images/default_face.png' document.getElementById("user").textContent = username theme_utils.dirlist(`/var/lib/lightdm-data/${username}`, true, (images) => { if(images) { for (let i = 0; i < images.length; i++) { let image = images[i] if(image.indexOf("/face.png") == image.length - 9) { document.getElementById("user-image").src = image return; } } } }); } function updateWallpapper(wallpapper) { var body = document.getElementsByTagName('body')[0]; body.style.backgroundImage = `url(wallpappers/${wallpapper})`; } function initGreeter() { let users = lightdm.users let defaultUser = localStorage.getItem(DEFAULT_USER) || users[0].username; updateUser(defaultUser); let select = document.getElementById('user-dropdown-content') for (let i = 0; i < users.length; i++) { var btn = document.createElement('button') btn.innerHTML = users[i].username btn.addEventListener("click", () => { updateUser(users[i].username) }) select.appendChild(btn) } const wallpappers = document.getElementById(WALLPAPPER_ELEMENT); wallpappers.addEventListener('change', (event) => { updateWallpapper(event.target.value); }); let defaultWallpapper = localStorage.getItem(DEFAULT_WALLPAPPER); if(defaultWallpapper) { selectItemByValue(wallpappers, defaultWallpapper); updateWallpapper(defaultWallpapper); } let sessions = lightdm.sessions let defaultSession = localStorage.getItem(DEFAULT_SESSION) || sessions[0].key; let sessionsSelect = document.getElementById('sessions') for (let i = 0; i < sessions.length; i++) { var opt = document.createElement('option') opt.innerHTML = sessions[i].key opt.value = sessions[i].key if(defaultSession == sessions[i].key) { opt.selected = true } sessionsSelect.appendChild(opt) } sessionsSelect.value = defaultSession; document.getElementById("date").textContent=dateFormat(theme_utils.get_current_localized_date()); document.getElementById("time").textContent=theme_utils.get_current_localized_time(); } window.addEventListener("GreeterReady", initGreeter)