放牧的风 - 免费 SS/SSR/V2Ray 页面增加“所有链接”

直接提取放牧的风在页面上提供的链接。

目前為 2019-11-19 提交的版本,檢視 最新版本

// ==UserScript==
// @name        放牧的风 - 免费 SS/SSR/V2Ray 页面增加“所有链接”
// @description 直接提取放牧的风在页面上提供的链接。
// @namespace   UnKnown
// @match       https://www.youneed.win/free-ss
// @match       https://www.youneed.win/free-ssr
// @match       https://www.youneed.win/free-v2ray
// @version     1.1
// @grant       none
// ==/UserScript==

(() => {

	const    parentNode =   document.querySelector('.context');
	const referenceNode = parentNode.querySelector(':scope > div');
	const      table = referenceNode.querySelector(':scope > table:only-child');

	if (!table) return false;

	const arraySelector = (
		selector = ':scope > *',
		parent = table,
	) => Array.from(
		parent.querySelectorAll( selector )
	);

	const getLinks = type => ({

		ss: () => arraySelector(':scope > tbody > tr').map(
				tr => {
					const d = data = arraySelector(':scope > td', tr).map(
						td => td.textContent
					);
					return 'ss://' + base64(`${d[4]}:${d[3]}@${d[1]}:${d[2]}`);
				}
			).join("\n"),

		ssr: () => Array.from(
			table.querySelectorAll(
				'a[href^="' + protocolMap.get( location.pathname.slice(6) ) + '"]'
			)
		).map( a => a.href ).join("\n"),

		v2ray: () => arraySelector(':scope > tbody > tr').map(
			tr => {
				const d = data = arraySelector(':scope > td', tr).map(
					td => td.textContent
				);
				return 'vmess://' + base64(`{"ps":"[youneed.win]${data[1]}","add":"${data[1]}","port":"${data[2]}","id":"${data[3]}","aid":"0","net":"${data[4]}","type":"none","host":"${data[5]}","tls":"${data[6]}"}`);
			}
		).join("\n"),

	})[type];

	const type = location.pathname.slice(6);

	let base64;
	if (type === "ss" || "v2ray") {
		if (!CryptoJS) return "ReferenceError: CryptoJS is not defined";
		base64 = str => CryptoJS.enc.Base64.stringify(
			CryptoJS.enc.Utf8.parse(str)
		);
	}

	resultStr = getLinks(type);

	// 元素

	// 所有链接
	const pre = document.createElement("pre");
	pre.style = "max-height: 12em; overflow-y: auto;";
	pre.textContent = resultStr;

	// 复制按钮
	const button = document.createElement("button");
	button.style = "width: 100%; font-size: large;";
	button.textContent = "复制全部链接";
	button.addEventListener("click", () => {
		try {
			if (navigator.clipboard) {
				navigator.clipboard.writeText(resultStr);
			} else {
				const eventCopyer = event => {
					event.preventDefault();
					event.clipboardData.setData("text/plain", resultStr);
				}
				document.addEventListener("copy", eventCopyer);
				document.execCommand("copy");
				document.removeEventListener("copy", eventCopyer);
			}
		} catch (error) {
			button.appendChild(str => {
				const info = document.createElement("pre");
				info.textContent ="若复制失败,请手动选择复制," +
					"PC 端用户可按 F12 获取详细错误信息,以便反馈。"
				+ "\n捕捉到的错误信息:" + str;
			})(error);
		}
	});

	const newNode = document.createElement("div");
	newNode.id = "AllLinks";

	newNode.appendChild(pre);
	newNode.appendChild(button);

	parentNode.insertBefore(newNode, referenceNode);

})();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址