QQ微博短链接直接跳转油猴脚本2.0

在浏览器油猴脚本新建填入如下代码:

// ==UserScript==
// @name         QQ,微博短链接直接跳转
// @namespace    http://tampermonkey.net/
// @version      2.0.0
// @description  跳过垃圾非官方页面的提示
// @author       原作者aotmd,dalao.net优化
// @match        https://c.pc.qq.com/*
// @match        http://t.cn/*
// @license MIT
// @grant        none
// @run-at document-start
// ==/UserScript==
( function() {
/*QQ提示*/
if ( /https:\/\/c\.pc\.qq\.com\/.+/.test( location.href ) ) {
    try {
        let pfurl = getQueryString( "pfurl" );
        let targetUrl = getQueryString( "url" );  // 获取 `url` 参数
        if (targetUrl != null) {
            // 确保 URL 末尾没有斜杠
            targetUrl = targetUrl.replace(/\/$/, "");
            window.location.href = decodeURIComponent( targetUrl );  // 跳转到 `url` 参数的链接
        } else if (pfurl != null) {
            // 确保 `pfurl` 末尾没有斜杠
            pfurl = pfurl.replace(/\/$/, "");
            window.location.href = decodeURIComponent( pfurl );
        }
    } catch ( e ) {}
}

addLoadEvent( () => {
    window.setTimeout( () => {
        /*QQ提示*/
        if ( /https:\/\/c\.pc\.qq\.com\/.+/.test( location.href ) ) {
            let targetUrl = document.querySelector( "#url" ) ? document.querySelector( "#url" ).innerText : null;
            if (targetUrl) {
                targetUrl = targetUrl.replace(/\/$/, "");  // 去除结尾斜杠
                window.location.href = targetUrl;
            }
        }
        /*微博短链提示*/
        if ( /http:\/\/t\.cn\/.+/.test( location.href ) ) {
            let targetUrl = document.querySelector( ".open-url>a" ).href;
            targetUrl = targetUrl.replace(/\/$/, "");  // 去除结尾斜杠
            window.location.href = targetUrl;
        }
    }, 0 );
} );

addStyle( `` );

/**
 * 添加浏览器执行事件
 * @param func 无参匿名函数
 */
function addLoadEvent( func ) {
    let oldOnload = window.onload;
    if ( typeof window.onload != 'function' ) {
        window.onload = func;
    } else {
        window.onload = function() {
            try {
                oldOnload();
            } catch ( e ) {
                console.log( e );
            } finally {
                func();
            }
        }
    }
}

/**
 * 获取get传的参数
 * @param name 参数名称
 * @returns {string|null}
 */
function getQueryString( name ) {
    var reg = new RegExp( "(^|&)" + name + "=([^&]*)(&|$)", "i" );
    var r = decodeURI( window.location.search ).substr( 1 ).match( reg );
    if ( r != null ) return ( r[ 2 ] );
    return null;
}

// 添加css样式
function addStyle( rules ) {
    let styleElement = document.createElement( 'style' );
    styleElement[ "type" ] = 'text/css';
    document.getElementsByTagName( 'head' )[ 0 ].appendChild( styleElement );
    styleElement.appendChild( document.createTextNode( rules ) );
}

})();

支持在 PC 端从 QQ、微博点链接跳转浏览器时,跳过拦截页面访问实际地址。

微信暂不支持,因为微信的拦截页面地址不含域名,无法跳转,有会查看拦截页面域名的可以分享一下。

本站资源均为作者提供和网友推荐收集整理而来,仅供学习和研究使用,请在下载后24小时内删除,谢谢合作!
QQ微博短链接直接跳转油猴脚本2.0|不死鸟资源网
QQ微博短链接直接跳转油猴脚本2.0
此内容为免费阅读,请登录后查看
¥0
限时特惠
¥99
文章采用CC BY-NC-SA 4.0许可协议授权
免费阅读
THE END
点赞6 分享