Digikala Loader Fix

Fixes loading bug on Digikala.com

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.

(У мене вже є менеджер скриптів, дайте мені встановити його!)

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         Digikala Loader Fix
// @namespace    *digikala.com/*
// @version      0.2
// @description  Fixes loading bug on Digikala.com
// @author       Alireza Ahmadi
// @include        *digikala.com/*
// @icon         data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
// @grant        none
// ==/UserScript==
function withRetry(job, maxDuration) {
  function retry(retryCount) {
    const delay = 2 ** retryCount
    if (delay > maxDuration) {
      return;
    }
    setTimeout(() => {
      job(retry.bind(null, retryCount + 1));
    }, delay);
  }

  job(retry.bind(null, 0));
}

(function () {
  "use strict";

  Framework.hideLoader = function () {
    setTimeout(function () {
      if ($('[data-remodal-id="loader"]').length) {
        withRetry((retry) => {
          const modal = $('[data-remodal-id="loader"]').remodal();
          if (modal.getState() === "opening") {
            retry();
          } else {
            modal.close();
          }
        }, 2500);
      }
    }, 500);
  };
})();