Prevent Logout on LowEndTalk

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

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

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

คุณจะต้องติดตั้งส่วนขยาย เช่น 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         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);

})();