Auto Select CF Language

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

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