mirror of
https://github.com/QingdaoU/OnlineJudge.git
synced 2025-11-04 14:49:58 +08:00
增加自动猜测代码语言和代码语言错误提示
This commit is contained in:
parent
fbd99450ec
commit
cd5ce220da
@ -92,9 +92,37 @@ require(["jquery", "codeMirror", "csrfToken", "bsAlert"], function ($, codeMirro
|
||||
})
|
||||
}
|
||||
|
||||
function guessLanguage(code) {
|
||||
//cpp
|
||||
if (code.indexOf("using namespace std") > -1) {
|
||||
return "2";
|
||||
}
|
||||
//c
|
||||
if (code.indexOf("printf") > -1) {
|
||||
return "1";
|
||||
}
|
||||
//java
|
||||
if (code.indexOf("public class Main")) {
|
||||
return "3";
|
||||
}
|
||||
}
|
||||
|
||||
$("#submit-code-button").click(function () {
|
||||
|
||||
var code = codeEditor.getValue();
|
||||
|
||||
if (!code.trim()) {
|
||||
bsAlert("请填写代码!");
|
||||
hideLoading();
|
||||
return false;
|
||||
}
|
||||
|
||||
if(guessLanguage(code) != language){
|
||||
if(!confirm("您选择的代码语言可能存在错误,是否继续提交?")){
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (location.href.indexOf("contest") > -1) {
|
||||
var problemId = location.pathname.split("/")[4];
|
||||
var contestId = location.pathname.split("/")[2];
|
||||
@ -118,15 +146,8 @@ require(["jquery", "codeMirror", "csrfToken", "bsAlert"], function ($, codeMirro
|
||||
|
||||
showLoading();
|
||||
|
||||
if (!code.trim()) {
|
||||
bsAlert("请填写代码!");
|
||||
hideLoading();
|
||||
return false;
|
||||
}
|
||||
|
||||
$("#result").html("");
|
||||
|
||||
|
||||
$.ajax({
|
||||
beforeSend: csrfTokenHeader,
|
||||
url: url,
|
||||
|
||||
Loading…
Reference in New Issue
Block a user