Merge pull request #164 from nonameShijian/PR-Branch

修复for in循环出现game.js定义的数组原型,增加includes的polyfill,修复layout.css的一个无意义大括号,修复game.print
This commit is contained in:
Spmario233 2023-07-22 10:57:58 +08:00 committed by GitHub
commit 0a8d2a9b8d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 192 additions and 101 deletions

View File

@ -7232,109 +7232,198 @@
return this.childNodes[row].childNodes[col]; return this.childNodes[row].childNodes[col];
} }
}; };
Array.prototype.filterInD=function(pos){ Object.defineProperty(Array.prototype, "filterInD", {
if(!pos) pos='o'; configurable:true,
var list=[]; enumerable:false,
for(var i=0;i<this.length;i++){ writable:true,
if(pos.indexOf(get.position(this[i],true))!=-1) list.push(this[i]); value:function(pos){
if(!pos) pos='o';
var list=[];
for(var i=0;i<this.length;i++){
if(pos.indexOf(get.position(this[i],true))!=-1) list.push(this[i]);
}
return list;
} }
return list; });
}; Object.defineProperty(Array.prototype, "contains", {
Array.prototype.contains=function(item){ configurable:true,
return this.indexOf(item)!=-1; enumerable:false,
}; writable:true,
Array.prototype.add=function(){ value:function(item){
for(var i=0;i<arguments.length;i++){ return this.indexOf(item)!=-1;
if(this.contains(arguments[i])){ }
});
Object.defineProperty(Array.prototype, "add", {
configurable:true,
enumerable:false,
writable:true,
value:function(){
for(var i=0;i<arguments.length;i++){
if(this.contains(arguments[i])){
return false;
}
this.push(arguments[i]);
}
return this;
}
});
Object.defineProperty(Array.prototype, "addArray", {
configurable:true,
enumerable:false,
writable:true,
value:function(arr){
for(var i=0;i<arr.length;i++){
this.add(arr[i]);
}
return this;
}
});
Object.defineProperty(Array.prototype, "remove", {
configurable:true,
enumerable:false,
writable:true,
value:function(item){
if(Array.isArray(item)){
for(var i=0;i<item.length;i++) this.remove(item[i]);
return;
}
var pos=this.indexOf(item);
if(pos==-1){
return false; return false;
} }
this.push(arguments[i]); this.splice(pos,1);
return this;
} }
return this; });
}; Object.defineProperty(Array.prototype, "removeArray", {
Array.prototype.addArray=function(arr){ configurable:true,
for(var i=0;i<arr.length;i++){ enumerable:false,
this.add(arr[i]); writable:true,
value:function(arr){
for(var i=0;i<arr.length;i++){
this.remove(arr[i]);
}
return this;
} }
return this; });
}; Object.defineProperty(Array.prototype, "randomGet", {
Array.prototype.remove=function(item){ configurable:true,
if(Array.isArray(item)){ enumerable:false,
for(var i=0;i<item.length;i++) this.remove(item[i]); writable:true,
return; value:function(){
var arr=this.slice(0);
for(var i=0;i<arguments.length;i++) arr.remove(arguments[i]);
return arr[Math.floor(Math.random()*arr.length)];
} }
var pos=this.indexOf(item); });
if(pos==-1){ Object.defineProperty(Array.prototype, "randomRemove", {
return false; configurable:true,
enumerable:false,
writable:true,
value:function(num){
if(typeof num=='number'){
var list=[];
for(var i=0;i<num;i++){
if(this.length){
list.push(this.randomRemove());
}
else{
break;
}
}
return list;
}
else{
return this.splice(Math.floor(Math.random()*this.length),1)[0];
}
} }
this.splice(pos,1); });
return this; Object.defineProperty(Array.prototype, "randomSort", {
}; configurable:true,
Array.prototype.removeArray=function(arr){ enumerable:false,
for(var i=0;i<arr.length;i++){ writable:true,
this.remove(arr[i]); value:function(){
var list=[];
while(this.length){
list.push(this.randomRemove());
}
for(var i=0;i<list.length;i++){
this.push(list[i]);
}
return this;
} }
return this; });
}; Object.defineProperty(Array.prototype, "randomGets", {
Array.prototype.randomGet=function(){ configurable:true,
var arr=this.slice(0); enumerable:false,
for(var i=0;i<arguments.length;i++) arr.remove(arguments[i]); writable:true,
return arr[Math.floor(Math.random()*arr.length)]; value:function(num){
}; if(num>this.length){
Array.prototype.randomRemove=function(num){ num=this.length;
if(typeof num=='number'){ }
var arr=this.slice(0);
var list=[]; var list=[];
for(var i=0;i<num;i++){ for(var i=0;i<num;i++){
if(this.length){ list.push(arr.splice(Math.floor(Math.random()*arr.length),1)[0]);
list.push(this.randomRemove());
}
else{
break;
}
} }
return list; return list;
} }
else{ });
return this.splice(Math.floor(Math.random()*this.length),1)[0]; Object.defineProperty(Array.prototype, "sortBySeat", {
configurable:true,
enumerable:false,
writable:true,
value:function(target){
lib.tempSortSeat=target;
this.sort(lib.sort.seat);
delete lib.tempSortSeat;
return this;
} }
}; });
Array.prototype.randomSort=function(){ if (!('includes' in Array.prototype)) {
var list=[]; Object.defineProperty(Array.prototype, 'includes', {
while(this.length){ enumerable: false,
list.push(this.randomRemove()); configurable: true,
} writable: true,
for(var i=0;i<list.length;i++){ value: function (searchElement, fromIndex) {
this.push(list[i]); if (this == null) {
} throw new TypeError('"this" is null or not defined');
return this; }
}; var o = Object(this);
Array.prototype.randomGets=function(num){ var len = o.length >>> 0;
if(num>this.length){ if (len === 0) {
num=this.length; return false;
} }
var arr=this.slice(0); var n = fromIndex | 0;
var list=[]; var k = Math.max(n >= 0 ? n : len - Math.abs(n), 0);
for(var i=0;i<num;i++){ function sameValueZero(x, y) {
list.push(arr.splice(Math.floor(Math.random()*arr.length),1)[0]); return x === y || (typeof x === 'number' && typeof y === 'number' && isNaN(x) && isNaN(y));
} }
return list; while (k < len) {
}; if (sameValueZero(o[k], searchElement)) {
Array.prototype.sortBySeat=function(target){ return true;
lib.tempSortSeat=target; }
this.sort(lib.sort.seat); k++;
delete lib.tempSortSeat; }
return this; return false;
}; }
});
}
if(!Array.from){ if(!Array.from){
Array.from=function(args){ Object.defineProperty(Array, "from", {
var list=[]; configurable:true,
if(args&&args.length){ enumerable:false,
for(var i=0;i<args.length;i++){ writable:true,
list.push(args[i]); value:function(args){
var list=[];
if(args&&args.length){
for(var i=0;i<args.length;i++){
list.push(args[i]);
}
} }
return list;
} }
return list; });
}
} }
window.onkeydown=function(e){ window.onkeydown=function(e){
if(!ui.menuContainer||!ui.menuContainer.classList.contains('hidden')){ if(!ui.menuContainer||!ui.menuContainer.classList.contains('hidden')){
@ -44825,6 +44914,7 @@
pre.style.margin=0; pre.style.margin=0;
pre.style.padding=0; pre.style.padding=0;
pre.style.position='relative'; pre.style.position='relative';
pre.style.webkitUserSelect = pre.style.userSelect = 'text';
lib.setScroll(pre); lib.setScroll(pre);
page.appendChild(text); page.appendChild(text);
@ -44921,26 +45011,28 @@
}); });
page.appendChild(text2); page.appendChild(text2);
game.print=function(){ game.print=function(){
var textstr=''; var args=[].slice.call(arguments);
for(var i=0;i<arguments.length;i++){ var printResult=args.map(arg=>{
if(get.is.object(arguments[i])){ if(get.is.object(arg)){
var argi=get.stringify(arguments[i]); var argi=get.stringify(arg);
if(argi&&argi.length<5000){ if(argi&&argi.length<5000){
textstr+=argi; textstr+=argi;
} }
else{ else{
textstr+=arguments[i].toString(); textstr+=arg.toString();
} }
}else{
var str=String(arg);
if (!/<[a-zA-Z]+[^>]*?\/?>.*?(?=<\/[a-zA-Z]+[^>]*?>|$)/.exec(str)) return String(arg)
.replace(/&/g, '&amp;')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;')
.replace(/"/g, '&quot;')
.replace(/'/g, '&#39;');
else return str;
} }
else{ }).join(' ');
textstr+=arguments[i]; pre.innerHTML+=printResult+'<br>';
}
if(i<arguments.length-1){
textstr+=' ';
}
}
textstr+='<br>';
pre.innerHTML+=textstr;
text.scrollTop=text.scrollHeight; text.scrollTop=text.scrollHeight;
} }
if(_status.toprint){ if(_status.toprint){

View File

@ -5373,5 +5373,4 @@ div[data-decoration="bronze"]::after{
/*--------其它--------*/ /*--------其它--------*/
::-webkit-scrollbar { ::-webkit-scrollbar {
display: none; display: none;
}
} }