Greasy Fork is available in English.

AddLinkToNewAtcoder

ja

  1. // ==UserScript==
  2. // @name AddLinkToNewAtcoder
  3. // @namespace AddLinkToNewAtcoder
  4. // @version 1.6
  5. // @author Luzhiled
  6. // @description ja
  7. // @include http://*atcoder.jp/*
  8. // @include https://*atcoder.jp/*
  9. // @grant none
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. 'use strict';
  14.  
  15. function ConvertToNewAtcodersURL() {
  16. let pathName = location.pathname;
  17. let query = location.search;
  18. if (pathName.match(/settings/) || pathName.match(/users/)) {
  19. return 'https://beta.atcoder.jp' + pathName;
  20. }
  21. if (location.href.match(/contest.atcoder.jp/)) {
  22. let contestName = location.href.replace(/^https?:\/\//, '').split('.')[0];
  23. pathName = pathName.replace(/assignments/g, "tasks");
  24. pathName = pathName.replace(/\/all/g, "");
  25. query = query.replace(/user_screen_name/g, "f.User");
  26. pathName = pathName.replace(/editorial/g, "");
  27. pathName = pathName.replace(/statistics/g, "");
  28. return 'https://beta.atcoder.jp/contests/' + contestName + pathName + query;
  29. } else {
  30. pathName = pathName.replace(/contest/g, "contests");
  31. pathName = pathName.replace(/user/g, "users");
  32. query = query.replace(/categories/g, "category");
  33. query = query.replace(/p=/g, "page=");
  34. return 'https://beta.atcoder.jp' + pathName + query;
  35. }
  36. }
  37.  
  38. function AddLinkToNewAtcoder() {
  39. if (location.href.match(/contest.atcoder.jp/)) {
  40. $('div.nav-collapse')
  41. .prepend(`
  42. <ul class="nav">
  43. <li class="divider-vertical"></li>
  44. <li><a href="${
  45. ConvertToNewAtcodersURL()}"><span class="lang lang-selected"><span class="lang-en lang-child hidden-lang">go to beta.atcoder.jp</span><span class="lang-ja lang-child">Beta版へ</span></span></a></li>
  46. </ul>
  47. `);
  48. } else {
  49. $('ul.nav.navbar-nav').not('.navbar-right').append(`<li><a href="${ConvertToNewAtcodersURL()}">Beta版へ</a></li>`);
  50. }
  51. }
  52.  
  53. function ConvertToAtcodersURL() {
  54. let pathName = location.pathname;
  55. let query = location.search;
  56. if (pathName.match(/settings/)) {
  57. pathName = pathName.replace(/icon/g, "");
  58. return 'https://practice.contest.atcoder.jp' + pathName;
  59. }
  60. if (location.href.match(/contests/)) {
  61. let contestName = pathName.replace(/\/contests\//, '').split('/')[0];
  62. if (contestName === "" || contestName === "archive") {
  63. query = query.replace(/category/g, "categories");
  64. query = query.replace(/page=/g, "p=");
  65. query = query.replace(/keyword=/g, "mode=button");
  66. return `http://atcoder.jp/contest/${contestName + query}`;
  67. } else {
  68. pathName = pathName.replace(RegExp('/contests/' + contestName), '');
  69. if (pathName.endsWith("/")) {
  70. pathName = pathName.slice(0, -1);
  71. }
  72. if (pathName === "/submissions") {
  73. pathName += "/all";
  74. }
  75. if (pathName === "/tasks") {
  76. pathName = "/assignments";
  77. }
  78. query = query.replace(/f.User/g, "user_screen_name");
  79. console.log(pathName);
  80. console.log(query);
  81. return `https://${contestName}.contest.atcoder.jp${pathName + query}`;
  82. }
  83. } else {
  84. return 'https://beta.atcoder.jp' + pathName + query;
  85. }
  86.  
  87. return 'https://atcoder.jp';
  88. }
  89.  
  90. function AddLinkToAtcoder() {
  91. $('ul.nav.navbar-nav').not('.navbar-right').append(`<li><a href="${ConvertToAtcodersURL()}">旧AtCoderへ</a></li>`);
  92. }
  93.  
  94. if (location.href.match(/beta.atcoder.jp/)) {
  95. AddLinkToAtcoder();
  96. } else {
  97. AddLinkToNewAtcoder();
  98. }
  99.  
  100. })();