AtCoder - You're top X% (only for algorithm ranking)

Displays your approximate ranking percentile among all active AtCoder users on your profile page.

  1. // ==UserScript==
  2. // @name AtCoder - You're top X% (only for algorithm ranking)
  3. // @namespace https://gist.github.com/k1832/9438a1469bb2fa94d26702e1556aff97
  4. // @version 1.2
  5. // @description Displays your approximate ranking percentile among all active AtCoder users on your profile page.
  6. // @author k1832 (Keita Morisaki)
  7. // @match https://atcoder.jp/users/*
  8. // @license MIT License, Copyright (c) 2024 Keita Morisaki
  9. // @grant GM_xmlhttpRequest
  10. // ==/UserScript==
  11.  
  12. (function () {
  13. 'use strict';
  14.  
  15. const url = new URL(window.location.href);
  16. const contestType = url.searchParams.get('contestType');
  17.  
  18. if (contestType === 'algo' || contestType === null) {
  19. /*
  20. * EN: Fetch the total number of active AtCoder users from a JSON file hosted on GitHub.
  21. * JA: GitHub でホストされている JSON ファイルから、AtCoder のアクティブユーザーの総数を取得します。
  22. *
  23. * API implementation/host: https://github.com/k1832/atcoder-api
  24. */
  25. GM_xmlhttpRequest({
  26. method: "GET",
  27. url: "https://k1832.github.io/atcoder-api/api/v1/total-active-users.json",
  28. onload: function (response) {
  29. const data = JSON.parse(response.responseText);
  30. const totalCount = data.val;
  31.  
  32. let rankNode = document.evaluate(
  33. '//th[text()="順位" or text()="Rank"]/following-sibling::td',
  34. document,
  35. null,
  36. XPathResult.ANY_TYPE,
  37. null
  38. ).iterateNext();
  39.  
  40. if (!rankNode) {
  41. console.error('Ranking element not found.');
  42. return;
  43. }
  44.  
  45. const rankText = rankNode.textContent;
  46.  
  47. // "8956th" -> 8956
  48. const rank = parseInt(rankText.slice(0, -2), 10);
  49. const percentage = rank / totalCount * 100;
  50. rankNode.textContent += ` (top ${percentage.toFixed(2)}%)`;
  51. },
  52. onerror: function (error) {
  53. console.error('Error fetching user count:', error);
  54. }
  55. });
  56. }
  57. })();

QingJ © 2025

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