// locale uojLocaleData = { "username": { "en": "Username", "zh-cn": "用户名" }, "contests::total score": { "en": "Score", "zh-cn": "总分" }, "contests::n participants": { "en": function(n) { return n + " participant" + (n <= 1 ? '' : 's'); }, "zh-cn": function(n) { return "共 " + n + " 名参赛者"; } }, "click-zan::good": { "en": "Good", "zh-cn": "好评" }, "click-zan::bad": { "en": "Bad", "zh-cn": "差评" }, "editor::language": { "en": "Language", "zh-cn": "语言" }, "editor::browse": { "en": "Browse", "zh-cn": "浏览" }, "editor::upload source": { "en": "Source", "zh-cn": "来源" }, "editor::upload by editor": { "en": "Editor", "zh-cn": "编辑器" }, "editor::upload from local": { "en": "Local file", "zh-cn": "本地文件" } }; function uojLocale(name) { locale = $.cookie('uoj_locale'); if (uojLocaleData[name] === undefined) { return ''; } if (uojLocaleData[name][locale] === undefined) { locale = 'zh-cn'; } val = uojLocaleData[name][locale]; if (!$.isFunction(val)) { return val; } else { var args = []; for (var i = 1; i < arguments.length; i++) { args.push(arguments[i]); } return val.apply(this, args); } } // utility function strToDate(str) { var a = str.split(/[^0-9]/); return new Date( parseInt(a[0]), parseInt(a[1]) - 1, parseInt(a[2]), parseInt(a[3]), parseInt(a[4]), parseInt(a[5]), 0); } function dateToStr(date) { return date.getFullYear() + '-' + (date.getMonth() + 1) + '-' + date.getDate() + ' ' + date.getHours() + ':' + date.getMinutes() + ':' + date.getSeconds(); } function toFilledStr(o, f, l) { var s = o.toString(); while (s.length < l) { s = f.toString() + s; } return s; } function getPenaltyTimeStr(x) { var ss = toFilledStr(x % 60, '0', 2); x = Math.floor(x / 60); var mm = toFilledStr(x % 60, '0', 2); x = Math.floor(x / 60); var hh = x.toString(); return hh + ':' + mm + ':' + ss; } function htmlspecialchars(str) { var s = ""; if (str.length == 0) return ""; s = str.replace(/&/g, "&"); s = s.replace(//g, ">"); s = s.replace(/"/g, """); return s; } function getColOfScore(score) { if (score == 0) { return ColorConverter.toStr(ColorConverter.toRGB(new HSV(0, 76, 86))); } else if (score == 100) { return ColorConverter.toStr(ColorConverter.toRGB(new HSV(130, 89, 72))); } else { return ColorConverter.toStr(ColorConverter.toRGB(new HSV(30 + score * 60 / 100, 83, 89))); } } function getUserLink(username, realname, color) { if (!username) { return ''; } var text = username; var style = ''; if (username.charAt(0) == '@') { username = username.substr(1); } if (realname) { text = text + ' (' + realname + ')'; } if (color) { style += 'color: ' + color + ';'; } return '' + text + ''; } function getUserSpan(username, realname, color) { if (!username) { return ''; } var text = username; var style = ''; if (username.charAt(0) == '@') { username = username.substr(1); } if (realname) { text = text + ' (' + realname + ')'; } if (color) { style += 'color: ' + color + ';'; } return '' + text + ''; } function replaceWithHighlightUsername() { var username = $(this).text(); var realname = $(this).data("realname"); var color = $(this).data("color"); if ($(this).data("link") != 0) { $(this).replaceWith(getUserLink(username, realname, color)); } else { $(this).replaceWith(getUserSpan(username, realname, color)); } } $.fn.uoj_honor = function() { return this.each(function() { var honor = $(this).text(); var realname = $(this).data("realname"); if (realname) { honor = honor + ' (' + realname + ')'; } $(this).css('color', '#007bff').html(honor); }); } function showErrorHelp(name, err) { if (err) { $('#div-' + name).addClass('has-validation has-error'); $('#div-' + name).addClass('is-invalid'); $('#input-' + name).addClass('is-invalid'); $('#help-' + name).text(err); return false; } else { $('#div-' + name).removeClass('has-validation has-error'); $('#div-' + name).removeClass('is-invalid'); $('#input-' + name).removeClass('is-invalid'); $('#help-' + name).text(''); return true; } } function getFormErrorAndShowHelp(name, val) { var err = val($('#input-' + name).val()); return showErrorHelp(name, err); } function validateSettingPassword(str) { if (str.length < 6) { return '密码长度不应小于6。'; } else if (! /^[!-~]+$/.test(str)) { return '密码应只包含可见ASCII字符。'; } else if (str != $('#input-confirm_password').val()) { return '两次输入的密码不一致。'; } else { return ''; } } function validatePassword(str) { if (str.length < 6) { return '密码长度不应小于6。'; } else if (! /^[!-~]+$/.test(str)) { return '密码应只包含可见ASCII字符。'; } else { return ''; } } function validateEmail(str) { if (str.length > 50) { return '电子邮箱地址太长。'; } else if (! /^(.+)@(.+)$/.test(str)) { return '电子邮箱地址非法。'; } else { return ''; } } function validateUsername(str) { if (str.length == 0) { return '用户名不能为空。'; } else if (! /^[a-zA-Z0-9_]+$/.test(str)) { return '用户名应只包含大小写英文字母、数字和下划线。'; } else { return ''; } } function validateQQ(str) { if (str.length < 5) { return 'QQ的长度不应小于5。'; } else if (str.length > 15) { return 'QQ的长度不应大于15。'; } else if (/\D/.test(str)) { return 'QQ应只包含0~9的数字。'; } else { return ''; } } function validateMotto(str) { if (str.length > 1024) { return '不能超过 1024 个字符。'; } else { return ''; } } // tags $.fn.uoj_problem_tag = function() { return this.each(function() { $(this).attr('href', uojHome + '/problems?tag=' + encodeURIComponent($(this).text())); }); } $.fn.uoj_list_tag = function() { return this.each(function() { $(this).attr('href', uojHome + '/lists?tag=' + encodeURIComponent($(this).text())); }); } $.fn.uoj_blog_tag = function() { return this.each(function() { $(this).attr('href', uojBlogUrl + '/archive?tag=' + encodeURIComponent($(this).text())); }); } // click zan function click_zan(zan_id, zan_type, zan_delta, node) { var loading_node = $('
_uid
。')))
).append(
$('')
.append($('').append(''))
.append($('').append(input_luogu_client_id))
.append($('').append($('').append('请填入 Cookie 中的 __client_id
。')))
);
} else if (oj == 'codeforces') {
var codeforces_account_data = {"JSESSIONID": ""};
var input_codeforces_jsessionid = $('');
if ('localStorage' in window) {
try {
var codeforces_account_data_str = localStorage.getItem('uoj_remote_judge_codeforces_account_data');
if (codeforces_account_data_str) {
codeforces_account_data = JSON.parse(codeforces_account_data_str);
}
} catch (e) {}
var save_codeforces_account_data = function() {
localStorage.setItem('uoj_remote_judge_codeforces_account_data', JSON.stringify(codeforces_account_data));
}
}
input_codeforces_jsessionid.change(function() {
codeforces_account_data.JSESSIONID = $(this).val();
input_my_account_data.val(JSON.stringify(codeforces_account_data));
save_codeforces_account_data();
my_account_validation_status.html('待验证');
});
my_account_validation_btn.click(function() {
validate_my_account({
type: 'codeforces',
JSESSIONID: input_codeforces_jsessionid.val(),
});
});
input_my_account_data.val(JSON.stringify(codeforces_account_data));
input_codeforces_jsessionid.val(codeforces_account_data.JSESSIONID);
if (codeforces_account_data.JSESSIONID) {
validate_my_account({
type: 'codeforces',
JSESSIONID: codeforces_account_data.JSESSIONID,
});
}
div_account_data.append(
$('')
.append($('').append(''))
.append($('').append(input_codeforces_jsessionid))
.append($('').append($('').append('请填入 Cookie 中的 JSESSIONID
。')))
);
} else if (oj == 'loj') {
var loj_account_data = {username: "", token: ""};
var input_loj_token = $('');
if ('localStorage' in window) {
try {
var loj_account_data_str = localStorage.getItem('uoj_remote_judge_loj_account_data');
if (loj_account_data_str) {
loj_account_data = JSON.parse(loj_account_data_str);
}
} catch (e) {}
var save_loj_account_data = function() {
localStorage.setItem('uoj_remote_judge_loj_account_data', JSON.stringify(loj_account_data));
}
} else {
var save_loj_account_data = function() {};
}
input_loj_token.change(function() {
loj_account_data.token = $(this).val();
input_my_account_data.val(JSON.stringify(loj_account_data));
save_loj_account_data();
my_account_validation_status.html('待验证');
});
my_account_validation_btn.click(function() {
validate_my_account({
type: 'loj',
token: input_loj_token.val(),
});
});
input_my_account_data.val(JSON.stringify(loj_account_data));
input_loj_token.val(loj_account_data.token);
if (loj_account_data.token) {
validate_my_account({
type: 'loj',
token: loj_account_data.token,
});
}
div_account_data.append(
$('')
.append($('').append(''))
.append($('').append(input_loj_token))
.append($('').append($('').append('请前往 LibreOJ 登录账号,然后输入在控制台中运行 console.log(JSON.parse(localStorage.appState).token)
的输出结果。')))
);
} else if (oj == 'uoj') {
var uoj_account_data = {"UOJSESSID": ""};
var input_uoj_uojsessid = $('');
if ('localStorage' in window) {
try {
var uoj_account_data_str = localStorage.getItem('uoj_remote_judge_uoj_account_data');
if (uoj_account_data_str) {
uoj_account_data = JSON.parse(uoj_account_data_str);
}
} catch (e) {}
var save_uoj_account_data = function() {
localStorage.setItem('uoj_remote_judge_uoj_account_data', JSON.stringify(uoj_account_data));
}
}
input_uoj_uojsessid.change(function() {
uoj_account_data.UOJSESSID = $(this).val();
input_my_account_data.val(JSON.stringify(uoj_account_data));
save_uoj_account_data();
my_account_validation_status.html('待验证');
});
my_account_validation_btn.click(function() {
validate_my_account({
type: 'uoj',
UOJSESSID: input_uoj_uojsessid.val(),
});
});
input_my_account_data.val(JSON.stringify(uoj_account_data));
input_uoj_uojsessid.val(uoj_account_data.UOJSESSID);
if (uoj_account_data.UOJSESSID) {
validate_my_account({
type: 'uoj',
UOJSESSID: uoj_account_data.UOJSESSID,
});
}
div_account_data.append(
$('')
.append($('').append(''))
.append($('').append(input_uoj_uojsessid))
.append($('').append($('').append('请填入 Cookie 中的 UOJSESSID
。')))
);
}
$(this).append(
$('').append(
$('')
.append(input_submit_type_bot)
.append($('').append(' 公用账号'))
).append(
$('')
.append(input_submit_type_my)
.append($('').append(' 自有账号'))
).append(
$('')
.append(input_submit_type_archive)
.append($('').append(' 归档'))
)
)
.append(div_submit_type_bot)
.append(div_submit_type_my)
.append(div_submit_type_archive)
.append(div_account_data)
.append(input_my_account_data);
});
}
// problem_configure: print problem.conf
$.fn.problem_conf_preview = function(problem_conf) {
return $(this).each(function() {
var keys = Object.keys(problem_conf);
var res = '';
for (var i = 0; i < keys.length; i++) {
var key = keys[i];
var value = problem_conf[key];
if (!value) {
continue;
}
if (key == 'use_builtin_judger' && value == 'off') {
continue;
}
if (key == 'use_builtin_checker' && value == 'ownchk') {
continue;
}
res += key + ' ' + value + '\n';
}
$(this).html('' + res + '
');
});
}
// problem_configure: point scores
$.fn.problem_configure_point_scores = function(problem_conf) {
return $(this).each(function() {
var _this = this;
var n_tests = parseInt(problem_conf['n_tests']);
$(this).empty();
if (isNaN(n_tests) || n_tests <= 0) {
$(this).html('不可用。');
return;
}
for (var i = 1; i <= n_tests; i++) {
var input_point_score = $('');
if (problem_conf['point_score_' + i]) {
input_point_score.val(problem_conf['point_score_' + i]);
}
(function(i){
input_point_score.change(function() {
problem_conf['point_score_' + i] = $(this).val();
$('#problem-conf-preview').problem_conf_preview(problem_conf);
});
})(i);
$(this).append(
$('').append(
$('')
.append($('').append(''))
.append($('').append(input_point_score))
)
);
}
$('.uoj-problem-configure-point-score-input', this).change(function() {
var full_score = 100;
var rest_tests = parseInt(problem_conf['n_tests'] || '10');
var score_type = problem_conf['score_type'] || 'int';
$('.uoj-problem-configure-point-score-input', _this).each(function() {
var point_score = parseInt($(this).val());
if (!isNaN(point_score)) {
full_score -= point_score;
rest_tests--;
}
});
$('.uoj-problem-configure-point-score-input', _this).each(function() {
if ($(this).val() == '') {
var val = full_score / rest_tests;
if (score_type == 'int') {
val = Math.floor(val);
} else {
var decimal_places = parseInt(score_type.substring(5));
val = val.toFixed(decimal_places);
}
$(this).attr('placeholder', val);
}
});
});
$('.uoj-problem-configure-point-score-input', this).first().trigger('change');
});
};
// problem_configure: subtasks
$.fn.problem_configure_subtasks = function(problem_conf) {
return $(this).each(function() {
var _this = this;
var n_subtasks = parseInt(problem_conf['n_subtasks'] || '0');
$(this).empty();
if (isNaN(n_subtasks)) {
$(this).html('不可用。');
return;
}
var input_n_subtasks = $('');
var div_subtasks = $('');
if (n_subtasks) {
input_n_subtasks.val(n_subtasks);
}
$(this).append(
$('').append(
$('').append(
$('').append('')
).append(
$('').append(input_n_subtasks)
)
)
).append(div_subtasks);
input_n_subtasks.change(function() {
div_subtasks.empty();
var n_subtasks = parseInt(input_n_subtasks.val() || '0');
var n_tests = parseInt(problem_conf['n_tests'] || '10');
problem_conf['n_subtasks'] = input_n_subtasks.val();
for (var i = 1; i <= n_subtasks; i++) {
var input_subtask_type = $('');
var input_subtask_end = $('');
var input_subtask_score = $('');
var input_subtask_used_time_type = $('');
input_subtask_type
.append($('').text('错一个就零分'))
.append($('').text('取所有测试点中的最小值'));
input_subtask_used_time_type
.append($('').text('全部相加'))
.append($('').text('取所有测试点中的最大值'));
(function(i) {
input_subtask_type.change(function() {
problem_conf['subtask_type_' + i] = $(this).val();
$('#problem-conf-preview').problem_conf_preview(problem_conf);
});
input_subtask_end.change(function() {
problem_conf['subtask_end_' + i] = $(this).val();
$('#problem-conf-preview').problem_conf_preview(problem_conf);
})
input_subtask_score.change(function() {
problem_conf['subtask_score_' + i] = $(this).val();
$('#problem-conf-preview').problem_conf_preview(problem_conf);
});
input_subtask_used_time_type.change(function() {
problem_conf['subtask_used_time_type_' + i] = $(this).val();
$('#problem-conf-preview').problem_conf_preview(problem_conf);
});
})(i);
if (problem_conf['subtask_type_' + i]) {
input_subtask_type.val(problem_conf['subtask_type_' + i]);
}
if (problem_conf['subtask_end_' + i]) {
input_subtask_end.val(problem_conf['subtask_end_' + i]);
}
if (problem_conf['subtask_score_' + i]) {
input_subtask_score.val(problem_conf['subtask_score_' + i]);
}
if (problem_conf['subtask_used_time_type_' + i]) {
input_subtask_used_time_type.val(problem_conf['subtask_used_time_type_' + i]);
}
div_subtasks.append(
$('').append(
$('').text('Subtask #' + i)
).append(
$('').append(
$('').append(
$('').append('')
).append(
$('').append(input_subtask_type)
)
).append(
$('').append(
$('').append('')
).append(
$('').append(input_subtask_end)
)
).append(
$('').append(
$('').append('')
).append(
$('').append(input_subtask_score)
)
).append(
$('').append(
$('').append('')
).append(
$('').append(input_subtask_used_time_type)
)
)
)
);
}
$('.uoj-problem-configure-subtask-score-input', _this).change(function() {
var full_score = 100;
var rest_subtasks = parseInt(problem_conf['n_subtasks'] || '10');
var score_type = problem_conf['score_type'] || 'int';
$('.uoj-problem-configure-subtask-score-input', _this).each(function() {
var subtask_score = parseInt($(this).val());
if (!isNaN(subtask_score)) {
full_score -= subtask_score;
rest_subtasks--;
}
});
$('.uoj-problem-configure-subtask-score-input', _this).each(function() {
if ($(this).val() == '') {
var val = full_score / rest_subtasks;
if (score_type == 'int') {
val = Math.floor(val);
} else {
var decimal_places = parseInt(score_type.substring(5));
val = val.toFixed(decimal_places);
}
$(this).attr('placeholder', val);
}
});
});
$('.uoj-problem-configure-subtask-score-input', _this).first().trigger('change');
$('#problem-conf-preview').problem_conf_preview(problem_conf);
});
input_n_subtasks.trigger('change');
});
};
// custom test
function custom_test_onsubmit(response_text, div_result, url) {
if (response_text != '') {
$(div_result).html('