Steam Account Switcher

Switch multiple account on Steam

目前为 2020-09-04 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name Steam Account Switcher
  3. // @version 0.1.1
  4. // @description Switch multiple account on Steam
  5. // @author lzt
  6. // @match *://store.steampowered.com/*
  7. // @grant GM_setValue
  8. // @grant GM_getValue
  9. // @grant GM_listValues
  10. // @grant GM_deleteValue
  11. // @grant GM_cookie
  12. // @grant unsafeWindow
  13. // @grant window
  14. // @namespace steam_account_switcher
  15. // ==/UserScript==
  16. (function() {
  17. 'use strict';
  18. // Your code here...
  19. let account = document.evaluate("//a[contains(@href, 'javascript:Logout()')]", document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
  20. if(account.snapshotLength != 1) {
  21. console.log("account error");
  22. unsafeWindow.account = null;
  23. }else{
  24. unsafeWindow.account = account.snapshotItem(0).children[0].innerText;
  25. };
  26.  
  27. var top = document.getElementById("global_action_menu");
  28. var total = document.createElement("div");
  29. var enter = document.createElement("span");
  30. var menu = document.createElement("div");;
  31.  
  32. total.id = "switcher_total";
  33. total.style.display = "inline-block";
  34. enter.id = "switcher_pulldown";
  35. enter.className = "pulldown global_action_link";
  36. enter.innerText = "切换账号";
  37. enter.addEventListener("click", function(e){e.stopPropagation();reloadmenu()});
  38. total.appendChild(enter);
  39. top.insertBefore(total, top.firstElementChild);
  40.  
  41. document.addEventListener("click", function(e){
  42. if (!menu.contains(e.target)) menu.style.display = "none";
  43. });
  44.  
  45. function fillmenu() {
  46. menu = menu ? document.createElement("div") : menu;
  47. menu.className = "popup_block_new account_switcher";
  48. menu.id = "sw_popup";
  49. menu.style.visibility = "visible";
  50. menu.style.display = "block";
  51. menu.style.top = enter.getBoundingClientRect().bottom;
  52. menu.style.left = enter.getBoundingClientRect().left;
  53.  
  54. var context = document.createElement("div");
  55. context.className = "popup_body popup_menu account_switcher";
  56. if (unsafeWindow.account != null & GM_getValue(unsafeWindow.account) == undefined) {
  57. let add = document.createElement("a");
  58. add.className = "popup_menu_item account_switcher";
  59. add.innerText = "添加 " + unsafeWindow.account;
  60. add.setAttribute("href", "#");
  61. add.addEventListener("click", function(e){e.stopPropagation();addaccount()});
  62. context.appendChild(add);
  63. };
  64.  
  65. let list = GM_listValues()
  66. for (let i = 0; i < list.length; i++) {
  67. let entity = document.createElement("div");
  68. entity.className = "popup_menu_item account_switcher";
  69.  
  70. let sw = document.createElement("a");
  71. sw.setAttribute("href", "#");
  72. sw.style.margin = "0px 10px 0px 0px"
  73. if (unsafeWindow.account == list[i]) {
  74. sw.innerText = "更新 " + list[i];
  75. sw.addEventListener("click", function(e){e.stopPropagation();addaccount();});
  76. }else{
  77. sw.innerText = "转到 " + list[i];
  78. sw.addEventListener("click", function(e){e.stopPropagation();swaccount(list[i])});
  79. };
  80.  
  81. let del = document.createElement("a");
  82. del.innerText = "删除";
  83. del.setAttribute("href", "#");
  84. del.addEventListener("click", function(e){e.stopPropagation();delaccount(list[i])});
  85.  
  86. entity.appendChild(sw);
  87. entity.appendChild(del);
  88. context.appendChild(entity);
  89. }
  90.  
  91. let login = document.createElement("a");
  92. login.className = "popup_menu_item account_switcher";
  93. login.innerText = "添加新账号";
  94. login.setAttribute("href", "#");
  95. login.addEventListener("click", function(e){
  96. e.stopPropagation();
  97. let lock = 0;
  98. GM_cookie("list", { path: "/" }, function(cookies) {
  99. if (cookies) {
  100. for(let i = 0; i < cookies.length; i++){
  101. GM_cookie("delete", {name: cookies[i]["name"]}, function(error) {
  102. console.log(error || "del " + cookies[i]["name"]);
  103. lock++;
  104. if (lock >= cookies.length) window.location.href = "https://store.steampowered.com/login/";
  105. });
  106. }
  107. }else{window.location.href = "https://store.steampowered.com/login/"}
  108. });
  109. });
  110. context.appendChild(login);
  111.  
  112. menu.appendChild(context);
  113. total.appendChild(menu);
  114. };
  115.  
  116. function reloadmenu() {
  117. let l = document.getElementsByClassName("account_switcher")
  118. for(let i = l.length - 1; i >= 0; i--){
  119. l[i].remove()
  120. }
  121. fillmenu()
  122. };
  123.  
  124. function addaccount() {
  125. console.log("add " + unsafeWindow.account);
  126. GM_cookie("list", { path: "/" }, function(cookies) {
  127. GM_setValue(unsafeWindow.account, JSON.stringify(cookies));
  128. reloadmenu();
  129. });
  130. };
  131.  
  132. function delaccount(id) {
  133. console.log("delete " + id);
  134. GM_deleteValue(id)
  135. reloadmenu()
  136. };
  137.  
  138. function swaccount(id) {
  139. console.log("switch to " + id);
  140. let l = JSON.parse(GM_getValue(id));
  141. let delock = 0
  142. GM_cookie("list", { path: "/" }, function(cookies) {
  143. for(let i = 0; i < cookies.length; i++){
  144. GM_cookie("delete", {name: cookies[i]["name"]}, function(error) {
  145. console.log(error || "del " + cookies[i]["name"]);
  146. delock++;
  147. if (delock >= cookies.length) {
  148. console.log("del complete")
  149. let addlock = 0;
  150. for(let i = 0; i < l.length; i++){
  151. GM_cookie("set", {
  152. name: l[i]['name'],
  153. value: l[i]['value'],
  154. domain: l[i]['domain'],
  155. path: l[i]['path'],
  156. secure: l[i]['secure'],
  157. httpOnly: l[i]['httpOnly'],
  158. sameSite: l[i]['sameSite'],
  159. expirationDate: l[i]['expirationDate'],
  160. hostOnly: l[i]['hostOnly']
  161. }, function(error) {
  162. console.log(error || "add " + l[i]["name"]);
  163. addlock++;
  164. if (addlock >= l.length) {
  165. let url = window.location.href;
  166. if (url.search("store.steampowered.com/wishlist") != -1) {
  167. window.location.href = "https://store.steampowered.com/wishlist"
  168. }else{
  169. window.location.reload()
  170. }
  171. };
  172. });
  173. }
  174. };
  175. });
  176. }
  177. });
  178. };
  179. })();

QingJ © 2025

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