EnterToLogin

Press Enter to trigger a login-related button if no input is focused.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey, το Greasemonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

You will need to install an extension such as Tampermonkey to install this script.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Userscripts για να εγκαταστήσετε αυτόν τον κώδικα.

You will need to install an extension such as Tampermonkey to install this script.

Θα χρειαστεί να εγκαταστήσετε μια επέκταση διαχείρισης κώδικα χρήστη για να εγκαταστήσετε αυτόν τον κώδικα.

(Έχω ήδη έναν διαχειριστή κώδικα χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

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.

(Έχω ήδη έναν διαχειριστή στυλ χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

// ==UserScript==
// @license MIT
// @name         EnterToLogin
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  Press Enter to trigger a login-related button if no input is focused.
// @author       aceitw
// @match        *://*/*
// @grant        none
// ==/UserScript==

(function () {
  'use strict';

  // Utility: normalize text for matching (e.g. "Sign In" -> "signin")
  function normalize(text) {
    return text.toLowerCase().replace(/\s+/g, '');
  }

  // Utility: is element visible?
  function isVisible(el) {
    const rect = el.getBoundingClientRect();
    return rect.width > 0 && rect.height > 0 && window.getComputedStyle(el).visibility !== 'hidden';
  }

  // Utility: is likely a login button based on text
  function isLoginText(text) {
    const normalized = normalize(text);
    return /^(log(in)?|sign(in)?)$/.test(normalized);
  }

  document.addEventListener('keydown', function (e) {
    if (e.key !== 'Enter') return;

    const active = document.activeElement;
    const isTyping = active && (
      active.tagName === 'INPUT' ||
      active.tagName === 'TEXTAREA' ||
      active.isContentEditable
    );
    if (isTyping) return;

    const candidates = Array.from(document.querySelectorAll('button, input[type="submit"], a'));
    const loginBtn = candidates.find(el => {
      const text = el.innerText || el.value || '';
      return isVisible(el) && isLoginText(text);
    });

    if (loginBtn) {
      loginBtn.click();
      e.preventDefault();
    }
  });
})();