2GIS Link Decoder

Decodes 2gis tracking links to direct URLs

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला 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         2GIS Link Decoder
// @namespace    http://tampermonkey.net/
// @version      1.3
// @description  Decodes 2gis tracking links to direct URLs
// @author       Jim_Di
// @license MIT
// @match        https://2gis.ru/*
// @match        https://2gis.kz/*
// @match        https://2gis.kg/*
// @match        https://2gis.am/*
// @match        https://2gis.ae/*
// @match        https://2gis.uz/*
// @match        https://2gis.by/*
// @match        https://2gis.az/*
// @match        https://2gis.ge/*
// @match        https://2gis.tj/*
// @grant        none
// @run-at       document-end
// ==/UserScript==

(function() {
    'use strict';

    function decodeLink(href) {
        try {
            const b64 = href.split('/').pop();
            const decoded = atob(decodeURIComponent(b64));
            const url = decoded.split('\n')[0].trim();
            return /^[a-z]+:\/\//i.test(url) || ['viber:','tel:','whatsapp:','tg:'].some(p => url.startsWith(p)) ? url : null;
        } catch (e) {
            console.warn('Decode failed:', href, e);
            return null;
        }
    }

    function process() {
        document.querySelectorAll('a[href^="https://link.2gis."]').forEach(a => {
            const url = decodeLink(a.href);
            if (url) {
                a.href = url;
                if (a.target === '_blank') a.rel = 'noopener';
            }
        });
    }

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