Greasy Fork is available in English.

ac-diff-reversal-notifier

AtCoderのコンテストにおいて前の問題より後ろの問題の正解者が多い時に通知します

  1. // ==UserScript==
  2. // @name ac-diff-reversal-notifier
  3. // @namespace https://github.com/polyester-CTRL
  4. // @version 0.1
  5. // @description AtCoderのコンテストにおいて前の問題より後ろの問題の正解者が多い時に通知します
  6. // @author polyester-CTRL
  7. // @match https://atcoder.jp/contests/*/standings
  8. // @match https://atcoder.jp/contests/*/standings/json
  9. // @require https://cdn.jsdelivr.net/npm/axios@0.19.0/dist/axios.min.js
  10. // @grant none
  11. // ==/UserScript==
  12.  
  13. (function () {
  14. 'use strict';
  15.  
  16. // My code
  17. if ((!('Notification' in window)) || (startTime === undefined)) {
  18. return;
  19. }
  20. let permission = Notification.permission;
  21. if (permission === 'denied') {
  22. return;
  23. }
  24. let jsonURL = window.location.href.replace(/\/+$/, '') + '/json';
  25. console.log(jsonURL);
  26. Notification.requestPermission().then(function () {
  27. if (endTime.isBefore()) {
  28. return;
  29. }
  30.  
  31. let id = setInterval(function () {
  32. if (startTime.isAfter()) {
  33. return;
  34. }
  35. if (endTime.isBefore()) {
  36. clearInterval(id);
  37. return;
  38. }
  39. let taskData;
  40. axios.get(jsonURL)
  41. .then(function (response) {
  42. taskData = response.TaskInfo;
  43. })
  44. .catch(function (error) {
  45. console.log(error);
  46. });
  47. vueStandings.$watch('standings', function (newData, oldData) {
  48. if (!newData) {
  49. return;
  50. }
  51. let tasks = newData.TaskInfo;
  52. for (let i = 0; i < tasks.length - 1; i++) {
  53. if (vueStandings.ac[i] < vueStandings.ac[i + 1]) {
  54. new Notification(taskData[i].Assignment + ':' + vueStandings.ac[i] + '/' +
  55. taskData[i + 1].Assignment + ':' + vueStandings.ac[i + 1]);
  56. }
  57. }
  58. });
  59. // 3分おきに動作させる
  60. }, 3 * 60 * 1000);
  61. });
  62. });