Nhentai.net Auto Login

Automatically fills in the login credentials on nhentai.net and clicks the sign in button on the home page.

// ==UserScript==
// @name         Nhentai.net Auto Login
// @namespace    http://tampermonkey.net/
// @version      2.0
// @description  Automatically fills in the login credentials on nhentai.net and clicks the sign in button on the home page.
// @author       longkidkoolstar
// @icon         https://th.bing.com/th/id/R.801ed06597579fe568cdc29b3830d5e8?rik=ZyxLZr%2fyc04MHg&pid=ImgRaw&r=0
// @match        https://nhentai.net/*
// @grant        GM_getValue
// @grant        GM_setValue
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';

    const email = GM_getValue('email');
    const password = GM_getValue('password');

    // Login page
    if (window.location.href.includes('/login/?next=/')) {
        if (!email || !password) {
            GM_setValue('email', prompt('Please enter your email:'));
            GM_setValue('password', prompt('Please enter your password:'));
        }
        document.getElementById('id_username_or_email').value = email;
        document.getElementById('id_password').value = password;
        const errorMessage = document.querySelector('#errors');
        if (!errorMessage || !errorMessage.textContent.includes('You need to solve the CAPTCHA.')) {
            document.querySelector('button[type="submit"]').click();
        } else {
            console.log('CAPTCHA detected. Cannot auto-login.');
        }
    }
})();