CF-problem-score-table

Add the "score table" to Codeforces in practice/virtual contest

  1. // ==UserScript==
  2. // @name CF-problem-score-table
  3. // @version 0.0.1
  4. // @description Add the "score table" to Codeforces in practice/virtual contest
  5. // @match *://codeforces.com/contest/*
  6. // @grant GM_getValue
  7. // @grant GM_setValue
  8. // @namespace https://gf.qytechs.cn/users/410786
  9. // ==/UserScript==
  10.  
  11.  
  12. (async function(){
  13. const contestId=location.pathname.match('^/contest/(\\d+)')[1]
  14. let problems
  15.  
  16. // stored value: [] for educational rounds, list of [index, points] otherwise
  17. if(GM_getValue('problem_score_'+contestId)!==undefined){
  18. problems=JSON.parse(GM_getValue('problem_score_'+contestId))
  19. if(problems.length>0&&problems[0][1]===null){ // fix a bug in previous version
  20. problems=[]
  21. GM_setValue('problem_score_'+contestId,JSON.stringify(problems))
  22. }
  23. }else{
  24. const data=await $.get(`/api/contest.standings?contestId=${contestId}&from=1&count=1`)
  25. if(data.status!=='OK'){
  26. console.log('Failed: ',data)
  27. return
  28. }
  29. problems=[]
  30. for(let problem of data.result.problems){
  31. if(!('points' in problem)){ // educational contest
  32. break
  33. }
  34. problems.push([problem.index,problem.points])
  35. }
  36. problems.sort()
  37. GM_setValue('problem_score_'+contestId,JSON.stringify(problems))
  38. }
  39. if(problems.length==0)
  40. return
  41.  
  42. //let lastDark=problems.length%2!=0 // more consistent with Codeforces (according to
  43. // http://web.archive.org/web/20160123153752/http://codeforces.com/contest/617), but is not as beautiful
  44. // because the header row is light.
  45.  
  46. let lastDark=false
  47.  
  48. function lastDarkState(){
  49. return lastDark?'dark':''
  50. }
  51. function nextDarkState(){
  52. lastDark=!lastDark
  53. return lastDarkState()
  54. }
  55.  
  56. // Thanks to the Internet Archive, I could get the "score table" HTML source without waiting for a real
  57. // contest. I just go to http://web.archive.org/web/*/https://codeforces.com/contest/*, then filter by
  58. // 'contest/' and sort by unique.
  59. // The page with the maximum unique count must have the score table.
  60. //
  61. // Taken from page: http://web.archive.org/web/20151230151115/http://codeforces.com/contest/611
  62. // (or http://web.archive.org/web/20160123153752/http://codeforces.com/contest/617 for Russian version)
  63. //
  64. // Currently only English is supported, but it's trivial to add the Russian version.
  65.  
  66. let problemsHTML=String.raw`
  67. <div class="roundbox sidebox" style="">
  68. <div class="roundbox-lt">&nbsp;</div>
  69. <div class="roundbox-rt">&nbsp;</div>
  70. <div class="caption titled">→ Score table
  71. <div class="top-links">
  72. </div>
  73. </div>
  74. <table class="rtable ">
  75. <tbody>
  76. <tr>
  77. <th class="left" style="width:100%;"></th>
  78. <th class="" style="width:8em;">Score</th>
  79. </tr>
  80. `
  81. for(let [index,score] of problems){
  82. problemsHTML+=String.raw`
  83. <tr>
  84. <td class="left ${nextDarkState()}"><a href="/contest/${contestId}/problem/${index}">Problem ${index}</a></td>
  85. <td class=" ${lastDarkState()}">${score}</td>
  86. </tr>
  87. `
  88. }
  89.  
  90. problemsHTML+=String.raw`
  91. <tr>
  92. <td class="left ${nextDarkState()}"><span style="color:green;">Successful hack</span></td>
  93. <td class=" ${lastDarkState()}">100</td>
  94. </tr>
  95. <tr>
  96. <td class="left ${nextDarkState()}"><span style="color:red;">Unsuccessful hack</span></td>
  97. <td class="${lastDarkState()}">-50</td>
  98. </tr>
  99. <tr>
  100. <td class="left ${nextDarkState()}"><span style="color:black;">Unsuccessful submission</span></td>
  101. <td class="${lastDarkState()}">-50</td>
  102. </tr>
  103. <tr>
  104. <td class="left bottom ${nextDarkState()}"><span style="color:black;">Resubmission</span></td>
  105. <td class="bottom ${lastDarkState()}">-50</td>
  106. </tr>
  107. </tbody>
  108. </table>
  109. </div>
  110. `
  111.  
  112. $('#sidebar').append(problemsHTML)
  113. $('#sidebar').append(String.raw`
  114. <div style="text-align:right; position:relative;bottom:1.75em;">
  115. <span class="small" style="color:gray;">* If you solve problem on 00:00 from the first attempt</span>
  116. </div>
  117. `)
  118.  
  119. })()

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址