PVNG Never Timeout

PVNG never timeout

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         PVNG Never Timeout
// @namespace    http://tampermonkey.net/
// @version      2.2
// @description  PVNG never timeout
// @author       DryChicken
// @match        https://*.aptech-inc.com/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=aptech-inc.com
// @grant        none
// ==/UserScript==

let timeoutCounter = 0;

function monitorandCloseDialogModal() {
    const timer = document.querySelector('#spanTimer');
    const closeButton = document.querySelector('#dialogSession .modal-footer .btn.btn-default');
    if (timer) {
        const config = {childList: true, characterData: true, subtree: false};
        // Create observer instance
        var observer = new MutationObserver((mutations) => {
            mutations.forEach((mutation) => {
                // Check childList changes or characterData changes
                if (mutation.type === 'childList' || mutation.type === 'characterData') {
                    timeoutCounter += 1;
                    var newText = timer.innerText;
                    console.log(`${newText}`);
                    // Perform action
                    closeButton.click();
                    console.log(`Clicked button, closed countdown: skipped ${timeoutCounter}`);
                    // Backup click 1.5 sec later
                    setTimeout(() => {closeButton.click()}, 1500);
                }
            });
        });
        console.log('Initiating session timeout modal observer');
        observer.observe(timer, config);
    }
}

function autofillCompany() {
    document.getElementById('ddlCompanies').value = '2';
    document.getElementById('PlaceHolderBody_ContinueButton').click();
}


function autoLogin() {
    
    const userNameInput = document.getElementById('PlaceHolderBody_Login1_UserName');
    const passwordInput = document.getElementById('PlaceHolderBody_Login1_Password');
    let passwordLength = passwordInput.textLength;
    
    function checkValueChange(input) {
        console.log(`Input event on password ${input.value}`)
        if (input.textLength > passwordLength + 4) {
            console.log('password filled')
            passwordInput.focus();
            passwordInput.blur();
        } else {
            passwordLength = input.textLength;
        }
    }

    passwordInput.addEventListener('input', (event) => {checkValueChange(event.target)});

    passwordInput.addEventListener('blur', () => {
        if (passwordInput.value !== '' && userNameInput.value !== '') {
            document.getElementById('PlaceHolderBody_Login1_LoginButton').click();
        }
    });
}

function autoMechanism() {
    const url = window.location.href;
    const legend = document.querySelector('legend');
    if (!legend) return;
    if (url.includes('Login') ||  legend.textContent == 'Login') {
        autoLogin();
    } else if (url.includes('CompanySelect') || legend.textContent == 'Company Select') {
        autofillCompany();
    }

}

autoMechanism();
monitorandCloseDialogModal();