let wheels

async function dataInit(){
  console.log("data init is a success")
//  tag("cypher").replaceChildren("hi")

const text = tag("post-content").querySelector("pre").innerText
wheels = text.split(String.fromCharCode(10))


//const message=cleanMessage()

//for(let x=0;xletters.length-1){
    index=0
  }else if(index<0){
    index=letters.length-1
  }
  retval=null
  wh.dataset.index=index
  for(let l=1;l<8;l++){
       if(l===4){retval=letters[index]}
       const letter=letters[index].trim()||document.createTextNode("\u00A0");
       tag(wh.id+"-"+l).replaceChildren(letter)
       index++
       if(index>letters.length-1){index=0}
  }    

  return  retval
}



function clickDisk(evt){
 

  let elem=evt.target
  while(elem.className!=="up" && elem.className!=="dn"){
    elem=elem.parentNode
  }

  let direction=-1
  if(elem.className==="up"){
      direction=1
  }

  if(tag("lock").innerHTML.includes("lock_open_right")){
    moveDisk(elem.id.split("-")[1],direction)
  }else{
    for(let x=1;x<=tag("cypher").querySelectorAll(".wheel").length;x++){
      moveDisk(x,direction)
    }  
  }
  
  disksToMessage()
  
}


function makeDisk(id,wheel){
var div = document.createElement('div');
div.id = `disk-${id}`
div.className = 'wheel'
div.dataset.letters=wheel
div.dataset.index = 0
wheelArray=wheel.split("")

for(let x=0;x<7;x++)if(wheelArray[x]===" ")wheelArray[x]=" "

div.innerHTML=`
arrow_circle_up
${wheelArray[0]}
${wheelArray[1]}
${wheelArray[2]}
${wheelArray[3]}
${wheelArray[4]}
${wheelArray[5]}
${wheelArray[6]}
arrow_circle_down
` div.addEventListener("click",clickDisk) tag('cypher').appendChild(div); } function tag(id){ return document.getElementById(id) } function shuffleString(s){ const a = s.split("") shuffleArray(a) return a.join("") } function shuffleArray(array) { for (let i = array.length - 1; i >= 0; i--) { const j = Math.floor(Math.random() * (i + 1)); [array[i], array[j]] = [array[j], array[i]]; } } function toggleLock(){ if(tag("lock").innerHTML.includes("lock_open_right")){ tag("lock").innerHTML="lock" }else{ tag("lock").innerHTML="lock_open_right" } } function dencode(){ console.log("at den code") const msg=cleanMessage().split("") for(let x=0;xmsg.length;x--){ tag("disk-"+x).remove() } } function spinDiskTo(diskNumber, value){ if(tag(`disk-${diskNumber}-4`).innerHTML.replace(" "," ")===value.toUpperCase()){return} const wh = tag("disk-"+diskNumber) const letters=wh.dataset.letters.split("") let index = parseInt(wh.dataset.index) const val=value.toUpperCase() if("ABCDEFGHIJKLMNOPQRSTUVWXYZ 0123456789".includes(val)){ while(true){ const diskValue = moveDisk(diskNumber) if(diskValue==val){break} } } } function cleanMessage(){ const msg = tag("message").value.toUpperCase().split("0").join("O").split("") console.log("msg",msg) for(let x=0;x