mc百科页面焕新

Display each mod in a card layout with miniature covers in the top right corner

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

  1. // ==UserScript==
  2. // @name mc百科页面焕新
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.3
  5. // @description Display each mod in a card layout with miniature covers in the top right corner
  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. // Initially hide the body to prevent flickering
  16. document.body.style.visibility = 'hidden';
  17.  
  18. // Ensure script only runs on the specific page
  19. if (window.location.search === '?mcver=1.20.1&api=2&sort=lastedittime&page=47') {
  20. window.addEventListener('load', function() {
  21. const blocks = document.querySelectorAll('.modlist-block');
  22. const listContainer = document.createElement('div');
  23. listContainer.style.margin = '20px auto'; // Center the container
  24. listContainer.style.display = 'flex';
  25. listContainer.style.flexWrap = 'wrap';
  26. listContainer.style.justifyContent = 'center'; // Ensure cards are centered
  27.  
  28. blocks.forEach(block => {
  29. const modCard = document.createElement('div');
  30. modCard.style.boxShadow = '0 4px 8px rgba(0,0,0,0.2)';
  31. modCard.style.border = '1px solid #ccc'; // Add border
  32. modCard.style.borderRadius = '10px'; // Rounded corners
  33. modCard.style.transition = '0.3s';
  34. modCard.style.width = '300px'; // Set a fixed width for each card
  35. modCard.style.margin = '10px';
  36. modCard.style.padding = '10px'; // Padding inside the card
  37. modCard.style.backgroundColor = '#fff'; // Card background color
  38. modCard.style.textAlign = 'left'; // Text align left
  39. modCard.style.position = 'relative'; // Required for absolute positioning of the cover
  40.  
  41. modCard.onmouseover = function() {
  42. this.style.boxShadow = '0 8px 16px rgba(0,0,0,0.6)';
  43. };
  44. modCard.onmouseout = function() {
  45. this.style.boxShadow = '0 4px 8px rgba(0,0,0,0.2)';
  46. };
  47.  
  48. const title = block.querySelector('.title').innerHTML;
  49. const description = block.querySelector('.intro-content span') ? block.querySelector('.intro-content span').textContent.trim() : '无描述';
  50. const coverImage = block.querySelector('.cover img');
  51. coverImage.style.width = '100%'; // Set image width to 100% of its container
  52. coverImage.style.height = 'auto'; // Auto-adjust the height to maintain aspect ratio
  53.  
  54. const coverDiv = document.createElement('div');
  55. coverDiv.style.position = 'absolute';
  56. coverDiv.style.top = '10px';
  57. coverDiv.style.right = '10px';
  58. coverDiv.style.width = '60px'; // Reduced size of the cover container
  59. coverDiv.style.height = '40px'; // Setting a fixed height for cover container
  60. coverDiv.style.overflow = 'hidden'; // Prevents content from spilling out
  61. coverDiv.appendChild(coverImage);
  62.  
  63. modCard.innerHTML = `<div class="title"><strong>${title}</strong></div><hr style="margin: 10px 0;"><p>${description}</p>`;
  64. modCard.appendChild(coverDiv);
  65.  
  66. listContainer.appendChild(modCard);
  67. });
  68.  
  69. const contentArea = document.querySelector('.modlist-list-frame');
  70. contentArea.innerHTML = '';
  71. contentArea.appendChild(listContainer);
  72.  
  73. // Make the body visible again after content replacement
  74. document.body.style.visibility = 'visible';
  75. });
  76. }
  77. })();

QingJ © 2025

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