Prevent Logout on LowEndTalk

Stops accidental logout on LowEndTalk by preventing access to the logout URL or similar variations using regex.

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

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo 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         Prevent Logout on LowEndTalk
// @namespace    http://tampermonkey.net/
// @version      1.4
// @description  Stops accidental logout on LowEndTalk by preventing access to the logout URL or similar variations using regex.
// @author       Zyra
// @match        *://lowendtalk.com/*
// @grant        none
// @license MIT
// ==/UserScript==

(function() {
    'use strict';

    const logoutRegex = /^https:\/\/lowendtalk\.com\/.*entry\/signout/i;

    function blockLogoutPage() {
        if (logoutRegex.test(window.location.href)) {
            window.location.href = 'https://lowendtalk.com/';
        }
    }

    blockLogoutPage();

    let previousURL = window.location.href;

    setInterval(() => {
        if (previousURL !== window.location.href) {
            previousURL = window.location.href;
            blockLogoutPage();
        }
    }, 500);

    document.body.addEventListener('click', function(event) {
        const target = event.target.closest('a');
        if (target && logoutRegex.test(target.href)) {
            event.preventDefault();
            alert("Logout prevented.");
        }
    });

    window.addEventListener('popstate', blockLogoutPage);
    window.addEventListener('hashchange', blockLogoutPage);

})();