Microsoft Store Direct Download

Adds direct download links to Microsoft Store when browsing apps.

当前为 2022-01-12 提交的版本,查看 最新版本

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

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

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name     Microsoft Store Direct Download
// @name:it     Download diretto dal Microsoft Store
// @namespace    StephenP
// @version  1.1.0
// @description  Adds direct download links to Microsoft Store when browsing apps.
// @description:it  Aggiunge i link per il download diretto dal Microsoft Store quando si naviga tra le applicazioni.
// @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_AppIdentityBuyButton");
  if((moreBtn)&&(!dlBtn)){
    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",function(){openLink(document.location.href,"url")});
    moreBtn.parentNode.appendChild(dlBtn);
  }
}
function openLink(id,type){
  try{
    var loading=setInterval(rotateCursor,100);
    var link="type="+type+"&url="+id+"&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);
        }
        output(response,type);
        if(type==="ProductId"){
          output(err,type);
        }
        else{
          let newId=document.querySelector('[name="ms.prod_id"]').getAttribute("content").toLowerCase();
          openLink(newId,"ProductId");
        }
      }
    });
  }
  catch(err){
    console.log(err);
    if(type==="ProductId"){
      output(err,type);
    }
    else{
      let newId=document.querySelector('[name="ms.prod_id"]').getAttribute("content").toLowerCase();
      openLink(newId,"ProductId");
    }
  }

}
function output(response,type){
  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 if((justTable===undefined)&&(type==="url")){
    let newId=document.querySelector('[name="ms.prod_id"]').getAttribute("content").toLowerCase();
    openLink(newId,"ProductId");
  }
  else{
    messageFromServer.style.color="red";
    document.getElementById("purchaseColumn").appendChild(messageFromServer);
  }
}
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";
  }
}