From b67d59abfb8fd8832768afde1af8a1287ade4e75 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9E=AB=E8=B0=B7=E5=89=91=E4=BB=99?= Date: Thu, 8 Oct 2020 02:14:58 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8E=BB=E9=99=A4=E6=97=A0=E7=94=A8=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 1 - script-universal_function.js | 83 ++++++------------------------------ script.js | 6 +-- 3 files changed, 15 insertions(+), 75 deletions(-) diff --git a/README.md b/README.md index c68778d1..a7502f9b 100644 --- a/README.md +++ b/README.md @@ -100,5 +100,4 @@ Please refer to existing files. # 使用开源软件 | Open source software used * [pad-rikuu](//github.com/kiootic/pad-rikuu) //Parse data * [html2canvas](//github.com/niklasvh/html2canvas) //Capture Image -* [localforage](//github.com/localForage/localForage) //Easy IndexedDB * [aaa](//github.com/jy4340132/aaa) //Play voice(ADPCM wav) \ No newline at end of file diff --git a/script-universal_function.js b/script-universal_function.js index 43f8e6b4..11ff94c0 100644 --- a/script-universal_function.js +++ b/script-universal_function.js @@ -27,46 +27,7 @@ const GM_xmlhttpRequest = function(GM_param) { //发送数据 xhr.send(GM_param.data ? GM_param.data : null); }; -//仿GM_getValue函数v1.0 -const GM_getValue = function(name, type){ - let value = localStorage.getItem(name); - if (value == undefined) return value; - if ((/^(?:true|false)$/i.test(value) && type == undefined) || type == "boolean") - { - if (/^true$/i.test(value)) - return true; - else if (/^false$/i.test(value)) - return false; - else - return Boolean(value); - } - else if((/^\-?[\d\.]+$/i.test(value) && type == undefined) || type == "number") - return Number(value); - else - return value; -}; -//仿GM_setValue函数v1.0 -const GM_setValue = function(name, value){ - localStorage.setItem(name, value); -}; -//仿GM_deleteValue函数v1.0 -const GM_deleteValue = function(name){ - localStorage.removeItem(name); -}; -//仿GM_listValues函数v1.0 -const GM_listValues = function(){ - var keys = []; - for (let ki=0, kilen=localStorage.length; kiString.fromCharCode(int)).join(''); -} -function stringToUint8Array(str){ - const codeArr = Array.from(str).map(chr=>chr.charCodeAt(0)); - return new Uint8Array(codeArr); +//数字补前导0 +Number.prototype.PrefixInteger = function(length) +{ + return (Array(length).join('0') + this).slice(-length); } -//数组去重 -/* https://www.cnblogs.com/baiyangyuanzi/p/6726258.html -* 实现思路:获取没重复的最右一值放入新数组。 -* (检测到有重复值时终止当前循环同时进入顶层循环的下一轮判断)*/ -Array.prototype.uniq = function() -{ - let temp = []; - const l = this.length; - for(let i = 0; i < l; i++) { - for(let j = i + 1; j < l; j++){ - if (this[i] === this[j]){ - i++; - j = i; - } - } - temp.push(this[i]); - } - return temp; -}; + //▼ADPCM播放相关,来自 https://github.com/jy4340132/aaa const pcmMemory = new WebAssembly.Memory({initial: 256, maximum: 256}); @@ -242,14 +183,14 @@ function awokenCountInTeam(team,awokenIndex,solo,teamsCount) //返回可用的怪物名称 function returnMonsterNameArr(card, lsList, defaultCode) { - let monNameArr = lsList.map(function(lc){ //取出每种语言 + const monNameArr = lsList.map(lc=>{ //取出每种语言 if (lc == defaultCode) - {return card.name;} + return card.name; else if(card.otLangName) - {return card.otLangName[lc];} - }).filter(function(ln){ //去掉空值和问号 - return typeof(ln) == "string" && ln.length>0 && !new RegExp("^(?:초월\\s*)?[\\?\\*]+","i").test(ln); - }); + return card.otLangName[lc]; + }).filter(ln=> //去掉空值和问号 + typeof(ln) == "string" && ln.length>0 && !new RegExp("^(?:초월\\s*)?[\\?\\*]+","i").test(ln) + ); if (monNameArr.length < 1) //如果本来的列表里没有名字 { diff --git a/script.js b/script.js index 47fcad45..5a021454 100644 --- a/script.js +++ b/script.js @@ -1195,11 +1195,11 @@ function initialize() { const monEditAwokensLabel = Array.from(monEditAwokensRow.querySelectorAll(".awoken-ul .awoken-icon")); function playVoiceAwoken() { //点击label才播放语音 - const card = Cards[editBox.mid]; if (parseInt(this.getAttribute("data-awoken-icon"), 10) === 63) { - let decoder = new Adpcm(adpcm_wasm, pcmImportObj); + const card = Cards[editBox.mid]; + const decoder = new Adpcm(adpcm_wasm, pcmImportObj); decoder.resetDecodeState(new Adpcm.State(0, 0)); - decodeAudio(`sound/voice/${currentDataSource.code}/padv${PrefixInteger(card.voiceId,3)}.wav`, decoder.decode.bind(decoder)); + decodeAudio(`sound/voice/${currentDataSource.code}/padv${card.voiceId.PrefixInteger(3)}.wav`, decoder.decode.bind(decoder)); } } monEditAwokensLabel.forEach(akDom => akDom.onclick = playVoiceAwoken);