admin管理员组

文章数量:1663900

一、前言

普通的url是无法拉起迅雷下载的,这个时候需要把url转成迅雷能识别的链接。

二、url转迅雷链接

首先就是在普通url前面加上 AA,尾部加上 ZZ,然后将拼接后的url转成base64,JavaScript提供了转成base64的函数(btoa 和 atob是两个全局函数,通常用来对「字符串」进行 Base64 「编码和解码」)有兴趣的可以自己详细了解。

其次是把base64字符串加上 thunder://  标识即可。

三、代码示例

<html lang="en">

	<body>
		<a data-thunder href="http://localhost:8000/download">
			test
		</a>
		<script>
			const links = document.querySelectorAll('a[data-thunder]');
			for(const link of links) {
				const base64 = btoa(`AA${link.href}ZZ`);
				link.href = `thunder://${base64}`; // 迅雷下载链接
			}
		</script>
	</body>

</html>

效果图:

本文标签: 迅雷下载链接链接url