Auto Select CF Language

Auto selects the language based on file extension, when you upload a file

当前为 2024-08-13 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Auto Select CF Language
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.0.3
  5. // @description Auto selects the language based on file extension, when you upload a file
  6. // @author Mushfiqur Rahman Talha
  7. // @match *codeforces.com/contest/*/problem/*
  8. // @match *codeforces.com/problemset/problem/*
  9. // @icon https://www.google.com/s2/favicons?sz=64&domain=codeforces.com
  10. // @grant none
  11. // @license Apache-2.0
  12. // ==/UserScript==
  13.  
  14. (function() {
  15. 'use strict';
  16.  
  17. /*
  18. Language Support:
  19. - GNU GCC C11 5.1.0
  20. - GNU G++20 13.2 (64 bit, winlibs)
  21. - C# 10, .NET SDK 6.0
  22. - D DMD32 v2.105.0
  23. - Go 1.22.2
  24. - Java 21 64bit
  25. - Kotlin 1.9.21
  26. - OCaml 4.02.1
  27. - PHP 8.1.7
  28. - PyPy 3.10 (7.3.15, 64bit)
  29. - Ruby 3.2.2
  30. - Rust 1.75.0 (2021)
  31. - Node.js 15.8.0 (64bit)
  32. */
  33. const fileInput = document.querySelector("input[name=sourceFile]");
  34. fileInput.addEventListener("change", event => {
  35. const file = event.target.files[0];
  36. if (!file) return;
  37. const ext = file.name.split('.').pop();
  38. let optionValue = null;
  39. switch (ext) {
  40. case "cpp":
  41. optionValue = "89";
  42. break;
  43. case "c":
  44. optionValue = "43";
  45. break;
  46. case "java":
  47. optionValue = "87";
  48. break;
  49. case "py":
  50. optionValue = "70";
  51. break;
  52. case "cs":
  53. optionValue = "79";
  54. break;
  55. case "js":
  56. optionValue = "55";
  57. break;
  58. case "d":
  59. optionValue = "28";
  60. break;
  61. case "go":
  62. optionValue = "32";
  63. break;
  64. case "kt":
  65. optionValue = "88";
  66. break;
  67. case "ml":
  68. optionValue = "19";
  69. break;
  70. case "php":
  71. optionValue = "6";
  72. break;
  73. case "rb":
  74. optionValue = "67";
  75. break;
  76. case "rs":
  77. optionValue = "75";
  78. break;
  79.  
  80. default:
  81. break;
  82. }
  83.  
  84. if (!optionValue) return;
  85. document.querySelectorAll("option").forEach(element => element.removeAttribute("selected"));
  86. document.querySelector(`option[value='${optionValue}']`).setAttribute("selected", "selected");
  87. });
  88. })();