// ==UserScript== // @name 小草简洁助手 // @namespace http://tampermonkey.net/ // @version 2.11 // @description 添加上一帖和下一帖的悬浮按钮,并根据提取的链接进行跳转,同时提供设置选项,包括上下帖导航、限制页面宽度为1080、等比例无缝看图和图片查看模式 // @match *://*/htm_data/* // @match http*://*/htm_data/*.html // @match http*://*/htm_mob/*.html // @match http*://*/read.php* // @match http*://*/personal.php* // @match http*://*/post.php* // @match http*://*/thread0806.php* // @grant GM_setValue // @grant GM_getValue // @grant GM_registerMenuCommand // @downloadURL none // ==/UserScript== (function() { 'use strict'; // 获取链接数组 var links = []; if (window.location.href.includes('/thread0806.php?fid=16')) { var threadLinks = document.querySelectorAll('a[href^="htm_mob"]'); for (var i = 0; i < threadLinks.length; i++) { links.push(threadLinks[i].href); } localStorage.setItem('threadLinks', JSON.stringify(links)); } else if (window.location.href.includes('/htm_mob/')) { links = JSON.parse(localStorage.getItem('threadLinks')) || []; } // 上下帖导航 var enableNavigation = GM_getValue('enableNavigation', true); // 限制页面宽度为1080 var limitPageWidth = GM_getValue('limitPageWidth', true); // 等比例无缝看图 var enableSeamlessView = GM_getValue('enableSeamlessView', true); // 图片查看模式 var enableImagePreview = GM_getValue('enableImagePreview', true); // 使用手机版面 var enableMobilePage = GM_getValue('enableMobilePage',true) // 手机版帖子简洁 var enableClearPage = GM_getValue('enableClearPage',true) if (window.location.href.includes('/htm_mob/')) { var previousButton = document.createElement('button'); previousButton.innerHTML = '上一帖'; previousButton.style.position = 'fixed'; previousButton.style.bottom = '10px'; previousButton.style.left = '40%'; previousButton.style.transform = 'translateX(-50%)'; previousButton.style.zIndex = '9999'; previousButton.addEventListener('click', function() { navigateToPreviousPost(); }); if (enableNavigation) { document.body.appendChild(previousButton); } var nextButton = document.createElement('button'); nextButton.innerHTML = '下一帖'; nextButton.style.position = 'fixed'; nextButton.style.bottom = '10px'; nextButton.style.right = '40%'; nextButton.style.transform = 'translateX(50%)'; nextButton.style.zIndex = '9999'; nextButton.addEventListener('click', function() { navigateToNextPost(); }); if (enableNavigation) { document.body.appendChild(nextButton); } } GM_registerMenuCommand('小草简洁助手 设置', function() { var settingsWindow = document.getElementById('settingsWindow'); if (settingsWindow) { settingsWindow.style.display = 'block'; } else { createSettingsWindow(); } }); function createSettingsWindow() { var settingsWindow = document.createElement('div'); settingsWindow.id = 'settingsWindow'; settingsWindow.style.position = 'fixed'; settingsWindow.style.top = '50%'; settingsWindow.style.left = '50%'; settingsWindow.style.transform = 'translate(-50%, -50%)'; settingsWindow.style.width = '200px'; settingsWindow.style.height = '280px'; settingsWindow.style.backgroundColor = '#fff'; settingsWindow.style.border = '1px solid #ccc'; settingsWindow.style.boxShadow = '0 0 10px rgba(0, 0, 0, 0.2)'; settingsWindow.style.padding = '20px'; settingsWindow.style.zIndex = '9999'; var titleLabel = document.createElement('h3'); titleLabel.innerHTML = '小草简洁助手 设置'; settingsWindow.appendChild(titleLabel); var navigationCheckbox = createCheckbox('enableNavigation', '上下帖导航', enableNavigation); settingsWindow.appendChild(navigationCheckbox); var limitWidthCheckbox = createCheckbox('limitPageWidth', '限制页面宽度为1080', limitPageWidth); settingsWindow.appendChild(limitWidthCheckbox); var seamlessViewCheckbox = createCheckbox('enableSeamlessView', '等比例无缝看图', enableSeamlessView); settingsWindow.appendChild(seamlessViewCheckbox); var imagePreviewCheckbox = createCheckbox('enableImagePreview', '图片查看模式', enableImagePreview); settingsWindow.appendChild(imagePreviewCheckbox); var MobilePageCheckbox = createCheckbox('enableMobilePage', '使用手机版面', enableMobilePage); settingsWindow.appendChild(MobilePageCheckbox); var ClearPageCheckbox = createCheckbox('enableClearPage', '手机版帖子简洁', enableClearPage); settingsWindow.appendChild(ClearPageCheckbox); var saveButton = document.createElement('button'); saveButton.innerHTML = '保存'; saveButton.addEventListener('click', function() { enableNavigation = document.getElementById('enableNavigation').checked; GM_setValue('enableNavigation', enableNavigation); limitPageWidth = document.getElementById('limitPageWidth').checked; GM_setValue('limitPageWidth', limitPageWidth); enableSeamlessView = document.getElementById('enableSeamlessView').checked; GM_setValue('enableSeamlessView', enableSeamlessView); enableImagePreview = document.getElementById('enableImagePreview').checked; GM_setValue('enableImagePreview', enableImagePreview); enableMobilePage = document.getElementById('enableMobilePage').checked; GM_setValue('enableMobilePage', enableMobilePage); enableClearPage = document.getElementById('enableClearPage').checked; GM_setValue('enableClearPage', enableClearPage); var successLabel = document.getElementById('successLabel'); successLabel.style.display = 'block'; setTimeout(function() { settingsWindow.style.display = 'none'; successLabel.style.display = 'none'; }, 2000); }); settingsWindow.appendChild(saveButton); var successLabel = document.createElement('label'); successLabel.id = 'successLabel'; successLabel.innerHTML = '保存成功,刷新页面生效!'; successLabel.style.display = 'none'; settingsWindow.appendChild(successLabel); document.body.appendChild(settingsWindow); } function createCheckbox(id, label, checked) { var checkbox = document.createElement('input'); checkbox.id = id; checkbox.type = 'checkbox'; checkbox.checked = checked; var checkboxLabel = document.createElement('label'); checkboxLabel.innerHTML = label; checkboxLabel.setAttribute('for', id); var container = document.createElement('div'); container.appendChild(checkbox); container.appendChild(checkboxLabel); return container; } function navigateToPreviousPost() { var currentURL = window.location.href; var currentIndex = links.indexOf(currentURL); if (currentIndex !== -1 && currentIndex > 0) { var previousURL = links[currentIndex - 1]; window.location.href = previousURL; } } function navigateToNextPost() { var currentURL = window.location.href; var currentIndex = links.indexOf(currentURL); if (currentIndex !== -1 && currentIndex < links.length - 1) { var nextURL = links[currentIndex + 1]; window.location.href = nextURL; } } // 限制页面宽度为1080 if (limitPageWidth) { var browserWidth = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth; var targetWidth = Math.min(browserWidth, 1080); document.body.style.maxWidth = targetWidth + 'px'; document.body.style.margin = '0 auto'; } // 等比例无缝看图 if (enableSeamlessView) { // 延迟执行函数 function delayedExecution() { // 获取tpc_cont元素 var tpcCont = document.querySelector('div.tpc_cont'); if (tpcCont) { // 获取tpc_cont元素下的所有子节点 var childNodes = tpcCont.childNodes; // 遍历子节点 for (var i = childNodes.length - 1; i >= 0; i--) { var node = childNodes[i]; // 判断节点类型是否为元素节点 if (node.nodeType === Node.ELEMENT_NODE) { // 判断节点名称是否为br if (node.nodeName === 'BR') { // 判断br标签下的内容是否为文本节点 if (node.nextSibling && node.nextSibling.nodeType === Node.TEXT_NODE) { // 如果br标签下的内容是文字,则保留br标签 continue; } else { // 删除br标签 tpcCont.removeChild(node); continue; } } } // 判断节点类型是否为文本节点,并且包含  if (node.nodeType === Node.TEXT_NODE && node.textContent.includes(' ')) { // 删除  node.textContent = node.textContent.replace(/ /g, ''); } } } } // 延迟2秒后执行函数 setTimeout(delayedExecution, 2000); function adjustMediaLayout() { // 获取tpc_cont元素 var tpcCont = document.querySelector('div.tpc_cont'); if (tpcCont) { // 获取tpc_cont元素下的所有子节点 var childNodes = tpcCont.childNodes; // 创建包裹媒体元素的容器 var mediaContainer = document.createElement('div'); mediaContainer.style.width = '100%'; mediaContainer.style.overflow = 'hidden'; // 遍历子节点 for (var i = 0; i < childNodes.length; i++) { var node = childNodes[i]; // 判断节点类型是否为元素节点 if (node.nodeType === Node.ELEMENT_NODE) { // 判断节点是否为媒体元素(图片、视频、音频) var isMediaElement = node.nodeName === 'IMG' || node.nodeName === 'VIDEO' || node.nodeName === 'AUDIO'; if (isMediaElement || node.nodeName === 'BR') { // 将媒体元素和换行元素添加到容器中 mediaContainer.appendChild(node); } else { // 将文本节点添加到容器中,并添加换行元素作为分隔 var textContainer = document.createElement('div'); textContainer.appendChild(node); textContainer.appendChild(document.createElement('br')); mediaContainer.appendChild(textContainer); } } } // 清空tpc_cont元素的内容 tpcCont.innerHTML = ''; // 将包含媒体元素和文字的容器添加到tpc_cont元素中 tpcCont.appendChild(mediaContainer); } // 调整媒体元素的宽度缩放 var mediaElements = document.querySelectorAll('div.tpc_cont img, div.tpc_cont video, div.tpc_cont audio'); for (var j = 0; j < mediaElements.length; j++) { var mediaElement = mediaElements[j]; mediaElement.style.width = '100%'; mediaElement.style.height = 'auto'; } } // 延迟2秒后执行函数 setTimeout(adjustMediaLayout, 2000); } // 图片查看模式 if (enableImagePreview) { var images = document.querySelectorAll('.tpc_content img'); for (var i = 0; i < images.length; i++) { var img = images[i]; img.style.cursor = 'pointer'; img.addEventListener('click', function() { var src = this.getAttribute('src'); var container = document.createElement('div'); container.style.position = 'fixed'; container.style.top = '0'; container.style.left = '0'; container.style.width = '100%'; container.style.height = '100%'; container.style.backgroundColor = 'rgba(0, 0, 0, 0.8)'; container.style.zIndex = '9999'; container.style.display = 'flex'; container.style.alignItems = 'center'; container.style.justifyContent = 'center'; var image = document.createElement('img'); image.setAttribute('src', src); image.style.maxHeight = '90%'; image.style.maxWidth = '90%'; image.addEventListener('click', function(e) { e.stopPropagation(); container.parentNode.removeChild(container); }); container.appendChild(image); document.body.appendChild(container); }); } } // 添加使用手机版页面功能的代码 if (enableMobilePage) { var url = window.location.href; var regex = /\/htm_data\//; if (regex.test(url)) { window.location.href = url.replace(regex, '/htm_mob/'); } } if(enableClearPage){ if (window.location.href.includes('/htm_mob/') || window.location.href.includes('read.php')) { // 延迟1秒后执行以下代码 setTimeout(function() { // 定义需要过滤的元素选择器 const adSelector = '.ad, .ads, .advertising, .advertisement, .ad-banner, .ad-container, .ad-frame, .ad-leaderboard, .ad-slot, .ad-wrapper, .banner-ad, .google-ads, .sponsored'; // 获取所有需要过滤的元素 const ads = document.querySelectorAll(adSelector); // 遍历所有需要过滤的元素,并将其从DOM树中移除 ads.forEach(ad => { ad.remove(); }); // 定义需要过滤的指定元素选择器 //const targetSelector = '.tpc_face, .tpc_face_svg,.tpc_icon,.f_one,.tpc_rp_btn,.fr,.post_comm,span.f18,div.t,.t_like,.h.guide,div.line:nth-child(3)'; const targetSelector = '.tpc_face,.tpc_icon.fl,.post_comm_face,.post_comm_face_svg,.f_one,.tpc_rp_btn,.fr,div.t,.t_like,.h.guide,div.line:nth-child(3)'; // 获取所有需要过滤的指定元素 const targets = document.querySelectorAll(targetSelector); // 遍历所有需要过滤的指定元素,并将其从DOM树中移除 targets.forEach(target => { target.remove(); }); // 处理用户名和时间为单行 var mainDiv = document.getElementById('main'); if (mainDiv) { var tpcDivs = mainDiv.getElementsByClassName('tpc_detail f10 fl'); for (var i = 0; i < tpcDivs.length; i++) { var div = tpcDivs[i]; var brTags = div.getElementsByTagName('br'); for (var j = brTags.length - 1; j >= 0; j--) { var br = brTags[j]; br.parentNode.replaceChild(document.createTextNode(' '), br); } } } }, 1000); // 延迟1秒后执行以上代码 } } })();