Wolt Open Notifier

This will notify you when a restaurant is open for delivery.

  1. // ==UserScript==
  2. // @name Wolt Open Notifier
  3. // @namespace Violentmonkey Scripts
  4. // @match https://wolt.com/*
  5. // @grant none
  6. // @version 1.4
  7. // @author dutzi
  8. // @license MIT
  9. // @description This will notify you when a restaurant is open for delivery.
  10. // ==/UserScript==
  11.  
  12. async function checkIfOpen() {
  13. const id = window.location.pathname.split('/').pop();
  14. return fetch(`https://restaurant-api.wolt.com/v3/venues/slug/${id}`)
  15. .then((res) => res.json())
  16. .then((res) => {
  17. return res.results[0].delivery_specs.delivery_enabled && res.results[0].online;
  18. });
  19. }
  20.  
  21. checkIfOpen().then((isOpen) => {
  22. if (isOpen) {
  23. return;
  24. }
  25.  
  26. const id = window.location.pathname.split('/').pop();
  27.  
  28. const button = document.createElement('button');
  29.  
  30. function startWatcher() {
  31. button.innerText = 'סבבה, נודיע!';
  32.  
  33. const interval = setInterval(async () => {
  34. const isOpen = await checkIfOpen();
  35. if (isOpen) {
  36. new Notification(`${id} is open!`);
  37. clearInterval(interval);
  38. }
  39. }, 1000);
  40. }
  41.  
  42. Object.assign(button.style, {
  43. position: 'fixed',
  44. top: '1rem',
  45. left: '1rem',
  46. padding: '1rem 2rem',
  47. fontFamily: 'inherit',
  48. fontSize: 'inherit',
  49. fontWeight: 'inherit',
  50. background: '#000',
  51. color: '#fff',
  52. direction: 'rtl'
  53. });
  54.  
  55. button.innerText = 'תודיעו לי כשפתוח';
  56.  
  57. document.body.appendChild(button);
  58.  
  59. function handleClick() {
  60. if (Notification.permission === 'denied') {
  61. alert('Could not show notifications :(');
  62. return;
  63. }
  64.  
  65. button.removeEventListener('click', handleClick);
  66.  
  67. if (Notification.permission === 'granted') {
  68. startWatcher();
  69. return;
  70. }
  71.  
  72. Notification.requestPermission().then(function (permission) {
  73. if (permission !== 'granted') {
  74. return;
  75. }
  76.  
  77. startWatcher();
  78. });
  79. }
  80.  
  81. button.addEventListener('click', handleClick);
  82. });