Skip to content

Instantly share code, notes, and snippets.

@demidenko
Created December 31, 2022 08:23
Show Gist options
  • Save demidenko/e87f671d3d0368845e45e25642fc76fc to your computer and use it in GitHub Desktop.
Save demidenko/e87f671d3d0368845e45e25642fc76fc to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name codeforces-friends-online
// @namespace demich
// @include https://codeforces.com/friends
// @version 2.0
// @grant none
// @require http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js
// ==/UserScript==
$(document).ready(function() {
let sel = $("div.datatable:nth-child(2) > div:nth-child(6) > table:nth-child(3)")
let handles = []
let rows = []
sel.find(".rated-user").each(function(){
let handle = $(this).text()
handles.push(handle)
rows.push($(this).parent().parent())
})
//console.log(handles)
$.get("https://codeforces.com/api/user.info?handles="+handles.join(';'), function(s){
let times = new Map()
for (friend of s.result){
times.set(friend.handle, friend.lastOnlineTimeSeconds)
console.log(friend.handle+" "+friend.lastOnlineTimeSeconds)
}
for(let i=0;i<rows.length;++i){
for(let j=i+1;j<rows.length;++j){
let ti = times.get(rows[i].find(".rated-user").text())
let tj = times.get(rows[j].find(".rated-user").text())
if(ti < tj){
let tmp = rows[i];
rows[i] = rows[j];
rows[j] = tmp;
}
}
let f = rows[i].find(".rated-user")
let handle = f.text()
//console.log(handle + " ? " + (times.get(handle)))
rows[i].find("td").each(function(){
if($(this).hasClass("dark"))
$(this).removeClass("dark")
if(i%2==1) $(this).addClass("dark")
})
sel.append(rows[i])
$.get("https://codeforces.com/profile/"+handle, function(s){
let p = $.parseHTML(s);
let q = $(p).find(".info > ul");
console.log(handle)
q.find("li").each(function(){
let t = $(this).text()
if(t.indexOf("Последнее посещение:")!=-1){
t = $(this).find("span")
t.text(" "+t.text())
t.insertAfter(f)
}
})
})
}
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment