Auto logout + keyboard shortcut

  • 22 March 2023
  • 6 replies
  • 218 views

Userlevel 3

Hi everyone, 

 

We have a reception desk with 2 computers and multiple people who use them and nobody was logging out of their mews account, so the first person who logged into mews that morning had every action on their name. What I did is create a code that loges out every x minutes and adds a keyboard shortcut Ctrl + L 

 

I thought I could be handy for more smaller hotels who have multiple employees sharing one pc. 

 

 

You can run it in Google Chrome using a JS extension like: https://chrome.google.com/webstore/detail/run-javascript/lmilalhkkdhfieeienjbiicclobibjao

// Set the desired logout time in minutes
const LogoutMinutes = 15;
// Calculate the logout time in milliseconds (1 minute = 60000 milliseconds)
const LogoutTime = LogoutMinutes * 60000;
// Initialize the timer variable
let timer = null;

// Add an event listener for 'keydown' events
document.addEventListener('keydown', e => {
// Reset the timer on any key press
resetTimer();
// If 'Control' key is held down and the 'l' key is pressed, log out
if (e.ctrlKey && e.key === 'l') {
// Prevent the default behavior of the 'l' key
e.preventDefault();
// Call the logout function
logout();
}
}, false);

// Add an event listener for 'mousemove' events
document.addEventListener('mousemove', () => {
// Reset the timer on any mouse movement
resetTimer();
}, false);

// Define the logout function
function logout() {
// Click the user avatar
const avatar = document.querySelector('[data-test-id="user-menu-avatar"]');
avatar.click();
// Click the "Lock Account" option after a short delay
setTimeout(() => document.querySelector('[value="Lock Account"]').click(), 100);
}

// Define the resetTimer function
function resetTimer(newT = LogoutTime) {
// Clear the existing timer
clearTimeout(timer);
// Set a new timer with the specified timeout
timer = setTimeout(logout, newT);
}

// Call resetTimer to start the initial timer
resetTimer();

 


6 replies

Userlevel 6
Badge +6

Nice one @Dirkjan, this is great. 

We’ve considered doing this across our group. I’ll be looking to see if we can implement it by way of group policy. 

Thank you for sharing!

Userlevel 2
Badge

Thank you Dirkjan, such amazing recommendations are exactly why we started our community. Really love how you solved this challenge. 

Userlevel 1
Badge

This is such an awesome solution, Dirkjan! 🤩 Thank you so much for sharing it with the community. 
 
Would you mind terribly if our Mews Support Team documented your recommendation in our public help center? We would, of course, give you all the credit for your hard work! 💪🏽

Userlevel 3

@wendy.batkova No problem at all. 
Would be even better if you implemented it directly into Mews. It would take me literally less than 5 minutes. 🤷🏻

I have a ton of small improvements that I could implement within a day if I could get into the room with one of the developers. 

  1. Sortable tables 
  2. auto export to PDF, plain email or print
  3. showing ‘confirmed’ availability blocks in the timeline
  4. Be able to set a total price including products etc. 
Userlevel 6
Badge +2

Hey @Dirkjan Thanks for the input. 💚 We’re always striving to make Mews the best it can be and we have more exciting features in the pipeline. I can see you’ve voted on these improvements that you’ve mentioned in our Feature Request site so stay tuned for updates from the product team. 
We’re working on introducing more community-led product discussions too so when we plan to have the next one, I’ll be sure to let you know. 

Userlevel 3
Badge +1

Hi there! Great script and great idea, ideed!
There might have been an update in the meantime, so the script above does not work for me any more, because the DOM identifier of the lock session element has changed.
However, it’s easy to amend, just
replace

setTimeout(() => document.querySelector('[value="Lock Account"]').click(), 100);

with

setTimeout(() => document.querySelector('[data-test-textkey="LockSession"]').click(), 100);

:-)

BTW: in Firefox the https://addons.mozilla.org/en-US/firefox/addon/violentmonkey add-on is available, for example, but it’s a beta-version, so take care ;-)

Reply