Greasy Fork 支持 简体中文。

Wolt Open Notifier

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

目前為 2021-12-01 提交的版本,檢視 最新版本

  1. // ==UserScript==
  2. // @name Wolt Open Notifier
  3. // @namespace Violentmonkey Scripts
  4. // @match https://wolt.com/*
  5. // @grant none
  6. // @version 1.3
  7. // @author -
  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 = 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. });
  53.  
  54. button.innerText = 'תודיעו לי כשפתוח';
  55.  
  56. document.body.appendChild(button);
  57.  
  58. function handleClick() {
  59. if (Notification.permission === 'denied') {
  60. alert('Could not show notifications :(');
  61. return;
  62. }
  63.  
  64. button.removeEventListener('click', handleClick);
  65.  
  66. if (Notification.permission === 'granted') {
  67. startWatcher();
  68. return;
  69. }
  70.  
  71. Notification.requestPermission().then(function (permission) {
  72. if (permission !== 'granted') {
  73. return;
  74. }
  75.  
  76. startWatcher();
  77. });
  78. }
  79.  
  80. button.addEventListener('click', handleClick);
  81. });