atcoder-problem-navigator

Shows a navigation bar on AtCoder contest pages for jumping to problems.

Version vom 26.05.2019. Aktuellste Version

  1. // ==UserScript==
  2. // @name atcoder-problem-navigator
  3. // @namespace https://github.com/yoshrc
  4. // @version 1.2
  5. // @description Shows a navigation bar on AtCoder contest pages for jumping to problems.
  6. // @author yoshrc
  7. // @match https://atcoder.jp/contests/*
  8. // @grant none
  9. // ==/UserScript==
  10.  
  11. (function() {
  12. 'use strict';
  13.  
  14. const contest = location.href.match(/^https:\/\/atcoder\.jp\/contests\/([^\/]+)/)[1];
  15. const key = 'atcoder-problem-navigator-' + contest;
  16.  
  17. if (location.href.match(/^https:\/\/atcoder\.jp\/contests\/([^\/]+)\/tasks\/?$/)) {
  18. const problems = [];
  19. const rows = document.querySelectorAll('tbody>tr');
  20. for (let i = 0; i < rows.length; i++) {
  21. const links = rows[i].querySelectorAll('a');
  22. const href = links[0].getAttribute('href');
  23. const text = links[0].textContent + ' - ' + links[1].textContent;
  24. problems.push({
  25. href: href,
  26. text: text
  27. });
  28. }
  29. localStorage[key] = JSON.stringify(problems);
  30. }
  31.  
  32. if (key in localStorage) {
  33. let problems = JSON.parse(localStorage[key]);
  34. const problemsBar = document.createElement('ul');
  35. problemsBar.className = 'nav nav-tabs';
  36. for (let i = 0; i < problems.length; i++) {
  37. const link = document.createElement('a');
  38. link.setAttribute('style', 'margin-left: 10px; margin-right: 10px; white-space: nowrap');
  39. link.setAttribute('href', problems[i].href);
  40. link.textContent = problems[i].text;
  41. const span = document.createElement('span');
  42. span.textContent = ' ';
  43. span.appendChild(link);
  44. problemsBar.appendChild(span);
  45. }
  46. document.getElementById('contest-nav-tabs').appendChild(problemsBar);
  47. }
  48. })();