Greasy Fork is available in English.

Microsoft Store Direct Download

Adds direct download links to Microsoft Store when browsing apps.

// ==UserScript==
// @name     Microsoft Store Direct Download
// @namespace    StephenP
// @version  1.0.1
// @description  Adds direct download links to Microsoft Store when browsing apps.
// @author       StephenP
// @grant    GM.xmlHttpRequest
// @connect	 rg-adguard.net
// @match    https://www.microsoft.com/*-*/p/*
// ==/UserScript==
var dlBtn;
(function(){
  setInterval(checkReload, 1000);
})();
function checkReload(){
  var moreBtn=document.getElementById("ButtonPanel_buttonPanel_OverflowMenuTrigger");
  if(moreBtn.parentNode.children.length<3){
    dlBtn = moreBtn.cloneNode(true);
    dlBtn.removeAttribute("aria-haspopup");
    dlBtn.removeAttribute("aria-expanded");
    dlBtn.removeAttribute("data-m");
    dlBtn.setAttribute("aria-label","Download from AdGuard Store");
    dlBtn.setAttribute("class","c-button");
    dlBtn.style.background="#00a686";
    dlBtn.style.color="#ffffff";
    dlBtn.style.minWidth="0";
    dlBtn.style.font="initial";
    dlBtn.innerText="\u25bc";
    dlBtn.addEventListener("click",openLink);
    moreBtn.parentNode.appendChild(dlBtn);
  }
}
function openLink(){
  try{
    var loading=setInterval(rotateCursor,100);
    var link="type=url&url="+document.location.href+"&ring=RP&lang=it-IT";
    GM.xmlHttpRequest({
      method: "POST",
      url: "https://store.rg-adguard.net/api/GetFiles",
      data: link,
      headers: {
        "Content-Type": "application/x-www-form-urlencoded"
      },
      onload: function(response) {
        clearInterval(loading);
        dlBtn.innerText="\u25bc";
        try{
          var oldTable=document.getElementById("linkTable");
          oldTable.parentNode.removeChild(oldTable);
          var oldMsg=document.getElementById("messageFromServer");
          oldMsg.parentNode.removeChild(oldMsg);
        }
        catch(err){
          console.log(err);
        }
        var linkTable = document.createElement("div");
        linkTable.innerHTML=response.responseText;
        var justTable=linkTable.getElementsByTagName("TABLE")[0];
        var messageFromServer=linkTable.getElementsByTagName("P")[0];
        messageFromServer.id="messageFromServer";
        messageFromServer.style.fontWeight="bold";
        if(justTable!==undefined){
          justTable.id="linkTable";
          document.getElementsByClassName("pi-content")[0].appendChild(justTable);
          messageFromServer.style.color="green";
          document.getElementById("purchaseColumn").appendChild(messageFromServer);
        }
        else{
          messageFromServer.style.color="red";
          document.getElementById("purchaseColumn").appendChild(messageFromServer);
        }
      }
    });
  }
  catch(err){
    console.log(err);
  }
}
function rotateCursor(){
  if(dlBtn.innerText=="\u25bc"){
    dlBtn.innerText="\u25d0";
  }
  if(dlBtn.innerText=="\u25d0"){
    dlBtn.innerText="\u25d3";
  }
  else if(dlBtn.innerText=="\u25d3"){
    dlBtn.innerText="\u25d1";
  }
  else if(dlBtn.innerText=="\u25d1"){
    dlBtn.innerText="\u25d2";
  }
  else if(dlBtn.innerText=="\u25d2"){
    dlBtn.innerText="\u25d0";
  }
}