如何创建链接在Chrome同窗口中打开Steam Chat指定好友的聊天标签页
Steam Chat指定好友跳转实现方法
- 首先获取目标用户SteamID64:Steam个人资料页默认暴露全局变量
g_rgProfileData,直接读取g_rgProfileData.steamid即可拿到当前页面对应用户的64位ID,无需额外解析页面。 - 调整跳转链接格式:Steam聊天页支持通过hash参数直接定位到指定好友对话,标准链接格式为
https://steamcommunity.com/chat/#/friends/[替换为目标用户SteamID64],拼接正确ID后打开页面会自动加载对应聊天窗口,不需要额外操作。 - 配置同窗口新标签打开:给a标签添加
target="_blank"属性即可,不要使用带自定义窗口尺寸参数的window.open调用,就不会弹出独立窗口,只会在当前Chrome窗口的新标签页加载页面。
你可以直接参考修改后的代码:
<span> <a href="https://steamcommunity.com/chat/#/friends/替换为你拿到的目标用户SteamID64" class="btn_profile_action btn_medium" target="_blank"> Steam Chat </a> </span>
如果是油猴脚本动态插入链接,可参考下面的JS逻辑:
// 读取当前页面用户的SteamID64 const targetSteamId = g_rgProfileData.steamid; // 生成按钮元素 const chatBtn = document.createElement('a'); chatBtn.href = `https://steamcommunity.com/chat/#/friends/${targetSteamId}`; chatBtn.className = 'btn_profile_action btn_medium'; chatBtn.target = '_blank'; chatBtn.innerText = 'Steam Chat'; // 将按钮插入到个人资料页的操作栏位置 document.querySelector('.profile_header_actions').appendChild(chatBtn);
内容的提问来源于stack exchange,提问作者AxJ
相关产品推荐
相关产品推荐

