Google Maps Image Downloader

الحصول على رابط الصورة في خرائط Google

Dovrai installare un'estensione come Tampermonkey, Greasemonkey o Violentmonkey per installare questo script.

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

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Userscripts per installare questo script.

Dovrai installare un'estensione come ad esempio Tampermonkey per installare questo script.

Dovrai installare un gestore di script utente per installare questo script.

(Ho già un gestore di script utente, lasciamelo installare!)

Advertisement:

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

(Ho già un gestore di stile utente, lasciamelo installare!)

Advertisement:

// ==UserScript==
// @name         Google Maps Image Downloader
// @namespace    https://tampermonkey.net/
// @version      1.0
// @description  الحصول على رابط الصورة في خرائط Google
// @match        https://www.google.com/maps/*
// @grant        none
// ==/UserScript==

(function () {
    'use strict';

    let currentImageUrl = null;

    // تلتقط أحدث صورة معروضة
    function updateCurrentImage() {
        const imgs = [...document.querySelectorAll('img[src*="googleusercontent.com"]')];

        if (!imgs.length) return;

        // Google Maps يعرض عدة صور، عادةً الصورة الأكبر هي الصورة الحالية
        let largestImg = imgs[0];
        let maxSize = 0;

        imgs.forEach(img => {
            const size = img.naturalWidth * img.naturalHeight;
            if (size > maxSize) {
                maxSize = size;
                largestImg = img;
            }
        });

        currentImageUrl = largestImg.src;
    }

    // زر فتح الصورة الأصلية
    function createButton() {
        if (document.getElementById("gm-full-image-btn")) return;

        const btn = document.createElement("button");
        btn.id = "gm-full-image-btn";
        btn.innerText = "فتح الصورة";
        btn.style.position = "fixed";
        btn.style.top = "20px";
        btn.style.left = "20px";
        btn.style.zIndex = "9999999";
        btn.style.padding = "10px 15px";
        btn.style.background = "#34A853";
        btn.style.color = "white";
        btn.style.border = "none";
        btn.style.borderRadius = "5px";
        btn.style.cursor = "pointer";

        btn.onclick = () => {
            updateCurrentImage(); // ← أهم نقطة
            if (!currentImageUrl) return alert("لم يتم العثور على صورة.");

            const fullUrl = currentImageUrl.replace(/=w\d+.*/, "=w0");
            window.open(fullUrl, "_blank");
        };

        document.body.appendChild(btn);
    }

    // راقب الصور وتعرّف على الصورة الحالية باستمرار
    function observeImages() {
        const observer = new MutationObserver(() => {
            updateCurrentImage();
        });

        observer.observe(document.body, {
            childList: true,
            subtree: true,
            attributes: true,
            attributeFilter: ["src"]
        });
    }

    window.addEventListener("load", () => {
        createButton();
        observeImages();

        // تحديث أولي
        setTimeout(updateCurrentImage, 2000);
    });

})();