Map Fullscreen

Simple map fullscreen toggle with M key

2025-05-22 يوللانغان نەشرى. ئەڭ يېڭى نەشرىنى كۆرۈش.

// ==UserScript==
// @name         Map Fullscreen 
// @namespace    bennoghg
// @match        https://map-making.app/*
// @grant        GM_addStyle
// @version      1.1.0
// @author       BennoGHG
// @description  Simple map fullscreen toggle with M key
// @run-at       document-idle
// ==/UserScript==

(function() {
  'use strict';

  // State management
  let fullEnabled = false;

  // Fullscreen toggle functions
  function enableFullscreen() {
    const container = document.querySelector('.gm-style')?.parentElement;
    if (!container) return;
    if (container.requestFullscreen) container.requestFullscreen();
    fullEnabled = true;
  }

  function disableFullscreen() {
    if (document.fullscreenElement) document.exitFullscreen();
    fullEnabled = false;
  }

  // Exit fullscreen when Street View opens
  function checkStreetView() {
    if (!fullEnabled) return;
    const pano = document.querySelector('.gm-iv-viewer, .gm-iv-container, [aria-label*="Street View"]');
    if (pano) disableFullscreen();
  }

  new MutationObserver(checkStreetView).observe(document.body, { childList: true, subtree: true });

  document.body.addEventListener('click', e => {
    if (fullEnabled && e.target.closest('a[href*="cbll="]')) disableFullscreen();
  });

  // Check if user is typing in a text field
  function isTypingInTextField() {
    const activeElement = document.activeElement;
    if (!activeElement) return false;

    const tagName = activeElement.tagName.toLowerCase();
    const inputType = activeElement.type?.toLowerCase();

    // Check for input fields, textareas, and contenteditable elements
    return (
      tagName === 'input' && (
        inputType === 'text' ||
        inputType === 'search' ||
        inputType === 'email' ||
        inputType === 'url' ||
        inputType === 'password' ||
        inputType === 'number' ||
        !inputType  // Default input type is text
      )
    ) ||
    tagName === 'textarea' ||
    activeElement.contentEditable === 'true' ||
    activeElement.isContentEditable;
  }

  // Keyboard shortcuts
  document.addEventListener('keydown', e => {
    // Only respond to M/m key and only if not typing in a text field
    if ((e.key === 'm' || e.key === 'M') && !isTypingInTextField()) {
      e.preventDefault(); // Prevent any default behavior
      fullEnabled ? disableFullscreen() : enableFullscreen();
    }
  });

})();