Wolt Open Notifier

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

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name        Wolt Open Notifier
// @namespace   Violentmonkey Scripts
// @match       https://wolt.com/*
// @grant       none
// @version     1.4
// @author      dutzi
// @license     MIT
// @description This will notify you when a restaurant is open for delivery.
// ==/UserScript==

async function checkIfOpen() {
  const id = window.location.pathname.split('/').pop();
  return fetch(`https://restaurant-api.wolt.com/v3/venues/slug/${id}`)
    .then((res) => res.json())
    .then((res) => {
      return res.results[0].delivery_specs.delivery_enabled && res.results[0].online;
    });
}

checkIfOpen().then((isOpen) => {
  if (isOpen) {
    return;
  }

  const id = window.location.pathname.split('/').pop();

  const button = document.createElement('button');

  function startWatcher() {
    button.innerText = 'סבבה, נודיע!';

    const interval = setInterval(async () => {
      const isOpen = await checkIfOpen();
      if (isOpen) {
        new Notification(`${id} is open!`);
        clearInterval(interval);
      }
    }, 1000);
  }

  Object.assign(button.style, {
    position: 'fixed',
    top: '1rem',
    left: '1rem',
    padding: '1rem 2rem',
    fontFamily: 'inherit',
    fontSize: 'inherit',
    fontWeight: 'inherit',
    background: '#000',
    color: '#fff',
    direction: 'rtl'
  });

  button.innerText = 'תודיעו לי כשפתוח';

  document.body.appendChild(button);

  function handleClick() {
    if (Notification.permission === 'denied') {
      alert('Could not show notifications :(');
      return;
    }

    button.removeEventListener('click', handleClick);

    if (Notification.permission === 'granted') {
      startWatcher();
      return;
    }

    Notification.requestPermission().then(function (permission) {
      if (permission !== 'granted') {
        return;
      }

      startWatcher();
    });
  }

  button.addEventListener('click', handleClick);
});