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.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' && now.getSeconds() == 1) { location.reload() }
    }
    setInterval(() => imonline(), 1000);

  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()}
      }
  }

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

  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 i = 0;

    if (mesto.textContent == 'Заоблачная Высь' && 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();
                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')
    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 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")
    perexChek.type = "radio"; kopChek.type = 'radio'; swimmChek.type = 'radio'; nuxChek.type = 'checkbox'; patrolChek.type = 'radio'; onlineChek.type = 'radio'; zorkChek.type = 'radio'
    perexChek.name = 'sett'; kopChek.name = 'sett'; swimmChek.name = 'sett'; patrolChek.name = 'sett'; onlineChek.name = 'sett'; zorkChek.name = 'sett'
    perexChek.value = 'perex'; kopChek.value = 'kop'; swimmChek.value = 'swimm'; patrolChek.value = 'patrol'; onlineChek.value = 'online'; zorkChek.value = 'zork'
    perexChek.checked = true;

    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(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 {
            alert ('Введи все поля!')
        }

        if (nuxChek.checked) {
            localStorage.nuxChecked = true
        } else {
          localStorage.nuxChecked = false
        }
    }
    stopButton.onclick = function stopOnline() {
        localStorage.online = 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 = 'Раскрыть 🡇'
    }
  }
})();