-
Notifications
You must be signed in to change notification settings - Fork 56
/
Copy pathticmobile.min.js
1 lines (1 loc) · 4.32 KB
/
ticmobile.min.js
1
javascript:krazete:var turn=Math.random()<.5?0:1,unit=(innerWidth<innerHeight?innerWidth:innerHeight)/11;function newUnit(){unit=(innerWidth<innerHeight?innerWidth:innerHeight)/11}var menu=document.createElement("div"),exit=(window.addEventListener("resize",function(){newUnit(),menu.style.height=9*unit+"px",menu.style.width=9*unit+"px"}),menu.style.position="fixed",menu.style.top="50%25",menu.style.left="50%25",menu.style.height=9*unit+"px",menu.style.width=9*unit+"px",menu.style.transform="translate(-50%25,-50%25)",menu.style.webkitTransform="translate(-50%25,-50%25)",menu.style.zIndex=9999,document.createElement("a")),board=(exit.style="background:white;position:absolute;left:100%25;cursor:pointer",exit.textContent="exit",exit.addEventListener("click",function(){menu.remove()}),menu.appendChild(exit),document.body.appendChild(menu),document.createElement("div"));board.style.background="rgba(255,255,255,0.9)",board.style.position="absolute",board.style.top=0,board.style.left=0,board.style.height="100%25",board.style.width="100%25",board.mark=null,menu.appendChild(board),BOXES=[],boxes=[[],[],[],[],[],[],[],[],[]];for(var i=0;i<3;i++)for(var j=0;j<3;j++){var BOX=document.createElement("div");BOX.style.position="absolute",BOX.style.top=100*i/3+"%25",BOX.style.left=100*j/3+"%25",BOX.style.height=100/3+"%25",BOX.style.width=100/3+"%25",BOX.mark=null;for(var k=0;k<3;k++)for(var l=0;l<3;l++){var box=document.createElement("div");box.addEventListener("mouseover",onmouseover),box.addEventListener("mouseout",onmouseout),box.addEventListener("click",pick),box.style.position="absolute",box.style.top=100*k/3+"%25",box.style.left=100*l/3+"%25",box.style.height=100/3+"%25",box.style.width=100/3+"%25",box.macro=3*i+j,box.micro=3*k+l,box.mark=null,boxes[3*i+j].push(box),box.macro%252==0?box.style.boxShadow="0 0 5px black inset":box.style.boxShadow="0 0 5px gray inset",BOX.appendChild(box)}BOXES.push(BOX),board.appendChild(BOX)}function check(e){var t=0;null!=e[0].mark&&(e[0].mark==e[1].mark&&e[1].mark==e[2].mark||e[0].mark==e[3].mark&&e[3].mark==e[6].mark)&&(t=1),null!=e[4].mark&&(e[3].mark==e[4].mark&&e[4].mark==e[5].mark||e[1].mark==e[4].mark&&e[4].mark==e[7].mark||e[0].mark==e[4].mark&&e[4].mark==e[8].mark||e[2].mark==e[4].mark&&e[4].mark==e[6].mark)&&(t=1),(t=null!=e[8].mark&&(e[6].mark==e[7].mark&&e[7].mark==e[8].mark||e[2].mark==e[5].mark&&e[5].mark==e[8].mark)?1:t)?marker(e[0].parentNode):null!=e[0].mark&&null!=e[1].mark&&null!=e[2].mark&&null!=e[3].mark&&null!=e[4].mark&&null!=e[5].mark&&null!=e[6].mark&&null!=e[7].mark&&null!=e[8].mark&&draw(e[0].parentNode)}function draw(e){e.mark=2,disable(e),e.style.pointerEvents="none"}function marker(e){if(0==turn){for(var t=document.createElement("div"),r=(t.style.boxSizing="border-box",t.style.position="absolute",t.style.top="10%25",t.style.left="10%25",t.style.height="80%25",t.style.width="80%25",0),n=0;n<9;n++)if(e==BOXES[n]){r=1;break}t.style.border=unit*(e==board?9:r?3:1)/5+"px solid black",window.addEventListener("resize",function(){newUnit(),t.style.border=unit*(e==board?9:r?3:1)/5+"px solid black"}),t.style.borderRadius="50%25",e.appendChild(t)}else{var o=document.createElement("div"),o=(o.style.boxSizing="border-box",o.style.background="black",o.style.position="absolute",o.style.top="10%25",o.style.left="40%25",o.style.height="80%25",o.style.width="20%25",o.style.transform="rotate(45deg)",o.style.webkitTransform="rotate(45deg)",e.appendChild(o),o.cloneNode());o.style.transform="rotate(-45deg)",o.style.webkitTransform="rotate(-45deg)",e.appendChild(o)}e.mark=turn,disable(e),e.style.pointerEvents="none"}function pick(){var e=this;if(marker(e),check(boxes[e.macro]),check(BOXES),turn=0<turn?0:1,null==BOXES[e.micro].mark){for(i=0;i<9;i++)for(var t=0;t<9;t++)disable(boxes[i][t]);for(i=0;i<9;i++)null==board.mark&&enable(boxes[e.micro][i])}else for(i=0;i<9;i++)for(t=0;t<9;t++)null==board.mark&&enable(boxes[i][t]);disable(e)}function disable(e){e.style.background="rgba(0,0,0,0.25)",e.removeEventListener("mouseover",onmouseover),e.removeEventListener("mouseout",onmouseout),e.removeEventListener("click",pick)}function enable(e){null==e.mark&&(e.style.background="transparent"),e.addEventListener("mouseover",onmouseover),e.addEventListener("mouseout",onmouseout),e.addEventListener("click",pick)}function onmouseover(){this.style.background="rgba(0,0,0,0.25)"}function onmouseout(){this.style.background="transparent"}