// ==UserScript== // @name route assistant // @namespace myhead // @description 金书红颜录路线武功规划脚本,需配合相关维基页面使用 // @version 1.1.4 // @grant none // @homepageURL https://greasyfork.org/zh-CN/scripts/13722-route-assistant // @include http://tpr.inkit.org/tpr5:route // @include http://tpr.inkit.org/doku.php?id=tpr5:route // @downloadURL https://update.greasyfork.icu/scripts/13722/route%20assistant.user.js // @updateURL https://update.greasyfork.icu/scripts/13722/route%20assistant.meta.js // ==/UserScript== /* oResult={ '拳':[aRegExpSearchResult1{[0](matched content),[1](captured content in parenthesis),[2],index,input},aRegExpSearchResult2...], '剑':[], '兵':[], '特':[], '暗':[], '内':[], '轻':[], '余':[] } Pos= aC1[i] ={ __Con: { sMResult: entries list contained by current position sPath: route position chain sName: route position name, sCon: RegExp context of the position, nStart: start index in sCon, nEnd: end index in sCon }, next: [] //next is deeper list of route option object } */ var aC1= [], //aC1 correspond to the list of route root object aRoute=[], oResult={}, sOrigin='', sResult='', t; window.mainDiv= document.createElement('div'), window.navi= document.createElement('div'), window.div1= document.createElement('div'), window.div2= document.createElement('div'), window.div2p= document.createElement('div'), window.div2f= document.createElement('div'), window.round= document.createElement('select'), window.speci= document.createElement('span'), window.toggle= document.createElement('button'), window.oTarget= {}; toggle.innerHTML="打开路线武功规划器"; toggle.onclick=function(){ if(sOrigin=== '') main(); mainDiv.style.display=''; }; window.onload=function(){ toggle.id='__toggle'; mainDiv.id='__mainDiv'; oTarget= document.getElementById('target'); oTarget.insertBefore(toggle,oTarget.firstChild); }; function main(){ //search route and set UI; if(!oTarget){ alert('找不到源数据'); return; } sOrigin=oTarget.textContent; var rP1= /#(.+)/g,sMR=''; for(var i=0,aTemp;i<100;i++) { aTemp=rP1.exec(sOrigin); //aTemp contains [0] [1] .index .input if (aTemp=== null) break; t= aTemp.input.match(/\n\s*.*/)[0].match(/@(.*)/); sMR= t? t[1]:''; aC1[i]={ //aC1[i] is route option object __Con: { sMResult: sMR, sPath: aTemp[0], sName: aTemp[1], sCon: aTemp.input, nStart: aTemp.index, nEnd: undefined }, next: [] //next is deeper list of route option object }; //initialise the route result array aRoute[i]= aC1[i]; if(i>0) aC1[i-1].__Con.nEnd= aTemp.index-1; } //create UI and set up initial option list mainDiv.setAttribute('style','position: absolute; left: 200px; top: 100px; width: 830px; height: 600px; background: white; border: solid #E0E0E0; overflow: auto;resize: both;'); // navi.innerHTML= ""+ ""+ ""; navi.setAttribute('style','border-bottom: solid #F0F0F0; background: #F0F0F0');navi.setAttribute('style','border-bottom: solid #F0F0F0;background: #F0F0F0'); div2.style.display='none'; div2.innerHTML+= '请选择周目:'; for(var i=1;i<7;i++) round.innerHTML+=''; div2.appendChild(round); button= document.createElement('button'); button.innerHTML='开始统计'; button.onclick= analyse; div2.appendChild(button); //create filter option bar div2f div2f.innerHTML+= '结果过滤器:'; speci.innerHTML+= '名称显示 '+ '类别'+ '阴阳'+ '最低数值'; div2f.appendChild(speci); button= document.createElement('button'); button.innerHTML='过滤结果'; button.onclick=filter; div2f.appendChild(button); div2.appendChild(div2f); div2.appendChild(div2p); div2.style.margin='10px'; var tarList=document.createElement('ol'); for(var i=0,li,doList;i0){ var select=document.createElement('select'); select.onchange=routeQuery; select.innerHTML+=""; for(var j=0;j"+doList[j].__Con.sName+""; } li.appendChild(select); } tarList.appendChild(li); } button= document.createElement('button'); button.innerHTML='检查路线冲突'; button.onclick=checkBinding; div1.appendChild(button); button= document.createElement('button'); button.innerHTML='路线导入导出'; button.onclick=exportAndImport; div1.appendChild(button); div1.appendChild(tarList); mainDiv.appendChild(navi); mainDiv.appendChild(div1); mainDiv.appendChild(div2); document.body.appendChild(mainDiv); } function dive(Pos,nSym){ //dive into route chain,group represents the number of option root var rP= new RegExp('\\s'+nSym+'(.*)','g'),sMR, sContext= Pos.__Con.sCon.substring(Pos.__Con.nStart,Pos.__Con.nEnd); for(var i=0,aTemp;i<100;i++) { aTemp= rP.exec(sContext); if(aTemp=== null) break; t= aTemp.input.match(/\n\s*.*/)[0].match(/@(.*)/); sMR= t? t[1]:''; Pos.next[i]={ __Con: { sMResult: Pos.__Con.sMResult+ sMR, sPath: Pos.__Con.sPath+'-'+aTemp[1], sName: aTemp[1], sCon: aTemp.input, nStart: aTemp.index, nEnd: undefined }, next: [] }; if(i>0) Pos.next[i-1].__Con.nEnd= aTemp.index-1; } return Pos.next; //the newly matched route to create drop-down of } function sort(aEntry,aTarget){ var i,nIndi; if(!aEntry[1]) aEntry.nIndi=0; else aEntry.nIndi=parseInt(aEntry[1].match(/\d/)[0]); if(!aTarget[0]){ aTarget[0]=aEntry; return; } for(i=0;i= i;j--){ aTarget[j+1]= aTarget[j]; } break; } } aTarget[i]= aEntry; } //following fuctions are event handle function routeQuery(){ //connecting with selcet.onchange, the event handle to search option of drop-down list,whose value corresponds to the index of content array.Then create relevant drop-down list. while(this.nextSibling) this.parentNode.removeChild(this.nextSibling); if(this.value== this.firstChild.value) return; var aValue=this.value.match(/\d+/g), //[this] is the node elements triggering the event.[this.value] has form like'1.2.3' Pos=aC1[aValue[0]], //Pos is route option object nSym= 0; //nSym is the current route layer of Pos for(var i=1;i0) { var select=document.createElement('select'); select.onchange=routeQuery; select.innerHTML+=""; for(var j=0;j"+list[j].__Con.sName+""; } this.parentNode.appendChild(select); } //if there is no sub option in deeper layer,log the result aRoute[aValue[0]]= Pos; } //connect with the button '开始统计' function analyse(){ oResult={}; for(var i=0,oT;i round.value) continue; if(!aT[2]) aT[2]='未分类'; else aT[2]=aT[2].substring(1); if(!oResult[aT[2]]) oResult[aT[2]]=[]; sort(aT,oResult[aT[2]]); } } sResult=''; //output for(var x in oResult){ sResult+= '类别——'+x+':
'; var rTp= /[^\-?\s]+/; for(var i=0;i'; if((i+1)% 4==0) sResult+= "" } sResult+='


'; } div2p.innerHTML= sResult; } //connect with button in filter bar function filter(){ var aOut= speci.children, rTp= /[^-?\s]+/; sResult= ''; //aOut[1]-- string representing type; aOut[2]-- string representing yin yang; aOut[3]-- number representing value rank for(var x in oResult){ if(aOut[1].value!= '0'){ var rP=new RegExp(aOut[1].value); if(!rP.test(x)) continue; } sResult+= '类别——'+x+':
'; if(aOut[0].value== 1){ for(var i= 0,j=0,aTemp;i= aOut[3].value){ sResult+="'; if((j+1)% 4==0) sResult+= ""; j++; } } } else{ for(var i= 0,j=0,aTemp;i aOut[3].value){ sResult+="'; if((j+1)% 4==0) sResult+= ""; j++; } } } sResult+='
"+aTemp[0].match(rTp)[0]+'
"+ aTemp[0]+'


'; } div2p.innerHTML= sResult; } //connect with button to confirm proper binding function checkBinding(){ var aBind=[],Compare={},sCollision=''; for(var i=0;i