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,18 +7232,32 @@
return this.childNodes[row].childNodes[col];
}
};
Array.prototype.filterInD=function(pos){
Object.defineProperty(Array.prototype, "filterInD", {
configurable:true,
enumerable:false,
writable:true,
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;
};
Array.prototype.contains=function(item){
}
});
Object.defineProperty(Array.prototype, "contains", {
configurable:true,
enumerable:false,
writable:true,
value:function(item){
return this.indexOf(item)!=-1;
};
Array.prototype.add=function(){
}
});
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;
@ -7251,14 +7265,24 @@
this.push(arguments[i]);
}
return this;
};
Array.prototype.addArray=function(arr){
}
});
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;
};
Array.prototype.remove=function(item){
}
});
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;
@ -7269,19 +7293,34 @@
}
this.splice(pos,1);
return this;
};
Array.prototype.removeArray=function(arr){
}
});
Object.defineProperty(Array.prototype, "removeArray", {
configurable:true,
enumerable:false,
writable:true,
value:function(arr){
for(var i=0;i<arr.length;i++){
this.remove(arr[i]);
}
return this;
};
Array.prototype.randomGet=function(){
}
});
Object.defineProperty(Array.prototype, "randomGet", {
configurable:true,
enumerable:false,
writable:true,
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)];
};
Array.prototype.randomRemove=function(num){
}
});
Object.defineProperty(Array.prototype, "randomRemove", {
configurable:true,
enumerable:false,
writable:true,
value:function(num){
if(typeof num=='number'){
var list=[];
for(var i=0;i<num;i++){
@ -7297,8 +7336,13 @@
else{
return this.splice(Math.floor(Math.random()*this.length),1)[0];
}
};
Array.prototype.randomSort=function(){
}
});
Object.defineProperty(Array.prototype, "randomSort", {
configurable:true,
enumerable:false,
writable:true,
value:function(){
var list=[];
while(this.length){
list.push(this.randomRemove());
@ -7307,8 +7351,13 @@
this.push(list[i]);
}
return this;
};
Array.prototype.randomGets=function(num){
}
});
Object.defineProperty(Array.prototype, "randomGets", {
configurable:true,
enumerable:false,
writable:true,
value:function(num){
if(num>this.length){
num=this.length;
}
@ -7318,15 +7367,54 @@
list.push(arr.splice(Math.floor(Math.random()*arr.length),1)[0]);
}
return list;
};
Array.prototype.sortBySeat=function(target){
}
});
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;
};
}
});
if (!('includes' in Array.prototype)) {
Object.defineProperty(Array.prototype, 'includes', {
enumerable: false,
configurable: true,
writable: true,
value: function (searchElement, fromIndex) {
if (this == null) {
throw new TypeError('"this" is null or not defined');
}
var o = Object(this);
var len = o.length >>> 0;
if (len === 0) {
return false;
}
var n = fromIndex | 0;
var k = Math.max(n >= 0 ? n : len - Math.abs(n), 0);
function sameValueZero(x, y) {
return x === y || (typeof x === 'number' && typeof y === 'number' && isNaN(x) && isNaN(y));
}
while (k < len) {
if (sameValueZero(o[k], searchElement)) {
return true;
}
k++;
}
return false;
}
});
}
if(!Array.from){
Array.from=function(args){
Object.defineProperty(Array, "from", {
configurable:true,
enumerable:false,
writable:true,
value:function(args){
var list=[];
if(args&&args.length){
for(var i=0;i<args.length;i++){
@ -7335,6 +7423,7 @@
}
return list;
}
});
}
window.onkeydown=function(e){
if(!ui.menuContainer||!ui.menuContainer.classList.contains('hidden')){
@ -44825,6 +44914,7 @@
pre.style.margin=0;
pre.style.padding=0;
pre.style.position='relative';
pre.style.webkitUserSelect = pre.style.userSelect = 'text';
lib.setScroll(pre);
page.appendChild(text);
@ -44921,26 +45011,28 @@
});
page.appendChild(text2);
game.print=function(){
var textstr='';
for(var i=0;i<arguments.length;i++){
if(get.is.object(arguments[i])){
var argi=get.stringify(arguments[i]);
var args=[].slice.call(arguments);
var printResult=args.map(arg=>{
if(get.is.object(arg)){
var argi=get.stringify(arg);
if(argi&&argi.length<5000){
textstr+=argi;
}
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{
textstr+=arguments[i];
}
if(i<arguments.length-1){
textstr+=' ';
}
}
textstr+='<br>';
pre.innerHTML+=textstr;
}).join(' ');
pre.innerHTML+=printResult+'<br>';
text.scrollTop=text.scrollHeight;
}
if(_status.toprint){

View File

@ -5374,4 +5374,3 @@ div[data-decoration="bronze"]::after{
::-webkit-scrollbar {
display: none;
}
}