您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
Switch multiple account on Steam
当前为
// ==UserScript== // @name Steam Account Switcher // @version 0.2 // @description Switch multiple account on Steam // @author lzt // @match *://store.steampowered.com/* // @grant GM_setValue // @grant GM_getValue // @grant GM_listValues // @grant GM_deleteValue // @grant GM_cookie // @grant unsafeWindow // @grant window // @namespace steam_account_switcher // ==/UserScript== (function() { 'use strict'; // Your code here... let account = document.evaluate("//a[contains(@href, 'javascript:Logout()')]", document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null); if(account.snapshotLength != 1) { console.log("account error"); unsafeWindow.account = null; }else{ unsafeWindow.account = account.snapshotItem(0).children[0].innerText; }; var top = document.getElementById("global_action_menu"); var total = document.createElement("div"); var enter = document.createElement("span"); var menu = document.createElement("div");; total.id = "switcher_total"; total.style.display = "inline-block"; enter.id = "switcher_pulldown"; enter.className = "pulldown global_action_link"; enter.innerText = "切换账号"; enter.addEventListener("click", function(e){e.stopPropagation();reloadmenu()}); total.appendChild(enter); top.insertBefore(total, top.firstElementChild); document.addEventListener("click", function(e){ if (!menu.contains(e.target)) menu.style.display = "none"; }); function fillmenu() { menu = menu ? document.createElement("div") : menu; menu.className = "popup_block_new account_switcher"; menu.id = "sw_popup"; menu.style.visibility = "visible"; menu.style.display = "block"; menu.style.top = enter.getBoundingClientRect().bottom; menu.style.left = enter.getBoundingClientRect().left; var context = document.createElement("div"); context.className = "popup_body popup_menu account_switcher"; if (unsafeWindow.account != null & GM_getValue(unsafeWindow.account) == undefined) { let add = document.createElement("a"); add.className = "popup_menu_item account_switcher"; add.innerText = "添加 " + unsafeWindow.account; add.setAttribute("href", "#"); add.addEventListener("click", function(e){e.stopPropagation();addaccount()}); context.appendChild(add); }; let list = GM_listValues() for (let i = 0; i < list.length; i++) { let entity = document.createElement("div"); entity.className = "popup_menu_item account_switcher"; let sw = document.createElement("a"); sw.setAttribute("href", "#"); sw.style.margin = "0px 10px 0px 0px" if (unsafeWindow.account == list[i]) { sw.innerText = "更新 " + list[i]; sw.addEventListener("click", function(e){e.stopPropagation();addaccount();}); }else{ sw.innerText = "转到 " + list[i]; sw.addEventListener("click", function(e){e.stopPropagation();swaccount(list[i])}); }; let del = document.createElement("a"); del.innerText = "删除"; del.setAttribute("href", "#"); del.addEventListener("click", function(e){e.stopPropagation();delaccount(list[i])}); entity.appendChild(sw); entity.appendChild(del); context.appendChild(entity); } let login = document.createElement("a"); login.className = "popup_menu_item account_switcher"; login.innerText = "添加新账号"; login.setAttribute("href", "#"); login.addEventListener("click", function(e){ e.stopPropagation(); let lock = 0; GM_cookie("list", { path: "/" }, function(cookies) { if (cookies) { for(let i = 0; i < cookies.length; i++){ GM_cookie("delete", {name: cookies[i]["name"]}, function(error) { console.log(error || "del " + cookies[i]["name"]); lock++; if (lock >= cookies.length) window.location.href = "https://store.steampowered.com/login/"; }); } }else{window.location.href = "https://store.steampowered.com/login/"} }); }); context.appendChild(login); menu.appendChild(context); total.appendChild(menu); }; function reloadmenu() { let l = document.getElementsByClassName("account_switcher") for(let i = l.length - 1; i >= 0; i--){ l[i].remove() } fillmenu() }; function addaccount() { console.log("add " + unsafeWindow.account); GM_cookie("list", { path: "/" }, function(cookies) { let c = [] for(let i = 0; i < cookies.length; i++){ if (cookies[i]["name"] == "browserid") c.push(cookies[i]); if (cookies[i]["name"] == "sessionid") c.push(cookies[i]); if (cookies[i]["name"] == "steamLoginSecure") c.push(cookies[i]); if (cookies[i]["name"] == "steamRememberLogin") c.push(cookies[i]); if (cookies[i]["name"].search("steamMachineAuth") != -1) c.push(cookies[i]); } //GM_setValue(unsafeWindow.account, JSON.stringify(cookies)); GM_setValue(unsafeWindow.account, JSON.stringify(c)); console.log(c); reloadmenu(); }); }; function delaccount(id) { console.log("delete " + id); GM_deleteValue(id) reloadmenu() }; function swaccount(id) { console.log("switch to " + id); let l = JSON.parse(GM_getValue(id)); let delock = 0; GM_cookie("list", { path: "/" }, function(cookies) { for(let i = 0; i < cookies.length; i++){ GM_cookie("delete", {name: cookies[i]["name"]}, function(error) { console.log(error || "del " + cookies[i]["name"]); delock++; if (delock >= cookies.length) { console.log("del complete") let addlock = 0; for(let i = 0; i < l.length; i++){ GM_cookie("set", { name: l[i]['name'], value: l[i]['value'], domain: l[i]['domain'], path: l[i]['path'], secure: l[i]['secure'], httpOnly: l[i]['httpOnly'], sameSite: l[i]['sameSite'], expirationDate: l[i]['expirationDate'], hostOnly: l[i]['hostOnly'] }, function(error) { console.log(error || "add " + l[i]["name"]); addlock++; if (addlock >= l.length) { let url = window.location.href; if (url.search("store.steampowered.com/wishlist") != -1) { window.location.href = "https://store.steampowered.com/wishlist" }else{ window.location.reload() } }; }); } }; }); } }); }; })();