KosaDeresa / New Userscript 2

// ==UserScript==
// @name         New Userscript 2
// @namespace    http://tampermonkey.net/
// @version      2024-05-03
// @description  try to take over the world!
// @author       You
// @match        https://catwar.net/cw3/
// @match        https://catwar.net/chat
// @match        https://catwar.su/chat
// @match        https://catwar.su/cw3/
// @icon         data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
// @license      MIT
// ==/UserScript==

(function() {

    let nux = 0;
    let patrolStep; let patrolN = 0; let step15_2 = 1; let step24_2 = 2;
    let whatClick;

    function imonline() {
        let now = new Date();
        if (localStorage.online == 'true') { location.reload() }
    }
    setInterval(() => imonline(), 285000);

  function messLong () {
      let mess = document.getElementById("block_mess")
      if (!mess) {
        if (whatClick == 'patrol') {patrol()}
        else if (whatClick == 'swim') {swimm()}
        else if (whatClick == 'perex') {clicl()}
        else if (whatClick == 'kop') {kop()}
        else if (whatClick == 'zork') {zork()}
        else if (whatClick == 'zakop') {zakop()}
        else if (localStorage.rash == 'true') {rash()}
      }
  }

  setInterval(() => messLong(), 2000)

    let step = 1;
  function zakop() {
    let items = document.querySelectorAll(".itemInMouth img")
    let arr = []
    for (i = 0; i < items.length; i++) {
      arr.push(items[i].getAttribute('src'))
    }
    for (i = 0; i < items.length; i++) {
      if (step == 1 && (items[i].getAttribute("src") == 'things/1035.png' || items[i].getAttribute("src") == 'things/416.png') && (arr.includes( 'things/1035.png' ) || arr.includes('things/416.png'))) {

        items[i].click()
        step = 2;
        break;
      } else if (!(arr.includes( 'things/1035.png' ) || arr.includes('things/416.png'))) {
        if (step == 1) {step = 3}
        break
      }
    }

    let dey = document.getElementById('thdey');

     if (step == 2) {
       let deyA = dey.firstChild.childNodes[10].firstChild;
       deyA.click()
       step = 1
    }

    let actons = document.querySelectorAll("a.dey");
    if (step == 3) {
      for (i = 0; i < actons.length; i++) {
        if (actons[i].getAttribute("data-id") == 17) {
            actons[i].click();
          step = 4;
      }
    }
  } else if (step == 4) {
    for (i = 0; i < actons.length; i++) {
      if (localStorage.nuxChecked == 'true' && actons[i].getAttribute("data-id") == 13) {
          actons[i].click();
          step = 1;
          whatClick = 0;
      }
    }
  }
  }

  function rash() {
    let actons = document.querySelectorAll("a.dey");
    for (let i = 0; i < actons.length; i++) {
      if (actons[i].getAttribute("data-id") == 60) {
        actons[i].click()
      }
    }
  }

  function zork () {
    let actons = document.querySelectorAll("a.dey");
    let mesto = document.getElementById("location");
    let cages = document.querySelectorAll("span.move_name");
    let son = document.getElementById('dream')
    let redWidth = 150 - son.lastChild.childNodes[0].offsetWidth;
    //let sonP = son.lastChild.lastChild.textContent.substr(-3, 3).substr(0, 2);
    //sonP = ~~sonP
    //console.log (sonP)
    let i = 0;

    if (mesto.textContent == 'Заоблачная Высь' && redWidth < 20) { //redWidth < 20
      while (i < actons.length) {
        if (actons[i].getAttribute("data-id") == 42) {
          actons[i].click()
        }
        i++
      }
    } else if (mesto.textContent == 'Заоблачная Высь' && redWidth >= 20) {
      while (i < cages.length) {
        if (cages[i].textContent == 'Вершина Горы') {
          cages[i].click()
        }
        i++
      }
    } else if (mesto.textContent == 'Вершина Горы') {
      while (i < actons.length) {
        if (actons[i].getAttribute("data-id") == 1) {
          actons[i].click()
          whatClick = 0;
        }
        i++
      }
    }
  }

    function patrol() {
        let cages = document.querySelectorAll("span.move_name");
        let actons = document.querySelectorAll("a.dey");
        let returnField = document.getElementById("tr_tos").childNodes[0].childNodes[0].childNodes[0].childNodes[0].childNodes[0];
        let mesto = document.getElementById("location");
        let j = 0; let i = 0;

      if (patrolN == 1) {
        if (mesto.textContent == 'Пологий берег') {patrolStep = 1}
        if (mesto.textContent == 'Скрытый лаз') {patrolStep = 2}
        if (mesto.textContent == 'Тихое место') {patrolStep = 3}
        if (mesto.textContent == 'Каюта малышей') {patrolStep = 4}
        if (mesto.textContent == 'Трюм') {patrolStep = 5}
        if (mesto.textContent == 'Подвал') {patrolStep = 6}
      } else if (patrolN == 2) {
        if (mesto.textContent == 'Верхняя палуба') {patrolStep = 1}
        if (mesto.textContent == 'Камбуз') {patrolStep = 2}
        if (mesto.textContent == 'Водохранилище') {patrolStep = 3}
        if (mesto.textContent == 'Штурвал') {patrolStep = 6} // ПРОПУСК
        if (mesto.textContent == 'Шлюпки') {patrolStep = 7}
      }

        while (i < actons.length) {
            if (localStorage.nuxChecked == 'true' && actons[i].getAttribute("data-id") == 13) {
                actons[i].click();
                nux = 1
            }
            i++
        }

        if (patrolN == 1 && !nux) {
            while (j < cages.length) {
                if (cages[j].textContent == 'Скрытый лаз' && patrolStep == 1) {
                    cages[j].click();
                    break
                }
                if (cages[j].textContent == 'Тихое место' && patrolStep == 2) {
                    cages[j].click();
                    break
                }
                if (cages[j].textContent == 'Каюта малышей' && patrolStep == 3) {
                    cages[j].click();
                    break
                }
                if (cages[j].textContent == 'Трюм' && patrolStep == 4) {
                    cages[j].click();
                    break
                }
                if (cages[j].textContent == 'Подвал' && patrolStep == 5) {
                    cages[j].click();
                    break
                }
                if (cages[j].textContent == 'Пологий берег' && patrolStep == 6) {
                    cages[j].click();
                    break
                }
                j++
            }
        }
        else if (patrolN == 2 && !nux) {
            while (j < cages.length) {
                if (cages[j].textContent == 'Камбуз' && patrolStep == 1 && step15_2 == 1) {
                    cages[j].click();
                    step15_2 = 5;
                    break
                }
                if (cages[j].textContent == 'Водохранилище' && patrolStep == 2 && step24_2 == 2) {
                    cages[j].click();
                    step24_2 = 4;
                    break
                }
                if (cages[j].textContent == 'Камбуз' && patrolStep == 3) {
                    cages[j].click();
                    break
                }
                if (cages[j].textContent == 'Верхняя палуба' && patrolStep == 2 && step24_2 == 4) {
                    cages[j].click();
                    step24_2 = 2;
                    break
                }
                if (cages[j].textContent == 'Штурвал' && patrolStep == 1 && step15_2 == 5) {
                    cages[j].click();
                    step15_2 = 1;
                    break
                }
                if (cages[j].textContent == 'Шлюпки' && patrolStep == 6) {
                    cages[j].click();
                    break
                }
                if (cages[j].textContent == 'Верхняя палуба' && patrolStep == 7) {
                    cages[j].click();
                    break
                }
                j++
            }
        }

        if (returnField.offsetWidth > 3) {
            returnField.childNodes[0].click();
            setTimeout(() => patrol(), 1000);
            nux = 0;
        }


    }

    function swimm() {
        let actons = document.querySelectorAll("a.dey");
        let i = 0;
        while (i < actons.length) {
            if (actons[i].getAttribute("data-id") == 24) {
                actons[i].click()
            }
            i++;
        }
    }

    function clicl() {
        let actons = document.querySelectorAll("a.dey");
        let returnField = document.getElementById("tr_tos").childNodes[0].childNodes[0].childNodes[0].childNodes[0].childNodes[0];
        let i = 0
        let j = 0

        while (i < actons.length) {
            if (localStorage.nuxChecked == 'true' && actons[i].getAttribute("data-id") == 13) {
                actons[i].click();
                nux = 1
            }
            i++
        }

        if (!nux) {
            let cages = document.querySelectorAll("span.move_name");
            while (j < 5) {
                if (cages[j].textContent == "Пологий берег") {
                    cages[j].click()
                    break
                }
                j++;
            }
        }

        if (returnField.offsetWidth > 3) {
            returnField.childNodes[0].click();
            nux = 0
        }
    }
    function kop() {
        let actons = document.querySelectorAll("a.dey");
        let clean = document.getElementById('clean')
        let redWidth = 150 - clean.lastChild.childNodes[0].offsetWidth;
        let returnField = document.getElementById("tr_tos").childNodes[0].childNodes[0].childNodes[0].childNodes[0].childNodes[0];
        let i = 0

        if (returnField.offsetWidth > 3) {
            returnField.childNodes[0].click();
        }

        while (i < actons.length) {
            if (localStorage.nuxChecked == 'true' && actons[i].getAttribute("data-id") == 13) {
                actons[i].click()
                break
            }
            else if (redWidth >= 4 && actons[i].getAttribute("data-id") == 3) {
                actons[i].click();
              console.log(redWidth)
                break
            }
            else if (actons[i].getAttribute("data-id") == 17) {
                actons[i].click();
                break
            }
            i++
        }
    }


    let mainDIV = document.createElement("div"); let DIVShow = document.createElement('div'); let content = document.createElement('div')
    if (window.location.href == 'https://catwar.net/cw3/' || window.location.href == 'https://catwar.su/cw3/') {
    document.body.append(mainDIV);
    }
    mainDIV.style.position = 'fixed'; mainDIV.style.right = '1px'; mainDIV.style.bottom = '1px'; content.style.display = 'flex'; content.style.flexDirection = 'column'; content.style.rowGap = '10px'; mainDIV.style.maxWidth = '15%'; mainDIV.style.border = '2px solid #2d2d2d'; mainDIV.style.color = 'black'; mainDIV.style.borderRadius = '5%'; mainDIV.style.backgroundColor = '#9c9c9c'; mainDIV.style.padding = '15px'
    DIVShow.style.border = '1px solid black'; DIVShow.style.borderRadius = '5px'; DIVShow.style.padding = '2px'; DIVShow.style.textAlign = 'center'; DIVShow.style.marginBottom = '5px'; DIVShow.style.cursor = 'pointer'

    let perexLabel = document.createElement("label"); perexLabel.textContent = "Переход"
    let kopLabel = document.createElement("label"); kopLabel.textContent = "Копание"
    let swimmLabel = document.createElement("label"); swimmLabel.textContent = "Плавание"
    let nuxLabel = document.createElement("label"); nuxLabel.textContent = "Нюхаем?"
    let patrolLabel = document.createElement("label"); patrolLabel.textContent = "Дозорим"
    let onlineLabel = document.createElement("label"); onlineLabel.textContent = "Обновление"
    let zorkLabel = document.createElement("label"); zorkLabel.textContent = 'Зоркаем'
    let rashLabel = document.createElement("label"); rashLabel.textContent = 'Расщелина'
    let zakopLabel = document.createElement("label"); zakopLabel.textContent = 'Закапываем'

    let perexChek = document.createElement("input")
    let kopChek = document.createElement("input")
    let swimmChek = document.createElement("input")
    let nuxChek = document.createElement("input")
    let patrolChek = document.createElement("input")
    let onlineChek = document.createElement("input")
    let zorkChek = document.createElement("input")
    let rashChek = document.createElement("input")
    let zakopChek = document.createElement("input")
    zakopChek.type = 'radio'; perexChek.type = "radio"; kopChek.type = 'radio'; swimmChek.type = 'radio'; nuxChek.type = 'checkbox'; patrolChek.type = 'radio'; onlineChek.type = 'radio'; zorkChek.type = 'radio'; rashChek.type = 'radio'
    zakopChek.name = 'sett'; perexChek.name = 'sett'; kopChek.name = 'sett'; swimmChek.name = 'sett'; patrolChek.name = 'sett'; onlineChek.name = 'sett'; zorkChek.name = 'sett'; rashChek.name = 'sett'
    zakopChek.value = 'zakop'; perexChek.value = 'perex'; kopChek.value = 'kop'; swimmChek.value = 'swimm'; patrolChek.value = 'patrol'; onlineChek.value = 'online'; zorkChek.value = 'zork'; rashChek.value = 'rash'


    if (localStorage.nuxChecked == 'true') {nuxChek.checked = true}

    let submitClick = document.createElement("button"); let stopButton = document.createElement("button");
    submitClick.textContent = 'OK'; stopButton.textContent = 'Стоп';

    let patrolSelect = document.createElement ('select')
    let patrolLabel2 = document.createElement('label'); patrolLabel2.textContent = 'Дозор: '
    let patrolNum = [document.createElement('option'),document.createElement('option')]
    for (let i = 0; i < patrolNum.length; i++) {
        patrolNum[i].value = i+1;
        patrolNum[i].textContent = i+1;
    }

  if (localStorage.mainDIVclosed == 'true') {
    content.classList.add('visually-hidden')
    DIVShow.textContent = 'Раскрыть 🡇'
  } else { DIVShow.textContent = 'Скрыть 🡅'}
  mainDIV.append(DIVShow); mainDIV.append(content)

    content.append(perexLabel); perexLabel.append(perexChek);
    content.append(kopLabel); kopLabel.append(kopChek);
    content.append(swimmLabel); swimmLabel.append(swimmChek);
    content.append(nuxLabel); nuxLabel.append(nuxChek);
    content.append(patrolLabel); patrolLabel.append(patrolChek)
    content.append(patrolLabel2); patrolLabel2.append(patrolSelect);
    for (let i = 0; i < patrolNum.length; i++) {patrolSelect.append(patrolNum[i])}
    content.append(zorkLabel); zorkLabel.append(zorkChek)
    content.append(onlineLabel); onlineLabel.append(onlineChek)
    content.append(rashLabel); rashLabel.append(rashChek)
    content.append(zakopLabel); zakopLabel.append(zakopChek)
    content.append(submitClick); content.append(stopButton)


    submitClick.onclick = function setClick() {
        if (perexChek.checked) {
            whatClick = 'perex'
        } else if (kopChek.checked) {
          whatClick = 'kop'
        } else if (swimmChek.checked) {
            whatClick = 'swim'
        } else if (patrolChek.checked) {
            whatClick = 'patrol'
            patrolN = patrolSelect.value;
        }
        else if (onlineChek.checked) {
            localStorage.online = true;
        }
        else if (zorkChek.checked) {
          whatClick = 'zork'
        } else if (rashChek.checked) {
          whatClick = 'rash'
          localStorage.rash = true
        } else if (zakopChek.checked) {
          whatClick = 'zakop'
        }
        else {
            alert ('Введи все поля!')
        }

        if (nuxChek.checked) {
            localStorage.nuxChecked = true
        } else {
          localStorage.nuxChecked = false
        }
    }
    stopButton.onclick = function stopOnline() {
        localStorage.online = false;
        localStorage.rash = false
        whatClick = 0;
    }
  DIVShow.onclick = function closeMainDIV() {
    if (localStorage.mainDIVclosed == 'true') {
      content.classList.remove('visually-hidden')
      localStorage.mainDIVclosed = 'false'
      DIVShow.textContent = 'Скрыть 🡅'
    } else {
      content.classList.add('visually-hidden')
      localStorage.mainDIVclosed = 'true'
      DIVShow.textContent = 'Раскрыть 🡇'
    }
  }

guessNumber = function() {
  let guess = false

  moreOrLess = function() {
  let messTr = document.querySelectorAll('.mess_tr')
  let messText = messTr[0].querySelector('.mess_td .mess_div .parsed').textContent
  let moreOrLess = messText.substr(0,1)
  if (messText.substr(0,2) == 'Мо') {
    guess = true
  }
  return moreOrLess
  }

  let numsGuess = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0,]
  let curNums = [5, 0, 0, 0, 0, 0, 0, 0, 0, 0,]
  let znak = 0;

  sendNumber = function() {
    let messSend = document.getElementById('mess_submit');
    messSend.click();
  }

  let check, lastCheck

  findNumber = function(j) {
  let messIn = document.getElementById('mess')

  messIn.textContent = `/number `

    if (!znak) {
      messIn.textContent += `0`
      sendNumber()
      let zcheck
      setTimeout(() => {zcheck = moreOrLess();
        if (zcheck == 'Б') {
          znak = '+'
        } else if (zcheck == 'М') {
          znak = '-'
        }
                       }, 1000)

    }
else if (znak == '+' && !guess) {
      messIn.textContent += `${znak}`
    if (!check) {
      for (i = 0; i < curNums.length; i++) {
        messIn.textContent += `${curNums[i]}`
      }
      sendNumber()

      setTimeout(() => {check = moreOrLess();}, 1000)
    }

    else if (check) {
      if (check == 'Б') {
        curNums[j]++;
      } else if (check == 'М') {
        curNums[j]--;
      }
      for (i = 0; i < curNums.length; i++) {
        messIn.textContent += `${curNums[i]}`
      }
      sendNumber()

      setTimeout(() => {lastCheck = check; check = moreOrLess();
                        if (check != lastCheck && check == 'М') {
                          curNums[j] -= 1;
                          curNums[j+1] = 5
                          numsGuess[j] = 1;
                          check = 0
                        } else if ( (check != lastCheck && check == 'Б') || (check == lastCheck && check == 'Б' && curNums[j] == 9) ) {
                          numsGuess[j] = 1
                          curNums[j+1] = 5
                          check = 0
                        }
                       }, 1000)
    }


}
    else if (znak == '-' && !guess) {
      messIn.textContent += `${znak}`
    if (!check) {
      for (i = 0; i < curNums.length; i++) {
        messIn.textContent += `${curNums[i]}`
      }
      sendNumber()

      setTimeout(() => {check = moreOrLess();}, 1000)
    }

    else if (check) {
      if (check == 'Б') {
        curNums[j]--;
      } else if (check == 'М') {
        curNums[j]++;
      }
      for (i = 0; i < curNums.length; i++) {
        messIn.textContent += `${curNums[i]}`
      }
      sendNumber()

      setTimeout(() => {lastCheck = check; check = moreOrLess();
                        if (check != lastCheck && check == 'Б') {
                          curNums[j] -= 1;
                          curNums[j+1] = 5
                          numsGuess[j] = 1;
                          check = 0
                        } else if ( (check != lastCheck && check == 'М') || (check == lastCheck && check == 'М' && curNums[j] == 9) ) {
                          numsGuess[j] = 1
                          curNums[j+1] = 5
                          check = 0
                        }
                       }, 1000)
    }


}
      runFindNum()

  }

  runFindNum = function() {
    for (i = 0; i < numsGuess.length; i++) {
      if (!numsGuess[i]) {
        setTimeout(() => findNumber(i), 5500)
        break
      }
    }
  }

  runFindNum()
  }

  if (window.location.href == 'https://catwar.net/chat' || window.location.href == 'https://catwar.su/chat') {
    let numButton = document.createElement('div')
    numButton.textContent = 'Играть в числа'
    numButton.style.position = 'absolute'; numButton.style.left = '1px'; numButton.style.bottom = '1px'; numButton.style.padding = '5px'; numButton.style.backgroundColor = 'white'
    document.body.append(numButton)
    numButton.onclick = guessNumber;
  }
})();