From 1aeabf1c2840ecee5079fcc122e76406c506a3f6 Mon Sep 17 00:00:00 2001 From: Sebastian Engelhardt Date: Sat, 24 May 2025 20:11:20 +0200 Subject: [PATCH 1/4] Fix creation of closeDate --- .../mensaar-show-next-day-when-closed.user.js | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/userscripts/mensaar-show-next-day-when-closed.user.js b/userscripts/mensaar-show-next-day-when-closed.user.js index ad88306..c86da89 100644 --- a/userscripts/mensaar-show-next-day-when-closed.user.js +++ b/userscripts/mensaar-show-next-day-when-closed.user.js @@ -28,21 +28,11 @@ function switchToNextDay(activeTab) { } let activeTabDate = new Date(tabDate); - let now = new Date(); + let closeDate = new Date(activeTabDate.getTime() + 14.5 * 60 * 60000); // add 14.5 hours for the time 2:30 pm - if (now - activeTabDate <= 0) { - return; - } - - let closeDate = new Date( - activeTabDate.getFullYear(), - activeTabDate.getMonth(), - activeTabDate.getDay(), - 14, - 30, - ); + let now = new Date(); - if (now - closeDate >= 0) { + if (now > closeDate) { activeTab.nextSibling?.click(); } } From 3012c923b95c7c5e571ac0c175027cb4f4c7240d Mon Sep 17 00:00:00 2001 From: Sebastian Engelhardt Date: Wed, 28 May 2025 08:42:04 +0200 Subject: [PATCH 2/4] incorporate earlier closing hours of mensa on Fridays --- .../mensaar-show-next-day-when-closed.user.js | 25 +++++++++++++------ 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/userscripts/mensaar-show-next-day-when-closed.user.js b/userscripts/mensaar-show-next-day-when-closed.user.js index ca89fd0..8907f6a 100644 --- a/userscripts/mensaar-show-next-day-when-closed.user.js +++ b/userscripts/mensaar-show-next-day-when-closed.user.js @@ -28,13 +28,24 @@ function switchToNextDay(activeTab) { } let activeTabDate = new Date(tabDate); - let closeDate = new Date( - activeTabDate.getFullYear(), - activeTabDate.getMonth(), - activeTabDate.getDate(), - 14, - 30, - ); + // mensa closes 15 minutes earlier on Fridays + if (activeTabDate.getDay() == 5) { + let closeDate = new Date( + activeTabDate.getFullYear(), + activeTabDate.getMonth(), + activeTabDate.getDate(), + 14, + 15 + ); + } else { + let closeDate = new Date( + activeTabDate.getFullYear(), + activeTabDate.getMonth(), + activeTabDate.getDate(), + 14, + 30, + ); + } let now = new Date(); if (now > closeDate) { From 3f24c47d0110a114e8e5972e7fbe24d9c0435958 Mon Sep 17 00:00:00 2001 From: Sebastian Engelhardt Date: Thu, 29 May 2025 13:16:33 +0200 Subject: [PATCH 3/4] Fix formatting --- .../mensaar-show-next-day-when-closed.user.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/userscripts/mensaar-show-next-day-when-closed.user.js b/userscripts/mensaar-show-next-day-when-closed.user.js index 8907f6a..eb0800a 100644 --- a/userscripts/mensaar-show-next-day-when-closed.user.js +++ b/userscripts/mensaar-show-next-day-when-closed.user.js @@ -30,15 +30,15 @@ function switchToNextDay(activeTab) { let activeTabDate = new Date(tabDate); // mensa closes 15 minutes earlier on Fridays if (activeTabDate.getDay() == 5) { - let closeDate = new Date( - activeTabDate.getFullYear(), - activeTabDate.getMonth(), - activeTabDate.getDate(), - 14, - 15 - ); + let closeDate = new Date( + activeTabDate.getFullYear(), + activeTabDate.getMonth(), + activeTabDate.getDate(), + 14, + 15, + ); } else { - let closeDate = new Date( + let closeDate = new Date( activeTabDate.getFullYear(), activeTabDate.getMonth(), activeTabDate.getDate(), From 8c391e239eba58e65013b4623e26886b6db252cd Mon Sep 17 00:00:00 2001 From: Sebastian Engelhardt Date: Fri, 30 May 2025 20:44:32 +0200 Subject: [PATCH 4/4] Fix undefined variable closeDate --- .../mensaar-show-next-day-when-closed.user.js | 25 ++++++------------- 1 file changed, 8 insertions(+), 17 deletions(-) diff --git a/userscripts/mensaar-show-next-day-when-closed.user.js b/userscripts/mensaar-show-next-day-when-closed.user.js index eb0800a..8b9527b 100644 --- a/userscripts/mensaar-show-next-day-when-closed.user.js +++ b/userscripts/mensaar-show-next-day-when-closed.user.js @@ -29,23 +29,14 @@ function switchToNextDay(activeTab) { let activeTabDate = new Date(tabDate); // mensa closes 15 minutes earlier on Fridays - if (activeTabDate.getDay() == 5) { - let closeDate = new Date( - activeTabDate.getFullYear(), - activeTabDate.getMonth(), - activeTabDate.getDate(), - 14, - 15, - ); - } else { - let closeDate = new Date( - activeTabDate.getFullYear(), - activeTabDate.getMonth(), - activeTabDate.getDate(), - 14, - 30, - ); - } + let closingMinutes = activeTabDate.getDay() == 5 ? 15 : 30; + let closeDate = new Date( + activeTabDate.getFullYear(), + activeTabDate.getMonth(), + activeTabDate.getDate(), + 14, + closingMinutes, + ); let now = new Date(); if (now > closeDate) {