Unshorten t.cn links

If someone shares a Weibo short link starting with t.cn, but you prefer not to click on it to avoid being tracked by Weibo, you can use this tool to reveal the actual destination URL that the Weibo short link redirects to. This tool uses our server to access the t.cn Weibo short link on your behalf and automatically follows multiple redirects to find the underlying real link. It also attempts to clean up some basic tracking link parameters using simple rules.

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

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

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         Unshorten t.cn links
// @namespace    https://tcnurl.prvcy.page/
// @version      1.0
// @description  If someone shares a Weibo short link starting with t.cn, but you prefer not to click on it to avoid being tracked by Weibo, you can use this tool to reveal the actual destination URL that the Weibo short link redirects to. This tool uses our server to access the t.cn Weibo short link on your behalf and automatically follows multiple redirects to find the underlying real link. It also attempts to clean up some basic tracking link parameters using simple rules.
// @author       O3O.Foundation
// @match        *://*/*
// @grant        none
// @license MIT
// ==/UserScript==

(function() {
    'use strict';

    function replaceTcnLinks() {
        const tcnLinks = document.querySelectorAll('a[href^="http://t.cn/"], a[href^="https://t.cn/"]');
        tcnLinks.forEach((link) => {
            const originalUrl = link.getAttribute('href');
            const suffix = originalUrl.split('/').pop();
            const newUrl = `https://tcnurl.prvcy.page/tcn-redirect.php?suffix=${suffix}`;
            link.setAttribute('href', newUrl);
            link.setAttribute('rel', 'nofollow noopener noreferrer');
            link.style.backgroundColor = '#dbffb0';
        });
    }

    // Replace t.cn links on initial page load
    replaceTcnLinks();

    // Replace t.cn links when new content is added dynamically
    const observer = new MutationObserver(replaceTcnLinks);
    observer.observe(document.body, { childList: true, subtree: true });
})();