DNEVNIKREFRESH

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

คุณจะต้องติดตั้งส่วนขยาย เช่น Tampermonkey, Greasemonkey หรือ Violentmonkey เพื่อติดตั้งสคริปต์นี้

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

คุณจะต้องติดตั้งส่วนขยาย เช่น Tampermonkey หรือ Violentmonkey เพื่อติดตั้งสคริปต์นี้

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

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

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==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 секунд

})();