atcoder-problem-navigator

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

Versão de: 24/05/2019. Veja: a última versão.

  1. // ==UserScript==
  2. // @name atcoder-problem-navigator
  3. // @namespace https://github.com/yoshrc
  4. // @version 1.1
  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. // @require http://code.jquery.com/jquery-3.3.1.min.js
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. 'use strict';
  14.  
  15. const contest = location.href.match(/^https:\/\/atcoder\.jp\/contests\/([^\/]+)/)[1];
  16. const key = 'atcoder-problem-navigator-' + contest;
  17.  
  18. if (location.href.match(/^https:\/\/atcoder\.jp\/contests\/([^\/]+)\/tasks\/?$/)) {
  19. const problems = [];
  20. const $rows = $('tbody>tr');
  21. for (let i = 0; i < $rows.length; i++) {
  22. const $links = $rows.eq(i).find('a');
  23. const href = $links.eq(0).attr('href');
  24. const text = $links.eq(0).text() + ' - ' + $links.eq(1).text();
  25. problems.push({
  26. href: href,
  27. text: text
  28. });
  29. }
  30. localStorage[key] = JSON.stringify(problems);
  31. }
  32.  
  33. if (key in localStorage) {
  34. let problems = JSON.parse(localStorage[key]);
  35. const $problemsBar = $('<ul class="nav nav-tabs"></ul>');
  36. for (let i = 0; i < problems.length; i++) {
  37. const $link = $('<a style="margin-left: 10px; margin-right: 10px; white-space: nowrap"></a>')
  38. .attr('href', problems[i].href)
  39. .text(problems[i].text);
  40. $problemsBar.append($('<span> </span>').append($link));
  41. }
  42. $('#contest-nav-tabs').append($problemsBar);
  43. }
  44. })();