kiper679 / FLY

// ==UserScript==
// @name         FLY
// @namespace    http://tampermonkey.net/
// @version      0.2
// @description  papapap
// @author       Anonimys
// @match        https://namars.com/subscriptions/
// @grant        none
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';


let isRunning = false; 
let videosWatched = 0;

function delay(ms) {
  return new Promise(resolve => setTimeout(resolve, ms));
}

function createSquareContainer() {
  const squareContainer = document.createElement('div');
  squareContainer.style.position = 'fixed';
  squareContainer.style.top = '10px';
  squareContainer.style.right = '10px';
  squareContainer.style.width = '7cm';
  squareContainer.style.height = '7cm';
  squareContainer.style.backgroundColor = 'green';
  squareContainer.style.border = '1mm solid blue';
  return squareContainer;
}

async function clickNextVideo() {
  const minDelay = 25000; 
  const maxDelay = 35000; 

  const squareContainer = createSquareContainer();
  document.body.appendChild(squareContainer);

  const statsElement = createStatsElement();
  const startButton = createControlButton('Старт', 'black', 'yellow');
  const stopButton = createControlButton('Стоп', 'black', 'red');

  let maxVideosToWatch = 45;
  videosWatched = 0; 
  startButton.addEventListener('click', async () => {
    if (!isRunning && videosWatched < maxVideosToWatch) {
      isRunning = true;
      startButton.disabled = true;
      stopButton.disabled = false;
      statsElement.textContent = `Просмотрено видео: ${videosWatched}`;

      while (isRunning && videosWatched < maxVideosToWatch) {
        const button = await waitForButton();
        button.click();
        videosWatched++;

        const randomDelay = Math.random() * (maxDelay - minDelay) + minDelay;
        await delay(randomDelay);

        statsElement.textContent = `Просмотрено видео: ${videosWatched}`;
        squareContainer.style.border = '1mm solid blue';
      }

      squareContainer.style.border = '1mm solid blue';
      startButton.disabled = false;
      stopButton.disabled = true;

      if (videosWatched >= maxVideosToWatch) {
        statsElement.textContent = 'Завершено просмотрено видео';
      } else {
        statsElement.textContent = 'Остановлен';
      }
    }
  });

  stopButton.addEventListener('click', () => {
    isRunning = false;
  });

  squareContainer.appendChild(statsElement);
  const buttonsContainer = document.createElement('div');
  buttonsContainer.style.display = 'flex';
  buttonsContainer.style.justifyContent = 'space-between';
  buttonsContainer.style.marginTop = '1cm'; // Уменьшил отступ сверху
  buttonsContainer.style.marginBottom = '1cm';
  buttonsContainer.style.padding = '0 15px';
  buttonsContainer.appendChild(startButton);
  buttonsContainer.appendChild(stopButton);
  squareContainer.appendChild(buttonsContainer);
}

function waitForButton() {
  return new Promise(resolve => {
    const intervalId = setInterval(() => {
      const button = document.querySelector('a.btn.btn-blue[data-load=""]');
      if (button) {
        clearInterval(intervalId);
        resolve(button);
      }
    }, 1000);
  });
}

function createControlButton(text, textColor, bgColor) {
  const button = document.createElement('button');
  button.textContent = text;
  button.style.color = textColor;
  button.style.backgroundColor = bgColor;
  button.style.border = '0.5mm solid black';
  button.style.borderRadius = '3.5cm';
  button.style.padding = '10px 15px';    ХАПАРШНГШОШОЩООГЩШЗГ
  button.style.fontSize = '18px'; 
  button.style.fontWeight = 'bold';
  button.style.width = '4cm'; 
  button.style.margin = '0.3cm'; 
}

function createStatsElement() {
  const statsElement = document.createElement('div');
  statsElement.style.fontWeight = 'bold';
  statsElement.style.color = 'black';
  statsElement.style.textAlign = 'center';
  statsElement.style.padding = '10px';
  statsElement.style.backgroundColor = 'white';
  statsElement.style.border = '0.5mm solid blue';
  return statsElement;
}

clickNextVideo();



})();