Oslo police station appointment script

Auto-click with countdown timer, availability alert, and sound

  1. // ==UserScript==
  2. // @name Oslo police station appointment script
  3. // @namespace http://tampermonkey.net/
  4. // @version 2024-09-23
  5. // @description Auto-click with countdown timer, availability alert, and sound
  6. // @author bipboup
  7. // @match https://politietbooking.nemo-q.se/Booking/Booking/Index/avtale
  8. // @grant none
  9. // @license MIT
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. 'use strict';
  14.  
  15. const timerDisplay = document.createElement('div');
  16. timerDisplay.style.position = 'fixed';
  17. timerDisplay.style.top = '10px';
  18. timerDisplay.style.right = '10px';
  19. timerDisplay.style.padding = '10px';
  20. timerDisplay.style.backgroundColor = 'rgba(0, 0, 0, 0.5)';
  21. timerDisplay.style.color = 'white';
  22. timerDisplay.style.fontSize = '20px';
  23. document.body.appendChild(timerDisplay);
  24.  
  25. let timeLeft = 10;
  26.  
  27. function playAlertSound() {
  28. const audio = new Audio('https://www.soundjay.com/buttons/sounds/button-1.mp3');
  29. let playCount = 0;
  30.  
  31. function playSound() {
  32. if (playCount < 3) {
  33. audio.play();
  34. playCount++;
  35. audio.onended = playSound;
  36. }
  37. }
  38. playSound();
  39. }
  40.  
  41. function checkAvailability() {
  42. const noAppointmentText = "Unfortunately, there are no available appointments at the moment. Please try again later or contact the police.";
  43. const pageContent = document.body.innerText || document.body.textContent;
  44.  
  45. if (!pageContent.includes(noAppointmentText)) {
  46. playAlertSound();
  47. }
  48. }
  49.  
  50. const countdown = setInterval(() => {
  51. if (timeLeft > 0) {
  52. timerDisplay.innerText = `Clic dans ${timeLeft} secondes...`;
  53. timeLeft--;
  54. } else {
  55. timeLeft = 10;
  56.  
  57. const bouton = document.querySelector('input[name="TimeSearchFirstAvailableButton"]');
  58. if (bouton) {
  59. bouton.click();
  60. }
  61.  
  62. checkAvailability();
  63. }
  64. }, 1000);
  65. })();