🏠 返回首頁 

Greasy Fork is available in English.

36RAIN_复制链接按钮

提取页面中的链接并添加一个按钮来复制这些链接


安装此脚本?
  1. // ==UserScript==
  2. // @name 36RAIN_复制链接按钮
  3. // @namespace http://tampermonkey.net/
  4. // @version 2024-12-02
  5. // @description 提取页面中的链接并添加一个按钮来复制这些链接
  6. // @author 冰红茶真好喝
  7. // @match http://36rain.com/u.php?action=favor&uid=*
  8. // @icon https://www.google.com/s2/favicons?sz=64&domain=36rain.com
  9. // @license MIT
  10. // @grant GM_setClipboard
  11. // @grant GM_addStyle
  12. // ==/UserScript==
  13. (function () {
  14. "use strict";
  15. // 获取并修改所有链接
  16. function getModifiedLinks() {
  17. const links = [];
  18. let index = 2;
  19. let linkElement;
  20. // 查找页面中的每个链接,并修改链接地址
  21. while (
  22. (linkElement = document.querySelector(
  23. `#u-contentmain > form > table > tbody > tr:nth-child(${index}) > th > a`
  24. ))
  25. ) {
  26. const originalLink = linkElement.href;
  27. const modifiedLink = originalLink.replace(
  28. "http://36rain.com/read.php?tid=",
  29. "https://rain36-vip.japaneast.cloudapp.azure.com/forum.php?mod=viewthread&tid="
  30. );
  31. links.push(modifiedLink);
  32. index++;
  33. }
  34. return links;
  35. }
  36. // 创建复制链接按钮
  37. function createCopyButton() {
  38. const copyButton = document.createElement("button");
  39. copyButton.textContent = "复制新站链接";
  40. // copyButton.className = "btn"; // 设置按钮样式
  41. copyButton.style.cssText = `
  42. padding: 10px 20px;
  43. cursor: pointer;
  44. background-color: #4CAF50;
  45. color: white;
  46. border: none;
  47. border-radius: 5px;
  48. margin-right: 10px;
  49. `;
  50. // 按钮点击事件:提取链接并复制到剪切板
  51. copyButton.addEventListener("click", () => {
  52. const links = getModifiedLinks(); // 获取修改后的链接
  53. if (links.length > 0) {
  54. GM_setClipboard(links.join("\n")); // 将链接拼接成一行,复制到剪切板
  55. alert("链接已复制到剪切板!");
  56. } else {
  57. alert("未找到任何链接!");
  58. }
  59. });
  60. return copyButton;
  61. }
  62. // 创建打开新站按钮
  63. function createOpenNewSiteButton() {
  64. const openButton = document.createElement("button");
  65. openButton.textContent = "打开新站";
  66. // openButton.className = "btn"; // 设置按钮样式
  67. openButton.style.cssText = `
  68. padding: 10px 20px;
  69. cursor: pointer;
  70. background-color: #008CBA;
  71. color: white;
  72. border: none;
  73. border-radius: 5px;
  74. `;
  75. // 按钮点击事件:打开新站链接
  76. openButton.addEventListener("click", () => {
  77. window.open("https://rain36-vip.japaneast.cloudapp.azure.com/", "_blank");
  78. });
  79. return openButton;
  80. }
  81. // 插入按钮到页面中
  82. function insertButtons() {
  83. const btnContainer = document.querySelector(
  84. "#u-contentmain > form > center > div"
  85. );
  86. if (btnContainer) {
  87. const copyButton = createCopyButton(); // 创建复制链接按钮
  88. const openButton = createOpenNewSiteButton(); // 创建打开新站按钮
  89. btnContainer.appendChild(copyButton); // 将复制按钮添加到页面
  90. btnContainer.appendChild(openButton); // 将打开新站按钮添加到页面
  91. }
  92. }
  93. // 等待页面加载完成后插入按钮
  94. window.addEventListener("load", insertButtons);
  95. })();