X-Git-Url: https://glassweightruler.freedombox.rocks/gitweb/Ventoy.git/blobdiff_plain/4bf43ab9d4e6b724836724c1d514760d164df79a..HEAD:/Plugson/www/static/js/vtoy.js diff --git a/Plugson/www/static/js/vtoy.js b/Plugson/www/static/js/vtoy.js index aee3379..ad82628 100644 --- a/Plugson/www/static/js/vtoy.js +++ b/Plugson/www/static/js/vtoy.js @@ -1,7 +1,23 @@ +function VtoyUTF16HexToAscii(hex) { + var str = ""; + for (var i = 0; i < hex.length; i += 4) { + str += String.fromCharCode(parseInt(hex.substring(i, i + 4), 16)); + } + + return str; +} + function ventoy_replace_slash(str) { var str1 = str.replace(/\\/g, '/'); var str2 = str1.replace(/\/\//g, '/'); + + if (str2 && str2.length > 0) { + if (str2.substr(-1) === "/") { + return str2.substr(0, str2.length - 1); + } + } + return str2; } @@ -17,6 +33,8 @@ function ventoy_get_ulen(str) { function ventoy_common_check_path(path) { + var curdir + if (path.indexOf('//') >= 0) { return false; } @@ -25,7 +43,12 @@ function ventoy_common_check_path(path) { return false; } - if (path.substr(0, g_current_dir.length) != g_current_dir) { + curdir = path.substr(0, g_current_dir.length); + if (curdir.match("^[a-z]:$")) { + curdir = curdir.toUpperCase(); + } + + if (curdir != g_current_dir) { return false; } @@ -281,71 +304,6 @@ String.prototype.endsWith = function(str) { return false; } -window.Message = function() { - var _showMsg = function(type, msg, time) { - var o = {type : type, msg : msg }; - if(time) { - o.time = time; - } - _show(o); - } - - var _show = function(options) { - var ops = { - msg : "提示内容", - type: 'S', - time: 3000 - }; - $.extend(ops, options); - - var msg_class = 'alert-success'; - if('S' === ops.type || 's' === ops.type) { - msg_class = 'alert-success'; - } else if ('E' === ops.type || 'e' === ops.type) { - msg_class = 'alert-danger'; - } else if ('W' === ops.type || 'w' === ops.type) { - msg_class = 'alert-warning'; - } else if ('I' === ops.type || 'i' === ops.type) { - msg_class = 'alert-info'; - } else { - alert("未知的类型,请使用: w-警告;s-成功;e-失败;i-提示"); - return; - } - var $messageContainer = $("#fcss_message"); - if($messageContainer.length === 0) { - $messageContainer = $('
'); - $messageContainer.appendTo($('body')); - } - var $div = $(''); - var $btn = $(''); - $div.append($btn).append(ops.msg).appendTo($messageContainer); - setTimeout(function() { - $div.remove(); - }, ops.time); - } - - var _success = function(msg, time) { - _showMsg('s', msg, time); - } - var _error = function(msg, time) { - _showMsg('e', msg, time || 5000); - } - var _warn = function(msg, time) { - _showMsg('w', msg, time); - } - var _info = function(msg, time) { - _showMsg('i', msg, time); - } - - return { - success : _success, - error : _error, - warn : _warn, - info : _info, - show : _show - } -}(); - var g_vtoy_cur_language_en = { @@ -369,6 +327,7 @@ var g_vtoy_cur_language_en = "STR_OPT_SETTING": "Option Setting", "STR_OPT_DESC": "Option Description", "STR_EDIT": "Edit", + "STR_RESET": "Reset", "STR_FILE": "File", "STR_DIR": "Dir", "STR_SAVE_TIP": "Data in current page has been modified. Do you want to save it?", @@ -429,10 +388,10 @@ var g_vtoy_cur_language_en = "STR_PATH_TOO_LONG": "The path exceeds the maximum supported length, please check!", "STR_INPUT_TOO_LONG": "The string exceeds the maximum supported length, please check!", - "STR_INVALID_FILE_PATH": "Invalid full file path, please check!", - "STR_INVALID_FILE_PATH1": "The 1st file path is invalid!", - "STR_INVALID_FILE_PATH2": "The 2nd file path is invalid!", - "STR_INVALID_NEW_FILE_PATH": "The full file path of new is invalid, please check!", + "STR_INVALID_FILE_PATH": "Invalid or nonexist full file path, please check!", + "STR_INVALID_FILE_PATH1": "The 1st file path is invalid or nonexist!", + "STR_INVALID_FILE_PATH2": "The 2nd file path is invalid or nonexist!", + "STR_INVALID_NEW_FILE_PATH": "The full file path of new is invalid or nonexist, please check!", "STR_INVALID_DIR_PATH": "Invalid directory path, please check!", "STR_INVALID_NUMBER": "Please input valid non-negative integer!", "STR_INVALID_AUTOSEL": "autosel exceeds the length of the list!", @@ -446,7 +405,7 @@ var g_vtoy_cur_language_en = "STR_SET_TIP_FOR_DIR": "Set Menu Tip For Directory", "STR_SET_INJECTION_FOR_FILE": "[image] Set injection for a file", "STR_SET_INJECTION_FOR_DIR": "[parent] Set the same injection for all the files under a directory.", - "STR_INVALID_ARCHIVE_PATH": "Invalid archive file path, please check!", + "STR_INVALID_ARCHIVE_PATH": "Invalid or nonexist archive file path, please check!", "STR_SET_PWD_FOR_FILE": "[file] Set password for a file.", "STR_SET_PWD_FOR_DIR": "[parent] Set the same password for all the files under a directory.", "STR_SET_AUTO_INSTALL_FOR_FILE": "[image] Set auto install template for a file", @@ -479,6 +438,12 @@ var g_vtoy_cur_language_en = "STR_SECURE_BOOT_ENABLE": "Enable", "STR_SECURE_BOOT_DISABLE": "Disable", "STR_SYNTAX_ERROR_TIP": "Syntax error detected in ventoy.json, so the configuration is not loaded!", + "STR_INVALID_CONFIG_TIP": "Invalid configuration detected in ventoy.json, so the configuration is not loaded!", + "STR_CONFIG_SAVE_ERROR_TIP": "Failed to write ventoy.json file. Check VentoyPlugson.log for more details!", + + "STR_JSON_PREVIEW": "JSON Preview", + "STR_JSON_COPY_SUCCESS": "JSON Copy Success", + "STR_JSON_COPY_FAILED": "JSON Copy Failed", "STR_XXX": "xxx" }; @@ -505,6 +470,7 @@ var g_vtoy_cur_language_cn = "STR_OPT_SETTING": "选项设置", "STR_OPT_DESC": "选项说明", "STR_EDIT": "设置", + "STR_RESET": "重置", "STR_FILE": "文件", "STR_DIR": "目录", "STR_SAVE_TIP": "当前页面数据已经修改,是否保存?", @@ -563,10 +529,10 @@ var g_vtoy_cur_language_cn = "STR_PATH_TOO_LONG": "路径超过最大支持长度,请检查!", "STR_INPUT_TOO_LONG": "字符串超过最大支持长度,请检查!", - "STR_INVALID_FILE_PATH": "文件路径不合法,请检查!", - "STR_INVALID_FILE_PATH1": "第1个文件路径不合法,请检查!", - "STR_INVALID_FILE_PATH2": "第2个文件路径不合法,请检查!", - "STR_INVALID_NEW_FILE_PATH": "new 文件路径不合法,请检查!", + "STR_INVALID_FILE_PATH": "文件路径不合法或不存在,请检查!", + "STR_INVALID_FILE_PATH1": "第1个文件路径不合法或不存在,请检查!", + "STR_INVALID_FILE_PATH2": "第2个文件路径不合法或不存在,请检查!", + "STR_INVALID_NEW_FILE_PATH": "new 文件路径不合法或不存在,请检查!", "STR_INVALID_DIR_PATH": "文件夹路径不合法,请检查!", "STR_INVALID_NUMBER": "请输入合法的非负整数!", "STR_INVALID_AUTOSEL": "autosel 的值超过了列表实际长度!", @@ -580,7 +546,7 @@ var g_vtoy_cur_language_cn = "STR_SET_TIP_FOR_DIR": "为目录设置菜单提示信息", "STR_SET_INJECTION_FOR_FILE": "[image] 为某一个文件设置注入", "STR_SET_INJECTION_FOR_DIR": "[parent] 为某个目录下的所有文件设置相同的注入", - "STR_INVALID_ARCHIVE_PATH": "Archive 文件路径非法,请检查!", + "STR_INVALID_ARCHIVE_PATH": "Archive 文件路径非法或不存在,请检查!", "STR_SET_PWD_FOR_FILE": "[file] 为指定文件设置密码", "STR_SET_PWD_FOR_DIR": "[parent] 为某个目录下的所有文件设置相同的密码", "STR_SET_AUTO_INSTALL_FOR_FILE": "[image] 为某个镜像文件设置自动安装脚本", @@ -613,8 +579,12 @@ var g_vtoy_cur_language_cn = "STR_SECURE_BOOT_ENABLE": "开启", "STR_SECURE_BOOT_DISABLE": "未开启", "STR_SYNTAX_ERROR_TIP": "ventoy.json 文件中存在语法错误,配置未加载!", + "STR_INVALID_CONFIG_TIP": "ventoy.json 文件中存在错误配置,配置未加载!", + "STR_CONFIG_SAVE_ERROR_TIP": "ventoy.json 文件写入失败,详细信息请参考 VentoyPlugson.log 文件!", - + "STR_JSON_PREVIEW": "JSON 预览", + "STR_JSON_COPY_SUCCESS": "JSON 内容复制成功", + "STR_JSON_COPY_FAILED": "JSON 内容复制失败", "STR_XXX": "xxx" }; @@ -625,12 +595,45 @@ var g_current_language = 'cn'; var g_vtoy_cur_language = g_vtoy_cur_language_cn; var g_vtoy_data_default_index = 6; +var g_bios_postfix = [ "", "_legacy", "_uefi", "_ia32", "_aa64", "_mips" ]; +var g_del_all_path = '4119ae33-98ea-448e-b9c0-569aafcf1fb4'; var g_file_with_extra = false; var g_dir_with_extra = false; var g_file_fuzzy_match = 0; var g_file_modal_callback; var g_dir_modal_callback; +function GetResetTabConfigTipMsg(index, name) { + var msgstr; + + if (g_current_language === 'en') { + msgstr = 'Are you sure to reset all the configurations on the ' + name + g_bios_postfix[index] + ' tab ?'; + } else { + msgstr = '确认要重置 ' + name + g_bios_postfix[index] + ' 标签页下的所有配置?'; + } + + return msgstr; +} + +function CommonUpdateTabTitleIcon(exists, id, name) { + var exspan = " "; + for (var i = 0; i < g_vtoy_data_default_index; i++) { + var fid = id + i + '"]'; + var oldhtml = $(fid).html(); + var newhtml; + + if (exists[i]) { + newhtml = name + g_bios_postfix[i] + exspan; + } else { + newhtml = name + g_bios_postfix[i]; + } + + if (newhtml != oldhtml) { + $(fid).html(newhtml); + } + } +} + function ventoy_file_submit(form, extra) { var filepath = $("#FilePath").val(); var fileextra = $("#FileExtra").val(); @@ -896,6 +899,7 @@ function VtoyCommonChangeLanguage(newlang) { utfmaxlen: $.validator.format("The string exceeds the maximum supported length"), start_slash: $.validator.format("Must start with /"), noquotes: $.validator.format("Can not include double quotes"), + filenamepart:$.validator.format("As part of file name, can not include invalid characters"), printascii: $.validator.format("Can not include non-ascii characters.") }); @@ -909,6 +913,8 @@ function VtoyCommonChangeLanguage(newlang) { $(this).text(" Plugin Official Document"); }); + $('#id_span_copy').text("Copy"); + $('#id_span_preview').text("Preview"); $('#id_span_language').text("中文"); $("tr[id=tr_title_desc_cn]").each(function(){ @@ -941,6 +947,7 @@ function VtoyCommonChangeLanguage(newlang) { utfmaxlen: $.validator.format("超过最大长度"), start_slash: $.validator.format("必须以反斜杠 / 开头"), noquotes: $.validator.format("不能包含双引号"), + filenamepart:$.validator.format("作为文件名的一部分,不能包含特殊的符号"), printascii: $.validator.format("不能包含中文或其他非 ascii 字符。") }); @@ -954,6 +961,8 @@ function VtoyCommonChangeLanguage(newlang) { $(this).text(" 插件官网文档"); }); + $('#id_span_copy').text("复制"); + $('#id_span_preview').text("预览"); $('#id_span_language').text("English"); $("tr[id=tr_title_desc_cn]").each(function(){ @@ -990,7 +999,10 @@ function VtoyCommonChangeLanguage(newlang) { $('#id_span_save').text(g_vtoy_cur_language.STR_SAVE); $('#id_span_reset').text(g_vtoy_cur_language.STR_RESET); $('#id_span_donation').text(g_vtoy_cur_language.STR_PLUG_DONATION); - + + $('span[id=id_btn_span_reset]').each(function(){ + $(this).text(' ' + g_vtoy_cur_language.STR_RESET); + }); $("span[id=id_span_btn_add]").each(function(){ $(this).text(g_vtoy_cur_language.STR_ADD); }); @@ -1062,13 +1074,13 @@ var g_type_select_validator = $("#TypeSelectForm").validate({ function VtoySelectType(cb, para) { $('#TypeSelectForm #TypeSelForm_lang_1').text(g_vtoy_cur_language.STR_SELECT); - + if (g_current_language === 'en') { - $('#SetDirForm #SetDirForm_lang_2').text(" OK"); - $('#SetDirForm #SetDirForm_lang_3').text("Cancel"); + $('#TypeSelectForm #TypeSelForm_lang_2').text(" OK"); + $('#TypeSelectForm #TypeSelForm_lang_3').text("Cancel"); } else { - $('#SetDirForm #SetDirForm_lang_2').text("确定"); - $('#SetDirForm #SetDirForm_lang_3').text("取消"); + $('#TypeSelectForm #TypeSelForm_lang_2').text("确定"); + $('#TypeSelectForm #TypeSelForm_lang_3').text("取消"); } var $tbl = $("#id_type_select_table tbody"); @@ -1102,7 +1114,8 @@ var g_set_key_validator = $("#SetKeyForm").validate({ }, SetKeyValue : { required: true, - utfmaxlen: true + utfmaxlen: true, + filenamepart: true } }, @@ -1130,11 +1143,11 @@ function VtoySetKey(cb, para) { $('#SetKeyForm #SetKeyForm_lang_3').text(para.title2); if (g_current_language === 'en') { - $('#SetDirForm #SetDirForm_lang_4').text(" OK"); - $('#SetDirForm #SetDirForm_lang_5').text("Cancel"); + $('#SetKeyForm #SetKeyForm_lang_4').text(" OK"); + $('#SetKeyForm #SetKeyForm_lang_5').text("Cancel"); } else { - $('#SetDirForm #SetDirForm_lang_4').text("确定"); - $('#SetDirForm #SetDirForm_lang_5').text("取消"); + $('#SetKeyForm #SetKeyForm_lang_4').text("确定"); + $('#SetKeyForm #SetKeyForm_lang_5').text("取消"); } g_set_key_callback = cb; @@ -1392,15 +1405,15 @@ function VtoySetDirFile(cb, para) { $('#SetDirFileModal #SetDirFileForm_label2').text(para.label2); if (g_current_language === 'en') { - $('#SetDirFileModal #SetDirFileModal_ok').text(" OK"); - $('#SetDirFileModal #SetDirFileModal_cancel').text("Cancel"); + $('#SetDirFileModal #SetDirFileForm_ok').text(" OK"); + $('#SetDirFileModal #SetDirFileForm_cancel').text("Cancel"); $('#SetDirFileModal #id_note_dirfile_cn').hide(); $('#SetDirFileModal #id_note_dirfile_en').show(); } else { - $('#SetDirFileModal #SetDirFileModal_ok').text("确定"); - $('#SetDirFileModal #SetDirFileModal_cancel').text("取消"); + $('#SetDirFileModal #SetDirFileForm_ok').text("确定"); + $('#SetDirFileModal #SetDirFileForm_cancel').text("取消"); $('#SetDirFileModal #id_note_dirfile_en').hide(); $('#SetDirFileModal #id_note_dirfile_cn').show();