您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
Auto selects the language based on file extension, when you upload a file
- // ==UserScript==
- // @name Auto Select CF Language
- // @namespace http://tampermonkey.net/
- // @version 0.2.0
- // @description Auto selects the language based on file extension, when you upload a file
- // @author Mushfiqur Rahman Talha
- // @match *codeforces.com/contest/*/problem/*
- // @match *codeforces.com/problemset/problem/*
- // @match *mirror.codeforces.com/contest/*/problem/*
- // @match *mirror.codeforces.com/problemset/problem/*
- // @icon https://www.google.com/s2/favicons?sz=64&domain=codeforces.com
- // @grant none
- // @license Apache-2.0
- // ==/UserScript==
- (function() {
- 'use strict';
- /*
- Language Support:
- - GNU GCC C11 5.1.0
- - GNU G++23 14.2 (64 bit, msys2)
- - C# 10, .NET SDK 6.0
- - D DMD32 v2.105.0
- - Go 1.22.2
- - Java 21 64bit
- - Kotlin 1.9.21
- - OCaml 4.02.1
- - PHP 8.1.7
- - PyPy 3.10 (7.3.15, 64bit)
- - Ruby 3.2.2
- - Rust 1.75.0 (2021)
- - Node.js 15.8.0 (64bit)
- */
- const fileInput = document.querySelector("input[name=sourceFile]");
- fileInput.addEventListener("change", event => {
- const file = event.target.files[0];
- if (!file) return;
- const ext = file.name.split('.').pop();
- let optionValue = null;
- switch (ext) {
- case "cpp":
- optionValue = "91";
- break;
- case "c":
- optionValue = "43";
- break;
- case "java":
- optionValue = "87";
- break;
- case "py":
- optionValue = "70";
- break;
- case "cs":
- optionValue = "79";
- break;
- case "js":
- optionValue = "55";
- break;
- case "d":
- optionValue = "28";
- break;
- case "go":
- optionValue = "32";
- break;
- case "kt":
- optionValue = "88";
- break;
- case "ml":
- optionValue = "19";
- break;
- case "php":
- optionValue = "6";
- break;
- case "rb":
- optionValue = "67";
- break;
- case "rs":
- optionValue = "75";
- break;
- default:
- break;
- }
- if (!optionValue) return;
- document.querySelectorAll("option").forEach(element => element.removeAttribute("selected"));
- document.querySelector(`option[value='${optionValue}']`).setAttribute("selected", "selected");
- });
- })();