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

QingJ © 2025

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