// ==UserScript==
// @name 图寻对局助手
// @namespace https://greasyfork.org/users/1179204
// @version 0.0.1
// @author KaKa
// @description 对局中查看对手信息
// @match *://tuxun.fun/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=tuxun.fun
// @require https://cdn.jsdelivr.net/npm/sweetalert2@11.4.10/dist/sweetalert2.all.min.js
// @license MIT
// @downloadURL none
// ==/UserScript==
(function() {
'use strict';
let avatar, mode, player_data={}, player_infos={}
let infoElement = document.createElement('div');
infoElement.className = 'ant-notification-notice ant-notification-notice-warning ant-notification-notice-closable';
const intervalId = setInterval(() => {
const avatars = document.querySelectorAll('[class*="avatarCover"]');
if (avatars) {
getGameData()
avatars.forEach(avatar => {
const parentElement = avatar.parentElement;
if (parentElement) {
parentElement.style.pointerEvents = 'none';
avatar.style.pointerEvents = 'auto';
}
avatar.addEventListener('mouseenter', () => {
const icon_url=String(avatar.style.backgroundImage)
const matchedPlayer = getMatchingPlayerKey(icon_url);
if (matchedPlayer) {
if(player_infos[matchedPlayer]){
showPopup(fillInfo(player_infos[matchedPlayer]),player_infos[matchedPlayer].playerName);}
else{
fetchUserProfile(matchedPlayer)
.then(data => {
showPopup(fillInfo(data),data.playerName)});
}
} else {
console.error('没有找到用户 ID');
}
});
avatar.addEventListener('mouseleave', () => {
Swal.close()
});
});
clearInterval(intervalId);
}
}, 1000);
function fillInfo(data){
const playerInfo = `
当前积分: ${data.rating || '无'}
当前排位: ${data.rank || '无'}
匹配局数: ${data.gameTimes || '0'}
胜率: ${parseFloat(data.soloWin/data.gameTimes)*100 || ''}%
最高连胜: ${data.longestWinningStreak||'0'}
上赛季排位: ${data.lastRanking || '无'}
历史最高分: ${data.maxRating || '无'}
`
return playerInfo
}
function getGameData() {
const currentHref = window.location.href;
const parts = currentHref.split('/');
const gameId = parts[parts.length - 1];
if (!gameId) {
console.error('无法从 URL 中提取 gameId');
return;
}
const apiUrl = `https://tuxun.fun/api/v0/tuxun/solo/get?gameId=${gameId}`;
fetch(apiUrl)
.then(response => response.json())
.then(data => {
mode=data.data.china
const players=data.data.players
if(players){
players.map((player)=>{
player_data[player.userId]=player.icon
})
}
})
.catch(error => {
console.error('请求失败:', error);
});
}
async function fetchUserProfile(userId) {
const apiUrl = `https://tuxun.fun/api/v0/tuxun/getProfile?userId=${userId}`;
try {
const response = await fetch(apiUrl);
if (!response.ok) {
throw new Error(`请求失败,状态码: ${response.status}`);
}
const data = await response.json();
if(data.data){
const player_info=mode?data.data.chinaRank:data.data.worldRank
player_info.playerName=data.data.userAO.userName
player_infos[userId]=player_info
return player_info
}
return data;
} catch (error) {
console.error('请求出错:', error);
}
}
function showPopup(playerInfo, user) {
Swal.fire({
title: `${user}`,
html: playerInfo,
icon: null,
width: '400px',
position: 'center',
backdrop: null,
showConfirmButton: false,
showCloseButton: false,
customClass: {
popup: 'swal-popup',
content: 'swal-content',
},
});
setTimeout(() => {
const popup = document.querySelector('.swal-popup');
if (popup) {
popup.style.opacity = '0.7';
popup.style.background = '#000000';
popup.style.color='#fff'
}
}, 50);
}
function getMatchingPlayerKey(icon_url) {
for (const [userId, icon] of Object.entries(player_data)) {
if (icon_url.includes(icon)) {
return userId;
}
}
return null;
}
})();