Add magnets to mOnkrus.ws

Extracts the magnet link from uniondht.org and adds it to the original page.

  1. // ==UserScript==
  2. // @name Add magnets to mOnkrus.ws
  3. // @version 1.1
  4. // @description Extracts the magnet link from uniondht.org and adds it to the original page.
  5. // @author Rust1667
  6. // @icon https://icons.duckduckgo.com/ip3/w14.monkrus.ws.ico
  7. // @match https://w14.monkrus.ws/*
  8. // @exclude-match https://w14.monkrus.ws/
  9. // @exclude-match https://w14.monkrus.ws/search/*
  10. // @grant GM_xmlhttpRequest
  11. // @namespace https://gf.qytechs.cn/users/980489
  12. // ==/UserScript==
  13.  
  14. window.onload = function() {
  15. 'use strict';
  16.  
  17. // Find all links pointing to uniondht.org within the post content
  18. const links = document.querySelectorAll('.post-body.entry-content a[href*="uniondht.org"]');
  19.  
  20. let uniondhtLink = null;
  21.  
  22. // Loop through all links to find the correct uniondhtLink
  23. links.forEach(link => {
  24. if (isValidURL(link.href)) {
  25. uniondhtLink = link;
  26. }
  27. });
  28.  
  29. if (uniondhtLink) {
  30. // Extract the URL
  31. const url = uniondhtLink.href;
  32.  
  33. // Send request to uniondht.org to fetch the page content
  34. GM_xmlhttpRequest({
  35. method: "GET",
  36. url: url,
  37. onload: function(response) {
  38. // Extract magnet link
  39. const parser = new DOMParser();
  40. const htmlDoc = parser.parseFromString(response.responseText, "text/html");
  41. const magnetLinkElement = htmlDoc.querySelector('td.tCenter:nth-child(3) > p:nth-child(2) > a:nth-child(1)');
  42. if (magnetLinkElement) {
  43. const magnetLink = magnetLinkElement.href;
  44. // Create link element in the original page
  45. const magnetButton = document.createElement('a');
  46. magnetButton.href = magnetLink;
  47. magnetButton.title = "Magnet found";
  48. magnetButton.innerHTML = '<img src="https://uniondht.org/images/magnet.png" alt="magnet">';
  49.  
  50. // Append the magnet link button to the bottom of the post content
  51. const postContent = document.querySelector('.post-body.entry-content');
  52. if (postContent) {
  53. postContent.appendChild(magnetButton);
  54. }
  55. } else {
  56. // Show "Magnet not found" message
  57. showMagnetNotFoundMessage();
  58. }
  59. }
  60. });
  61. } else {
  62. // Show "Magnet not found" message
  63. showMagnetNotFoundMessage();
  64. }
  65. };
  66.  
  67. // Function to check if URL is valid
  68. function isValidURL(url) {
  69. const pattern = /^(http|https):\/\/[^ "]+$/;
  70. return pattern.test(url);
  71. }
  72.  
  73. // Function to show "Magnet not found" message
  74. function showMagnetNotFoundMessage() {
  75. const postContent = document.querySelector('.post-body.entry-content');
  76. if (postContent) {
  77. const magnetNotFoundMessage = document.createElement('p');
  78. magnetNotFoundMessage.textContent = "Magnet not found";
  79. magnetNotFoundMessage.style.color = "red";
  80. postContent.appendChild(magnetNotFoundMessage);
  81. }
  82. }

QingJ © 2025

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