From 69bcf4ec22e3ff16e96a8f58235cb3c99889dc38 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9E=AB=E8=B0=B7=E5=89=91=E4=BB=99?= Date: Fri, 16 Oct 2020 01:14:34 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E7=B2=BE=E7=AE=80=E7=A9=BA=E5=86=85?= =?UTF-8?q?=E5=AE=B9=E6=97=B6=E7=9A=84url=E9=93=BE=E6=8E=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- script-universal_function.js | 14 ++++++++++++++ script.js | 5 +++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/script-universal_function.js b/script-universal_function.js index a9007014..576157f0 100644 --- a/script-universal_function.js +++ b/script-universal_function.js @@ -54,6 +54,20 @@ Number.prototype.PrefixInteger = function(length) { return (Array(length).join('0') + this).slice(-length); } +//数组删除自己尾部的空元素 +Array.prototype.DeleteLatter = function(item = null) +{ + let index = this.length - 1; + for (; index>=0; index--) + { + if (this[index] !== item) + { + break; + } + } + this.splice(index + 1); + return this; +} //▼ADPCM播放相关,来自 https://github.com/jy4340132/aaa const pcmMemory = new WebAssembly.Memory({initial: 256, maximum: 256}); diff --git a/script.js b/script.js index 86f94a5f..95830ea3 100644 --- a/script.js +++ b/script.js @@ -129,6 +129,7 @@ var Member = function() { }; Member.prototype.outObj = function() { const m = this; + if (m.id == 0) return null; let obj = [m.id]; if (m.level != undefined) obj[1] = m.level; if (m.awoken != undefined) obj[2] = m.awoken; @@ -254,10 +255,10 @@ Formation.prototype.outObj = function() { const teamArr = []; teamArr[0] = t[0].map(m => m.outObj() - ); + ).DeleteLatter(); teamArr[1] = t[1].map(m => m.outObj() - ); + ).DeleteLatter(); if (t[2]) teamArr[2] = t[2]; return teamArr; }); From f3cf2bec51f112261d75687ec3a2354b2da28030 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9E=AB=E8=B0=B7=E5=89=91=E4=BB=99?= Date: Fri, 16 Oct 2020 02:58:55 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=BA=86=E4=B8=80?= =?UTF-8?q?=E5=A0=86=E5=8F=AF=E8=83=BD=E5=87=BA=E9=94=99=E7=9A=84=E5=89=8D?= =?UTF-8?q?=E8=BF=9B=E5=90=8E=E9=80=80=E7=9A=84=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- script.js | 84 ++++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 67 insertions(+), 17 deletions(-) diff --git a/script.js b/script.js index 95830ea3..4ad9f7b8 100644 --- a/script.js +++ b/script.js @@ -151,6 +151,7 @@ Member.prototype.outObj = function() { Member.prototype.loadObj = function(m, dataVersion) { if (m == undefined) //如果没有提供数据,直接返回默认 { + this.id = 0; return; } if (dataVersion == undefined) dataVersion = 1; @@ -263,9 +264,28 @@ Formation.prototype.outObj = function() { return teamArr; }); obj.v = dataStructure; + /*if (obj.f.every(team=>team[0].length == 0 && team[1].length == 0 && team[2] == undefined) && + !obj.t && + !obj.d) + return null;*/ return obj; }; Formation.prototype.loadObj = function(f) { + if (f == undefined) //如果没有提供数据,要返回空的 + { + this.title = ""; + this.detail = ""; + this.teams.forEach(function(t, ti) { + t[0].forEach(function(m, mi) { + m.loadObj(null); + }); + t[1].forEach(function(m, mi) { + m.loadObj(null); + }); + if (t[2] != undefined) t.splice(2); + }); + return; + } const dataVeision = f.v ? f.v : (f.f ? 2 : 1); //是第几版格式 this.title = dataVeision > 1 ? f.t : f.title; this.detail = dataVeision > 1 ? f.d : f.detail; @@ -432,7 +452,7 @@ function turnPage(toPage, e = null) { location.href = newURL; } } -window.onload = function() { +window.onload = function(event) { controlBox = document.body.querySelector(".control-box"); statusLine = controlBox.querySelector(".status"); //显示当前状态的 formationBox = document.body.querySelector(".formation-box"); @@ -694,30 +714,55 @@ function loadData(force = false) } } //重新读取URL中的Data数据并刷新页面 -function reloadFormationData() { +function reloadFormationData(event) { let formationData; - try { - let parameterDataString = getQueryString("d") || getQueryString("data"); - formationData = JSON.parse(parameterDataString); - } catch (e) { - console.error("URL中队伍数据JSON解码出错", e); - return; + if (event && event.state && event.state.outForm) + { + //直接使用现有数据 + formationData = event.state.outForm; + //console.log("直接读取",formationData); + }else + { + try { + const parameterDataString = getQueryString("d") || getQueryString("data"); + formationData = JSON.parse(parameterDataString); + //console.log("从URL读取",formationData); + + } catch (e) { + console.error("URL中队伍数据JSON解码出错", e); + return; + } } - if (formationData) { + + if (formationData) + { formation.loadObj(formationData); refreshAll(formation); } + if (isGuideMod) { - const mid = parseInt(getQueryString("id")); + let mid; + if (event && event.state && event.state.mid) + { + mid = event.state.mid; + }else + { + mid = parseInt(getQueryString("id"),10); + } + if (!isNaN(mid)) { editBox.mid = mid; editBoxChangeMonId(mid); } + if (event && event.state && event.state.searchArr) + { + showSearch(event.state.searchArr.map(id=>Cards[id])); + } } } -window.onpopstate = reloadFormationData; //前进后退时修改页面 +window.addEventListener('popstate',reloadFormationData); //前进后退时修改页面 //创建新的分享地址 function creatNewUrl(arg) { if (arg == undefined) arg = {}; @@ -729,13 +774,16 @@ function creatNewUrl(arg) { const newSearch = new URLSearchParams(); if (language_i18n) newSearch.set("l", language_i18n); if (datasource && datasource != "ja") newSearch.set("s", datasource); - const dataJsonStr = JSON.stringify(outObj); //数据部分的字符串 - newSearch.set("d", dataJsonStr); + if (outObj) + { + const dataJsonStr = JSON.stringify(outObj); //数据部分的字符串 + newSearch.set("d", dataJsonStr); + } - const newUrl = (arg.url || "") + '?' + newSearch.toString(); + const newUrl = (arg.url || "") + (newSearch.toString().length > 0 ? '?' + newSearch.toString() : ""); if (!arg.notPushState) { - history.pushState(null, null, newUrl); + history.pushState({outForm: outObj}, null, newUrl.length > 0 ? newUrl : location.pathname); } else { return newUrl; } @@ -1321,14 +1369,16 @@ function initialize() { if (isGuideMod) { + const idArr = searchMonList.originalHeads.map(head=>head.card.id); + const state = {searchArr:idArr,mid:newId}; const locationURL = new URL(location); if (newId === 0) { locationURL.searchParams.delete('id'); - history.pushState(null, null, locationURL); + history.pushState(state, null, locationURL); }else { locationURL.searchParams.set('id', newId); - history.pushState(null, null, locationURL); + history.pushState(state, null, locationURL); } }