完成“生成随机字符串”

This commit is contained in:
2019-12-12 15:00:47 +08:00
parent d0f5d34c8f
commit 2dc03fbe55
4 changed files with 147 additions and 59 deletions

16
js/tool.min.js vendored
View File

@@ -1,6 +1,8 @@
var SettingFontSize=localStorage.getItem("SettingFont");function toolSettingsFont(mode){var RootEle=document.querySelector("html");var Input=document.querySelector(".tool-setting-font p input");var Output=document.querySelector(".tool-setting-font p label");switch(mode){case"reset":SettingFontSize="16";localStorage.setItem("SettingFont",SettingFontSize);Output.innerHTML=Input.value=SettingFontSize;RootEle.style.fontSize=SettingFontSize+"px";break;case"get":if(SettingFontSize==null){toolSettingsFont("reset");}
Output.innerHTML=Input.value=SettingFontSize;RootEle.style.fontSize=SettingFontSize+"px";break;case"show":Output.innerHTML=Input.value;break;case"set":SettingFontSize=Input.value;localStorage.setItem("SettingFont",SettingFontSize);RootEle.style.fontSize=SettingFontSize+"px";break;default:break;}}
toolSettingsFont("get");function toolUnixTimeToUnix(GetTime,isMillisecond){var Time=new Date();Time.setFullYear(GetTime.substring(0,4));Time.setMonth(GetTime.substring(5,7)-1);Time.setDate(GetTime.substring(8,10));Time.setHours(GetTime.substring(11,13));Time.setMinutes(GetTime.substring(14,16));Time.setSeconds(GetTime.substring(17,19));if(isMillisecond==false){var TextLength=Time.getTime().toString().length;return Time.getTime().toString().substring(0,TextLength-3);}else if(isMillisecond==true){var TextLength=Time.getTime().toString().length;return Time.getTime().toString().substring(0,TextLength-3)+"000";}else{return"模式有误!";}}
var Settings={Global:{FontSize:localStorage.getItem("SettingFont")},Tool:{GenString:{length:"8",hasNum:true,hasChar:false,hasSymbol:false,caseSense:true,lowerCase:false}}}
function toTop(){document.body.scrollTop=0;document.documentElement.scrollTop=0;}
function toolSettingsFont(mode){var RootEle=document.querySelector("html");var Input=document.querySelector(".tool-setting-font p input");var Output=document.querySelector(".tool-setting-font p label");switch(mode){case"reset":Settings.Global.FontSize="16";localStorage.setItem("SettingFont",Settings.Global.FontSize);Output.innerHTML=Input.value=Settings.Global.FontSize;RootEle.style.fontSize=Settings.Global.FontSize+"px";break;case"get":if(Settings.Global.FontSize==null){toolSettingsFont("reset");}
Output.innerHTML=Input.value=Settings.Global.FontSize;RootEle.style.fontSize=Settings.Global.FontSize+"px";break;case"show":Output.innerHTML=Input.value;break;case"set":Settings.Global.FontSize=Input.value;localStorage.setItem("SettingFont",Settings.Global.FontSize);RootEle.style.fontSize=Settings.Global.FontSize+"px";break;default:break;}}
function toolUnixTimeToUnix(GetTime,isMillisecond){var Time=new Date();Time.setFullYear(GetTime.substring(0,4));Time.setMonth(GetTime.substring(5,7)-1);Time.setDate(GetTime.substring(8,10));Time.setHours(GetTime.substring(11,13));Time.setMinutes(GetTime.substring(14,16));Time.setSeconds(GetTime.substring(17,19));if(isMillisecond==false){var TextLength=Time.getTime().toString().length;return Time.getTime().toString().substring(0,TextLength-3);}else if(isMillisecond==true){var TextLength=Time.getTime().toString().length;return Time.getTime().toString().substring(0,TextLength-3)+"000";}else{return"模式有误!";}}
function toolUnixTimeToTime(GetUnix,isMillisecond){var Time=new Date();if(isMillisecond==false){GetUnix=GetUnix+"000";Time.setTime(GetUnix);}else if(isMillisecond==true){Time.setTime(GetUnix);}else{Time.setTime("0");}
var TimeYear=Time.getFullYear();var TimeMonth=Time.getMonth()+1;if(TimeMonth<10){TimeMonth="0"+TimeMonth;}
var TimeDate=Time.getDate();if(TimeDate<10){TimeDate="0"+TimeDate;}
@@ -21,13 +23,17 @@ if(GetSettingType[0].checked==true){var GetFirst=parseInt(GetSettingA[1].value);
Num=String.fromCharCode(i);CheckReverse();}}else if(GetFirst>GetLast){GetResult.placeholder="字母先后顺序有误。\n请按此顺序填写\nA - Z a - z\n例如\n从 a 到 d\n从 A 到 D\n从 X 到 g";}else if(GetFirst==GetLast){GetResult.placeholder="仅有 1 条链接,无需生成。";}else{GetResult.placeholder="异常。";}}else{GetResult.placeholder="超出范围。";}}else{GetResult.placeholder="类型选择有误";}
GetResult.value=LinkResult;}
function toolGenLinkClear(){var GetResult=document.getElementById("tool-genlink-result");GetResult.value='';GetResult.placeholder="结果";}
function toolGenString(length,hasNum,hasChar,hasSymbol,caseSense,lowerCase){var m="";if(hasNum=="0"&&hasChar=="0"&&hasSymbol=="0")return m;for(var i=length;i>=0;i--){var num=Math.floor((Math.random()*94)+33);if(((hasNum=="0")&&((num>=48)&&(num<=57)))||((hasChar=="0")&&(((num>=65)&&(num<=90))||((num>=97)&&(num<=122))))||((hasSymbol=="0")&&(((num>=33)&&(num<=47))||((num>=58)&&(num<=64))||((num>=91)&&(num<=96))||((num>=123)&&(num<=127))))){i++;continue;}
function toolGenString(length,hasNum,hasChar,hasSymbol,caseSense,lowerCase){var m="请选中数字、字母或其他符号的其中一项!";if(hasNum==false&&hasChar==false&&hasSymbol==false){return m;}
m="";for(var i=length;i>0;i--){var num=Math.floor((Math.random()*94)+33);if(((hasNum==false)&&((num>=48)&&(num<=57)))||((hasChar==false)&&(((num>=65)&&(num<=90))||((num>=97)&&(num<=122))))||((hasSymbol==false)&&(((num>=33)&&(num<=47))||((num>=58)&&(num<=64))||((num>=91)&&(num<=96))||((num>=123)&&(num<=127))))){i++;continue;}
m+=String.fromCharCode(num);}
if(caseSense=="0"){m=(lowerCase=="0")?m.toUpperCase():m.toLowerCase();}
if(caseSense==false){m=(lowerCase==false)?m.toUpperCase():m.toLowerCase();}
return m;}
function toolGenStringSettings(name){var InputSettings=document.querySelectorAll("#genstring-settings p input");var ObjSettings=Settings.Tool.GenString;switch(name){case"length":ObjSettings.length=InputSettings[0].value;break;case"hasNum":ObjSettings.hasNum=InputSettings[1].checked;break;case"hasChar":ObjSettings.hasChar=InputSettings[2].checked;break;case"hasSymbol":ObjSettings.hasSymbol=InputSettings[3].checked;break;case"caseSense":ObjSettings.caseSense=InputSettings[4].checked;break;case"lowerCase":ObjSettings.lowerCase=InputSettings[5].checked;break;default:break;}}
function toolGenStringSubmit(){var Result=document.querySelector("#genstring-result input");var ObjSettings=Settings.Tool.GenString;var Str=toolGenString(ObjSettings.length,ObjSettings.hasNum,ObjSettings.hasChar,ObjSettings.hasSymbol,ObjSettings.caseSense,ObjSettings.lowerCase);Result.value=Str;}
function toolNewWindowSubmit(){var link=document.querySelector("#tool-newwindow-link input").value;var width=document.querySelectorAll("#tool-newwindow-meta input")[0].value;var height=document.querySelectorAll("#tool-newwindow-meta input")[1].value;if(width==""){width=400;}
if(height==""){height=300;}
window.open(link,"_blank","height="+height+", width="+width+", toolbar=no, menubar=no, scrollbars=yes, resizable=yes, location=yes, status=yes");}
function toolNewWindowClear(){document.querySelector("#tool-newwindow-link input").value="";document.querySelectorAll("#tool-newwindow-meta input")[0].value="";document.querySelectorAll("#tool-newwindow-meta input")[1].value="";}
function toolRunJSSubmit(){var GetCode=document.querySelector("#tool-runjs-input");eval(GetCode.value);}
function toolRunJSClear(){var GetCode=document.querySelector("#tool-runjs-input");GetCode.value='';}
toolSettingsFont("get");