优化游戏内控制台显示内容

This commit is contained in:
shijian 2023-11-23 22:18:52 +08:00
parent d8b333a995
commit 06f1424496
1 changed files with 43 additions and 18 deletions

View File

@ -51580,26 +51580,51 @@ new Promise(resolve=>{
}); });
page.appendChild(text2); page.appendChild(text2);
game.print=function(){ game.print=function(){
var args=[].slice.call(arguments); const args=[...arguments];
var printResult=args.map(arg=>{ const printResult=args.map(arg=>{
if(get.is.object(arg)||typeof arg=='function'){ if(typeof arg!='string'){
var argi=get.stringify(arg); const parse=(obj)=>{
if(argi/*&&argi.length<5000*/){ if(Array.isArray(obj)){
return argi.replace(/&/g, '&amp;') return `[${String(obj)}]`;
.replace(/</g, '&lt;') }else if(typeof obj=='function'){
.replace(/>/g, '&gt;') return `Function`;
.replace(/"/g, '&quot;') }else if(typeof obj!='string'){
.replace(/'/g, '&#39;'); return String(obj);
}else{
return `'${String(obj)}'`;
}
};
if(typeof arg=='function'){
let argi;
try{
argi=get.stringify(arg);
if(argi==='') argi=arg.toString();
}catch(_){
argi=arg.toString();
}
return argi.replace(/&/g,'&amp;')
.replace(/</g,'&lt;')
.replace(/>/g,'&gt;')
.replace(/"/g,'&quot;')
.replace(/'/g,'&#39;');
}
else if(typeof arg=='object'){
let msg='';
for(const name in arg){
msg+=`${name}: ${parse(arg[name])}<br>`;
}
return `<details><summary>${parse(arg)}</summary>${msg}</details>`;
}else{
return parse(arg);
} }
else return arg.toString();
}else{ }else{
var str=String(arg); const str=String(arg);
if (!/<[a-zA-Z]+[^>]*?\/?>.*?(?=<\/[a-zA-Z]+[^>]*?>|$)/.exec(str)) return String(arg) if (!/<[a-zA-Z]+[^>]*?\/?>.*?(?=<\/[a-zA-Z]+[^>]*?>|$)/.exec(str)) return str
.replace(/&/g, '&amp;') .replace(/&/g,'&amp;')
.replace(/</g, '&lt;') .replace(/</g,'&lt;')
.replace(/>/g, '&gt;') .replace(/>/g,'&gt;')
.replace(/"/g, '&quot;') .replace(/"/g,'&quot;')
.replace(/'/g, '&#39;'); .replace(/'/g,'&#39;');
else return str; else return str;
} }
}).join(' '); }).join(' ');