Greasy Fork is available in English.

atcoder-problem-navigator

Show a navigation bar on AtCoder contest pages for jumping to problems

От 22.05.2019. Виж последната версия.

  1. // ==UserScript==
  2. // @name atcoder-problem-navigator
  3. // @namespace https://github.com/yoshrc
  4. // @version 1.0
  5. // @description Show 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. const scriptName = 'atcoder-problem-navigator';
  15.  
  16. const contest = location.href.match(/^https:\/\/atcoder\.jp\/contests\/([^\/]+)/)[1];
  17. const key = scriptName + "-" + contest;
  18.  
  19. if (location.href.match(/^https:\/\/atcoder\.jp\/contests\/([^\/]+)\/tasks\/?$/)) {
  20. console.log(contest);
  21. const problems = [];
  22. const $rows = $('tbody>tr');
  23. for (let i = 0; i < $rows.length; i++) {
  24. console.log(i);
  25. const $links = $rows.eq(i).find('a');
  26. const href = $links.eq(0).attr('href');
  27. console.log(href);
  28. const text = $links.eq(0).text() + " - " + $links.eq(1).text();
  29. problems.push({
  30. href: href,
  31. text: text
  32. });
  33. }
  34. localStorage[key] = JSON.stringify(problems);
  35. }
  36.  
  37. if (key in localStorage) {
  38. let problems = JSON.parse(localStorage[key]);
  39. const $contestBar = $('#contest-nav-tabs');
  40. const $problemsBar = $('<ul class="nav nav-tabs"></ul>');
  41. for (let i = 0; i < problems.length; i++) {
  42. const $span = $('<span style="margin-left: 10px; margin-right: 10px; white-space: nowrap"></span>')
  43. const $link = $('<a></a>')
  44. .attr('href', problems[i].href)
  45. .text(problems[i].text);
  46. $span.append($link);
  47. const $separator = $('<span></span>');
  48. $problemsBar.append($span);
  49. $problemsBar.append($separator);
  50. }
  51. $contestBar.append($problemsBar);
  52. }
  53. })();