// ==UserScript== // @name route assistant // @namespace myhead // @description 金书红颜录路线武功规划脚本,需配合相关维基页面使用 // @version 1 // @grant none // @include // @downloadURL none // ==/UserScript== /* oResult={ '拳':[aRegExpSearchResult1{[0](matched content),[1](captured content in parenthesis),[2],index,input},aRegExpSearchResult2...], '剑':[], '兵':[], '特':[], '暗':[], '内':[], '轻':[], '余':[] } Pos= aC1[i] ={ __Con: { 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; var mainDiv=document.createElement('div'), navi=document.createElement('div'), div1=document.createElement('div'), div2=document.createElement('div'), div2p=document.createElement('code'), div2f=document.createElement('div'), round=document.createElement('select'), speci=document.createElement('span'), toggle= document.createElement('button'), oTarget= {}; toggle.innerHTML="打开路线武功规划器" toggle.onclick=function(){ if(sOrigin== '') main(); mainDiv.style.display=''; }; window.onload=function(){ oTarget= document.getElementById('bodyContent'); oTarget.insertBefore(toggle,oTarget.firstChild); }; function main(){ //search route and set UI; if(!oTarget){ alert('找不到源数据'); return; }; sOrigin=oTarget.textContent; var rP1= /#(.+)/g; for(var i=0,aTemp;i<100;i++) { aTemp=rP1.exec(sOrigin); //aTemp contains [0] [1] .index .input if (aTemp== null) break; aC1[i]={ //aC1[i] is route option object __Con: { 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: 800px; 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); 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); }; div1.innerHTML=''; 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'), 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; Pos.next[i]={ __Con: { 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(!aTarget[0]){ aTarget[0]=aEntry; return; } if(!aEntry[1]) nIndi=0; else nIndi=parseInt(aEntry[1].match(/\d/)[0]); 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(aOut[0].value== 1){ for(var i= 0,aTemp;i= aOut[3].value) sResult+= aTemp[0].match(rTp)[0]+'  '; }; } else{ for(var i= 0,aTemp;i aOut[3].value) sResult+= aTemp[0]+'  '; } } sResult+='

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