longkidkoolstar / Nhentai.net Auto Login

// ==UserScript==
// @name         Nhentai.net Auto Login
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  Automatically fills in the login credentials on nhentai.net and clicks the sign in button on the home page.
// @author       longkidkoolstar
// @match        https://nhentai.net/*
// @grant        GM_getValue
// @grant        GM_setValue
// @licence      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;

        // Check if CAPTCHA is present
        let captchaCheck = setInterval(function() {
            let captcha = document.querySelector('label.rc-anchor-center-item.rc-anchor-checkbox-label');
            if (captcha && captcha.textContent == "I'm not a robot") {
                clearInterval(captchaCheck);
                document.querySelector('.button-wide').click(); // Clicks the login button
            } else if (document.querySelector('li.errorlist li').textContent == "You need to solve the CAPTCHA.") {
                clearInterval(captchaCheck);
            }
        }, 1000);
    }

    // Home page
    if (window.location.href == 'https://nhentai.net/') {
        document.querySelector('li.menu-sign-in a').click();
    }
})();