Advertisement
Guest User

Untitled

a guest
Apr 5th, 2020
196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function checkTimes() {
  2.   // fetch("https://barbora.lt/api/eshop/v1/cart/deliveries", {
  3.   //   credentials: "include",
  4.   //   headers: {
  5.  
  6.   //   },
  7.   //   referrer: "https://barbora.lt/",
  8.   //   referrerPolicy: "no-referrer-when-downgrade",
  9.   //   body: null,
  10.   //   method: "GET",
  11.   //   mode: "cors"
  12.   // })
  13.   //>> COPY PASTER FECH REQUEST FOR api/eshop/v1/cart/deliveries HERE
  14.  
  15.  
  16.  
  17.   //<< COPY PASTER FECH REQUEST FOR api/eshop/v1/cart/deliveries HERE
  18.     .then(r => r.json())
  19.     .then(r => {
  20.       const timeStamp = new Date()
  21.         .toISOString()
  22.         .slice(0, 19)
  23.         .replace("T", " ");
  24.  
  25.       const days = r.deliveries[0].params.matrix;
  26.       let availableDelivery = null;
  27.  
  28.       for (let i = 0; i < days.length; i++) {
  29.         const day = days[i];
  30.         const available = day.hours.filter(h => h.available);
  31.         if (available.length) {
  32.           availableDelivery = available[0];
  33.           break;
  34.         }
  35.       }
  36.  
  37.       if (availableDelivery) {
  38.         console.log(timeStamp);
  39.         console.log(availableDelivery);
  40.         window.open("https://www.youtube.com/watch?v=PvncVl6jbbw", "_blank");
  41.       } else {
  42.         console.log(timeStamp + ": no times");
  43.       }
  44.     });
  45. }
  46.  
  47. setInterval(checkTimes, 10000);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement