Show friend's accepted submissions.
当前为
// ==UserScript==
// @name Better atcoder friend problemset
// @namespace https://atcoder.jp
// @version 0.2
// @description Show friend's accepted submissions.
// @author Ftt2333
// @match https://atcoder.jp/*
// @connect kenkoooo.com
// @connect atcoder.jp
// @icon data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
// @grant GM_xmlhttpRequest
// @license MIT
// ==/UserScript==
var userList
var contestId, problemId
let GetColorByRating = (rating) => {
if (rating < 400) return 'user-gray';
if (400 <= rating && rating < 800) return 'user-brown'
if (800 <= rating && rating < 1200) return 'user-green'
if (1200 <= rating && rating < 1600) return 'user-cyan'
if (1600 <= rating && rating < 2000) return 'user-blue'
if (2000 <= rating && rating < 2400) return 'user-yellow'
if (2400 <= rating && rating < 2800) return 'user-orange'
if (2800 <= rating) return 'user-red'
}
var availableUsers = [], counter = 0
var result = []
let Display = () => {
let str1 = "Solved by " + result.length.toString() + " friend" + (result.length > 1 ? "s. " : ". ")
let str2 = ""
for (let i = 0; i < result.length; i++) {
str2 += `<span class = "` + result[i].color + `">` + result[i].userId + "</span>"
if (i + 1 != result.length) str2 += ", "
}
let str = `<br><span style = "font-size: 16px; color: grey;">` + str1 + str2 + "</span>"
let node = document.querySelector(`#main-div > div.container > div.row > div:nth-child\(2\) > span`)
node.innerHTML += str
}
let GetUserColor = async (userId) => {
let tmp = {}, cnt = 10
let url = "https://atcoder.jp/users/" + userId
while (cnt >= 0 && tmp.status != 200) tmp = await fetch(url), cnt--
tmp.text().then((data) => {
let tmp = /<tr><th class="no-break">Rating<\/th><td><span class='user-(\w*)'>(\d*)<\/span>/
let arr = tmp.exec(data)
if (arr != null) result.push({userId : userId, color : GetColorByRating(parseInt(arr[2]))})
else result.push({userId : userId, color : "user-unrated"})
counter--
if (counter == 0) Display()
})
}
let GetColors = () => {
counter = availableUsers.length
availableUsers.forEach((data) => { GetUserColor(data) })
}
let CheckIfAvailable = async (userId) => {
let tmp = {}, cnt = 10
let url = "https://atcoder.jp/contests/" + contestId + "/submissions?f.Task=" + problemId + "&f.LanguageName=&f.Status=AC&f.User=" + userId
while (cnt >= 0 && tmp.status != 200) tmp = await fetch(url), cnt--
tmp.text().then((data) => {
let tmp = /<span class='label label-success' data-toggle='tooltip' data-placement='top' title="Accepted">AC<\/span>/
let arr = tmp.exec(data)
if (arr != null) availableUsers.push(userId)
counter--
if (counter == 0) GetColors()
})
}
let GetAvailableUsers = () => {
counter = userList.length
userList.forEach((data) => { CheckIfAvailable(data) })
}
let Init = () => {
let tmp1 = /atcoder.jp\/contests\/(\w*)\/tasks\/(\w*)/
let tmp2 = tmp1.exec(location.href)
if (tmp2 == null) return
contestId = tmp2[1], problemId = tmp2[2]
userList = JSON.parse(localStorage.fav)
GetAvailableUsers()
}
Init()