OpenStreetMap IP Geolocation

Overrides the "Show My Location" button to provide location from IP geolocation

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey, Greasemonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्क्रिप्ट व्यवस्थापक एक्स्टेंशन इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्क्रिप्ट व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्टाईल व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

// ==UserScript==
// @name        OpenStreetMap IP Geolocation
// @namespace   Violentmonkey Scripts
// @match       *://www.openstreetmap.org/*
// @grant       GM.xmlhttpRequest
// @connect     ip-api.com
// @version     1.5
// @author      CyrilSLi
// @description Overrides the "Show My Location" button to provide location from IP geolocation
// @license     MIT
// @require     https://update.greasyfork.org/scripts/533461/1652653/Get%20OpenStreetMap%20Leaflet%20object.js
// ==/UserScript==

unsafeWindow.onOSMReady(() => {
    if (!unsafeWindow.userscriptMap) {
        return;
    }
    GM.xmlhttpRequest({
        method: "GET",
        url: "http://ip-api.com/json/",
        onload: function(response) {
            ipJSON = JSON.parse(response.responseText);
            geoButton = document.getElementsByClassName("control-locate")[0].children[0];
            geoButton.parentNode.replaceChild(geoButton.cloneNode(true), geoButton);
            tooltips = document.getElementsByClassName("tooltip-inner");
            while(tooltips[0]) {
                container = tooltips[0].parentNode;
                container.parentNode.removeChild(container);
            }
            geoButton = document.getElementsByClassName("control-locate")[0].children[0];
            geoButton.addEventListener("click", ev => {
                unsafeWindow.userscriptMap.setView([ipJSON["lat"], ipJSON["lon"]], 12);
            });
            keyButton = document.getElementsByClassName("control-legend")[0].children[0];
            keyButton.click();
            keyButton.click();
        }
    });
});