LOLZ_Refresh

Lolz Auto Refresh

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         LOLZ_Refresh
// @namespace    Lolz Auto Refresh
// @description  Lolz Auto Refresh
// @version      0.5
// @author       el9in
// @license      el9in
// @match        https://zelenka.guru
// @match        https://lolz.guru
// @match        https://lolz.live
// @match        https://zelenka.guru/*
// @match        https://lolz.guru/*
// @match        https://lolz.live/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=zelenka.guru
// @grant        GM.setValue
// @grant        GM.getValue
// ==/UserScript==

(async function() {
    'use strict';
    const autoReloadTimeout = 5000; // Автоматическая перезагрузка в МС 1000 мс = 1 секунда
    const reloadButton = document.querySelector(".UpdateFeedButton");
    let _timer = null;
    if(reloadButton) {
        let _refresh = await GM.getValue("LZT_Auto_Refresh");
        let spanElement = document.createElement('span');
        spanElement.className = 'fa fa-clock lolzauthrefresh';
        spanElement.title = 'Обновить ленту';
        spanElement.style.marginLeft = '15px';
        spanElement.style.padding = '11px';
        reloadButton.parentNode.insertBefore(spanElement, reloadButton.nextSibling);
        spanElement.addEventListener('click', function() {
            set();
        });
        function set() {
            if(_timer) {
                GM.setValue("LZT_Auto_Refresh", 0);
                clearInterval(_timer);
                _timer = null;
                XenForo.alert('Автоматическое обновление отключено.', "LOLZ Auto Refresh", 2000);
            } else {
                GM.setValue("LZT_Auto_Refresh", 1);
                _timer = setInterval(click, autoReloadTimeout);
                XenForo.alert('Автоматическое обновление активировано.', "LOLZ Auto Refresh", 2000);
            }
        }
        function click() {
            if(document.hasFocus()) reloadButton.click();
        }
        document.addEventListener('keydown', function(event) {
            if (event.altKey && event.keyCode === 53) {
                set();
            } else if(event.keyCode === 53) {
                click();
                XenForo.alert('Обновили страницу.', "LOLZ Auto Refresh", 2000);
            }
        });
        if(autoReloadTimeout > 2000 && _refresh) _timer = setInterval(click, autoReloadTimeout)
    }
})();