// ==UserScript== // @name Osu! YutangCupS7 Calculator // @namespace http://tampermonkey.net/ // @version 0.1 // @description osu鱼塘杯专用计分器 // @author Kaguya_1096 // @match https://osu.ppy.sh/community/matches/* // @icon https://www.google.com/s2/favicons?sz=64&domain=baidu.com // @grant none // @license MIT // @downloadURL none // ==/UserScript== (function() { 'use strict'; // Your code here... const playerData = { "1460342": { team: "吃惊", T: 0 }, "7111118": { team: "吃惊", T: 0 }, "3824882": { team: "吃惊", T: 1 }, "1": { team: "吃惊", T: 1 }, "3826301": { team: "吃惊", T: 2 }, "2759340": { team: "吃惊", T: 2 }, "6854920": { team: "吃惊", T: 3 }, "13617153": { team: "吃惊", T: 3 }, "1712195": { team: "po仓鼠催婚协会", T: 0 }, "2": { team: "po仓鼠催婚协会", T: 0 }, "12585048": { team: "po仓鼠催婚协会", T: 1 }, "4858747": { team: "po仓鼠催婚协会", T: 1 }, "2385405": { team: "po仓鼠催婚协会", T: 2 }, "1766764": { team: "po仓鼠催婚协会", T: 2 }, "5179557": { team: "po仓鼠催婚协会", T: 3 }, "12764539": { team: "po仓鼠催婚协会", T: 3 }, }; var redTeamScore = 0, blueTeamScore = 0; const redColor = "red", blueColor = "DeepSkyBlue"; var finalScoreTable = {}; const compareByScore = (r, b) => (b.score - r.score); const compareByAcc = (r, b) => (b.acc - r.acc); const sum = (total, player) => (player.finalScore + total); function getFinalScore(redPlayer, blueTeam, color, rankingMethod) { blueTeam.push(redPlayer); if(rankingMethod) { blueTeam.sort(compareByScore); } else { blueTeam.sort(compareByAcc); } let rank = blueTeam.indexOf(redPlayer); redPlayer.setFinalScore(rank + 1); if(rankingMethod && rank < 4 && redPlayer.score > 2 * blueTeam[rank + 1].score && !blueTeam[rank + 1].highScoreFlag) { redPlayer.finalScore += 0.5; blueTeam[rank + 1].highScoreFlag = true; } blueTeam.splice(rank, 1); redPlayer.color = color; finalScoreTable[redPlayer.id] = redPlayer; } window.onload = function() { const title = $("h3")[0].innerHTML; const redTeamName = title.slice(title.indexOf("(") + 1, title.indexOf(")")); const blueTeamName = title.slice(title.lastIndexOf("(") + 1, title.lastIndexOf(")")); var games = $(".mp-history-game__player-scores.mp-history-game__player-scores--no-teams"); for(let game of games) { let redTeam = [], blueTeam = []; // 不同语言环境下的判断条件? var rankingMethod = game.previousSibling.querySelector(".mp-history-game__stats-box").lastChild.innerHTML == "最高分"; for(let playerInfo of game.childNodes) { var playerId = playerInfo.getElementsByClassName("mp-history-player-score__username")[0].getAttribute("href").split("/").pop(); var score = playerInfo.getElementsByClassName("mp-history-player-score__stat-number mp-history-player-score__stat-number--large")[0].innerHTML.replace(/,/g, ""); if(score == 0) continue; var acc = playerInfo.getElementsByClassName("mp-history-player-score__stat mp-history-player-score__stat--accuracy")[0].lastChild.innerHTML.replace("%", ""); var player = { score: score, id: playerId, acc: acc, T: playerData[playerId].T, finalScore: -1, highScoreFlag: false, color: "", setFinalScore: function(rank) { var sc = 11 - 2 * rank; var threshold = 9 - this.T * 2; if(rank == 1) { if (this.T == 0) { sc = 10; } else { sc = 9.5 - this.T; } } else if(this.T != 0 && sc > threshold) { sc = threshold + (sc - threshold) / 2; } this.finalScore = sc; } }; if(playerData[playerId].team == redTeamName) { redTeam.push(player); } else if(playerData[playerId].team == blueTeamName) { blueTeam.push(player) } } finalScoreTable = {}; for(let redPlayer of redTeam) { getFinalScore(redPlayer, blueTeam, redColor, rankingMethod); } for(let bluePlayer of blueTeam) { getFinalScore(bluePlayer, redTeam, blueColor, rankingMethod); } for(let playerInfo of game.childNodes) { let playerId = playerInfo.getElementsByClassName("mp-history-player-score__username")[0].getAttribute("href").split("/").pop(); let scoreNode = playerInfo.getElementsByClassName("mp-history-player-score__stat mp-history-player-score__stat--score")[0]; let player = finalScoreTable[playerId]; if(player == null) continue; let score = `