mc百科页面焕新

Display each mod in a card layout with miniature covers in the top right corner, with modal preview.

目前為 2024-04-23 提交的版本,檢視 最新版本

  1. // ==UserScript==
  2. // @name mc百科页面焕新
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.7
  5. // @description Display each mod in a card layout with miniature covers in the top right corner, with modal preview.
  6. // @author klnon
  7. // @match https://www.mcmod.cn/modlist.html*
  8. // @grant none
  9. // @license MIT
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. 'use strict';
  14.  
  15. window.addEventListener('load', function() {
  16. const blocks = document.querySelectorAll('.modlist-block');
  17. const listContainer = document.createElement('div');
  18. listContainer.style.margin = '20px auto';
  19. listContainer.style.display = 'flex';
  20. listContainer.style.flexWrap = 'wrap';
  21. listContainer.style.justifyContent = 'center';
  22.  
  23. // Create a modal to display mod details
  24. const modal = document.createElement('div');
  25. modal.style.position = 'fixed';
  26. modal.style.left = '0';
  27. modal.style.top = '0';
  28. modal.style.width = '100%';
  29. modal.style.height = '100%';
  30. modal.style.backgroundColor = 'rgba(0, 0, 0, 0.5)';
  31. modal.style.display = 'none';
  32. modal.style.alignItems = 'center';
  33. modal.style.justifyContent = 'center';
  34. modal.style.zIndex = '1000';
  35.  
  36. const modalContent = document.createElement('iframe');
  37. modalContent.style.width = '80%';
  38. modalContent.style.height = '80%';
  39. modalContent.style.borderRadius = '10px';
  40. modalContent.style.border = 'none';
  41.  
  42. modal.appendChild(modalContent);
  43. document.body.appendChild(modal);
  44.  
  45. // Function to open modal
  46. function openModal(url) {
  47. modalContent.src = url;
  48. modal.style.display = 'flex';
  49. }
  50.  
  51. // Function to close modal
  52. modal.addEventListener('click', function() {
  53. modal.style.display = 'none';
  54. modalContent.src = '';
  55. });
  56.  
  57. blocks.forEach(block => {
  58. const modCard = document.createElement('div');
  59. modCard.style.boxShadow = '0 4px 8px rgba(0,0,0,0.2)';
  60. modCard.style.border = '1px solid #ccc';
  61. modCard.style.borderRadius = '10px';
  62. modCard.style.transition = '0.3s';
  63. modCard.style.width = '300px';
  64. modCard.style.margin = '10px';
  65. modCard.style.padding = '10px';
  66. modCard.style.backgroundColor = '#fff';
  67. modCard.style.textAlign = 'left';
  68. modCard.style.position = 'relative';
  69. modCard.style.cursor = 'pointer';
  70.  
  71. modCard.onmouseover = function() {
  72. this.style.boxShadow = '0 8px 16px rgba(0,0,0,0.6)';
  73. };
  74. modCard.onmouseout = function() {
  75. this.style.boxShadow = '0 4px 8px rgba(0,0,0,0.2)';
  76. };
  77.  
  78. const title = block.querySelector('.title').innerHTML;
  79. const description = block.querySelector('.intro-content span') ? block.querySelector('.intro-content span').textContent.trim() : '无描述';
  80. const link = block.querySelector('.title a').getAttribute('href');
  81.  
  82. const coverImage = block.querySelector('.cover img');
  83. coverImage.style.width = '100%';
  84. coverImage.style.height = 'auto';
  85.  
  86. const coverDiv = document.createElement('div');
  87. coverDiv.style.position = 'absolute';
  88. coverDiv.style.top = '10px';
  89. coverDiv.style.right = '10px';
  90. coverDiv.style.width = '60px';
  91. coverDiv.style.height = '40px';
  92. coverDiv.style.overflow = 'hidden';
  93. coverDiv.appendChild(coverImage);
  94.  
  95. const contentDiv = document.createElement('div');
  96. contentDiv.style.paddingRight = '70px';
  97. contentDiv.innerHTML = `<div class="title"><strong>${title}</strong></div><hr style="margin: 10px 0;"><p>${description}</p>`;
  98.  
  99. modCard.appendChild(contentDiv);
  100. modCard.appendChild(coverDiv);
  101. modCard.addEventListener('click', () => openModal(link));
  102.  
  103. listContainer.appendChild(modCard);
  104. });
  105.  
  106. const contentArea = document.querySelector('.modlist-list-frame');
  107. contentArea.innerHTML = '';
  108. contentArea.appendChild(listContainer);
  109.  
  110. document.body.style.visibility = 'visible';
  111. });
  112. })();

QingJ © 2025

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