Browndust2 News EasyRead

在 browndust2.com 的新聞頁面中新增EasyRead按鈕,打開固定的燈箱顯示新聞內容

  1. // ==UserScript==
  2. // @name Browndust2 News EasyRead
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.0.2
  5. // @description 在 browndust2.com 的新聞頁面中新增EasyRead按鈕,打開固定的燈箱顯示新聞內容
  6. // @author Souseihaku
  7. // @license MIT
  8. // @match https://www.browndust2.com/zh-tw/news/*
  9. // @grant none
  10. // ==/UserScript==
  11.  
  12.  
  13. (function() {
  14. 'use strict';
  15.  
  16. console.log('Browndust2 News Lightbox UserScript loaded');
  17.  
  18. var checkInterval = setInterval(function() {
  19. var rightOptContainer = document.querySelector('[class*="right-opt"]');
  20. if (rightOptContainer) {
  21. clearInterval(checkInterval);
  22. insertButton(rightOptContainer);
  23. }
  24. }, 500);
  25.  
  26. function insertButton(container) {
  27. var btn = document.createElement('button');
  28. btn.textContent = 'EasyRead';
  29. btn.style.padding = '5px 10px';
  30. btn.style.marginLeft = '10px';
  31. btn.style.cursor = 'pointer';
  32. btn.style.border = '1px solid #ccc';
  33. btn.style.borderRadius = '4px';
  34. btn.style.backgroundColor = '#fff';
  35.  
  36. container.appendChild(btn);
  37. btn.addEventListener('click', openLightbox);
  38. }
  39.  
  40. function openLightbox() {
  41. var viewContent = document.querySelector('div[class*="view-content"]');
  42. if (!viewContent) {
  43. console.error('找不到 div._view-content_xdbj7_414');
  44. return;
  45. }
  46.  
  47. var overlay = document.createElement('div');
  48. overlay.id = 'custom-news-lightbox-overlay';
  49. overlay.style.position = 'fixed';
  50. overlay.style.top = '0';
  51. overlay.style.left = '0';
  52. overlay.style.width = '100vw';
  53. overlay.style.height = '100dvh';
  54. overlay.style.backgroundColor = 'rgba(0, 0, 0, 0.9)';
  55. overlay.style.display = 'flex';
  56. overlay.style.alignItems = 'center';
  57. overlay.style.justifyContent = 'center';
  58. overlay.style.zIndex = '10000';
  59.  
  60. var modal = document.createElement('div');
  61. modal.style.backgroundColor = '#fff';
  62. modal.style.maxWidth = '1024px';
  63. modal.style.width = '100%';
  64. modal.style.height = '100dvh';
  65. modal.style.overflowY = 'auto';
  66. modal.style.display = 'flex';
  67. modal.style.flexDirection = 'column';
  68. modal.style.position = 'relative';
  69. modal.style.padding = '0';
  70. modal.style.boxSizing = 'border-box';
  71. modal.style.borderRadius = '8px';
  72.  
  73. var closeContainer = document.createElement('div');
  74. closeContainer.style.display = 'flex';
  75. closeContainer.style.justifyContent = 'end';
  76. closeContainer.style.padding = '8px 12px';
  77. closeContainer.style.borderBottom = '1px solid #ddd';
  78.  
  79. var closeBtn = document.createElement('button');
  80. closeBtn.innerHTML = '✖';
  81. closeBtn.style.fontSize = '16px';
  82. closeBtn.style.width = '24px';
  83. closeBtn.style.height = '24px';
  84. closeBtn.style.lineHeight = '24px';
  85. closeBtn.style.textAlign = 'center';
  86. closeBtn.style.cursor = 'pointer';
  87. closeBtn.style.border = 'none';
  88. closeBtn.style.backgroundColor = 'transparent';
  89. closeBtn.style.color = '#666';
  90. closeBtn.style.borderRadius = '50%';
  91. closeBtn.style.transition = 'color 0.2s ease';
  92. closeBtn.addEventListener('mouseenter', () => closeBtn.style.color = '#000');
  93. closeBtn.addEventListener('mouseleave', () => closeBtn.style.color = '#666');
  94.  
  95. closeBtn.addEventListener('click', function() {
  96. document.body.removeChild(overlay);
  97. });
  98.  
  99. closeContainer.appendChild(closeBtn);
  100.  
  101. var contentWrapper = document.createElement('div');
  102. contentWrapper.style.flexGrow = '1';
  103. contentWrapper.style.overflowY = 'auto';
  104. contentWrapper.style.padding = '15px';
  105. contentWrapper.style.boxSizing = 'border-box';
  106.  
  107. // **複製 viewContent,並加入 lightbox_view_content**
  108. var contentClone = viewContent.cloneNode(true);
  109. contentClone.classList.add('lightbox_view_content');
  110.  
  111. // **確保 overflow 恢復預設 (unset) 並加上 !important**
  112. contentClone.style.setProperty('overflow', 'unset', 'important');
  113.  
  114. // **確保燈箱內所有 <span> 字體大小為 18px**
  115. var spans = contentClone.querySelectorAll('span');
  116. spans.forEach(span => {
  117. span.style.setProperty('font-size', '18px', 'important');
  118. });
  119.  
  120. contentWrapper.appendChild(contentClone);
  121.  
  122. modal.appendChild(closeContainer);
  123. modal.appendChild(contentWrapper);
  124. overlay.appendChild(modal);
  125. document.body.appendChild(overlay);
  126.  
  127. overlay.addEventListener('click', function(e) {
  128. if (e.target === overlay) {
  129. document.body.removeChild(overlay);
  130. }
  131. });
  132. }
  133.  
  134.  
  135. })();

QingJ © 2025

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