Add Esc key on Google Maps

Add Esc key on Google Maps for better UX.

Από την 02/01/2022. Δείτε την τελευταία έκδοση.

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

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

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το 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==
// @name        Add Esc key on Google Maps
// @namespace   https://github.com/gslin/add-esc-key-on-google-maps
// @match       https://www.google.com/maps*
// @grant       none
// @version     0.20220102.0
// @author      Gea-Suan Lin <[email protected]>
// @description Add Esc key on Google Maps for better UX.
// @license     MIT
// ==/UserScript==

(() => {
    'use strict';

    window.addEventListener('keydown', ev => {
        // Esc only
        if (27 !== ev.keyCode) {
            return;
        }
        console.debug('Application "Add Esc key on Google Maps" esc key detected.');

        // User page.
        let el = document.querySelector('button[aria-label="Close"], button[aria-label="關閉"]');
        if (el && el.offsetHeight > 0 && el.offsetWidth > 0) {
            el.click();
            return;
        }

        // Comment page.
        el = document.querySelector('button[aria-label="Back"], button[aria-label="返回"]');
        if (el && el.offsetHeight > 0 && el.offsetWidth > 0) {
            el.click();
            return;
        }

        // Store page.
        el = document.querySelector('a[guidedhelpid="clear_search"]');
        if (el && el.offsetHeight > 0 && el.offsetWidth > 0) {
            el.click();
            return;
        }
    }, true);

    console.debug('Application "Add Esc key on Google Maps" installed.');
})();