Greasy Fork is available in English.

AtCoder dos2unix UserScript

submit code using LF instead of CRLF

À partir de 2018-12-17. Voir la dernière version.

  1. // ==UserScript==
  2. // @name AtCoder dos2unix UserScript
  3. // @namespace https://github.com/kmyk
  4. // @version 1.5
  5. // @description submit code using LF instead of CRLF
  6. // @author Kimiyuki Onaka
  7. // @match *://atcoder.jp/contests/*/submit*
  8. // @match *://atcoder.jp/contests/*/tasks/*
  9. // @match *://beta.atcoder.jp/contests/*/submit*
  10. // @match *://beta.atcoder.jp/contests/*/tasks/*
  11. // @match *://*.contest.atcoder.jp/submit*
  12. // ==/UserScript==
  13. function post(path, payload, expectedURL) {
  14. const xhr = new XMLHttpRequest();
  15. xhr.open("POST", path, false);
  16. xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
  17. xhr.send(payload);
  18. console.log(xhr);
  19. if (xhr.responseURL == expectedURL) {
  20. location.href = xhr.responseURL;
  21. }
  22. else {
  23. alert("AtCoder dos2unix UserScript: something wrong / なんか変だよ ソースコードが空だったり連投制限に引っ掛かってたりしませんか");
  24. }
  25. }
  26. function beta() {
  27. const taskScreenName = document.getElementsByName("data.TaskScreenName")[0];
  28. const sourceCode = document.getElementsByName("sourceCode")[0];
  29. const csrfToken = document.getElementsByName("csrf_token")[0];
  30. const submit = document.getElementById("submit");
  31. submit.innerText += " (dos2unix)";
  32. submit.addEventListener("click", function (e) {
  33. e.preventDefault();
  34. // NOTE: I didn't know why, but the "data.LanguageId" must be gotten here. see https://github.com/kmyk/atcoder-dos2unix-userscript/issues/2
  35. const languageId = document.getElementsByName("data.LanguageId")[0];
  36. const contestId = location.pathname.split('/')[2];
  37. const data = [];
  38. for (const tag of [taskScreenName, languageId, sourceCode, csrfToken]) {
  39. var value = tag.value;
  40. if (tag === sourceCode) {
  41. value = $(sourceCode).data('editor').getValue();
  42. }
  43. data.push(tag.name + '=' + encodeURIComponent(value));
  44. console.log([tag.name, value]);
  45. }
  46. const payload = data.join('&');
  47. console.log(payload);
  48. const path = "/contests/" + contestId + "/submit";
  49. const expectedURL = location.origin + "/contests/" + contestId + "/submissions/me";
  50. post(path, payload, expectedURL);
  51. });
  52. }
  53. function alpha() {
  54. const session = document.getElementsByName("__session")[0];
  55. const taskId = document.getElementsByName("task_id")[0];
  56. const languageId207 = document.getElementsByName("language_id_207")[0];
  57. const languageId2520 = document.getElementsByName("language_id_2520")[0];
  58. const sourceCode = document.getElementsByName("source_code")[0];
  59. const submit = document.getElementsByTagName("button")[0];
  60. submit.innerText += " (dos2unix)";
  61. submit.addEventListener("click", function (e) {
  62. e.preventDefault();
  63. const data = [];
  64. for (const tag of [session, taskId, languageId207, languageId2520, sourceCode]) {
  65. data.push(tag.name + '=' + encodeURIComponent(tag.value));
  66. console.log([tag.name, tag.value]);
  67. }
  68. const payload = data.join('&');
  69. console.log(payload);
  70. const path = "/submit?task_id=" + taskId.value;
  71. const expectedURL = location.origin + "/submissions/me";
  72. post(path, payload, expectedURL);
  73. });
  74. }
  75. function main() {
  76. if (location.hostname.endsWith(".contest.atcoder.jp")) {
  77. alpha();
  78. }
  79. else {
  80. beta();
  81. }
  82. }
  83. main();