Microsoft Store Direct Download

Adds direct download links to Microsoft Store when browsing apps.

  1. // ==UserScript==
  2. // @name Microsoft Store Direct Download
  3. // @name:it Download diretto dal Microsoft Store
  4. // @namespace StephenP
  5. // @version 2.0.4
  6. // @description Adds direct download links to Microsoft Store when browsing apps.
  7. // @description:it Aggiunge i link per il download diretto dal Microsoft Store quando si naviga tra le applicazioni.
  8. // @author StephenP
  9. // @grant GM.xmlHttpRequest
  10. // @connect rg-adguard.net
  11. // @match https://apps.microsoft.com/*
  12. // @match https://apps.microsoft.com/*
  13. // @contributionURL https://buymeacoffee.com/stephenp_greasyfork
  14. // ==/UserScript==
  15. var dlBtn;
  16. (function(){
  17. setInterval(checkReload, 1000);
  18. })();
  19. function checkReload(){
  20. let moreBtn=querySelectorAllShadows(".buy-box-container");
  21. if((moreBtn.length>0)&&(querySelectorAllShadows("#dlBtn").length==0)){
  22. /*const origDlBtn=querySelectorAllShadows("sl-button[href^=ms-windows-store]",moreBtn[0]);
  23. console.log(origDlBtn);*/
  24. dlBtn = document.createElement("DIV");
  25. dlBtn.id="dlBtn";
  26. dlBtn.setAttribute("aria-label","Download from AdGuard Store");
  27. dlBtn.style.background="#00a686";
  28. dlBtn.style.font="initial";
  29. dlBtn.style.textAlign="center";
  30. dlBtn.style.borderRadius="var(--sl-input-border-radius-large)";
  31. dlBtn.style.marginTop="0.5em";
  32. dlBtn.innerText="";
  33. dlBtn.appendChild(document.createElement("P"));
  34. dlBtn.firstChild.innerText="\u25bc";
  35. dlBtn.addEventListener("click",function(){openLink(document.location.href,"url")});
  36. moreBtn[0].appendChild(dlBtn);
  37. }
  38. }
  39. function openLink(id,type){
  40. try{
  41. dlBtn.firstChild.innerText="...";
  42. var link="type="+type+"&url="+id+"&ring=RP&lang=it-IT";
  43. GM.xmlHttpRequest({
  44. method: "POST",
  45. url: "https://store.rg-adguard.net/api/GetFiles",
  46. data: link,
  47. headers: {
  48. "Content-Type": "application/x-www-form-urlencoded"
  49. },
  50. onload: function(response) {
  51. dlBtn.firstChild.innerText="\u25bc";
  52. try{
  53. var oldTable=querySelectorAllShadows("#linkTable");
  54. oldTable[0].parentNode.removeChild(oldTable[0]);
  55. var oldMsg=querySelectorAllShadows("#messageFromServer");
  56. oldMsg[0].parentNode.removeChild(oldMsg[0]);
  57. }
  58. catch(err){
  59. console.log(err);
  60. }
  61. try{
  62. output(response,type);
  63. }
  64. catch(err){
  65. console.log(err);
  66. if(type==="ProductId"){
  67. output(err,type);
  68. }
  69. else{
  70. let newId=querySelectorAllShadows("[product-id]")[0].getAttribute("product-id");
  71. openLink(newId,"ProductId");
  72. }
  73. }
  74. }
  75. });
  76. }
  77. catch(err){
  78. console.log(err);
  79. if(type==="ProductId"){
  80. output(err,type);
  81. }
  82. else{
  83. let newId=querySelectorAllShadows("[product-id]")[0].getAttribute("product-id");
  84. openLink(newId,"ProductId");
  85. }
  86. }
  87. }
  88. function output(response,type){
  89. var linkTable = document.createElement("div");
  90. linkTable.innerHTML=response.responseText;
  91. var justTable=linkTable.getElementsByTagName("TABLE")[0];
  92. var messageFromServer=linkTable.getElementsByTagName("P")[0];
  93. messageFromServer.id="messageFromServer";
  94. messageFromServer.style.fontWeight="bold";
  95. if(justTable!==undefined){
  96. if(!document.getElementById("realign")){
  97. let realign=document.createElement("STYLE");
  98. realign.id="realign"
  99. realign.innerText="div.details.two-column{display: initial}}";
  100. document.getElementsByTagName("HEAD")[0].appendChild(realign);
  101. }
  102. justTable.id="linkTable";
  103. const rows=justTable.getElementsByTagName("TBODY")[0].getElementsByTagName("TR");
  104. for(let row of rows){
  105. if(row.firstChild.firstChild){
  106. if(row.firstChild.firstChild.innerHTML.match(/\.appx$|\.appxbundle$|\.msix$|\.msixbundle$|\.exe$/)){
  107. row.style.fontWeight="bold";
  108. }
  109. }
  110. }
  111. let tableStyle=document.createElement("STYLE");
  112. tableStyle.innerHTML="td:last-child{word-break: break-all}";
  113. let pNl=querySelectorAllShadows("sl-card");
  114. if(pNl.length>0){
  115. const pN=pNl[0].parentNode;
  116. pN.insertBefore(justTable, pN.querySelector("sl-card"));
  117. pN.insertBefore(tableStyle, pN.querySelector("sl-card"));
  118. justTable.style.marginTop="2em";
  119. messageFromServer.style.color="green";
  120. pN.insertBefore(messageFromServer, pN.querySelector("sl-card"));
  121. }
  122.  
  123. }
  124. else if((justTable===undefined)&&(type==="url")){
  125. let newId=querySelectorAllShadows("[product-id]")[0].getAttribute("product-id");
  126. openLink(newId,"ProductId");
  127. }
  128. else{
  129. messageFromServer.style.color="red";
  130. dlBtn.parentNode.parentNode.parentNode.appendChild(messageFromServer);
  131. }
  132. }
  133.  
  134.  
  135. //The following function has been taken from https://stackoverflow.com/questions/38701803/how-to-get-element-in-user-agent-shadow-root-with-javascript
  136. /**
  137. * Finds all elements in the entire page matching `selector`, even if they are in shadowRoots.
  138. * Just like `querySelectorAll`, but automatically expand on all child `shadowRoot` elements.
  139. * @see https://stackoverflow.com/a/71692555/2228771
  140. */
  141. function querySelectorAllShadows(selector, el = document.body) {
  142. // recurse on childShadows
  143. const childShadows = Array.from(el.querySelectorAll('*')).
  144. map(el => el.shadowRoot).filter(Boolean);
  145.  
  146. // console.log('[querySelectorAllShadows]', selector, el, `(${childShadows.length} shadowRoots)`);
  147.  
  148. const childResults = childShadows.map(child => querySelectorAllShadows(selector, child));
  149.  
  150. // fuse all results into singular, flat array
  151. const result = Array.from(el.querySelectorAll(selector));
  152. return result.concat(childResults).flat();
  153. }

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址