как в этом коде уменьшить кол-во вызовов checkCorruptUrl
  var tmdb_proxy = {
    name: 'TMDB Proxy',
    version: '1.0.1',
    description: 'Проксирование постеров и API сайта TMDB',
    path_image: 'https://apn.ndst.pw/v1?url=https://image.tmdb.org/',
    path_api: 'https://apn.ndst.pw/v1?url=https://api.themoviedb.org/3/',
    stb_path_image: 'https://stream.ndst.pw/tmdb/img/',
    stb_path_api: 'https://apn.ndst.pw/v1?url=https://stream.ndst.pw/tmdb/api/3/'
  };
  var lastApiUrl = null;
  var lastImageUrl = null;
  //https:// - 8
  function filter_url(u, base) {
    var s = u.slice(0, base.length);
    var e = u.slice(base.length).replace(/\/+/g, '/');
    return s + e;
  }
  function checkCorruptUrl(base, url, type) {
    var stb;
    if (type === "api") {
      stb = tmdb_proxy.stb_path_api;
    } else if (type === "img") {
      stb = tmdb_proxy.stb_path_image;
    } else {
      stb = base;
    }
    var chekUrl = base + url;
    var xhrC = new XMLHttpRequest();
    xhrC.open('GET', chekUrl, true);
    xhrC.timeout = 2000;
    xhrC.onreadystatechange = function () {
      if (xhrC.readyState === 4) {
        var finalUrl;
        if (xhrC.status >= 200 && xhrC.status < 300) {
          finalUrl = base;
        } else {
          finalUrl =  stb;
        }
        if (type === "api") {
          lastApiUrl = finalUrl;
        } else if (type === "img") {
          lastImageUrl = finalUrl;
        }
      }
    };
    xhrC.ontimeout = function () {
      if (type === "api") {
        lastApiUrl = stb;
      } else if (type === "img") {
        lastImageUrl = stb;
      }
    };
    xhrC.send();
  }

  Lampa.TMDB.image = function (url) {
    var base = filter_url(tmdb_proxy.stb_path_image + url, tmdb_proxy.stb_path_image);
    if (url.indexOf("kinopoiskapiunofficial.tech") !== -1) {
      return url.replace('t/p/w500/', '');
    }
    checkCorruptUrl(tmdb_proxy.path_image, url, "img");
    return (lastImageUrl ? filter_url(lastImageUrl + url, lastImageUrl) : base)
  };

  Lampa.TMDB.api = function (url) {
    var base = filter_url(tmdb_proxy.stb_path_api + url, tmdb_proxy.stb_path_api);
    if (url.indexOf("apn.ndst.pw") !== -1) {
      var urlStartIndex = url.indexOf('?url=') + '?url='.length;
      var streamUrl = decodeURIComponent(url.substring(urlStartIndex));
      if (streamUrl && streamUrl.indexOf("https://stream.ndst.pw/ndi/aisearch") === 0) {
        var params = streamUrl.split('?')[1];
        if (params) {
          var paramPairs = params.split('&');
          var newParams = [];
          for (var i = 0; i < paramPairs.length; i++) {
            var pair = paramPairs[i];
            var equalIndex = pair.indexOf('=');
            if (equalIndex !== -1) {
              var paramName = decodeURIComponent(pair.substring(0, equalIndex));
              var paramValue = decodeURIComponent(pair.substring(equalIndex + 1));
              if (paramName === 'deviceid' || paramName === 'query') {
                newParams.push(paramName + '=' + paramValue);
              }
            }
          }
          var finalUrl = 'https://apn.ndst.pw/v1?url=https://stream.ndst.pw/ndi/aisearch?' + newParams.join('&');
          return finalUrl;
        }
      }
    }
    checkCorruptUrl(tmdb_proxy.path_api, url, "api");
    return (lastApiUrl ? filter_url(lastApiUrl + url, lastApiUrl) : base)
  };

  Lampa.Settings.listener.follow('open', function (e) {
    if (e.name == 'tmdb') {
      e.body.find('[data-parent="proxy"]').remove();
    }
  });
  console.log('TMDB-Proxy', 'started, enabled:', Lampa.Storage.field('proxy_tmdb'));