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

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,21 +51580,46 @@ new Promise(resolve=>{
});
page.appendChild(text2);
game.print=function(){
var args=[].slice.call(arguments);
var printResult=args.map(arg=>{
if(get.is.object(arg)||typeof arg=='function'){
var argi=get.stringify(arg);
if(argi/*&&argi.length<5000*/){
const args=[...arguments];
const printResult=args.map(arg=>{
if(typeof arg!='string'){
const parse=(obj)=>{
if(Array.isArray(obj)){
return `[${String(obj)}]`;
}else if(typeof obj=='function'){
return `Function`;
}else if(typeof obj!='string'){
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 return arg.toString();
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{
var str=String(arg);
if (!/<[a-zA-Z]+[^>]*?\/?>.*?(?=<\/[a-zA-Z]+[^>]*?>|$)/.exec(str)) return String(arg)
return parse(arg);
}
}else{
const str=String(arg);
if (!/<[a-zA-Z]+[^>]*?\/?>.*?(?=<\/[a-zA-Z]+[^>]*?>|$)/.exec(str)) return str
.replace(/&/g,'&amp;')
.replace(/</g,'&lt;')
.replace(/>/g,'&gt;')