AtCoder-RedirectRecentABC

The tools to redirect the recent AtCoder Beginner Contest.

คุณจะต้องติดตั้งส่วนขยาย เช่น Tampermonkey, Greasemonkey หรือ Violentmonkey เพื่อติดตั้งสคริปต์นี้

คุณจะต้องติดตั้งส่วนขยาย เช่น Tampermonkey หรือ Violentmonkey เพื่อติดตั้งสคริปต์นี้

คุณจะต้องติดตั้งส่วนขยาย เช่น Tampermonkey หรือ Violentmonkey เพื่อติดตั้งสคริปต์นี้

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

  1. // ==UserScript==
  2. // @name AtCoder-RedirectRecentABC
  3. // @namespace https://github.com/PenguinCabinet
  4. // @version v0.0.1
  5. // @description The tools to redirect the recent AtCoder Beginner Contest.
  6. // @author PenguinCabinet
  7. // @license MIT
  8. // @match https://atcoder.jp/contests*
  9. // @grant none
  10. // ==/UserScript==
  11.  
  12. //config
  13. //config
  14.  
  15. async function Newest_N(elem_id1, elem_id2) {
  16. const r = /AtCoder Beginner Contest ([1-9][0-9]*)/g;
  17.  
  18. const contests_HTML_text = await (await fetch("https://atcoder.jp/contests/")).text();
  19. const doc = new DOMParser().parseFromString(contests_HTML_text, "text/html");
  20. let elem = doc.getElementById(elem_id1);
  21. if (!elem) {
  22. elem = doc.getElementById(elem_id2);
  23. }
  24. const text = elem.outerHTML;
  25. const ABC_texts = [...text.matchAll(r)];
  26. const Numbers = ABC_texts.map((e) => parseInt(e[1]));
  27.  
  28. return Math.min.apply(null, Numbers);
  29. }
  30.  
  31. (async function () {
  32. 'use strict';
  33.  
  34. let urlHash = location.hash;
  35. if (urlHash) {
  36. const r = /#recent_abc((\-|\+)[1-9][0-9]*)?/;
  37. const result = urlHash.match(r);
  38. if (result != null) {
  39. let Ans = await Newest_N("contest-table-action", "contest-table-upcoming");
  40.  
  41. let diff = result[1];
  42. if (diff === undefined) diff = 0;
  43. diff = parseInt(diff, 10);
  44.  
  45. if (Ans != null) {
  46. window.location.replace(`https://atcoder.jp/contests/abc${Ans + diff}`);
  47. }
  48. }
  49. }
  50. // Your code here...
  51. })();