// ==UserScript== // @name steam好友昵称更新 // @namespace http://tampermonkey.net/ // @version 0.32 // @description 在当前这页帖子中,将所有是你steam好友的发贴用户的steam昵称更新为论坛id // @author duya12345 // @match https://keylol.com/t* // @match https://steamcommunity.com/profiles/*/friends/ // @match https://steamcommunity.com/id/*/friends/ // @icon https://www.google.com/s2/favicons?domain=keylol.com // @grant GM_setValue // @grant GM_getValue // @downloadURL none // ==/UserScript== var show_steamName = 0; var name_prefix = "keylol_"; (function() { 'use strict'; if(window.location.href.search("keylol.com") != -1){ get_ql_info(); goto_friend(); } else if(window.location.href.search("steamcommunity.com") != -1){ window.onload = function(){ let post_steamId = GM_getValue("post_steamId"); let post_qlName = GM_getValue("post_qlName"); let friends_steamId = Array.from(document.getElementsByClassName("selectable friend_block_v2 persona")).map(a => a.getAttribute("data-steamid"));//读取拥有的好友steamid let friends_steamName = Array.from(document.getElementsByClassName("selectable friend_block_v2 persona")).map(a => a.getAttribute("data-search").replace(" ; ", ""))//读取拥有的好友steam昵称 let sessionId = get_sessionid(); for(let i = 0; i < friends_steamId.length; i++){ for(let j = 0; j < post_steamId.length; j++){ if(friends_steamId[i] == post_steamId[j]){ console.log(post_steamId[j], post_qlName[j]); change_nick(sessionId, post_steamId[j], name_prefix + post_qlName[j] + show_steamName ? '/'+friends_steamName[i] : ""); } } } } } })(); //其乐帖子页面的操作 function get_ql_info(){ //读取一页帖子中的steamid var post_steamId = Array.from(document.getElementsByClassName("steam_connect_user_bar_link steam_connect_user_bar_link_profile")).map(a => a.getAttribute("href")).map(b => b.replace(/\D+/g, '')) //读取一页帖子中的论坛账号 var post_qlName = Array.from(document.getElementsByClassName("pls favatar")).map(a => a.getElementsByClassName("pi")[0]).map(a => a.getElementsByClassName("authi")[0]).map(a => a.getElementsByClassName("xw1")[0]).map(a => a.innerText) GM_setValue("post_steamId", post_steamId); GM_setValue("post_qlName", post_qlName); } //进入自己的steam好友界面 async function goto_friend(){ var ql_profile_url = document.getElementsByClassName("dropdown")[1].firstChild.href let ql_profile_xml = await goto_qlProfife(ql_profile_url) console.log(ql_profile_xml) var my_steamId = ql_profile_xml.getElementsByClassName("pbm mbm bbda cl")[ql_profile_xml.getElementsByClassName("pbm mbm bbda cl").length-1].getElementsByClassName("pf_l")[0].children[3].lastChild.href.replace(/\D+/g, ""); window.open("https://steamcommunity.com/profiles/" + my_steamId + "/friends/", "_blank"); } //进入自己的其乐个人资料界面 function goto_qlProfife(get_url) { return new Promise((resolve, reject) => { var xhr = new XMLHttpRequest(); xhr.open("GET", get_url, true); xhr.onload = () => resolve(string2XML(xhr.responseText)) xhr.send(); }); } //steam好友页面的操作 //发送更改昵称请求 function change_nick(sessionid, steamId, nickname){ var formData = new FormData() formData.append("nickname", nickname); formData.append("sessionid", sessionid); var post_url = "https://steamcommunity.com/profiles/" + steamId +"/ajaxsetnickname/"; var xhr = new XMLHttpRequest(); xhr.withCredentials = true; xhr.addEventListener("readystatechange", function () { if (this.readyState === 4) { console.log(this.responseText); } }); xhr.open("POST", post_url); xhr.send(formData); } //读取seesionid function get_sessionid(){ let sessionid = 0; let steam_cookie = document.cookie.split("; ").map(a => a.split("=")) steam_cookie.forEach(element => { if(element[0] == "sessionid"){ sessionid = element[1]; } }); return sessionid; } //将字符串转换成xml对象 function string2XML(xmlString) { var parser = new DOMParser(); var xmlObject = parser.parseFromString(xmlString, "text/html"); return xmlObject; }