Auto Reload Every X Seconds

Perform auto reload on nocodb table

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

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

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

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

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

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name         Auto Reload Every X Seconds
// @namespace    https://udun.mordorintelligence.com
// @version      0.2
// @description  Perform auto reload on nocodb table
// @author       Rishabh Nishad
// @match        https://udun.mordorintelligence.com/*
// @icon         data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
// @grant        none
// @license      MIT
// ==/UserScript==

const delayToAutoReloadInMilliseconds = 60*1000;
const reloadCSSSelector = 'div.ml-1:nth-child(6) > svg.nc-icon';

setInterval(performReloadClick, delayToAutoReloadInMilliseconds);

async function performReloadClick() {

      if(!/https:\/\/udun\.mordorintelligence\.com\/dashboard\/.*\/.*\/.*\/.*/igm.test(window.location.href)) return;

      await waitForElement(reloadCSSSelector);
      //console.log('Reload icon is ready');

      var divElement = document.querySelector(reloadCSSSelector);

      if(!divElement) return;
      //console.log("divElement",divElement);


        var clickEvent = new Event('click');
        divElement.dispatchEvent(clickEvent);
        //console.log("Clicked Reload");

}




function waitForElement(selector) {
    return new Promise(resolve => {
        if (document.querySelector(selector)) {
            return resolve(document.querySelector(selector));
        }

        const observer = new MutationObserver(mutations => {
            if (document.querySelector(selector)) {
                observer.disconnect();
                resolve(document.querySelector(selector));
            }
        });

        observer.observe(document.body, {
            childList: true,
            subtree: true
        });
    });
}