AutoJump

为了应对QQ,知乎,简书...等网站不自动跳转第三方URL的问题

当前为 2022-03-03 提交的版本,查看 最新版本

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

You will need to install an extension such as Tampermonkey to install this script.

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         AutoJump
// @name:zh-CN   自动跳转第三方URL
// @namespace    https://greasyfork.org/zh-CN/scripts/440863-autojump
// @version      1.3
// @description  为了应对QQ,知乎,简书...等网站不自动跳转第三方URL的问题
// @author       Antecer
// @include      *
// @icon64       https://antecer.gitlab.io/amusingdevice/icon/antecer.ico
// @icon         https://antecer.gitlab.io/amusingdevice/icon/antecer.ico
// @run-at       document-start
// @grant        none
// @license      MIT
// ==/UserScript==

(function () {
	'use strict';
	// 创建sleep方法(用于async/await的延时处理)
	function Sleep(ms) {
		return new Promise((resolve) => setTimeout(resolve, ms));
	}

	var jumpLink = null;
	var fromUrl = location.origin + location.pathname;
	// 规则列表
	var fromUrls = {
		'https://c.pc.qq.com/middlem.html': /(?<=pfurl=)[^&]+/, // QQ
		'https://link.zhihu.com/': /(?<=target=)[^&]+/, // 知乎
		'https://www.jianshu.com/go-wild': /(?<=url=)[^&]+/, // 简书
		'https://link.csdn.net/': /(?<=target=)[^&]+/, // csdn
	}
	// 查找规则
	if (fromUrls[fromUrl]) {
		let jumpMatch = window.location.search.match(fromUrls[fromUrl]);
		if (jumpMatch) jumpLink = decodeURIComponent(jumpMatch[0]);
	}
	// 贴吧跳转页(贴吧跳转url加密了,需要特殊对待)
	if (fromUrl == 'http://jump2.bdimg.com/safecheck/index') {
		(async () => {
			while (!document.querySelector('.link')) Sleep(100);
			jumpLink = document.querySelector('.link').innerText;
		})();
	}

	// 跳转到目标网页
	if (jumpLink) {
		document.documentElement.innerHTML = `正在跳转到目标网站...<br>${jumpLink}`;
		top.location = jumpLink;
	}
})();