diff --git a/web/.codegraph/.gitignore b/web/.codegraph/.gitignore new file mode 100644 index 0000000..d20c0fe --- /dev/null +++ b/web/.codegraph/.gitignore @@ -0,0 +1,5 @@ +# CodeGraph data files — local to each machine, not for committing. +# Ignore everything in .codegraph/ except this file itself, so transient +# files (the database, daemon.pid, sockets, logs) never show up in git. +* +!.gitignore diff --git a/web/include/db_info.inc.php b/web/include/db_info.inc.php index 24abc85..3f8fd3d 100644 --- a/web/include/db_info.inc.php +++ b/web/include/db_info.inc.php @@ -147,9 +147,9 @@ static $OJ_MENU_NEWS=true; /* LLM AI Review - AI错误点评功能 */ static $OJ_LLM_ENABLED=true; // 总开关,设为true开启AI点评 -static $OJ_LLM_API_URL="https://api.minimaxi.com/anthropic/v1/messages"; // API地址(MiniMax Anthropic兼容格式) -static $OJ_LLM_API_KEY="sk-cp-w571CJpA_6WP5P6b_xGVbjOqXOGBWTQsiNY9xxAPambouIhD7ic3GHIoWce0ON_Y7Q0rVLzBWtgwwS8cQVUxS1guBxYkPJoJ33q0jEcx0Qei60bx5La4fB4"; // 填入你的MiniMax API Key -static $OJ_LLM_MODEL="MiniMax-M3"; // 模型名称,如 MiniMax-M3 / MiniMax-M2.7 / MiniMax-M2.5 / MiniMax-M2.5-highspeed +static $OJ_LLM_API_URL="https://newapi.klarkxy.xyz/v1/messages"; // API地址(MiniMax Anthropic兼容格式) +static $OJ_LLM_API_KEY="sk-2qWDjt8NJ5gwuAq1WWpaVsdIZ0qlImKDjtGpByYm3RvHV2NP"; // 填入你的MiniMax API Key +static $OJ_LLM_MODEL="minimax-m3"; // 模型名称,如 MiniMax-M3 / MiniMax-M2.7 / MiniMax-M2.5 / MiniMax-M2.5-highspeed static $OJ_LLM_MAX_TOKENS=65536; // 最大输出token数 static $OJ_LLM_TIMEOUT=60; // 请求超时(秒),LLM响应较慢建议60秒 static $OJ_LLM_SYSTEM_PROMPT=""; // 自定义系统prompt,留空使用内置默认 diff --git a/web/lang/cn.php b/web/lang/cn.php index ad44026..d1fb2e3 100644 --- a/web/lang/cn.php +++ b/web/lang/cn.php @@ -358,7 +358,39 @@ $MSG_YOURS="你的程序输出"; $MSG_FILENAME="文件名"; $MSG_SIZE="大小"; - + + // reinfo.php 友好提示 + $MSG_RUNTIME_GENERIC_ERROR="程序运行时发生了未明确的错误。建议:检查边界条件、空输入、特殊值处理。"; + $MSG_FORBIDDEN_SYSCALL="使用了系统禁止的操作系统调用,看看是否越权访问了文件或进程等资源。"; + $MSG_HINT_TLE="程序运行超过了题目设定的时间限制 (TLE)。常见原因:算法复杂度过高(如 O(n²) 当 n ≤ 10⁵)、死循环、I/O 效率低(建议用 scanf/printf 或更快 I/O)。"; + $MSG_HINT_MLE="程序使用的内存超过了题目设定的限制 (MLE)。常见原因:数组开得过大、递归过深未释放、全局变量占用空间过多。"; + $MSG_HINT_OLE="输出内容超过了限制 (OLE)。常见原因:死循环输出、忘记换行、调试信息未删除。"; + $MSG_RAW_ERROR="查看原始错误信息"; + $MSG_RESULT_BANNER="判题结果"; + $MSG_QUICK_ACTIONS="快捷操作"; + $MSG_RESUBMIT="重新提交"; + $MSG_VIEW_SOURCE="查看我的代码"; + $MSG_VIEW_PROBLEM="查看题目"; + $MSG_DOWNLOAD_DATA="下载测试数据"; + $MSG_FRIENDLY_EXPLAIN="错误解释"; + $MSG_DEDUP_HINT="已折叠 %d 个相同测试点"; + $MSG_AI_REVIEW_DESC="基于你的代码和判题结果分析"; + $MSG_DEDUP_GROUP="%s: %s (共 %d 个测试点)"; + + // 新增 RE 模式(覆盖 glibc / Java / Python / Go) + $MSG_STACK_SMASHING_DETECTED="栈保护触发(stack smashing detected),通常是数组越界写入了栈上的数据。检查字符数组、循环写入是否越界。"; + $MSG_TERMINATE_CALLED="C++ 抛出未捕获的异常(terminate called after throwing an instance of...)。检查代码中的 throw 语句是否有对应的 try/catch。"; + $MSG_NULL_POINTER_EXCEPTION="空指针异常(NullPointerException)。某处对未初始化的对象调用了方法或访问了字段。"; + $MSG_NUMBER_FORMAT_EXCEPTION="数字格式异常(NumberFormatException)。把非数字字符串转换成数字时出错,检查输入解析逻辑。"; + $MSG_CLASS_CAST_EXCEPTION="类型转换异常(ClassCastException)。把对象强制转换为不兼容的类型。"; + $MSG_NEGATIVE_ARRAY_SIZE_EXCEPTION="数组长度为负数(NegativeArraySizeException)。检查计算数组长度时是否出现负值。"; + $MSG_PYTHON_TRACEBACK="Python 抛出异常,下方是调用栈,从下往上读就是异常发生的位置。"; + $MSG_PYTHON_RECURSION_ERROR="递归层数过多(RecursionError)。递归深度超过了默认限制(1000),考虑改为迭代或手动加深递归限制。"; + $MSG_PYTHON_INDENTATION_ERROR="缩进错误(IndentationError)。Python 用缩进表示代码块,请检查空格/Tab 是否混用。"; + $MSG_PYTHON_ZERO_DIVISION="除以零错误(ZeroDivisionError)。"; + $MSG_PYTHON_NAME_ERROR="使用了未定义的变量或函数(NameError)。检查拼写、是否忘记 import。"; + $MSG_GO_PANIC="Go 运行时报错(panic),通常是越界访问、nil 指针或类型断言失败。"; + $MSG_ABORTED_CORE_DUMPED="程序被 abort() 终止(Aborted),通常源于 assert 失败或 std::terminate。"; // template/../ceinfo.php $MSG_ERROR_EXPLAIN="辅助解释"; diff --git a/web/lang/en.php b/web/lang/en.php index 266d41e..d6d4243 100644 --- a/web/lang/en.php +++ b/web/lang/en.php @@ -357,6 +357,39 @@ $MSG_INVALID_CONVERSION="The implicit type conversion is invalid, try to use explicit coercion such as (int *)malloc(....)"; $MSG_NO_RETURN_TYPE_IN_MAIN="In the C++ standard, the main function must have a return value."; $MSG_NOT_DECLARED_IN_SCOPE="The variable has not been declared, check for spelling errors!"; + + // reinfo.php friendly hints + $MSG_RUNTIME_GENERIC_ERROR="An unspecified runtime error occurred. Check boundary conditions, empty inputs, and edge cases."; + $MSG_FORBIDDEN_SYSCALL="A forbidden system call was used. Check if you tried to access files, network, or processes directly."; + $MSG_HINT_TLE="Time Limit Exceeded (TLE). Common causes: high algorithm complexity (e.g. O(n²) when n ≤ 10⁵), infinite loops, slow I/O. Use scanf/printf or faster I/O."; + $MSG_HINT_MLE="Memory Limit Exceeded (MLE). Common causes: oversized arrays, deep recursion, unreleased memory."; + $MSG_HINT_OLE="Output Limit Exceeded (OLE). Common causes: infinite output loops, missing newlines, leftover debug prints."; + $MSG_RAW_ERROR="View raw error information"; + $MSG_RESULT_BANNER="Verdict"; + $MSG_QUICK_ACTIONS="Quick actions"; + $MSG_RESUBMIT="Resubmit"; + $MSG_VIEW_SOURCE="View my code"; + $MSG_VIEW_PROBLEM="View problem"; + $MSG_DOWNLOAD_DATA="Download test data"; + $MSG_FRIENDLY_EXPLAIN="Error explanation"; + $MSG_DEDUP_HINT="Collapsed %d duplicate test cases"; + $MSG_AI_REVIEW_DESC="Analyzing your code and verdict"; + $MSG_DEDUP_GROUP="%s: %s (in %d test cases)"; + + // Additional RE patterns + $MSG_STACK_SMASHING_DETECTED="Stack smashing detected. Usually means an out-of-bounds write into a stack buffer. Check char arrays and loop write bounds."; + $MSG_TERMINATE_CALLED="C++ exception was thrown but not caught (terminate called after throwing). Check that all throw statements are wrapped in try/catch."; + $MSG_NULL_POINTER_EXCEPTION="NullPointerException. A method or field was called on an uninitialized object."; + $MSG_NUMBER_FORMAT_EXCEPTION="NumberFormatException. Failed to parse a non-numeric string as a number. Check your input parsing."; + $MSG_CLASS_CAST_EXCEPTION="ClassCastException. Tried to cast an object to an incompatible type."; + $MSG_NEGATIVE_ARRAY_SIZE_EXCEPTION="NegativeArraySizeException. The array size computed to a negative value."; + $MSG_PYTHON_TRACEBACK="Python raised an exception. The traceback below shows the call stack — read from bottom to top to find the origin."; + $MSG_PYTHON_RECURSION_ERROR="RecursionError: maximum recursion depth exceeded. Consider converting to iteration or raising the limit."; + $MSG_PYTHON_INDENTATION_ERROR="IndentationError. Python uses indentation for code blocks. Check for mixed tabs/spaces."; + $MSG_PYTHON_ZERO_DIVISION="ZeroDivisionError."; + $MSG_PYTHON_NAME_ERROR="NameError. Used an undefined name (variable or function). Check spelling and imports."; + $MSG_GO_PANIC="Go panic — usually out-of-bounds access, nil pointer, or failed type assertion."; + $MSG_ABORTED_CORE_DUMPED="Aborted. Usually caused by a failed assert or std::terminate."; $MSG_MAIN_MUST_RETURN_INT="In the standard C language, the return value type of the main function must be int, and the use of void in teaching materials and VC is a non-standard usage."; $MSG_PRINTF_NOT_DECLARED_IN_SCOPE="The printf function is called without a declaration, and check whether the or header file is imported."; $MSG_IGNOREING_RETURN_VALUE="Warning: Ignore the return value of the function, it may be that the function is used incorrectly or the return value is not considered abnormal."; diff --git a/web/reinfo.php b/web/reinfo.php index 6decd40..249223e 100644 --- a/web/reinfo.php +++ b/web/reinfo.php @@ -24,9 +24,10 @@ if(!isset($_GET['sid'])){ function is_valid($str2){ global $_SESSION,$OJ_NAME,$OJ_FRIENDLY_LEVEL; if(isset($_SESSION[$OJ_NAME.'_'.'source_browser'])) return true; - return true; // 如果希望能让任何人都查看对比和RE,放开行首注释,并设定$OJ_SHOW_DIFF=true; if you fail to view diff , try remove the // at beginning of this line. if($OJ_FRIENDLY_LEVEL>3) return true; - + // 如果希望能让任何人都查看对比和RE,放开行首注释,并设定$OJ_SHOW_DIFF=true; + // return true; + $n = strlen($str2); $str = str_split($str2); $m = 1; @@ -65,39 +66,190 @@ if(!empty($spj)&&$spj[0][0]==2 && $OJ_HIDE_RIGHT_ANSWER && !isset($_SESSION[$OJ_ $view_errors = "

$MSG_MARK:$mark


"; $ok = false; } +/** + * 把 N 个相同测试点的 RE 折叠为 "1.in~5.in: Aborted (共 5 个测试点)" + */ +function dedup_runtimeinfo($text, &$dedup_count) { + $lines = explode("\n", $text); + $buckets = array(); // reason => [testcase, ...] + $other = array(); + foreach ($lines as $line) { + $line = trim($line); + if ($line === "") continue; + // 形如 "data/1001/1.in:Aborted" 或 "1.in: Segmentation fault" + if (preg_match('/^(?:data\/\d+\/)?([^\s:]+(?:[.:][^\s:]+)*?):\s*(.+)$/', $line, $m)) { + $tc = $m[1]; + $reason = trim($m[2]); + $buckets[$reason][] = $tc; + } else { + $other[] = $line; + } + } + $out = array(); + foreach ($other as $o) $out[] = $o; + foreach ($buckets as $reason => $tcs) { + $count = count($tcs); + if ($count == 1) { + $out[] = $tcs[0] . ": " . $reason; + } else { + $first = $tcs[0]; + $last = $tcs[$count - 1]; + $range = ($first === $last) ? $first : ($first . "~" . $last); + $out[] = $range . ": " . $reason . " (共 " . $count . " 个测试点)"; + $dedup_count += ($count - 1); + } + } + return implode("\n", $out); +} + $view_reinfo = ""; +$view_reinfo_raw = ""; // 原始(管理员/有权限者看) +$view_reinfo_summary = ""; // 折叠后(普通用户看) +$view_reinfo_dedup_count = 0; // 折叠掉的测试点数 +$verdict_color_class = "blue"; // semantic ui color: green/red/orange/yellow/grey +$result_icon = "info circle"; +$verdict_tip = ""; +$verdict_hints = array(); + if($ok){ if($row['user_id']!=$_SESSION[$OJ_NAME.'_'.'user_id']){ $view_mail_link= "Mail the auther"; } - + $sql = "SELECT `error` FROM `runtimeinfo` WHERE `solution_id`=?"; - $result = pdo_query($sql,$id); - - if(isset($result[0])){ - $row = $result[0]; - $view_reinfo = str_replace("\n\r","\n",$row['error']); - // $view_reinfo=htmlentities($view_reinfo,ENT_QUOTES,"UTF-8"); + $rt = pdo_query($sql,$id); + $raw_error = ""; + if(isset($rt[0])){ + $raw_error = str_replace("\n\r","\n",$rt[0]['error']); } - if(strpos($row['error'],"judge/")!==false&&!isset($_SESSION[$OJ_NAME."_administrator"])) $view_reinfo = "潜在的数组或指针越界,请检查代码。"; - else if(strpos($row['error'],"php")!==false) $view_reinfo = "error2"; - else if(strpos($row['error'],"PASS")!==false) $view_reinfo = "error3"; - else if($OJ_SHOW_DIFF && $row && ($ok||$isRE) && ($OJ_TEST_RUN||is_valid($row['error'])||$ok)){ - $view_reinfo = str_replace("\n\r","\n",$row['error']); - $view_reinfo = htmlspecialchars_decode($view_reinfo,ENT_QUOTES); - // $view_reinfo = htmlentities($view_reinfo,ENT_QUOTES,"UTF-8"); - // $view_reinfo = "```\n" . $view_reinfo. "```\n"; - - $view_reinfo .="
$MSG_MARK:$mark"; + // === 阶段 1:基于 solution.result 给"主解释"(永远非空)=== + $result_code = intval($row['result']); + $is_admin_session = isset($_SESSION[$OJ_NAME."_administrator"]); + $is_source_browser = isset($_SESSION[$OJ_NAME.'_'.'source_browser']); + // 颜色 + 图标 + switch ($result_code) { + case 4: $verdict_color_class = "green"; $result_icon = "check circle"; break; + case 5: // PE + case 6: $verdict_color_class = "red"; $result_icon = "times circle"; break; + case 7: // TLE + case 8: // MLE + case 9: $verdict_color_class = "yellow";$result_icon = "hourglass end"; break; + case 10: $verdict_color_class = "red"; $result_icon = "bug"; break; + case 11: $verdict_color_class = "grey"; $result_icon = "code"; break; + case 13: $verdict_color_class = "blue"; $result_icon = "play circle"; break; + default: $verdict_color_class = "blue"; $result_icon = "info circle"; } - else{ - $view_errors = $MSG_WARNING_ACCESS_DENIED; - //$view_reinfo = "出于数据保密原因,当前错误提示不可查看,如果希望能让任何人都查看对比和运行错误,请管理员配置\$OJ_SHOW_DIFF=true;
然后编辑本文件,开放18行首注释,令is_valid总是返回true。
\n Sorry , not available (RE:".$isRE.",OJ_SHOW_DIFF:".$OJ_SHOW_DIFF.",TR:".$OJ_TEST_RUN.",valid:".is_valid($row['error']).")"; + + // 友好提示 + switch ($result_code) { + case 4: // AC + $verdict_tip = "本次提交通过了所有测试点"; + $verdict_hints[] = "注意时间/内存是否接近限制,考虑是否有更优的算法"; + $verdict_hints[] = "可以继续挑战更高难度或查看其他人的标程"; + break; + case 5: // PE + $verdict_tip = "输出与预期基本一致但格式不符(Presentation Error)"; + $verdict_hints[] = "对照样例:每行末尾是否多/少换行"; + $verdict_hints[] = "检查空格、大小写、标点符号"; + $verdict_hints[] = "PE 通常是细微的格式问题,请逐字符对比"; + break; + case 6: // WA + $verdict_tip = "输出与预期不符(Wrong Answer)"; + $verdict_hints[] = "对照样例手动模拟程序执行过程"; + $verdict_hints[] = "检查边界条件:n=0、n=1、极值、空输入"; + $verdict_hints[] = "注意 long long 溢出、int 范围"; + break; + case 7: // TLE + $verdict_tip = $MSG_HINT_TLE; + $verdict_hints[] = "检查是否有死循环(循环变量未更新)"; + $verdict_hints[] = "优化算法复杂度(如 O(n²) → O(n log n))"; + $verdict_hints[] = "递归层数过深?改为迭代或加深栈"; + break; + case 8: // MLE + $verdict_tip = $MSG_HINT_MLE; + $verdict_hints[] = "大数组开在函数内(栈)?改为全局或 new"; + $verdict_hints[] = "Java: 减小内存使用或调整 JVM 参数"; + $verdict_hints[] = "递归太深未释放,考虑显式清理"; + break; + case 9: // OLE + $verdict_tip = $MSG_HINT_OLE; + $verdict_hints[] = "是否有死循环输出"; + $verdict_hints[] = "调试用的 print/cout 是否忘记删除"; + break; + case 10: // RE + $verdict_tip = "程序运行中发生错误(Runtime Error)"; + $verdict_hints[] = "数组下标是否越界(i .title { display: none; } - .single-subtask > .content { padding: 0 !important; } - .accordion > .content > .accordion { margin-top: 0; margin-bottom: 0; } - .accordion > .content > .accordion > .content { margin-top: 0; margin-bottom: 14px; } - .accordion > .content > .accordion > .content > :last-child { margin-bottom: -10px !important; } + +/* === reinfo 友好化样式 === */ +#result-banner { + margin-bottom: 18px; + border-left: 5px solid; +} +#result-banner.green { border-left-color: #21ba45; } +#result-banner.red { border-left-color: #db2828; } +#result-banner.yellow{ border-left-color: #fbbd08; } +#result-banner.blue { border-left-color: #2185d0; } +#result-banner.grey { border-left-color: #767676; } + +#result-banner h2.ui.header { + margin: 0; +} +#result-banner .verdict-stats { + margin-top: 6px; + font-size: 0.95em; + color: rgba(0,0,0,0.6); +} +#result-banner .verdict-stats .stat { + margin-right: 16px; +} +#result-banner .verdict-stats i.icon { + margin-right: 4px; +} + +#friendly-explain { + margin-bottom: 18px; +} +#friendly-explain .verdict-tip { + font-size: 1.05em; + margin-bottom: 12px; + padding: 8px 12px; + background: rgba(33,150,243,0.08); + border-radius: 6px; + border-left: 3px solid #2185d0; +} +#friendly-explain .verdict-hints { + margin: 0; + padding-left: 22px; +} +#friendly-explain .verdict-hints li { + margin-bottom: 6px; + line-height: 1.5; +} + +#raw-info-accordion { + margin-bottom: 18px; +} +#raw-info-accordion > .content { + padding: 8px 14px; +} +#raw-info-accordion pre#errtxt { + margin: 0; + padding: 12px; + background: #f7f7f9; + border-radius: 4px; + font-family: 'Fira Mono', 'Cascadia Code', Consolas, monospace; + font-size: 0.9em; + white-space: pre-wrap; + word-break: break-all; +} +#raw-info-accordion .title .dedup-label { + margin-left: 8px; +} +#raw-info-accordion .empty-notice { + color: #999; + font-style: italic; +} + +.quick-actions { + text-align: center; + margin-top: 24px; + margin-bottom: 12px; +} +.quick-actions .ui.buttons { + box-shadow: none; +} + +/* AI 点评区 */ +#llm-section { + margin-top: 20px; + margin-bottom: 18px; +} +#llm-section .ui.header { + margin-top: 0; +} +#llm-review-result { + word-break: break-word; +} + +/* 错误解释列表(由 JS explain() 填充) */ +#errexp-list { + list-style: disc; + padding-left: 22px; + margin: 0; +} +#errexp-list li { + margin-bottom: 6px; + line-height: 1.5; +} +#errexp-list li code { + background: rgba(0,0,0,0.05); + padding: 1px 4px; + border-radius: 3px; + font-size: 0.9em; +}
-
-

- -

-
-
-
-

-
-
-
+ -
-

- -

-
-
-
-
-
- - - - - - - - -
-
-
- 🤖 AI 点评 -
+ +
+

+
-
- - - - + +
+ : % + KB + ms +
+

+
+ + +
+
+ + +
+
+ + +
+ +
    + +
  • + +
+ + +
    +
    + + +
    +
    + + + + + + + + + (无) + +
    +
    + +

    当前判题结果没有原始错误信息(如 TLE/MLE 通常不会写 runtimeinfo)。

    + +
    +
    - + +
    +
    + +
    + +
    + +
    + + + + + + + + + + diff --git a/web/template/syzoj/submitpage.php b/web/template/syzoj/submitpage.php index 5f81125..1c0d9cf 100644 --- a/web/template/syzoj/submitpage.php +++ b/web/template/syzoj/submitpage.php @@ -1,24 +1,143 @@ - - -
    - -
    " method="post" onsubmit='do_submit()' enctype="multipart/form-data" > - - - - - -Problem - -25) $pid=25; -?> -Problem of Contest - - - -Language: - - -: -click to change - - - - - - - -1 || !$OJ_TEST_RUN ){?> - - - - - - - - - - -
    - - - - -

    指定上传文件:$solution_name

    "; - - } - - ?> - -
    -
    - -
    -
    - -
    -
    -
    - - - + border: 1px dashed #c0c0c0; + color: #555; + font-size: 1.1em; +} + +.solution-name-title { + text-align: center; + color: #2185d0; + margin: 0 0 16px 0; + font-weight: 600; +} + +#blockly { + margin: 16px 0; +} + +#result.badge { + display: inline-block; + padding: 4px 10px; + border-radius: 12px; + background: #e8e8e8; + color: rgba(0,0,0,.6); + font-size: 0.85em; + font-weight: 700; + white-space: nowrap; +} + +@media (max-width: 600px) { + .submit-card { + padding: 16px; + } + .submit-title { + font-size: 1.2em; + } + #source { + height: 350px; + } + .btn { + padding: 6px 12px; + font-size: 0.95em; + } +} + + +
    +
    +
    +

    + + + + # + + + Contest # + +

    + + " method="post" onsubmit="do_submit()" enctype="multipart/form-data"> - -
    - - - - - - - +
    + +
    + + +
    + + +
    + +
    -
    + + +
    + + + click to change +
    + +
    + + +
    +
    + +
    + + + +
    +
    +
    +
    - + +
    +
    + +
    + +
    + + + +
    +
    +
    + +
    + +
    +
    +
    + + +
    + +
    +
    + +
    + +
    + + + +

    📎

    + + +
    +
    + + + + + + + + +
    + + +
    + + +
    + +
    + +
    + + + + + + + - - - -
    Blockly
    - - -
    +
    + @@ -515,7 +849,7 @@ function loadFromBlockly(){ editor.getSession().on("change", syncEditorSource); switchLang(); syncEditorSource(); - reloadtemplate($("#language").val()); + reloadtemplate($("#language").val()); function getSourceDraftKey(languageOverride){ let language=languageOverride; if(language===undefined||language===null||language===""){ @@ -534,22 +868,18 @@ function loadFromBlockly(){ if(typeof(editor) != "undefined") $("#hide_source").val(editor.getValue()); localStorage.setItem(key,$("#hide_source").val()); - //console.log("autosaving "+key+"..."+new Date()); } } $(document).ready(function(){ - $("#source").css("height",window.innerHeight-180); - if($("#vcode")!=undefined) $("#vcode").click(); + $("#source").css("height",window.innerHeight-220); + if($("#vcode-img")!=undefined) $("#vcode-img").click(); if(!!localStorage){ let key=getSourceDraftKey(); let saved=localStorage.getItem(key); if(saved!=null&&saved!=""&&saved.length>editor.getValue().length){ - //let load=confirm("发现自动保存的源码,是否加载?(仅有一次机会)"); - //if(load){ - console.log("loading "+saved.length); - if(typeof(editor) != "undefined") - editor.setValue(saved); - //} + console.log("loading "+saved.length); + if(typeof(editor) != "undefined") + editor.setValue(saved); } } @@ -574,7 +904,7 @@ function loadFromBlockly(){ } function toggleTheme(event) { event.preventDefault(); - + if (editor.getTheme() === "ace/theme/xcode") { editor.setTheme("ace/theme/monokai"); } else { @@ -585,9 +915,9 @@ function loadFromBlockly(){ var level = 0; var LOOP_SIZE = 100; function finishTabifier(code) { - code = code.replace(/\n\s*\n/g, '\n'); //blank lines - code = code.replace(/^[\s\n]*/, ''); //leading space - code = code.replace(/[\s\n]*$/, ''); //trailing space + code = code.replace(/\n\s*\n/g, '\n'); + code = code.replace(/^[\s\n]*/, ''); + code = code.replace(/[\s\n]*$/, ''); level = 0; var session = editor.getSession(); session.setValue(code); @@ -596,7 +926,7 @@ function finishTabifier(code) { function cleanCStyle(code) { var i = 0; - code = code.replace(/\)\n[\s]*/g,')\n '); //single line if while for + code = code.replace(/\)\n[\s]*/g,')\n '); function cleanAsync() { var iStart = i; for (; i < code.length && i < iStart + LOOP_SIZE; i++) { @@ -616,8 +946,7 @@ function cleanCStyle(code) { } out += c; } else if (instring) { - if (instring == c && // this string closes at the next matching quote - // unless it was escaped, or the escape is escaped + if (instring == c && ('\\' != code.charAt(i - 1) || '\\' == code.charAt(i - 2)) ) { instring = false; @@ -678,9 +1007,9 @@ function cleanCStyle(code) { } } - code = code.replace(/^[\s\n]*/, ''); //leading space - code = code.replace(/[\s\n]*$/, ''); //trailing space - code = code.replace(/[\n\r]+/g, '\n'); //collapse newlines + code = code.replace(/^[\s\n]*/, ''); + code = code.replace(/[\s\n]*$/, ''); + code = code.replace(/[\n\r]+/g, '\n'); var out = tabs(), li = level, c = ''; var infor = false, forcount = 0, instring = false, incomment = false; @@ -691,14 +1020,10 @@ function tabs() { for (var j = 0; j < level; j++) s += '\t'; return s; } -// Functions function formatCode() { var session = editor.getSession(); cleanCStyle(session.getValue()); } - - -