Skip to main content

Auto logout + keyboard shortcut

  • March 22, 2023
  • 13 replies
  • 604 views

Dirkjan

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();

 

13 replies

Mick
Guru
Forum|alt.badge.img+6
  • Guru
  • March 23, 2023

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!


matthijswelle
Mews Employee
Forum|alt.badge.img
  • Mews Employee
  • March 23, 2023

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


wendy.batkova
Mews Employee
Forum|alt.badge.img
  • Mews Employee
  • March 23, 2023

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! 💪🏽


Dirkjan
  • Author
  • Contributor
  • March 23, 2023

@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. 

Sarah.Masterton-Brown
Mews Employee
Forum|alt.badge.img+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. 


j.spiess
Superstar Guru
Forum|alt.badge.img+3
  • Superstar Guru
  • January 20, 2024

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 ;-)


j.spiess
Superstar Guru
Forum|alt.badge.img+3
  • Superstar Guru
  • May 14, 2024

Hello everybody!

Short update - we are using the tampermonkey browser extension to install the user script. This extension is available accross all browsers.

For the script (see above) we are using the following header:

// ==UserScript==
// @name Lock Session in mews.com
// @match https://app.mews.com/Commander/*
// @grant none
// @version 1.0
// @author -
// @description 20.1.2024, 23:15:48
// @require https://cdn.jsdelivr.net/npm/[email protected]/HackTimer.min.js
// ==/UserScript==

It also loads (@require …. ) the external module HackTimer (https://github.com/turuslan/HackTimer ), which should allow the timer to run also in backgrounded browser tabs. I have not verified that third party module - so use at your own risk and evaluation - but it looks to be rather simple and harmless to me.

Regards,

JP.


j.spiess
Superstar Guru
Forum|alt.badge.img+3
  • Superstar Guru
  • May 16, 2024

For all thos using Chrome - look at the following post by a mews employee (@CharlieDelamare) who made a custom chrom extension that solves that very elegantly.

 


Robin Gustavsson
Senior Guru
Forum|alt.badge.img+2

Hello!

@ Mews team - any plans on implementering this functionality across the board from your end? 


mauritsbots
Superstar Guru
Forum|alt.badge.img+3
  • Superstar Guru
  • April 23, 2025

@CharlieDelamare ​@Rui Oliveira ​could be a nice feature to also have in the (security) privileges; eg that an admin can ‘force’ this on a property level!


Robin Gustavsson
Senior Guru
Forum|alt.badge.img+2

@CharlieDelamare ​@Rui Oliveira ​could be a nice feature to also have in the (security) privileges; eg that an admin can ‘force’ this on a property level!

I 100% agree. Great input!


j.spiess
Superstar Guru
Forum|alt.badge.img+3
  • Superstar Guru
  • April 23, 2025

Hi!

There are feature requests at

https://feedback.mews.com/forums/918232-property-operations-pms/suggestions/48763490-automatic-lock-session

I woud recommend to support them / upvote them.

Kind regards,

JP.


mauritsbots
Superstar Guru
Forum|alt.badge.img+3
  • Superstar Guru
  • April 24, 2025

Yes thats quite a new one.. see also this one - not the same but similar

https://feedback.mews.com/forums/918232-property-operations-pms/suggestions/36659680-automatic-logout-of-users