提取页面中的链接并添加一个按钮来复制这些链接
// ==UserScript==// @name 36RAIN_复制链接按钮// @namespace http://tampermonkey.net/// @version 2024-12-02// @description 提取页面中的链接并添加一个按钮来复制这些链接// @author 冰红茶真好喝// @match http://36rain.com/u.php?action=favor&uid=*// @icon https://www.google.com/s2/favicons?sz=64&domain=36rain.com// @license MIT// @grant GM_setClipboard// @grant GM_addStyle// ==/UserScript==(function () {"use strict";// 获取并修改所有链接function getModifiedLinks() {const links = [];let index = 2;let linkElement;// 查找页面中的每个链接,并修改链接地址while ((linkElement = document.querySelector(`#u-contentmain > form > table > tbody > tr:nth-child(${index}) > th > a`))) {const originalLink = linkElement.href;const modifiedLink = originalLink.replace("http://36rain.com/read.php?tid=","https://rain36-vip.japaneast.cloudapp.azure.com/forum.php?mod=viewthread&tid=");links.push(modifiedLink);index++;}return links;}// 创建复制链接按钮function createCopyButton() {const copyButton = document.createElement("button");copyButton.textContent = "复制新站链接";// copyButton.className = "btn"; // 设置按钮样式copyButton.style.cssText = `padding: 10px 20px;cursor: pointer;background-color: #4CAF50;color: white;border: none;border-radius: 5px;margin-right: 10px;`;// 按钮点击事件:提取链接并复制到剪切板copyButton.addEventListener("click", () => {const links = getModifiedLinks(); // 获取修改后的链接if (links.length > 0) {GM_setClipboard(links.join("\n")); // 将链接拼接成一行,复制到剪切板alert("链接已复制到剪切板!");} else {alert("未找到任何链接!");}});return copyButton;}// 创建打开新站按钮function createOpenNewSiteButton() {const openButton = document.createElement("button");openButton.textContent = "打开新站";// openButton.className = "btn"; // 设置按钮样式openButton.style.cssText = `padding: 10px 20px;cursor: pointer;background-color: #008CBA;color: white;border: none;border-radius: 5px;`;// 按钮点击事件:打开新站链接openButton.addEventListener("click", () => {window.open("https://rain36-vip.japaneast.cloudapp.azure.com/", "_blank");});return openButton;}// 插入按钮到页面中function insertButtons() {const btnContainer = document.querySelector("#u-contentmain > form > center > div");if (btnContainer) {const copyButton = createCopyButton(); // 创建复制链接按钮const openButton = createOpenNewSiteButton(); // 创建打开新站按钮btnContainer.appendChild(copyButton); // 将复制按钮添加到页面btnContainer.appendChild(openButton); // 将打开新站按钮添加到页面}}// 等待页面加载完成后插入按钮window.addEventListener("load", insertButtons);})();