// 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::use advanced editor": { "en": "use advanced editor", "zh-cn": "使用高级编辑器" }, "editor::language": { "en": "Language", "zh-cn": "语言" }, "editor::browse": { "en": "Browse", "zh-cn": "浏览" }, "editor::upload by editor": { "en": "Upload by editor", "zh-cn": "使用编辑器上传" }, "editor::upload from local": { "en": "Upload from local", "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, 100, 80))); } else if (score == 100) { return ColorConverter.toStr(ColorConverter.toRGB(new HSV(120, 100, 80))); } else { return ColorConverter.toStr(ColorConverter.toRGB(new HSV(30 + score * 60 / 100, 100, 90))); } } function getUserLink(username, realname) { if (!username) { return ''; } var text = username; if (username.charAt(0) == '@') { username = username.substr(1); } if (realname) { text = text + ' (' + realname + ')'; } return '' + text + ''; } function getUserSpan(username, realname) { if (!username) { return ''; } var text = username; if (username.charAt(0) == '@') { username = username.substr(1); } if (realname) { text = text + ' (' + realname + ')'; } return '' + text + ''; } function replaceWithHighlightUsername() { var username = $(this).text(); var realname = $(this).data("realname"); if ($(this).data("link") != 0) { $(this).replaceWith(getUserLink(username, realname)); } else { $(this).replaceWith(getUserSpan(username, realname)); } } $.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(isBootstrap5Page ? 'has-validation' : 'has-error'); if (isBootstrap5Page) $('#div-' + name + ' .form-floating, #input-' + name).addClass('is-invalid'); $('#help-' + name).text(err); return false; } else { $('#div-' + name).removeClass(isBootstrap5Page ? 'has-validation' : 'has-error'); if (isBootstrap5Page) $('#div-' + name+ ' .form-floating, #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 = $('