Greasy Fork

Greasy Fork is available in English.

自动跳转微博短链接

fuck weibo url shorter service (t.cn) redirect blocking page, and redirect to target page automatically.

当前为 2020-11-13 提交的版本,查看 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         自动跳转微博短链接
// @version      0.1.2
// @author       wlkz
// @description  fuck weibo url shorter service (t.cn) redirect blocking page, and redirect to target page automatically.
// @homepage     https://github.com/wlkz/userscript-fuck-weibo-redirect-block
// @supportURL   https://github.com/wlkz/userscript-fuck-weibo-redirect-block/issues
// @match        *://t.cn/*
// @match        *://weibo.cn/sinaurl?*
// @grant        none
// @run-at       document-end
// @license MIT
// @namespace https://github.com/wlkz/userscript-fuck-weibo-redirect-block
// ==/UserScript==

(function () {
    'use strict';
    function redirectTo(url) {
        location.replace(url);
    }

    function processer0() {
        // match '如需浏览,请长按网址复制后使用浏览器访问' page
        var targetElement = document.getElementsByClassName('link')[0];
        if (targetElement !== undefined) {
            var targetLink = targetElement.textContent;
            if (targetLink) {
                var p = document.createElement("p");
                p.textContent = 'redirect to target page, please wait.'
                document.getElementsByClassName('wrap')[0].append(p);
                setTimeout(redirectTo, 1000, targetLink);
                return true;
            }
        }
        return false;
    }

    function processer1() {
        // match '警告:访问的网址可能存在风险' page
        var targetElement = document.getElementsByClassName('url_view_code')[0];
        if (targetElement !== undefined) {
            var targetLink = targetElement.textContent;
            if (targetLink) {
                var p = document.createElement("p");
                p.textContent = 'redirect to target page, please wait.'
                p.classList.add('normal_note');
                document.getElementsByClassName('link_quality_note')[0].append(p);
                setTimeout(redirectTo, 1000, targetLink);
                return true;
            }
        }
        return false; 
    }

    var processers = [processer0, processer1];
    for (var i = 0; i < processers.length; i++) {
        if (processers[i]()) {
            return;
        }
    }
})();