AtCoder Judge Status to Title Bar

Display AtCoder's judge status to a title bar

As of 2021-04-10. See the latest version.

  1. // ==UserScript==
  2. // @name AtCoder Judge Status to Title Bar
  3. // @namespace https://github.com/mihatsu-s/
  4. // @version 1.0.0
  5. // @description Display AtCoder's judge status to a title bar
  6. // @author Mihatsu
  7. // @match https://atcoder.jp/contests/*/submissions/*
  8. // @exclude https://atcoder.jp/*/json
  9. // ==/UserScript==
  10.  
  11. (() => {
  12. const judgeStatusElement = document.getElementById("judge-status");
  13. if (!judgeStatusElement) return;
  14.  
  15. const state = {
  16. rawTitle: document.title,
  17.  
  18. _hasFocus: true,
  19. get hasFocus() {
  20. return this._hasFocus;
  21. },
  22. set hasFocus(val) {
  23. this._hasFocus = val;
  24. this._onUpdate();
  25. },
  26.  
  27. _judgeStatus: "",
  28. _previousJudgeStatus: "",
  29. get judgeStatus() {
  30. return this._judgeStatus;
  31. },
  32. set judgeStatus(val) {
  33. this._previousJudgeStatus = this._judgeStatus;
  34. this._judgeStatus = val;
  35. this._onUpdate();
  36. },
  37.  
  38. _onUpdate() {
  39. document.title = this.hasFocus ? this.rawTitle : this.judgeStatus;
  40. },
  41. };
  42.  
  43. state.hasFocus = document.hasFocus();
  44. window.addEventListener("focus", () => {
  45. state.hasFocus = true;
  46. });
  47. window.addEventListener("blur", () => {
  48. state.hasFocus = false;
  49. });
  50.  
  51. function readJudgeStatus() {
  52. return judgeStatusElement.textContent;
  53. }
  54. state.judgeStatus = readJudgeStatus();
  55. new MutationObserver(() => {
  56. state.judgeStatus = readJudgeStatus();
  57. }).observe(judgeStatusElement, {
  58. subtree: true,
  59. characterData: true,
  60. });
  61. })();