Handle TimeOut - @KMKnation

Run a continuous interval on a specific webpage

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         Handle TimeOut - @KMKnation
// @namespace    mayurkanojiya
// @version      1.0
// @description  Run a continuous interval on a specific webpage
// @match        https://in.bookmyshow.com/sports/winner-of-semi-final-1-vs-winner-of-semi-final-2/seat-layout/aerialcanvas/ET00367598/SPSM/10068?groupEventCode=ET00367203
// @grant        none
// ==/UserScript==

(function() {
  'use strict';

  function myFunction() {
    console.log("@KMKnation - Mayur Kanojiya Script is running...");
    let hour = new Date().getHours();
    if (hour < 20){
        console.log("Going to refresh on same page after 10 seconds");
        setTimeout(() => {
            window.location = window.location.href;
        }, 1000);

    }else{
        console.log("Not going to refresh after 8 PM");
    }
  }
  

  const interval = setInterval(myFunction, 9000); // 1000ms = 1 second
  localStorage.setItem('myInterval', interval);

  window.addEventListener('beforeunload', function() {
      const storedInterval = localStorage.getItem('myInterval');
      if (storedInterval) {
          clearInterval(parseInt(storedInterval));
      }
  });
})();