SHARE
TWEET

Untitled

a guest Apr 20th, 2019 71 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // hello, dear ctfer
  2. // here is some govnokod
  3. // but it is not necessary to see it
  4. // vuln is in server side
  5.  
  6. const cards = document.querySelectorAll('.memory-card');
  7.  
  8. let hasFlippedCard = false;
  9. let lockBoard = false;
  10. let firstCard, secondCard;
  11. let right = 0;
  12.  
  13. function getInfo(img) {
  14.     var xhr = new XMLHttpRequest();
  15.     xhr.open('GET', '?getInfo=' + img.id, false);
  16.     xhr.send();
  17.  
  18.  
  19.     if (xhr.status === 200) {
  20.         var response = JSON.parse(xhr.response);
  21.         if (response.error == "WASTED"){
  22.             alert("Sorry, it is the end..) more than 3 errors.");
  23.             location.reload();
  24.  
  25.         } else {
  26.             if (response.flag != 0) alert(response.flag);
  27.             console.log(response);
  28.             img.src = response.card + '.jpg';
  29.             document.getElementById("error").innerText = response.errors;
  30.             document.getElementById("passes").innerText = response.passes;
  31.         }
  32.     }
  33.     else {
  34.         alert('Request failed.  Returned status of ' + xhr.status);
  35.     }
  36.  
  37.  
  38. }
  39.  
  40. function sendAnswer() {
  41.     var answer = '';
  42.     cards.forEach(card => answer += card.children[0].src.split('.')[1].slice(-1) + ',');
  43.  
  44.     answer = answer.slice(0, -1);
  45.  
  46.     var xhr = new XMLHttpRequest();
  47.     xhr.open('GET', '?answers=' + answer, false);
  48.     xhr.send();
  49.  
  50.     if (xhr.status === 200) {
  51.         var response = JSON.parse(xhr.response);
  52.         if (response.error == "WASTED"){
  53.             alert("WASTED, SOrry))");
  54.             document.getElementById("error").innerText = response.errors;
  55.             document.getElementById("passes").innerText = response.passes;
  56.             initBoard();
  57.  
  58.         } else {
  59.             if (response.flag != 0) alert(response.flag);
  60.             console.log(response);
  61.             document.getElementById("error").innerText = response.errors;
  62.             document.getElementById("passes").innerText = response.passes;
  63.  
  64.             initBoard();
  65.         }
  66.     }
  67.     else {
  68.         alert('Request failed.  Returned status of ' + xhr.status);
  69.     }
  70. }
  71.  
  72. function flipCard() {
  73.     if (lockBoard) return;
  74.     if (this === firstCard) return;
  75.  
  76.     var img = this.children[0];
  77.  
  78.     getInfo(img);
  79.  
  80.     this.classList.add('flip');
  81.  
  82.     if (!hasFlippedCard) {
  83.         hasFlippedCard = true;
  84.         firstCard = this;
  85.  
  86.         return;
  87.     }
  88.  
  89.     secondCard = this;
  90.     checkForMatch();
  91. }
  92.  
  93. function checkForMatch() {
  94.     let isMatch = firstCard.children[0].src == secondCard.children[0].src;
  95.  
  96.     isMatch ? disableCards() : disableCards();
  97. }
  98.  
  99. function disableCards() {
  100.     firstCard.removeEventListener('click', flipCard);
  101.     secondCard.removeEventListener('click', flipCard);
  102.  
  103.     resetBoard();
  104.  
  105.     right += 2;
  106.     if (right == 12){
  107.         sendAnswer();
  108.     }
  109. }
  110.  
  111. function unflipCards() {
  112.     lockBoard = true;
  113.  
  114.     setTimeout(() => {
  115.         firstCard.classList.remove('flip');
  116.         secondCard.classList.remove('flip');
  117.  
  118.         resetBoard();
  119.     }, 1500);
  120. }
  121.  
  122. function resetBoard() {
  123.     [hasFlippedCard, lockBoard] = [false, false];
  124.     [firstCard, secondCard] = [null, null];
  125. }
  126.  
  127. function initBoard(){
  128.     resetBoard();
  129.     cards.forEach(card => card.classList.remove('flip'));
  130.     cards.forEach(card => card.addEventListener('click', flipCard));
  131.     right = 0;
  132. }
  133.  
  134. cards.forEach(card => card.addEventListener('click', flipCard));
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
 
Top