Created
March 26, 2025 21:16
-
-
Save asukaminato0721/f60dd7e0314986c424df4a8c96dbdaf7 to your computer and use it in GitHub Desktop.
自动将 c.pc.qq.com/ios.html 的跳转链接重定向到其 'url' 参数指定的目标地址。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name QQ PC 链接自动跳转 | |
// @namespace http://tampermonkey.net/ // 你可以修改为你自己的命名空间 | |
// @version 1.1 | |
// @description 自动将 c.pc.qq.com/ios.html 的跳转链接重定向到其 'url' 参数指定的目标地址。 | |
// @author Your Name // 替换为你的名字 | |
// @match https://c.pc.qq.com/ios.html?* | |
// @grant none | |
// @run-at document-start | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
// 获取当前页面的完整 URL | |
const currentHref = window.location.href; | |
// 使用 URL 对象来方便地解析查询参数 | |
try { | |
const currentUrl = new URL(currentHref); | |
// 获取 'url' 查询参数的值 | |
// URLSearchParams 会自动处理 URL 解码 | |
const targetUrlParam = currentUrl.searchParams.get('url'); | |
// 检查 'url' 参数是否存在且不为空 | |
if (targetUrlParam) { | |
console.log('油猴脚本: 正在从', currentHref, '跳转到', targetUrlParam); | |
// 使用 replace 进行跳转,这样浏览器的历史记录中不会留下 QQ 的中间页面 | |
// 这意味着用户点击“后退”按钮时,会回到访问 QQ 链接之前的页面,而不是 QQ 中间页 | |
window.location.replace(targetUrlParam); | |
} else { | |
// 如果没有找到 'url' 参数,则在控制台输出提示,脚本不执行跳转 | |
console.log('油猴脚本: 在', currentHref, '中未找到有效的 "url" 参数。'); | |
} | |
} catch (e) { | |
// 如果 URL 解析失败或其他错误,则在控制台输出错误信息 | |
console.error('油猴脚本: 处理URL时发生错误:', e); | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment