SHARE
TWEET

Untitled

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