Xbox-Now.com

Just go on the page, and press ARROW UP

K instalaci tototo skriptu si budete muset nainstalovat rozšíření jako Tampermonkey, Greasemonkey nebo Violentmonkey.

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

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Userscripts.

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

K instalaci tohoto skriptu si budete muset nainstalovat manažer uživatelských skriptů.

(Už mám manažer uživatelských skriptů, nechte mě ho nainstalovat!)

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.

(Už mám manažer uživatelských stylů, nechte mě ho nainstalovat!)

// ==UserScript==
// @name         Xbox-Now.com
// @namespace    XN	
// @version      1.0
// @description  Just go on the page, and press ARROW UP
// @author       XN
// @match        https://www.microsoft.com/*/p/*
// @require      https://openuserjs.org/src/libs/sizzle/GM_config.js
// @grant       GM_notification
// @grant       window.focus
// ==/UserScript==

(function() {
  'use strict';

  var flagAutobuy = false;
  var flagNextButtonClicked = false;

  var timeRefresh = 200;

  $(window).keydown(function(event) {
      if (event.which == 38) startAutoBuy();
      else if (event.which == 40) stopAutoBuy();
  });


  $("body").bind('DOMNodeInserted', function(event) {
    if (flagAutobuy)
    {
      if ($(event.target).attr('id') == 'wb_auto_blend_container')
      {
        flagNextButtonClicked = false;

        goClickConfirmButton();
      }
    }
  });

  function goClickConfirmButton()
  {
    if ($('#wb_auto_blend_container').contents().find('#confirmButton').length > 0)
    {
      $('#wb_auto_blend_container').contents().find('#confirmButton').click();
      checkNextButton();
    }
    else
    {
      setTimeout(goClickConfirmButton, timeRefresh);
    }
  }

  function checkNextButton()
  {
    if ($('#wb_auto_blend_container').contents().find('.cli_errorCode').length > 0 &&
      $('#wb_auto_blend_container').contents().find('.cli_errorCode').text() == 'PUR-UserAlreadyOwnsContent')
    {
      flagAutobuy = false;
      GM_notification({
        text: 'BUY OK',
        title: "Xbox-Now.com",
        onclick: function() { window.focus(); },
      });
    }
    else
    {
      if ($('#wb_auto_blend_container').contents().find('#cancelButton').length > 0)
      {
        $('#wb_auto_blend_container').contents().find('#cancelButton').click();
        goClickBuyButton();

        flagNextButtonClicked = true;
        setTimeout(checkNextButton, timeRefresh);
      }
      else
      {
        if (flagNextButtonClicked == false)
        {
          setTimeout(checkNextButton, timeRefresh);
        }
        else
        {
          goClickBuyButton();
        }
      }
    }

  }




  function checkNextButton2()
  {
    if ($('#wb_auto_blend_container').contents().find('#cancelButton').length > 0)
    {
      $('#wb_auto_blend_container').contents().find('#cancelButton').click();
      goClickBuyButton();

      flagNextButtonClicked = true;
      setTimeout(checkNextButton, timeRefresh);
    }
    if ($('#wb_auto_blend_container').contents().find('#cli_errorCode').length > 0 &&
      $('#wb_auto_blend_container').contents().find('#cli_errorCode').text() == 'PUR-UserAlreadyOwnsContent')
    {
      flagAutobuy = false;
      GM_notification({
        text: 'BUY OK',
        title: "Xbox-Now.com",
        onclick: function() { window.focus(); },
      });
    }
    else
    {
      if (flagNextButtonClicked == false)
      {
        setTimeout(checkNextButton, timeRefresh);
      }
      else
      {
        goClickBuyButton();
      }
    }
  }

  function goClickBuyButton()
  {
    if ($('body').find('#buttonPanel_AppIdentityBuyButton').length > 0)
    {
      $('body').find('#buttonPanel_AppIdentityBuyButton').click();
    }
  }

  function startAutoBuy()
  {
    flagAutobuy = true;
    GM_notification({
      text: 'Autobuyer enabled',
      title: "Xbox-Now.com",
      onclick: function() { window.focus(); },
    });
  }

  function stopAutoBuy()
  {
    flagAutobuy = false;
    GM_notification({
      text: 'Autobuyer disabled',
      title: "Xbox-Now.com",
      onclick: function() { window.focus(); },
    });
  }


})();