From cd5ce220da35b2ef4aa1db86ee5ce22e10ad3983 Mon Sep 17 00:00:00 2001 From: virusdefender <1670873886@qq.com> Date: Tue, 8 Sep 2015 17:48:46 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E8=87=AA=E5=8A=A8=E7=8C=9C?= =?UTF-8?q?=E6=B5=8B=E4=BB=A3=E7=A0=81=E8=AF=AD=E8=A8=80=E5=92=8C=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E8=AF=AD=E8=A8=80=E9=94=99=E8=AF=AF=E6=8F=90=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- static/src/js/app/oj/problem/problem.js | 37 +++++++++++++++++++------ 1 file changed, 29 insertions(+), 8 deletions(-) diff --git a/static/src/js/app/oj/problem/problem.js b/static/src/js/app/oj/problem/problem.js index 4612a94c..823afc82 100644 --- a/static/src/js/app/oj/problem/problem.js +++ b/static/src/js/app/oj/problem/problem.js @@ -1,7 +1,7 @@ require(["jquery", "codeMirror", "csrfToken", "bsAlert"], function ($, codeMirror, csrfTokenHeader, bsAlert) { var codeEditorSelector = $("#code-editor")[0]; // 部分界面逻辑会隐藏代码输入框,先判断有没有。 - if (codeEditorSelector == undefined){ + if (codeEditorSelector == undefined) { return; } var codeEditor = codeMirror(codeEditorSelector, "text/x-csrc"); @@ -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,