MSGPIntegration

Allows access to the Microsoft Store Generation Project from within Microsoft Store itself.

当前为 2024-06-10 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name MSGPIntegration
  3. // @name:de MSGPIntegration
  4. // @name:en MSGPIntegration
  5. // @namespace sun/userscripts
  6. // @version 2.0.10
  7. // @description Allows access to the Microsoft Store Generation Project from within Microsoft Store itself.
  8. // @description:de Integriert das Microsoft Store Generation Project in den Microsoft Store selbst.
  9. // @description:en Allows access to the Microsoft Store Generation Project from within Microsoft Store itself.
  10. // @compatible chrome
  11. // @compatible edge
  12. // @compatible firefox
  13. // @compatible opera
  14. // @compatible safari
  15. // @homepageURL https://forgejo.sny.sh/sun/userscripts
  16. // @supportURL https://forgejo.sny.sh/sun/userscripts/issues
  17. // @contributionURL https://liberapay.com/sun
  18. // @contributionAmount €1.00
  19. // @author Sunny <sunny@sny.sh>
  20. // @include https://apps.microsoft.com/store/detail/*/*
  21. // @match https://apps.microsoft.com/store/detail/*/*
  22. // @connect store.rg-adguard.net
  23. // @run-at document-end
  24. // @inject-into auto
  25. // @grant GM.addStyle
  26. // @grant GM_addStyle
  27. // @grant GM.xmlHttpRequest
  28. // @grant GM_xmlhttpRequest
  29. // @noframes
  30. // @require https://greasemonkey.github.io/gm4-polyfill/gm4-polyfill.js
  31. // @icon https://forgejo.sny.sh/sun/userscripts/raw/branch/main/icons/MSGPIntegration.ico
  32. // @copyright 2021-present, Sunny (https://sny.sh/)
  33. // @license Hippocratic License; https://forgejo.sny.sh/sun/userscripts/src/branch/main/LICENSE.md
  34. // ==/UserScript==
  35.  
  36. (function () {
  37. "use strict";
  38.  
  39. const observer = new MutationObserver((mutationList, observer) => {
  40. mutationList.forEach((mutation) => {
  41. if (
  42. Array.from(mutation.addedNodes).filter((node) =>
  43. node.classList.contains("c013"),
  44. ).length
  45. ) {
  46. observer.disconnect();
  47.  
  48. document
  49. .querySelector("[id^=getOrRemoveButton]")
  50. .insertAdjacentHTML(
  51. "afterend",
  52. "<button id='msgpintegration-button' class='c0151 c0158' style='border-radius: 4px; padding: 0 20px; margin-bottom: 4px' disabled><span id='msgpintegration-text'>Loading...</span></button>",
  53. );
  54. }
  55. });
  56. });
  57.  
  58. observer.observe(document.body, {
  59. childList: true,
  60. subtree: true,
  61. });
  62.  
  63. const url = location.pathname.split("/")[4];
  64.  
  65. GM.xmlHttpRequest({
  66. method: "POST",
  67. url: "https://store.rg-adguard.net/api/GetFiles",
  68. data: "type=ProductId&url=" + url + "&lang=en_US",
  69. headers: {
  70. "Content-Type": "application/x-www-form-urlencoded",
  71. },
  72. onload: function (response) {
  73. const element = document.createElement("html");
  74. element.innerHTML = response.responseText;
  75.  
  76. if (
  77. element.getElementsByTagName("p")[0].innerText !==
  78. "The links were successfully received from the Microsoft Store server."
  79. ) {
  80. document.getElementById("msgpintegration-text").innerText =
  81. "No links found.";
  82. return;
  83. }
  84.  
  85. document
  86. .getElementById("msgpintegration-button")
  87. .classList.remove("c0158");
  88. document
  89. .getElementById("msgpintegration-button")
  90. .removeAttribute("disabled");
  91. document.getElementById("msgpintegration-text").innerText =
  92. element.getElementsByClassName("tftable")[0].rows.length -
  93. 1 +
  94. " links found.";
  95.  
  96. document.body.insertAdjacentHTML(
  97. "beforeend",
  98. "<div id='msgpintegration-background'></div>",
  99. );
  100. document
  101. .getElementById("msgpintegration-background")
  102. .insertAdjacentElement(
  103. "beforeend",
  104. element.getElementsByClassName("tftable")[0],
  105. );
  106. GM.addStyle(`
  107. #msgpintegration-background {
  108. position: fixed;
  109. top: 0;
  110. width: 100vw;
  111. height: 100vh;
  112. z-index: 701;
  113. background-color: white;
  114. overflow-y: auto;
  115. display: none;
  116. }
  117. .tftable {
  118. margin: 3em auto;
  119. }
  120. @media (min-width: 1035px) {
  121. .tftable {
  122. margin-top: calc(3em + 54px);
  123. }
  124. }
  125. `);
  126.  
  127. document
  128. .getElementById("msgpintegration-button")
  129. .addEventListener("click", function () {
  130. document.getElementById("msgpintegration-background").style.display =
  131. "initial";
  132. });
  133.  
  134. document
  135. .getElementById("msgpintegration-background")
  136. .addEventListener("click", function (e) {
  137. if (
  138. e.target === document.getElementById("msgpintegration-background")
  139. )
  140. document.getElementById(
  141. "msgpintegration-background",
  142. ).style.display = "none";
  143. });
  144. },
  145. });
  146. })();