SHARE
TWEET

Untitled

a guest Jul 24th, 2019 131 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name     ________________1LichessInputMovesKeyboard
  3. // @version  1
  4. // @grant    none
  5. // @run-at document-idle
  6. // @include /^https://lichess\.org/([a-zA-Z0-9]+(/(white|black).*)?$|analysis|training)
  7. // The original script and inspiration by Vempele: https://gist.github.com/Vempele/46333e85e33b6d488c3ffb131942272d
  8. // ==/UserScript==
  9.  
  10.  
  11. setTimeout(function(){
  12. var cx,cy;
  13.  
  14.     document.getElementById("clinput").remove();
  15.  
  16. var pFK = "w",    //pawn forward
  17. pLK = "q",     //pawn takes to the left
  18. pRK = "e",   //pawn takes to the right
  19. qK = "s",   //queen
  20. roL = "1",   //left rook
  21. roR = "3",   //right rook
  22. knL = "a",   //left knight
  23. knR = "d",   //right knight
  24. biK = " ",   //bishop
  25. kingK = "Shift",   //king
  26. rmtch = "4",  // offer rematch
  27. cprm = "2";   //cancel premoves
  28.  
  29.  
  30. var bparent = $(".cg-wrap")[0];
  31.     var wclock, bclock;
  32.     var mycolor;
  33.     wclock = $("div.clock_white");
  34.     wclock = wclock.length ? wclock[0] : null;
  35.      function isFlipped() {
  36.         return bparent.className.includes("orientation-black");
  37.     }
  38.    function get_color() {
  39.         var mycolor = isFlipped() ? "black" : "white";
  40.         var fen_els = $("input.copyable");
  41.         if (fen_els.length > 0)
  42.             mycolor = fen_els[0].value.split(" ")[1] === "w" ? "white" : "black";
  43.         if (wclock) mycolor = wclock.className.includes("clock_bottom") ? "white" : "black";
  44.         // TODO: in puzzles, detect that it's not a game and therefore mycolor = getTurn()
  45.         //console.log("mycolor=" + mycolor);
  46.         return mycolor;
  47.     }
  48.  
  49.  
  50.  
  51.    // var colorclock = document.getElementsByClassName("time")[1].title;
  52.    // var mycolor = colorclock.replace(/ .*/,'');
  53.  
  54.     mycolor = get_color();
  55.  
  56.     //console.log(mycolor);
  57. //console.log(get_color());
  58.     var nn0,nn1;
  59.     if (mycolor == "white")
  60.     {
  61.         nn0=0;
  62.         nn1=1;
  63.  
  64.          if (document.getElementsByClassName(mycolor+" rook")[nn1] != undefined)
  65.        document.getElementsByClassName(mycolor+" rook")[nn1].style.backgroundImage = "url('data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz48c3ZnIHZlcnNpb249IjEuMSIgaWQ9IkxheWVyXzEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgeG1sbnM6eGxpbms9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkveGxpbmsiIHg9IjBweCIgeT0iMHB4IiB2aWV3Qm94PSIwIDAgNDUgNDUiIHN0eWxlPSJlbmFibGUtYmFja2dyb3VuZDpuZXcgMCAwIDQ1IDQ1OyIgeG1sOnNwYWNlPSJwcmVzZXJ2ZSI+PHN0eWxlIHR5cGU9InRleHQvY3NzIj4uc3Qwe2ZpbGw6I0ZGRkZGRjtzdHJva2U6IzAwMDAwMDtzdHJva2Utd2lkdGg6MS41O3N0cm9rZS1saW5lam9pbjpyb3VuZDt9LnN0MXtmaWxsOiNGRkZGRkY7c3Ryb2tlOiMwMDAwMDA7c3Ryb2tlLXdpZHRoOjEuNTtzdHJva2UtbGluZWNhcDpyb3VuZDtzdHJva2UtbGluZWpvaW46cm91bmQ7fS5zdDJ7ZmlsbDojRkZGRkZGO3N0cm9rZTojMDAwMDAwO3N0cm9rZS13aWR0aDoxLjU7fS5zdDN7ZmlsbDpub25lO3N0cm9rZTojMDAwMDAwO3N0cm9rZS13aWR0aDoxLjU7c3Ryb2tlLWxpbmVjYXA6cm91bmQ7fS5zdDR7ZmlsbDojM0VBRjRFO3N0cm9rZTojMDAwMDAwO3N0cm9rZS13aWR0aDoxLjE4MjE7c3Ryb2tlLWxpbmVjYXA6cm91bmQ7c3Ryb2tlLWxpbmVqb2luOnJvdW5kO308L3N0eWxlPjxnPjxwYXRoIGNsYXNzPSJzdDAiIGQ9Ik05LDM5aDI3di0zSDlWMzl6IE0xMiwzNnYtNGgyMXY0SDEyeiBNMTEsMTRWOWg0djJoNVY5aDV2Mmg1VjloNHY1Ii8+PHBhdGggY2xhc3M9InN0MSIgZD0iTTM0LDE0bC0zLDNIMTRsLTMtMyIvPjxwYXRoIGNsYXNzPSJzdDIiIGQ9Ik0zMSwxN3YxMi41SDE0VjE3Ii8+PHBhdGggY2xhc3M9InN0MSIgZD0iTTMxLDI5LjVsMS41LDIuNWgtMjBsMS41LTIuNSIvPjxwYXRoIGNsYXNzPSJzdDMiIGQ9Ik0xMSwxNGgyMyIvPjwvZz48cmVjdCB4PSIyOC44IiB5PSIyOCIgY2xhc3M9InN0NCIgd2lkdGg9IjEzLjgiIGhlaWdodD0iMTMuOCIvPjwvc3ZnPg==')";
  66.          if (document.getElementsByClassName(mycolor+" knight")[nn1] != undefined)
  67.      document.getElementsByClassName(mycolor+" knight")[nn1].style.backgroundImage = "url('data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz48c3ZnIHZlcnNpb249IjEuMSIgaWQ9IkxheWVyXzEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgeG1sbnM6eGxpbms9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkveGxpbmsiIHg9IjBweCIgeT0iMHB4IiB2aWV3Qm94PSIwIDAgNDUgNDUiIHN0eWxlPSJlbmFibGUtYmFja2dyb3VuZDpuZXcgMCAwIDQ1IDQ1OyIgeG1sOnNwYWNlPSJwcmVzZXJ2ZSI+PHN0eWxlIHR5cGU9InRleHQvY3NzIj4uc3Qwe2ZpbGw6I0ZGRkZGRjtzdHJva2U6IzAwMDAwMDtzdHJva2Utd2lkdGg6MS41O3N0cm9rZS1saW5lY2FwOnJvdW5kO3N0cm9rZS1saW5lam9pbjpyb3VuZDt9LnN0MXtzdHJva2U6IzAwMDAwMDtzdHJva2Utd2lkdGg6MS41O3N0cm9rZS1saW5lY2FwOnJvdW5kO3N0cm9rZS1saW5lam9pbjpyb3VuZDt9LnN0MntmaWxsOiMzRUFGNEU7c3Ryb2tlOiMwMDAwMDA7c3Ryb2tlLXdpZHRoOjEuMTgyMTtzdHJva2UtbGluZWNhcDpyb3VuZDtzdHJva2UtbGluZWpvaW46cm91bmQ7fTwvc3R5bGU+PGc+PHBhdGggY2xhc3M9InN0MCIgZD0iTTIyLDEwYzEwLjUsMSwxNi41LDgsMTYsMjlIMTVjMC05LDEwLTYuNSw4LTIxIi8+PHBhdGggY2xhc3M9InN0MCIgZD0iTTI0LDE4YzAuNCwyLjktNS41LDcuNC04LDljLTMsMi0yLjgsNC4zLTUsNGMtMS0wLjksMS40LTMsMC0zYy0xLDAsMC4yLDEuMi0xLDJjLTEsMC00LDEtNC00YzAtMiw2LTEyLDYtMTJzMS45LTEuOSwyLTMuNWMtMC43LTEtMC41LTItMC41LTNjMS0xLDMsMi41LDMsMi41aDJjMCwwLDAuOC0yLDIuNS0zYzEsMCwxLDMsMSwzIi8+PHBhdGggY2xhc3M9InN0MSIgZD0iTTkuNSwyNS41QzkuNSwyNS44LDkuMywyNiw5LDI2cy0wLjUtMC4yLTAuNS0wLjVTOC43LDI1LDksMjVTOS41LDI1LjIsOS41LDI1LjV6IE0xNC45LDE1LjdjLTAuNCwwLjctMC45LDEuMi0xLjIsMS4xYy0wLjItMC4xLTAuMS0wLjgsMC4zLTEuNWMwLDAsMCwwLDAsMGMwLjQtMC43LDAuOS0xLjIsMS4yLTEuMUMxNS41LDE0LjMsMTUuNCwxNSwxNC45LDE1LjdDMTQuOSwxNS43LDE0LjksMTUuNywxNC45LDE1Ljd6Ii8+PHJlY3QgeD0iMjguOCIgeT0iMjgiIGNsYXNzPSJzdDIiIHdpZHRoPSIxMy44IiBoZWlnaHQ9IjEzLjgiLz48L2c+PC9zdmc+')";
  68.     }
  69.      if (mycolor == "black")
  70.     {
  71.         nn0=1;
  72.         nn1=0;
  73.         if (document.getElementsByClassName(mycolor+" rook")[nn1] != undefined)
  74.          document.getElementsByClassName(mycolor+" rook")[nn1].style.backgroundImage = "url('data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz48c3ZnIHZlcnNpb249IjEuMSIgaWQ9IkxheWVyXzEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgeG1sbnM6eGxpbms9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkveGxpbmsiIHg9IjBweCIgeT0iMHB4IiB2aWV3Qm94PSIwIDAgNDUgNDUiIHN0eWxlPSJlbmFibGUtYmFja2dyb3VuZDpuZXcgMCAwIDQ1IDQ1OyIgeG1sOnNwYWNlPSJwcmVzZXJ2ZSI+PHN0eWxlIHR5cGU9InRleHQvY3NzIj4uc3Qwe3N0cm9rZTojMDAwMDAwO3N0cm9rZS13aWR0aDoxLjU7c3Ryb2tlLWxpbmVqb2luOnJvdW5kO30uc3Qxe3N0cm9rZTojMDAwMDAwO3N0cm9rZS13aWR0aDoxLjU7fS5zdDJ7ZmlsbDpub25lO3N0cm9rZTojRUNFQ0VDO3N0cm9rZS1saW5lY2FwOnJvdW5kO30uc3Qze2ZpbGw6IzNFQUY0RTtzdHJva2U6I0ZGRkZGRjtzdHJva2Utd2lkdGg6MS4xODIxO3N0cm9rZS1saW5lY2FwOnJvdW5kO3N0cm9rZS1saW5lam9pbjpyb3VuZDt9PC9zdHlsZT48Zz48cGF0aCBjbGFzcz0ic3QwIiBkPSJNOSwzOWgyN3YtM0g5VjM5eiBNMTIuNSwzMmwxLjUtMi41aDE3bDEuNSwyLjVIMTIuNXogTTEyLDM2di00aDIxdjRIMTJ6Ii8+PHBhdGggY2xhc3M9InN0MSIgZD0iTTE0LDI5LjV2LTEzaDE3djEzSDE0eiIvPjxwYXRoIGNsYXNzPSJzdDAiIGQ9Ik0xNCwxNi41TDExLDE0aDIzbC0zLDIuNUgxNHogTTExLDE0VjloNHYyaDVWOWg1djJoNVY5aDR2NUgxMXoiLz48cGF0aCBjbGFzcz0ic3QyIiBkPSJNMTIsMzUuNWgyMSBNMTMsMzEuNWgxOSBNMTQsMjkuNWgxNyBNMTQsMTYuNWgxNyBNMTEsMTRoMjMiLz48L2c+PHJlY3QgeD0iMjguOCIgeT0iMjgiIGNsYXNzPSJzdDMiIHdpZHRoPSIxMy44IiBoZWlnaHQ9IjEzLjgiLz48L3N2Zz4=')";
  75.      if (document.getElementsByClassName(mycolor+" knight")[nn1] != undefined)
  76.       document.getElementsByClassName(mycolor+" knight")[nn1].style.backgroundImage = "url('data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz48c3ZnIHZlcnNpb249IjEuMSIgaWQ9IkxheWVyXzEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgeG1sbnM6eGxpbms9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkveGxpbmsiIHg9IjBweCIgeT0iMHB4IiB2aWV3Qm94PSIwIDAgNDUgNDUiIHN0eWxlPSJlbmFibGUtYmFja2dyb3VuZDpuZXcgMCAwIDQ1IDQ1OyIgeG1sOnNwYWNlPSJwcmVzZXJ2ZSI+PHN0eWxlIHR5cGU9InRleHQvY3NzIj4uc3Qwe3N0cm9rZTojMDAwMDAwO3N0cm9rZS13aWR0aDoxLjU7c3Ryb2tlLWxpbmVjYXA6cm91bmQ7c3Ryb2tlLWxpbmVqb2luOnJvdW5kO30uc3Qxe2ZpbGw6I0VDRUNFQztzdHJva2U6I0VDRUNFQztzdHJva2Utd2lkdGg6MS41O3N0cm9rZS1saW5lY2FwOnJvdW5kO3N0cm9rZS1saW5lam9pbjpyb3VuZDt9LnN0MntmaWxsOiNFQ0VDRUM7fS5zdDN7ZmlsbDojM0VBRjRFO3N0cm9rZTojRkZGRkZGO3N0cm9rZS13aWR0aDoxLjE4MjE7c3Ryb2tlLWxpbmVjYXA6cm91bmQ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WR0aD0iMTMuOCIgaGVpZ2h0PSIxMy44Ii8+PC9zdmc+')";
  77.  
  78. /*
  79.              if (document.getElementsByClassName(mycolor+" rook")[nn1] != undefined)
  80.        document.getElementsByClassName(mycolor+" rook")[nn1].style.backgroundImage = "url('data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz48c3ZnIHZlcnNpb249IjEuMSIgaWQ9IkxheWVyXzEiIGltYWdlLXJlbmRlcmluZz0ib3B0aW1pemVRdWFsaXR5IiBzaGFwZS1yZW5kZXJpbmc9Imdlb21ldHJpY1ByZWNpc2lvbiIgdGV4dC1yZW5kZXJpbmc9Imdlb21ldHJpY1ByZWNpc2lvbiIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiB4bWxuczp4bGluaz0iaHR0cDovL3d3dy53My5vcmcvMTk5OS94bGluayIgeD0iMHB4IiB5PSIwcHgiIHZpZXdCb3g9IjAgMCAxNDEuNyAxNDEuNyIgc3R5bGU9ImVuYWJsZS1iYWNrZ3JvdW5kOm5ldyAwIDAgMTQxLjcgMTQxLjc7IiB4bWw6c3BhY2U9InByZXNlcnZlIj48c3R5bGUgdHlwZT0idGV4dC9jc3MiPi5zdDB7ZmlsbDojMUYxQTE3O30uc3Qxe2ZpbGw6dXJsKCNTVkdJRF8xXyk7fS5zdDJ7ZmlsbDojM0VBRjRFO3N0cm9rZTojMDAwMDAwO3N0cm9rZS13aWR0aDozLjM0MDc7c3Ryb2tlLWxpbmVjYXA6cm91bmQ7c3Ryb2tlLWxpbmVqb2luOnJvdW5kO308L3N0eWxlPjxwYXRoIGNsYXNzPSJzdDAiIGQ9Ik04MC41LDI2LjFoMTJ2LTkuNmgxOS4zdjI2LjRsLTE1LjYsMTJ2MzMuNmwxMiwxMnYxNC40aDEwLjh2MTYuOGgtOTZ2LTE2LjhoMTAuOHYtMTQuNGwxMi0xMlY1NC45bC0xNS42LTEyVjE2LjVoMTkuMnY5LjZoMTJ2LTkuNmgxOS4yVjI2LjF6Ii8+PGxpbmVhckdyYWRpZW50IGlkPSJTVkdJRF8xXyIgZ3JhZGllbnRVbml0cz0idXNlclNwYWNlT25Vc2UiIHgxPSItMjA0LjUwNDYiIHkxPSIyNjMuNDE1NyIgeDI9Ii0xNDguMjM5NiIgeTI9IjI2My40MTU3IiBncmFkaWVudFRyYW5zZm9ybT0ibWF0cml4KDIuODM0NiAwIDAgLTIuODM0NiA2NDAuMjkxNCA4MjAuNzc4KSI+PHN0b3AgIG9mZnNldD0iMCIgc3R5bGU9InN0b3AtY29sb3I6I0ZGRkZGRiIvPjxzdG9wICBvZmZzZXQ9IjEiIHN0eWxlPSJzdG9wLWNvbG9yOiNGRkZGRkY7c3RvcC1vcGFjaXR5OjAiLz48L2xpbmVhckdyYWRpZW50PjxwYXRoIGNsYXNzPSJzdDEiIGQ9Ik05My44LDUwLjFsOC45LTcuMkgzOS4xbDksNy4ySDkzLjh6IE0xMTQuMiwxMTkuNkgyNy43djcuMmg4Ni41VjExOS42eiBNMTAzLjMsMTA1LjNIMzguNnY5LjZoNjQuN0wxMDMuMywxMDUuM3ogTTkxLjMsNTQuOUg1MC41djMzLjZoNDAuOFY1NC45eiBNMTA2LjksMzguMVYyMS4zaC05LjZ2OS42SDc1LjZ2LTkuNmgtOS41djkuNkg0NC41di05LjZoLTkuNnYxNi44SDEwNi45eiBNMTAxLjUsMTAwLjVsLTcuMi03LjJINDcuNmwtNy40LDcuMkgxMDEuNXoiLz48cmVjdCB4PSI5NS41IiB5PSI5NS4xIiBjbGFzcz0ic3QyIiB3aWR0aD0iMzkiIGhlaWdodD0iMzkiLz48L3N2Zz4=')";
  81.          if (document.getElementsByClassName(mycolor+" knight")[nn1] != undefined)
  82.      document.getElementsByClassName(mycolor+" knight")[nn1].style.backgroundImage = "url('data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz48c3ZnIHZlcnNpb249IjEuM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SwzLjRjMCwxLjUtMC43LDIuNC0yLjIsMi41Yy0xLjcsMC4yLTIuNS0wLjUtMi41LTIuMWMwLjItMy4xLDEuNi01LjUsNC4yLTcuNGMxLjItMSwyLjQtMC45LDMuNCwwLjNDMjcuOSw4MS45LDI3LjcsODMsMjYuNSw4My45TDI2LjUsODMuOXogTTQ3LjMsNTAuNGMwLjYsMC45LDAuOCwxLjksMC43LDNjLTAuNSwzLTIuMSw0LjItNSwzLjhjLTAuNy0wLjEtMS40LTAuNC0yLTAuOGMtMC4yLDAuMi0wLjUsMC43LTAuOCwxLjVjLTAuNSwxLjUtMS41LDItMywxLjZjLTEuNC0wLjYtMi0xLjYtMS43LTMuMmMyLjEtNS40LDUuOS05LjEsMTEuNC0xMS4xYzEuNi0wLjUsMi43LDAsMy4yLDEuNGMwLjYsMS41LDAuMSwyLjUtMS4zLDMuMWMtMC4yLDAuMS0wLjUsMC4zLTAuOCwwLjRDNDcuOSw1MC4xLDQ3LjYsNTAuMyw0Ny4zLDUwLjR6Ii8+PHJlY3QgeD0iOTUuNSIgeT0iOTUuMSIgY2xhc3M9InN0MiIgd2lkdGg9IjM5IiBoZWlnaHQ9IjM5Ii8+PC9zdmc+')";
  83.     }
  84.      if (mycolor == "black")
  85.     {
  86.         nn0=1;
  87.         nn1=0;
  88.         if (document.getElementsByClassName(mycolor+" rook")[nn1] != undefined)
  89.          document.getElementsByClassName(mycolor+" rook")[nn1].style.backgroundImage = "url('data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz48c3ZnIHZlcnNpb249IjEuMSIgaWQ9IkxheWVyXzEiIGltYWdlLXJlbmRlcmluZz0ib3B0aW1pemVRdWFsaXR5IiBzaGFwZS1yZW5kZXJpbmc9Imdlb21ldHJpY1ByZWNpc2lvbiIgdGV4dC1yZW5kZXJpbmc9Imdlb21ldHJpY1ByZWNpc2lvbiIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDA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mVhckdyYWRpZW50PjxwYXRoIGNsYXNzPSJzdDEiIGQ9Ik03MC45LDk5LjNINDEuOGwtMy4yLDN2NC4xaDY0Ljd2LTQuMWwtMy4yLTNINzAuOXogTTM4LjYsMTEzLjd2Ny4yaDY0Ljd2LTcuMkgzOC42eiBNNzAuOSwzN2gtMzZ2My4ybDUuMSwzLjloNjEuOGw1LTMuOVYzN0g3MC45eiBNNzAuOSw0OC44SDQ2LjNsNC4yLDMuM3Y0aDQwLjh2LTRsNC4yLTMuM0w3MC45LDQ4Ljh6IE03MC45LDg3LjJINTAuNXYzLjJsLTQuMiw0LjFoNDkuMmwtNC4yLTQuMXYtMy4ySDcwLjl6Ii8+PHJlY3QgeD0iOTUuNSIgeT0iOTUuMSIgY2xhc3M9InN0MiIgd2lkdGg9IjM5IiBoZWlnaHQ9IjM5Ii8+PC9zdmc+')";
  90.      if (document.getElementsByClassName(mycolor+" knight")[nn1] != undefined)
  91.       document.getElementsByClassName(mycolor+" knight")[nn1].style.backgroundImage = "url('data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz48c3ZnIHZlcnNpb249IjEuMSIgaWQ9IkxheWVyXzEiIGltYWdlLXJlbmRlcmluZz0ib3B0aW1pemVRdWFsaXR5IiBzaGFwZS1yZW5kZXJpbmc9Imdlb21ldHJpY1ByZWNpc2lvbiIgdGV4dC1yZW5kZXJpbmc9Imdlb21ldHJpY1ByZWNpc2lvbiIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiB4bWxuczp4bGluaz0iaHR0cDovL3d3dy53My5vcmcvMTk5OS94bGluayIgeD0iMHB4IiB5PSIwcHgiIHZpZXdCb3g9IjAgMCAxNDEuNyAxNDEuNyIgc3R5bGU9ImVuYWJsZS1iYWNrZ3JvdW5kOm5ldyAwIDAgMTQxLjcgMTQxLjc7IiB4bWw6c3BhY2U9InByZXNlcnZlIj48c3R5bGUgdHlwZT0idGV4d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UgxMjEuOHogTTI2LjgsODUuNGMxLjMtMSwxLjUtMi4xLDAuNC0zLjRjLTEuMS0xLjEtMi40LTEuMi0zLjctMC4zYy0yLjksMS45LTQuNCw0LjMtNC42LDcuNGMwLDEuNSwxLDIuMywyLjgsMi4yYzEuNy0wLjEsMi41LTEsMi40LTIuNkMyNC41LDg3LjIsMjUuMyw4Ni4xLDI2LjgsODUuNHoiLz48cmVjdCB4PSI5NS41IiB5PSI5NS4xIiBjbGFzcz0ic3QyIiB3aWR0aD0iMzkiIGhlaWdodD0iMzkiLz48L3N2Zz4=')";
  92. */
  93.  
  94.  
  95.  
  96.  
  97.  
  98.     }
  99.  
  100.  
  101.     var rect,x0,y0,w,sqsize;
  102.     var board = document.querySelectorAll("cg-board")[0];
  103.     rect = board.getBoundingClientRect();
  104.         x0 = rect.left;
  105.         y0 = rect.top;
  106.         w = rect.width;
  107.         sqsize = w / 8;
  108. //var cou = 0;
  109. var boardx,boardy,horiz,vertic,horiz2,vertic2;
  110.     var horiz0,vertic0;
  111.    // var time1,n11=0;
  112.      // document.addEventListener("mousemove",function(e) {
  113.           board.addEventListener("mousemove",function(e) {
  114.          // time1 = performance.now();
  115.          //     n11=n11+1;
  116.     cx = e.clientX;
  117.     cy = e.clientY;
  118.              /*
  119.              document.addEventListener("mousedown", function(){
  120.              var noPiecesIncluded = '.black, .white';
  121.               if (event.target.matches(noPiecesIncluded)) {
  122.               console.log("piece");
  123.               }
  124.               });
  125.               */
  126.  
  127.  
  128. boardx = cx - rect.left;
  129.     boardy = cy - rect.top;
  130. horiz = Math.ceil(boardx/sqsize);
  131.    vertic = 9-Math.ceil(boardy/sqsize);
  132.           if (horiz != horiz2 || vertic != vertic2)
  133.               {
  134.                   keysT = keys.slice(0);
  135.                  // console.log(keys,keysT);
  136.                 //  time = performance.now();
  137.                   horiz0 = horiz;
  138.           vertic0 = vertic;
  139.                   makemoves();
  140.                  // cou = cou+1;
  141.                 //  console.log("cou",cou);
  142.          //console.log(horiz,vertic);
  143.       }
  144.        horiz2 = horiz;
  145.           vertic2 = vertic;
  146.             //  console.log(performance.now()-time1,"move",n11);
  147. });
  148.  
  149.  /*   document.addEventListener("mousedown",function(e) {
  150.     cx = e.clientX;
  151.     cy = e.clientY;
  152.         checkpiece = document.elementFromPoint(cx, cy);
  153.     console.log(checkpiece);
  154. });*/
  155.  
  156.  function register(x,y,el=board) {
  157.         var ev = new MouseEvent("mouseup", {
  158.             "view": window,
  159.             "bubbles": true,
  160.             "cancelable": false,
  161.             "clientX": x,
  162.             "clientY": y
  163.         });
  164.         el.dispatchEvent(ev);
  165.         //console.log(x,y);
  166.     }
  167.  
  168. var mp;
  169. var keysT = [];
  170.     var numK,checkpiece,pieceX,pieceY,toX,toY;
  171.     var pawnX, pawnY, pawnC, pawnrect, pawnN, pawn2X,pawn2Y,p2;
  172.     var pawnLX, pawnLY, pawnLC, pawnLrect;
  173.     var pawnRX, pawnRY, pawnRC, pawnRrect;
  174.     var kingC,kingrect,kingX,kingY;
  175.     var queenC,queenrect,queenX,queenY,queenN;
  176.     var bishC,bishrect,bishX,bishY,bishN;
  177.     var rook0C,rook0rect,rook0X,rook0Y;
  178.     var rook1C,rook1rect,rook1X,rook1Y;
  179.     var rookC,rookrect,rookX,rookY,rookN,rooktX,rooktY,rooktrect;
  180.     var knightC,knightrect,knightX,knightY,knightN;
  181.     // function Making moves
  182.      function makemoves() {
  183.  
  184. hor = horiz0;
  185.  vert = vertic0;
  186.  
  187.          mp = 0;
  188.          if (turnC == 1)
  189.          {
  190.            //  console.log("notpremove");
  191.              for (var chk = 0; chk < st.length; ++chk) {
  192.                 // console.log(horiz0*10+vertic, st[chk],st.length,st);
  193.                  if ((horiz0*10+vertic0) == st[chk])
  194.                      {
  195.                         mp = 1;
  196.                         // console.log("piece");
  197.                          break;
  198.                      } else {
  199.                          mp = 0;
  200.                      }
  201.  
  202.              }
  203.          }
  204.  
  205.  
  206.  
  207.  
  208.          if (mp == 0)
  209.          {
  210.  
  211.  
  212.      //if (turnC == 1 && 1) {
  213.          numK = keysT.length;
  214.            //  console.log(numK,keys,keysT);
  215.             // keysT = keys.slice(0);
  216.    for( var y = 0; y < numK; y++){
  217.        //console.log(keysT);
  218.  
  219.        // Making moves
  220.  
  221.  
  222. if (keysT[0] == pFK) {
  223.     pawnC = document.getElementsByClassName(mycolor+" pawn");
  224.     //console.log(pawnC);
  225.     pawnN = pawnC.length;
  226.     p2 = 0;
  227.         if (document.getElementsByClassName("ghost "+mycolor+" pawn")[0] != undefined && document.getElementsByClassName("ghost "+mycolor+" pawn")[0] != null)
  228.         {
  229.             pawnN = pawnN-1;
  230.         }
  231.     for( var pn = 0; pn < pawnN; pn++){
  232.         pawnrect = pawnC[pn].getBoundingClientRect();
  233. pawnX = Math.ceil(((pawnrect.left+sqsize/2)-rect.left)/sqsize)
  234.     pawnY = 9-Math.ceil(((pawnrect.top+sqsize/2)-rect.top)/sqsize)
  235.        // console.log(pawnX,pawnY,horiz0,vertic0);
  236. if ((pawnX == horiz0) && (pawnY == vertic0-1))
  237. {
  238.  
  239.     toX = (horiz0)*sqsize+rect.left-sqsize/2;
  240.    toY = (9-vertic0)*sqsize+rect.top-sqsize/2;
  241.     //console.log(pawnrect.left+sqsize/2,pawnrect.top+sqsize/2,toX,toY,cx,cy)
  242. tts(pawnrect.left+sqsize/2,pawnrect.top+sqsize/2,toX,toY);
  243.     //console.log("pawn");
  244. p2 = 0;
  245. break;
  246. //} else if ((pawnX == horiz0) && (pawnY == vertic0-2)) {
  247.     } else if ((pawnX == horiz0) && (pawnY == 2) && (vertic0 == 4)) {
  248.         // console.log(pawnX,horiz0,pawnY,vertic0);
  249.         p2 = 1;
  250.         pawn2X = pawnrect.left+sqsize/2;
  251.             pawn2Y = pawnrect.top+sqsize/2;
  252. /*toX = (horiz0)*sqsize+rect.left-sqsize/2;
  253.    toY = (9-vertic0)*sqsize+rect.top-sqsize/2;
  254.     //console.log(pawnrect.left+sqsize/2,pawnrect.top+sqsize/2,toX,toY,cx,cy)
  255. tts(pawnrect.left+sqsize/2,pawnrect.top+sqsize/2,toX,toY);
  256. break;*/
  257. }
  258.     }
  259.     if (p2 == 1)
  260.         {
  261.             toX = (horiz0)*sqsize+rect.left-sqsize/2;
  262.    toY = (9-vertic0)*sqsize+rect.top-sqsize/2;
  263.             tts(pawn2X,pawn2Y,toX,toY);
  264.         }
  265.     };
  266.  
  267. if (keysT[0] == pLK) {
  268.     pawnLC = document.getElementsByClassName(mycolor+" pawn");
  269.     pawnN = pawnLC.length;
  270.         if (document.getElementsByClassName("ghost "+mycolor+" pawn")[0] != undefined && document.getElementsByClassName("ghost "+mycolor+" pawn")[0] != null)
  271.         {
  272.             pawnN = pawnN-1;
  273.         }
  274.     for( var pnL = 0; pnL < pawnN; pnL++){
  275.         pawnLrect = pawnLC[pnL].getBoundingClientRect();
  276. pawnLX = Math.ceil(((pawnLrect.left+sqsize/2)-rect.left)/sqsize)
  277.     pawnLY = 9-Math.ceil(((pawnLrect.top+sqsize/2)-rect.top)/sqsize)
  278.        // console.log(pawnLX,pawnLY,horiz0,vertic0);
  279. if ((pawnLX == horiz0+1) && (pawnLY == vertic0-1))
  280. {
  281.     toX = (horiz0)*sqsize+rect.left-sqsize/2;
  282.    toY = (9-vertic0)*sqsize+rect.top-sqsize/2;
  283.     //console.log(pawnLrect.left+sqsize/2,pawnLrect.top+sqsize/2,toX,toY,cx,cy)
  284. tts(pawnLrect.left+sqsize/2,pawnLrect.top+sqsize/2,toX,toY);
  285. break;
  286. }
  287.     }
  288.     };
  289.  
  290. if (keysT[0] == pRK) {
  291.     pawnRC = document.getElementsByClassName(mycolor+" pawn");
  292.     pawnN = pawnRC.length;
  293.         if (document.getElementsByClassName("ghost "+mycolor+" pawn")[0] != undefined && document.getElementsByClassName("ghost "+mycolor+" pawn")[0] != null)
  294.         {
  295.             pawnN = pawnN-1;
  296.         }
  297.     for( var pnR = 0; pnR < pawnN; pnR++){
  298.         pawnRrect = pawnRC[pnR].getBoundingClientRect();
  299. pawnRX = Math.ceil(((pawnRrect.left+sqsize/2)-rect.left)/sqsize)
  300.     pawnRY = 9-Math.ceil(((pawnRrect.top+sqsize/2)-rect.top)/sqsize)
  301.        // console.log(pawnLX,pawnLY,horiz0,vertic0);
  302. if ((pawnRX == horiz0-1) && (pawnRY == vertic0-1))
  303. {
  304.     toX = (horiz0)*sqsize+rect.left-sqsize/2;
  305.    toY = (9-vertic0)*sqsize+rect.top-sqsize/2;
  306.     //console.log(pawnLrect.left+sqsize/2,pawnLrect.top+sqsize/2,toX,toY,cx,cy)
  307. tts(pawnRrect.left+sqsize/2,pawnRrect.top+sqsize/2,toX,toY);
  308. break;
  309. }
  310.     }
  311.     };
  312.  
  313. if (keysT[0] == kingK) {
  314.     kingC = document.getElementsByClassName(mycolor+" king")[0];
  315.    // console.log(kingC);
  316.     kingrect = kingC.getBoundingClientRect();
  317. kingX = Math.ceil(((kingrect.left+sqsize/2)-rect.left)/sqsize)
  318.     kingY = 9-Math.ceil(((kingrect.top+sqsize/2)-rect.top)/sqsize)
  319.        // console.log(pawnLX,pawnLY,horiz0,vertic0);
  320. if (((kingX == horiz0) && (kingY == vertic0-1)) || ((kingX == horiz0) && (kingY == vertic0+1)) || ((kingX == horiz0-1) && (kingY == vertic0)) || ((kingX == horiz0+1) && (kingY == vertic0)) || ((kingX == horiz0-1) && (kingY == vertic0-1)) || ((kingX == horiz0-1) && (kingY == vertic0+1)) || ((kingX == horiz0+1) && (kingY == vertic0-1)) || ((kingX == horiz0+1) && (kingY == vertic0+1)) || ((kingX == horiz0+2) && (kingY == vertic0)) || ((kingX == horiz0-2) && (kingY == vertic0)))
  321. {
  322.     toX = (horiz0)*sqsize+rect.left-sqsize/2;
  323.    toY = (9-vertic0)*sqsize+rect.top-sqsize/2;
  324.     //console.log(pawnLrect.left+sqsize/2,pawnLrect.top+sqsize/2,toX,toY,cx,cy)
  325. tts(kingrect.left+sqsize/2,kingrect.top+sqsize/2,toX,toY);
  326. }
  327.     };
  328.  
  329. if (keysT[0] == qK) {
  330.     queenC = document.getElementsByClassName(mycolor+" queen");
  331.     queenN = queenC.length;
  332.         if (document.getElementsByClassName("ghost "+mycolor+" queen")[0] != undefined && document.getElementsByClassName("ghost "+mycolor+" queen")[0] != null)
  333.         {
  334.             queenN = queenN-1;
  335.         }
  336.     for( var qR = 0; qR < queenN; qR++){
  337.  
  338.     queenrect = queenC[qR].getBoundingClientRect();
  339.   queenX = Math.ceil(((queenrect.left+sqsize/2)-rect.left)/sqsize)
  340.   queenY = 9-Math.ceil(((queenrect.top+sqsize/2)-rect.top)/sqsize)
  341.     // console.log(pawnLX,pawnLY,horiz0,vertic0);
  342. if (((queenX == horiz0) || (queenY == vertic0) || (Math.abs(horiz0-queenX) == Math.abs(vertic0-queenY))) && !((queenX == horiz0) && (queenY == vertic0)))
  343. {
  344.     toX = (horiz0)*sqsize+rect.left-sqsize/2;
  345.     toY = (9-vertic0)*sqsize+rect.top-sqsize/2;
  346.     //console.log(pawnLrect.left+sqsize/2,pawnLrect.top+sqsize/2,toX,toY,cx,cy)
  347.     tts(queenrect.left+sqsize/2,queenrect.top+sqsize/2,toX,toY);
  348.     break;
  349. }
  350.     }
  351. };
  352.  
  353. if (keysT[0] == biK) {
  354.     bishC = document.getElementsByClassName(mycolor+" bishop");
  355.     //console.log(bishC);
  356.     bishN = bishC.length;
  357.         if (document.getElementsByClassName("ghost "+mycolor+" bishop")[0] != undefined && document.getElementsByClassName("ghost "+mycolor+" bishop")[0] != null)
  358.         {
  359.             bishN = bishN-1;
  360.         }
  361.     for( var bR = 0; bR < bishN; bR++){
  362. bishrect = bishC[bR].getBoundingClientRect();
  363. bishX = Math.ceil(((bishrect.left+sqsize/2)-rect.left)/sqsize)
  364. bishY = 9-Math.ceil(((bishrect.top+sqsize/2)-rect.top)/sqsize)
  365. if ((Math.abs(horiz0-bishX) == Math.abs(vertic0-bishY)) && !((bishX == horiz0) && (bishY == vertic0)))
  366. {
  367.     toX = (horiz0)*sqsize+rect.left-sqsize/2;
  368.     toY = (9-vertic0)*sqsize+rect.top-sqsize/2;
  369.     tts(bishrect.left+sqsize/2,bishrect.top+sqsize/2,toX,toY);
  370.     break;
  371. }
  372. }
  373.     };
  374.  
  375. if (keysT[0] == roL) {
  376.   /*  rook0C = document.getElementsByClassName(mycolor+" rook")[nn0];
  377.     rook0rect = rook0C.getBoundingClientRect();
  378.   rook0X = Math.ceil(((rook0rect.left+sqsize/2)-rect.left)/sqsize)
  379.   rook0Y = 9-Math.ceil(((rook0rect.top+sqsize/2)-rect.top)/sqsize)
  380.     // console.log(pawnLX,pawnLY,horiz0,vertic0);
  381. if ((rook0X == horiz0) || (rook0Y == vertic0))
  382. {
  383.     toX = (horiz0)*sqsize+rect.left-sqsize/2;
  384.     toY = (9-vertic0)*sqsize+rect.top-sqsize/2;
  385.     //console.log(pawnLrect.left+sqsize/2,pawnLrect.top+sqsize/2,toX,toY,cx,cy)
  386.     tts(rook0rect.left+sqsize/2,rook0rect.top+sqsize/2,toX,toY);
  387. } else {
  388.   rook1C = document.getElementsByClassName(mycolor+" rook")[nn1];
  389.     rook1rect = rook1C.getBoundingClientRect();
  390.   rook1X = Math.ceil(((rook1rect.left+sqsize/2)-rect.left)/sqsize)
  391.   rook1Y = 9-Math.ceil(((rook1rect.top+sqsize/2)-rect.top)/sqsize)
  392.     // console.log(pawnLX,pawnLY,horiz0,vertic0);
  393. if ((rook1X == horiz0) || (rook1Y == vertic0))
  394. {
  395.     toX = (horiz0)*sqsize+rect.left-sqsize/2;
  396.     toY = (9-vertic0)*sqsize+rect.top-sqsize/2;
  397.     //console.log(pawnLrect.left+sqsize/2,pawnLrect.top+sqsize/2,toX,toY,cx,cy)
  398.     tts(rook1rect.left+sqsize/2,rook1rect.top+sqsize/2,toX,toY);
  399. }
  400. }
  401. */
  402.     if (mycolor == "white")
  403.     {
  404.     rookC = document.getElementsByClassName(mycolor+" rook");
  405.        // console.log(rookC);
  406.         rookN = rookC.length;
  407.         if (document.getElementsByClassName("ghost "+mycolor+" rook")[0] != undefined && document.getElementsByClassName("ghost "+mycolor+" rook")[0] != null)
  408.         {
  409.             rookN = rookN-1;
  410.         }
  411.     for( var rR = 0; rR < rookN; rR++){
  412.   rookrect = rookC[rR].getBoundingClientRect();
  413.   rookX = Math.ceil(((rookrect.left+sqsize/2)-rect.left)/sqsize)
  414.   rookY = 9-Math.ceil(((rookrect.top+sqsize/2)-rect.top)/sqsize)
  415.       //  console.log(rookX,rookY,horiz0,vertic0);
  416.     if (((rookX == horiz0) || (rookY == vertic0)) && !((rookX == horiz0) && (rookY == vertic0)))
  417. {
  418.     //trying to fix rooks on the same line
  419.  
  420.     if ((rR == 0) && (turnC == 1) && (rookN>1)) {
  421. //time = performance.now();
  422.         rooktrect = rookC[1].getBoundingClientRect();
  423.         rooktX = Math.ceil(((rooktrect.left+sqsize/2)-rect.left)/sqsize)
  424.   rooktY = 9-Math.ceil(((rooktrect.top+sqsize/2)-rect.top)/sqsize)
  425. //console.log(rooktY,rookY,horiz0);
  426. if (((rooktX == rookX && rookX == horiz0) && ((rooktY<vertic0 && rookY<vertic0 && rookY<rooktY) || (rooktY>vertic0 && rookY>vertic0 && rookY>rooktY))) || ((rooktY == rookY && rookY == vertic0) && ((rooktX<horiz0 && rookX<horiz0 && rookX<rooktX) || (rooktX>horiz0 && rookX>horiz0 && rookX>rooktX))))
  427. {
  428.  
  429.     toX = (horiz0)*sqsize+rect.left-sqsize/2;
  430.     toY = (9-vertic0)*sqsize+rect.top-sqsize/2;
  431.     //console.log(pawnLrect.left+sqsize/2,pawnLrect.top+sqsize/2,toX,toY,cx,cy)
  432.     tts(rooktrect.left+sqsize/2,rooktrect.top+sqsize/2,toX,toY);
  433.  
  434.     break;
  435.  
  436. }
  437.  
  438.     }
  439.     //end
  440.  
  441.    // console.log(rookX,rookY,horiz0,vertic0);
  442.     toX = (horiz0)*sqsize+rect.left-sqsize/2;
  443.     toY = (9-vertic0)*sqsize+rect.top-sqsize/2;
  444.     //console.log(pawnLrect.left+sqsize/2,pawnLrect.top+sqsize/2,toX,toY,cx,cy)
  445.     tts(rookrect.left+sqsize/2,rookrect.top+sqsize/2,toX,toY);
  446.     break;
  447. }
  448.     }
  449.     }
  450.     if (mycolor == "black")
  451.     {
  452.     rookC = document.getElementsByClassName(mycolor+" rook");
  453.         rookN = rookC.length;
  454.         if (document.getElementsByClassName("ghost "+mycolor+" rook")[0] != undefined && document.getElementsByClassName("ghost "+mycolor+" rook")[0] != null)
  455.         {
  456.             rookN = rookN-1;
  457.         }
  458.     for( var rbR = rookN-1; rbR>(-1); rbR--){
  459.   rookrect = rookC[rbR].getBoundingClientRect();
  460.   rookX = Math.ceil(((rookrect.left+sqsize/2)-rect.left)/sqsize)
  461.   rookY = 9-Math.ceil(((rookrect.top+sqsize/2)-rect.top)/sqsize)
  462.     if (((rookX == horiz0) || (rookY == vertic0)) && !((rookX == horiz0) && (rookY == vertic0)))
  463. {
  464.     //trying to fix rooks on the same line
  465.  
  466.     if ((rbR == rookN-1) && (turnC == 1) && (rookN>1)) {
  467.  
  468.         rooktrect = rookC[rookN-2].getBoundingClientRect();
  469.         rooktX = Math.ceil(((rooktrect.left+sqsize/2)-rect.left)/sqsize)
  470.   rooktY = 9-Math.ceil(((rooktrect.top+sqsize/2)-rect.top)/sqsize)
  471.  
  472. if (((rooktX == rookX && rookX == horiz0) && ((rooktY<vertic0 && rookY<vertic0 && rookY<rooktY) || (rooktY>vertic0 && rookY>vertic0 && rookY>rooktY))) || ((rooktY == rookY && rookY == vertic0) && ((rooktX<horiz0 && rookX<horiz0 && rookX<rooktX) || (rooktX>horiz0 && rookX>horiz0 && rookX>rooktX))))
  473. {
  474.  
  475.     toX = (horiz0)*sqsize+rect.left-sqsize/2;
  476.     toY = (9-vertic0)*sqsize+rect.top-sqsize/2;
  477.     //console.log(pawnLrect.left+sqsize/2,pawnLrect.top+sqsize/2,toX,toY,cx,cy)
  478.     tts(rooktrect.left+sqsize/2,rooktrect.top+sqsize/2,toX,toY);
  479.     break;
  480. }
  481.  
  482.     }
  483.     //end
  484.     toX = (horiz0)*sqsize+rect.left-sqsize/2;
  485.     toY = (9-vertic0)*sqsize+rect.top-sqsize/2;
  486.     //console.log(pawnLrect.left+sqsize/2,pawnLrect.top+sqsize/2,toX,toY,cx,cy)
  487.     tts(rookrect.left+sqsize/2,rookrect.top+sqsize/2,toX,toY);
  488.     break;
  489. }
  490.     }
  491.     }
  492. };
  493.  
  494. if (keysT[0] == roR) {
  495.     if (mycolor == "white")
  496.     {
  497.     rookC = document.getElementsByClassName(mycolor+" rook");
  498.         rookN = rookC.length;
  499.         if (document.getElementsByClassName("ghost "+mycolor+" rook")[0] != undefined && document.getElementsByClassName("ghost "+mycolor+" rook")[0] != null)
  500.         {
  501.             rookN = rookN-1;
  502.         }
  503.     for( var r1bR = rookN-1; r1bR>(-1); r1bR--){
  504.   rookrect = rookC[r1bR].getBoundingClientRect();
  505.   rookX = Math.ceil(((rookrect.left+sqsize/2)-rect.left)/sqsize)
  506.   rookY = 9-Math.ceil(((rookrect.top+sqsize/2)-rect.top)/sqsize)
  507.     if (((rookX == horiz0) || (rookY == vertic0)) && !((rookX == horiz0) && (rookY == vertic0)))
  508. {
  509.     //trying to fix rooks on the same line
  510.  
  511.     if ((r1bR == rookN-1) && (turnC == 1) && (rookN>1)) {
  512.  
  513.         rooktrect = rookC[rookN-2].getBoundingClientRect();
  514.         rooktX = Math.ceil(((rooktrect.left+sqsize/2)-rect.left)/sqsize)
  515.   rooktY = 9-Math.ceil(((rooktrect.top+sqsize/2)-rect.top)/sqsize)
  516.  
  517. if (((rooktX == rookX && rookX == horiz0) && ((rooktY<vertic0 && rookY<vertic0 && rookY<rooktY) || (rooktY>vertic0 && rookY>vertic0 && rookY>rooktY))) || ((rooktY == rookY && rookY == vertic0) && ((rooktX<horiz0 && rookX<horiz0 && rookX<rooktX) || (rooktX>horiz0 && rookX>horiz0 && rookX>rooktX))))
  518. {
  519.  
  520.     toX = (horiz0)*sqsize+rect.left-sqsize/2;
  521.     toY = (9-vertic0)*sqsize+rect.top-sqsize/2;
  522.     //console.log(pawnLrect.left+sqsize/2,pawnLrect.top+sqsize/2,toX,toY,cx,cy)
  523.     tts(rooktrect.left+sqsize/2,rooktrect.top+sqsize/2,toX,toY);
  524.     break;
  525. }
  526.  
  527.     }
  528.     //end
  529.     toX = (horiz0)*sqsize+rect.left-sqsize/2;
  530.     toY = (9-vertic0)*sqsize+rect.top-sqsize/2;
  531.     //console.log(pawnLrect.left+sqsize/2,pawnLrect.top+sqsize/2,toX,toY,cx,cy)
  532.     tts(rookrect.left+sqsize/2,rookrect.top+sqsize/2,toX,toY);
  533.     break;
  534. }
  535.     }
  536.     }
  537.     if (mycolor == "black")
  538.     {
  539.     rookC = document.getElementsByClassName(mycolor+" rook");
  540.         rookN = rookC.length;
  541.         if (document.getElementsByClassName("ghost "+mycolor+" rook")[0] != undefined && document.getElementsByClassName("ghost "+mycolor+" rook")[0] != null)
  542.         {
  543.             rookN = rookN-1;
  544.         }
  545.     for( var r1R = 0; r1R < rookN; r1R++){
  546.   rookrect = rookC[r1R].getBoundingClientRect();
  547.   rookX = Math.ceil(((rookrect.left+sqsize/2)-rect.left)/sqsize)
  548.   rookY = 9-Math.ceil(((rookrect.top+sqsize/2)-rect.top)/sqsize)
  549.     if (((rookX == horiz0) || (rookY == vertic0)) && !((rookX == horiz0) && (rookY == vertic0)))
  550. {
  551.     //trying to fix rooks on the same line
  552.  
  553.     if ((r1R == 0) && (turnC == 1) && (rookN>1)) {
  554.  
  555.         rooktrect = rookC[1].getBoundingClientRect();
  556.         rooktX = Math.ceil(((rooktrect.left+sqsize/2)-rect.left)/sqsize)
  557.   rooktY = 9-Math.ceil(((rooktrect.top+sqsize/2)-rect.top)/sqsize)
  558. //console.log(rooktY,rookY,horiz0);
  559. if (((rooktX == rookX && rookX == horiz0) && ((rooktY<vertic0 && rookY<vertic0 && rookY<rooktY) || (rooktY>vertic0 && rookY>vertic0 && rookY>rooktY))) || ((rooktY == rookY && rookY == vertic0) && ((rooktX<horiz0 && rookX<horiz0 && rookX<rooktX) || (rooktX>horiz0 && rookX>horiz0 && rookX>rooktX))))
  560. {
  561.  
  562.     toX = (horiz0)*sqsize+rect.left-sqsize/2;
  563.     toY = (9-vertic0)*sqsize+rect.top-sqsize/2;
  564.     //console.log(pawnLrect.left+sqsize/2,pawnLrect.top+sqsize/2,toX,toY,cx,cy)
  565.     tts(rooktrect.left+sqsize/2,rooktrect.top+sqsize/2,toX,toY);
  566.     break;
  567. }
  568.  
  569.     }
  570.     //end
  571.     toX = (horiz0)*sqsize+rect.left-sqsize/2;
  572.     toY = (9-vertic0)*sqsize+rect.top-sqsize/2;
  573.     //console.log(pawnLrect.left+sqsize/2,pawnLrect.top+sqsize/2,toX,toY,cx,cy)
  574.     tts(rookrect.left+sqsize/2,rookrect.top+sqsize/2,toX,toY);
  575.     break;
  576. }
  577.     }
  578.     }
  579. };
  580.  
  581. if (keysT[0] == knL) {
  582.     if (mycolor == "white")
  583.     {
  584.     knightC = document.getElementsByClassName(mycolor+" knight");
  585.         //console.log(knightC);
  586.         knightN = knightC.length;
  587.         if (document.getElementsByClassName("ghost "+mycolor+" knight")[0] != undefined && document.getElementsByClassName("ghost "+mycolor+" knight")[0] != null)
  588.         {
  589.             knightN = knightN-1;
  590.         }
  591.     for( var kR = 0; kR < knightN; kR++){
  592.   knightrect = knightC[kR].getBoundingClientRect();
  593.   knightX = Math.ceil(((knightrect.left+sqsize/2)-rect.left)/sqsize)
  594.   knightY = 9-Math.ceil(((knightrect.top+sqsize/2)-rect.top)/sqsize)
  595.     if (((knightX == horiz0+1) && (knightY == vertic0-2)) || ((knightX == horiz0+2) && (knightY == vertic0-1)) || ((knightX == horiz0+2) && (knightY == vertic0+1)) || ((knightX == horiz0+1) && (knightY == vertic0+2)) || ((knightX == horiz0-1) && (knightY == vertic0+2)) || ((knightX == horiz0-2) && (knightY == vertic0+1)) || ((knightX == horiz0-2) && (knightY == vertic0-1)) || ((knightX == horiz0-1) && (knightY == vertic0-2)))
  596. {
  597.     toX = (horiz0)*sqsize+rect.left-sqsize/2;
  598.     toY = (9-vertic0)*sqsize+rect.top-sqsize/2;
  599.     //console.log(pawnLrect.left+sqsize/2,pawnLrect.top+sqsize/2,toX,toY,cx,cy)
  600.     tts(knightrect.left+sqsize/2,knightrect.top+sqsize/2,toX,toY);
  601.     break;
  602. }
  603.     }
  604.     }
  605.     if (mycolor == "black")
  606.     {
  607.     knightC = document.getElementsByClassName(mycolor+" knight");
  608.         knightN = knightC.length;
  609.      if (document.getElementsByClassName("ghost "+mycolor+" knight")[0] != undefined && document.getElementsByClassName("ghost "+mycolor+" knight")[0] != null)
  610.         {
  611.             knightN = knightN-1;
  612.         }
  613.     for( var kbR = knightN-1; kbR>(-1); kbR--){
  614.   knightrect = knightC[kbR].getBoundingClientRect();
  615.   knightX = Math.ceil(((knightrect.left+sqsize/2)-rect.left)/sqsize)
  616.   knightY = 9-Math.ceil(((knightrect.top+sqsize/2)-rect.top)/sqsize)
  617.     if (((knightX == horiz0+1) && (knightY == vertic0-2)) || ((knightX == horiz0+2) && (knightY == vertic0-1)) || ((knightX == horiz0+2) && (knightY == vertic0+1)) || ((knightX == horiz0+1) && (knightY == vertic0+2)) || ((knightX == horiz0-1) && (knightY == vertic0+2)) || ((knightX == horiz0-2) && (knightY == vertic0+1)) || ((knightX == horiz0-2) && (knightY == vertic0-1)) || ((knightX == horiz0-1) && (knightY == vertic0-2)))
  618. {
  619.     toX = (horiz0)*sqsize+rect.left-sqsize/2;
  620.     toY = (9-vertic0)*sqsize+rect.top-sqsize/2;
  621.     //console.log(pawnLrect.left+sqsize/2,pawnLrect.top+sqsize/2,toX,toY,cx,cy)
  622.     tts(knightrect.left+sqsize/2,knightrect.top+sqsize/2,toX,toY);
  623.     break;
  624. }
  625.     }
  626.     }
  627. };
  628.  
  629. if (keysT[0] == knR) {
  630.     if (mycolor == "white")
  631.     {
  632.     knightC = document.getElementsByClassName(mycolor+" knight");
  633.         knightN = knightC.length;
  634.         if (document.getElementsByClassName("ghost "+mycolor+" knight")[0] != undefined && document.getElementsByClassName("ghost "+mycolor+" knight")[0] != null)
  635.         {
  636.             knightN = knightN-1;
  637.         }
  638.     for( var k1bR = knightN-1; k1bR>(-1); k1bR--){
  639.   knightrect = knightC[k1bR].getBoundingClientRect();
  640.   knightX = Math.ceil(((knightrect.left+sqsize/2)-rect.left)/sqsize)
  641.   knightY = 9-Math.ceil(((knightrect.top+sqsize/2)-rect.top)/sqsize)
  642.     if (((knightX == horiz0+1) && (knightY == vertic0-2)) || ((knightX == horiz0+2) && (knightY == vertic0-1)) || ((knightX == horiz0+2) && (knightY == vertic0+1)) || ((knightX == horiz0+1) && (knightY == vertic0+2)) || ((knightX == horiz0-1) && (knightY == vertic0+2)) || ((knightX == horiz0-2) && (knightY == vertic0+1)) || ((knightX == horiz0-2) && (knightY == vertic0-1)) || ((knightX == horiz0-1) && (knightY == vertic0-2)))
  643. {
  644.     toX = (horiz0)*sqsize+rect.left-sqsize/2;
  645.     toY = (9-vertic0)*sqsize+rect.top-sqsize/2;
  646.     //console.log(pawnLrect.left+sqsize/2,pawnLrect.top+sqsize/2,toX,toY,cx,cy)
  647.     tts(knightrect.left+sqsize/2,knightrect.top+sqsize/2,toX,toY);
  648.     break;
  649. }
  650.     }
  651.     }
  652.     if (mycolor == "black")
  653.     {
  654.     knightC = document.getElementsByClassName(mycolor+" knight");
  655.         knightN = knightC.length;
  656.         if (document.getElementsByClassName("ghost "+mycolor+" knight")[0] != undefined && document.getElementsByClassName("ghost "+mycolor+" knight")[0] != null)
  657.         {
  658.             knightN = knightN-1;
  659.         }
  660.     for( var k1R = 0; k1R < knightN; k1R++){
  661.   knightrect = knightC[k1R].getBoundingClientRect();
  662.   knightX = Math.ceil(((knightrect.left+sqsize/2)-rect.left)/sqsize)
  663.   knightY = 9-Math.ceil(((knightrect.top+sqsize/2)-rect.top)/sqsize)
  664.     if (((knightX == horiz0+1) && (knightY == vertic0-2)) || ((knightX == horiz0+2) && (knightY == vertic0-1)) || ((knightX == horiz0+2) && (knightY == vertic0+1)) || ((knightX == horiz0+1) && (knightY == vertic0+2)) || ((knightX == horiz0-1) && (knightY == vertic0+2)) || ((knightX == horiz0-2) && (knightY == vertic0+1)) || ((knightX == horiz0-2) && (knightY == vertic0-1)) || ((knightX == horiz0-1) && (knightY == vertic0-2)))
  665. {
  666.     toX = (horiz0)*sqsize+rect.left-sqsize/2;
  667.     toY = (9-vertic0)*sqsize+rect.top-sqsize/2;
  668.     //console.log(pawnLrect.left+sqsize/2,pawnLrect.top+sqsize/2,toX,toY,cx,cy)
  669.     tts(knightrect.left+sqsize/2,knightrect.top+sqsize/2,toX,toY);
  670.     break;
  671. }
  672.     }
  673.     }
  674. };
  675.  
  676. //console.log(keysT);
  677. keysT.splice(0, 1);
  678.       //console.log(keysT);
  679.  
  680.  
  681. }
  682.  
  683. /*if ((document.getElementsByClassName("move-dest") != undefined) && (document.getElementsByClassName("move-dest") != null) && (turnC == 1))
  684.     {
  685.     cancelPrem();
  686.     }*/
  687.      }
  688.      };
  689.  
  690.  
  691.  
  692.  
  693.       function formation(x,y,el=board) {
  694.         var ev = new MouseEvent("mousedown", {
  695.             "view": window,
  696.             "bubbles": true,
  697.             "cancelable": false,
  698.             "clientX": x,
  699.             "clientY": y,
  700.         });
  701.         el.dispatchEvent(ev);
  702.     }
  703.  
  704.  
  705.  
  706.  
  707.        function tts1(x,y,el=board) {
  708.         formation(x,y,el);
  709.         register(x,y,el);
  710.     }
  711.     var hor,vert;
  712.     var movecount = 0;
  713.     function tts(x,y,tx,ty,el=board) {
  714.         tts1(x,y,el);
  715.         tts1(tx,ty,el);
  716.         movecount = movecount+1;
  717.       //  console.log(movecount,"data",x,y,tx,ty);
  718.         //console.log(performance.now()-time);
  719.         //deselecting experiment
  720.          window.setTimeout(function(){
  721.                 var ds = board.children;
  722.                 //console.log(c);
  723.                 for (var ii = 0; ii < ds.length; ++ii) {
  724.                     if (ds[ii].className.includes("selected")) {
  725.                         tts1(tx,ty,el);
  726.                         return;
  727.                     }
  728.                 }
  729.             },0);
  730.  
  731.         //end
  732.        // movecount = movecount+1;
  733.        // console.log(performance.now()-time);
  734.     };
  735.  
  736.  
  737. var keys = [];
  738. var twice;
  739. document.addEventListener('keydown', function(event) {
  740.  
  741.      const key = event.key;
  742.     if (key == cprm)
  743.     {
  744. cancelPrem();
  745.     }
  746.     // keys[event.key] = true;
  747.  
  748.  window.Mousetrap.bind("f", function() {});
  749.  
  750.     if (!keys.includes(event.key) && event.key != 'Control' && event.key != 'Alt')
  751.     {
  752.        // time = performance.now();
  753.     keys.unshift(event.key);
  754.         keysT.unshift(event.key);
  755.         makemoves();
  756.    // console.log(keys);
  757.     }
  758.  
  759.       if (key == rmtch) {
  760.       document.getElementsByClassName("fbt rematch white")[0].click();
  761.       };
  762.       if (key == biK) {
  763.       for (var ee = 0; ee < document.getElementsByClassName(mycolor+" bishop").length; ee++) {
  764.                    document.getElementsByClassName(mycolor+" bishop")[ee].style.backgroundColor = "blue";
  765.       };
  766.       };
  767.       if (key == qK) {
  768.            if (document.getElementsByClassName(mycolor+" queen")[0] != undefined)
  769.       document.getElementsByClassName(mycolor+" queen")[0].style.backgroundColor = "blue";
  770.       };
  771.       if (key == roL) {
  772.           if (document.getElementsByClassName(mycolor+" rook")[nn0] != undefined)
  773.       document.getElementsByClassName(mycolor+" rook")[nn0].style.backgroundColor = "blue";
  774.       };
  775.       if (key == roR) {
  776.            if (document.getElementsByClassName(mycolor+" rook")[nn1] != undefined)
  777.       document.getElementsByClassName(mycolor+" rook")[nn1].style.backgroundColor = "blue";
  778.       };
  779.       if (key == knL) {
  780.            if (document.getElementsByClassName(mycolor+" knight")[nn0] != undefined)
  781.       document.getElementsByClassName(mycolor+" knight")[nn0].style.backgroundColor = "blue";
  782.       };
  783.       if (key == knR) {
  784.           if (document.getElementsByClassName(mycolor+" knight")[nn1] != undefined)
  785.       document.getElementsByClassName(mycolor+" knight")[nn1].style.backgroundColor = "blue";
  786.       };
  787.       if (key == kingK) {
  788.       document.getElementsByClassName(mycolor+" king")[0].style.backgroundColor = "blue";
  789.       };
  790.       if (key == pLK || key == pFK || key == pRK) {
  791.       for (var e1 = 0; e1 < document.getElementsByClassName(mycolor+" pawn").length; e1++) {
  792.       document.getElementsByClassName(mycolor+" pawn")[e1].style.backgroundColor = "blue";
  793.       };
  794.       }
  795. });
  796.  
  797.     document.addEventListener('keyup', function(event) {
  798.      const key = event.key;
  799.  
  800.         for( var i = 0; i < keys.length; i++){
  801.    if ( keys[i] === event.key) {
  802.      keys.splice(i, 1);
  803.    }
  804. }
  805.  
  806.         for( var j = 0; j < keysT.length; j++){
  807.    if ( keysT[j] === event.key) {
  808.      keysT.splice(j, 1);
  809.    }
  810. }
  811.       if (key == biK) {
  812.       for (var ee = 0; ee < document.getElementsByClassName(mycolor+" bishop").length; ee++) {
  813.                    document.getElementsByClassName(mycolor+" bishop")[ee].style.backgroundColor = "";
  814.       };
  815.       };
  816.       if (key == qK) {
  817.           //console.log("this");
  818.           if (document.getElementsByClassName(mycolor+" queen")[0] != undefined)
  819.       document.getElementsByClassName(mycolor+" queen")[0].style.backgroundColor = "";
  820.       };
  821.       if (key == roL) {
  822.           if (document.getElementsByClassName(mycolor+" rook")[nn0] != undefined)
  823.       document.getElementsByClassName(mycolor+" rook")[nn0].style.backgroundColor = "";
  824.       };
  825.       if (key == roR) {
  826.           if (document.getElementsByClassName(mycolor+" rook")[nn1] != undefined)
  827.       document.getElementsByClassName(mycolor+" rook")[nn1].style.backgroundColor = "";
  828.       };
  829.       if (key == knL) {
  830.           if (document.getElementsByClassName(mycolor+" knight")[nn0] != undefined)
  831.       document.getElementsByClassName(mycolor+" knight")[nn0].style.backgroundColor = "";
  832.       };
  833.       if (key == knR) {
  834.           if (document.getElementsByClassName(mycolor+" knight")[nn1] != undefined)
  835.       document.getElementsByClassName(mycolor+" knight")[nn1].style.backgroundColor = "";
  836.       };
  837.       if (key == kingK) {
  838.          // if (document.getElementsByClassName(mycolor+" king")[0] != undefined)
  839.       document.getElementsByClassName(mycolor+" king")[0].style.backgroundColor = "";
  840.       };
  841.       if (key == pLK || key == pFK || key == pRK) {
  842.       for (var e1 = 0; e1 < document.getElementsByClassName(mycolor+" pawn").length; e1++) {
  843.       document.getElementsByClassName(mycolor+" pawn")[e1].style.backgroundColor = "";
  844.       };
  845.       }
  846.      //  keys[event.key] = false;
  847.        // console.log(keys);
  848.  
  849.     });
  850.     var mypieces,st = [],pcc,pccn,time;
  851.     var turnC;
  852.     var observer;
  853.     var config;
  854.     var oncebeep = 0,whosmove;
  855.     var target = document.getElementsByClassName('rclock-bottom')[0];
  856. observer = new MutationObserver(function (mutations) {
  857.     mutations.forEach(function (mutation) {
  858.         //console.log(mutation.type);
  859.         if (document.getElementsByClassName("rclock rclock-bottom running")[0] != undefined && document.getElementsByClassName("rclock rclock-bottom running")[0] != null)
  860.         {
  861.             if (oncebeep == 1) {
  862.       //  console.log("mymove");
  863.             turnC = 1;
  864.             keysT = keys.slice(0);
  865.                 oncebeep = 0;
  866.                 st = [];
  867.                 //trying to avoid illegal moves (capturing my own pieces)
  868.                 window.setTimeout(function(){
  869.             mypieces = board.children;
  870.  
  871.  
  872.                 //time = Date.now;
  873.                 for (var ppp = 0; ppp < mypieces.length; ++ppp) {
  874.                     if ((mypieces[ppp].className.includes(mycolor)) && !(mypieces[ppp].className.includes("ghost"))) {
  875.                        pcc = mypieces[ppp].getBoundingClientRect();
  876.                        // console.log(mypieces[ppp]);
  877.                         pccn = (1+Math.round((pcc.left-rect.left)/sqsize))*10+(8-Math.round((pcc.top-rect.top)/sqsize));
  878.                         st.push(pccn);
  879.  
  880.                     }
  881.                 }
  882.  
  883.                //console.log(Date.now-time);
  884.                 //end of the experiment
  885.                // time = performance.now();
  886.                     console.log("moveonmyturn",keysT,keys);
  887.        makemoves();
  888.  
  889.                     },35);
  890.  
  891.             }
  892.         }
  893.         if (document.getElementsByClassName("rclock rclock-bottom running")[0] == undefined || document.getElementsByClassName("rclock rclock-bottom running")[0] == null)
  894.         {
  895.             if (oncebeep == 0) {
  896.       //  console.log("oppmove");
  897.             turnC = 0;
  898.                 st = [];
  899.             keysT = keys.slice(0);
  900.                // time = performance.now();
  901.                 //trying to prevent wrong clicking
  902.                 if ((hor != horiz0) || (vert != vertic0))
  903.                     {
  904.                 window.setTimeout(function(){
  905.         makemoves();
  906.                      },15);
  907.                 }
  908.                 //timeout end
  909.  
  910.                 oncebeep = 1;
  911.             }
  912.         }
  913.     });
  914. });
  915. config = {
  916.      attributes: true,
  917.    // childList: true,
  918.    subtree: false
  919. };
  920.     if (target != undefined && target != null)
  921. {
  922.      observer.observe(target, config);
  923. }
  924. /*
  925. var keys = { length: 0 };
  926.  
  927. document.onkeydown = function(e){
  928.     if(!keys[e.key]) {
  929.         keys[e.key] = true;
  930.         keys.length++;
  931.         console.log(keys);
  932.     }
  933. }
  934.  
  935. document.onkeyup = function(e){
  936.     if(keys[e.key]) {
  937.         keys[e.key] = false;
  938.         keys.length--;
  939.         console.log(keys);
  940.     }
  941. }
  942. */
  943. var premove,prerect;
  944.     function getPremove() {
  945.         if (document.getElementsByClassName("current-premove")[0] != undefined && document.getElementsByClassName("current-premove")[0] != null)
  946.         {
  947. premove = 1;
  948.         }
  949.     };
  950.  
  951.     function cancelPrem() {
  952.            tts1(rect.left+5,rect.bottom-5);
  953.         tts1(rect.left+5,rect.bottom-5);
  954.     };
  955.  
  956.  
  957.     }, 300);
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top