Showcase_Tools_2

从点数商店购买第三个展柜

  1. // ==UserScript==
  2. // @name:zh-CN 我需要更多展柜2
  3. // @name Showcase_Tools_2
  4. // @namespace https://blog.chrxw.com
  5. // @supportURL https://blog.chrxw.com/scripts.html
  6. // @contributionURL https://afdian.com/@chr233
  7. // @version 1.2
  8. // @description 从点数商店购买第三个展柜
  9. // @description:zh-CN 从点数商店购买第三个展柜
  10. // @author Chr_
  11. // @include https://store.steampowered.com/points/shop/*
  12. // @license AGPL-3.0
  13. // @connect api.steampowered.com
  14. // @icon https://blog.chrxw.com/favicon.ico
  15. // ==/UserScript==
  16.  
  17. // 初始化
  18. (() => {
  19. "use strict";
  20.  
  21. function addPanel() {
  22. const container = document.querySelector("#points_shop_root>div>div");
  23.  
  24. if (!container) {
  25. console.error("找不到元素");
  26. return;
  27. }
  28.  
  29. const token = JSON.parse(
  30. document
  31. .querySelector("#application_config")
  32. ?.getAttribute("data-loyaltystore")
  33. )?.webapi_token;
  34.  
  35. if (!token) {
  36. console.error("获取token失败");
  37. return;
  38. }
  39.  
  40. const btn = document.createElement("button");
  41. btn.textContent = "购买更多展柜";
  42. btn.addEventListener("click", () => showPanel(token));
  43. btn.title = btn.textContent;
  44. btn.style = "position: absolute;right: 50%;top: 10px;padding: 5px;";
  45. container.appendChild(btn);
  46. }
  47.  
  48. function showPanel(token) {
  49. const showCases = {
  50. Steam年度回顾: 24,
  51. 完满主义者展柜: 23,
  52. 精选艺术作品展柜: 22,
  53. // 奖励展柜: 21,
  54. // 特卖星人统计数据: 20,
  55. 成就展柜: 17,
  56. 我的指南: 16,
  57. 收藏的指南: 15,
  58. 视频展柜: 14,
  59. 艺术作品展柜: 13,
  60. 我的创意工坊展柜: 12,
  61. 创意工坊展柜: 11,
  62. 评测展柜: 10,
  63. 最喜爱的组: 9,
  64. 自定义信息框: 8,
  65. 截图展柜: 7,
  66. 最喜爱的游戏: 6,
  67. 徽章收藏家: 5,
  68. 打算交易的物品: 4,
  69. 物品展柜: 3,
  70. 游戏收藏家: 2,
  71. // 最稀有成就展柜: 1,
  72. };
  73.  
  74. const div = document.createElement("div");
  75.  
  76. const select = document.createElement("select");
  77. select.style = "padding: 5px;margin-right: 10px;";
  78. for (let name in showCases) {
  79. const option = document.createElement("option");
  80. option.value = showCases[name];
  81. option.textContent = name;
  82. option.title = name;
  83. select.appendChild(option);
  84. }
  85.  
  86. div.appendChild(select);
  87.  
  88. const dialog = ShowDialog("要购买什么展柜?", div);
  89.  
  90. const button = document.createElement("button");
  91. button.textContent = "买!!! (请确保点数充裕)";
  92. button.style = "padding: 3px;";
  93. button.addEventListener("click", async () => {
  94. await buyShowcases(token, select.value);
  95.  
  96. dialog.Dismiss();
  97. });
  98. div.appendChild(button);
  99. }
  100.  
  101. setTimeout(addPanel, 2000);
  102.  
  103. // 购买展柜
  104. function buyShowcases(token, type = 1) {
  105. return new Promise((resolve, reject) => {
  106. fetch(
  107. `https://api.steampowered.com/ILoyaltyRewardsService/RedeemPointsForProfileCustomization/v1/?access_token=${token}&customization_type=${type}`,
  108. {
  109. method: "POST",
  110. }
  111. )
  112. .then((response) => {
  113. response.json().then((json) => {
  114. const { success } = json;
  115. resolve(success);
  116. });
  117. })
  118. .catch((err) => {
  119. console.error(err);
  120. reject(`购买展柜失败 ${err}`);
  121. });
  122. });
  123. }
  124. })();