DNEVNIKREFRESH

Периодически отправляет запросы для продления сессии на сайт e-school.obr.lenreg.ru.

Dovrai installare un'estensione come Tampermonkey, Greasemonkey o Violentmonkey per installare questo script.

You will need to install an extension such as Tampermonkey to install this script.

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Userscripts per installare questo script.

Dovrai installare un'estensione come ad esempio Tampermonkey per installare questo script.

Dovrai installare un gestore di script utente per installare questo script.

(Ho già un gestore di script utente, lasciamelo installare!)

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

(Ho già un gestore di stile utente, lasciamelo installare!)

// ==UserScript==
// @name         DNEVNIKREFRESH
// @namespace	 https://greasyfork.org/users/1535975
// @version      1.1
// @description  Периодически отправляет запросы для продления сессии на сайт e-school.obr.lenreg.ru.
// @author       SPASIBOKVN
// @homepage     http://sk-3.ru/
// @icon         http://sk-3.ru/ini/spasibokvn.png
// @icon64       http://sk-3.ru/ini/spasibokvn.png
// @match        https://e-school.obr.lenreg.ru/*
// @grant        none
// @license      GNU GPLv3
// ==/UserScript==

(function() {
    'use strict';

    console.log('DNEVNIKREFRESH: Скрипт поддержания сессии запущен.');

    // === НАСТРОЙКИ ===
    const PING_URL = 'https://e-school.obr.lenreg.ru/webapi/context/state';
    const PING_INTERVAL = 5 * 60 * 1000; // 5 минут

    // === СОЗДАНИЕ ИНДИКАТОРА ===
    function createIndicator() {
        // Проверяем, не создан ли уже индикатор
        if (document.getElementById('dnevnik-refresh-indicator')) {
            return document.getElementById('dnevnik-refresh-indicator');
        }

        // Создаём div для индикатора
        const indicator = document.createElement('div');
        indicator.id = 'dnevnik-refresh-indicator';
        
        // Стилизуем индикатор (фиксированное положение поверх всего)
        indicator.style.cssText = `
            position: fixed;
            top: 20px;
            right: 20px;
            width: 40px;
            height: 40px;
            border-radius: 50%;
            background-color: rgba(0, 0, 0, 0.7);
            display: flex;
            align-items: center;
            justify-content: center;
            font-size: 24px;
            z-index: 999999;
            opacity: 0;
            transition: opacity 0.3s ease;
            pointer-events: none;
            box-shadow: 0 2px 10px rgba(0,0,0,0.3);
            color: white;
        `;
        
        // Добавляем зелёный круг
        indicator.innerHTML = '🟢';
        
        // Добавляем на страницу
        document.body.appendChild(indicator);
        
        return indicator;
    }

    // === ФУНКЦИИ УПРАВЛЕНИЯ ИНДИКАТОРОМ ===
    function showIndicator() {
        const indicator = document.getElementById('dnevnik-refresh-indicator') || createIndicator();
        indicator.style.opacity = '1';
    }

    function hideIndicator() {
        const indicator = document.getElementById('dnevnik-refresh-indicator');
        if (indicator) {
            indicator.style.opacity = '0';
        }
    }

    // Создаём индикатор при загрузке страницы
    createIndicator();

    // === ФУНКЦИЯ ПИНГОВАНИЯ СЕРВЕРА ===
    function pingServer() {
        console.log('DNEVNIKREFRESH: Отправка запроса к API для продления сессии...');
        
        // Показываем индикатор
        showIndicator();

        fetch(PING_URL, {
            method: 'GET',
            credentials: 'include',
            headers: {
                'X-Requested-With': 'XMLHttpRequest'
            }
        })
        .then(response => {
            if (response.ok) {
                console.log('DNEVNIKREFRESH: ✅ Запрос успешен, сессия активна.');
            } else if (response.status === 401) {
                console.warn('DNEVNIKREFRESH: ⚠️ Сессия, вероятно, истекла (401).');
            } else {
                console.warn(`DNEVNIKREFRESH: ⚠️ Неожиданный статус: ${response.status}`);
            }
        })
        .catch(error => {
            console.error('DNEVNIKREFRESH: ❌ Ошибка при запросе:', error);
        })
        .finally(() => {
            // Прячем индикатор через 1 секунду после завершения запроса
            setTimeout(hideIndicator, 1000);
        });
    }

    // === ЗАПУСК ПО ИНТЕРВАЛУ ===
    // Ждём 30 секунд после загрузки страницы перед первым запросом
    setTimeout(() => {
        pingServer(); // Первый пинг
        setInterval(pingServer, PING_INTERVAL); // Регулярные пинги
    }, 30000); // 30 секунд

})();