2GIS Link Decoder

Decodes 2gis tracking links to direct URLs

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 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 });
})();