// ==UserScript== // @name 小草简洁助手 // @namespace http://tampermonkey.net/ // @version 2.1 // @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) { var imgs = document.querySelectorAll('.tpc_cont img'); for (var i = 0; i < imgs.length; i++) { var img = imgs[i]; var prev = img.previousSibling; while (prev && (prev.nodeType !== 1 || prev.tagName === 'BR' || (prev.nodeType === 3 && prev.nodeValue.trim() === '') || (prev.nodeType === 3 && /^\s+$/.test(prev.nodeValue)))) { var current = prev; prev = prev.previousSibling; current.parentNode.removeChild(current); } img.addEventListener('click', function(e) { this.removeAttribute('href'); e.stopPropagation(); var div = this.parentNode; var imgs = div.querySelectorAll('img'); 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.overflow = 'auto'; var imgContainer = document.createElement('div'); imgContainer.style.width = targetWidth + 'px'; imgContainer.style.margin = '0 auto'; for (var i = 0; i < imgs.length; i++) { var img = imgs[i]; var src = img.getAttribute('src'); var imgEl = document.createElement('img'); imgEl.setAttribute('src', src); imgEl.style.maxWidth = '100%'; imgEl.style.display = 'block'; imgContainer.appendChild(imgEl); } container.appendChild(imgContainer); var closeBtn = document.createElement('div'); closeBtn.style.position = 'absolute'; closeBtn.style.top = '10px'; closeBtn.style.right = '10px'; closeBtn.style.width = '30px'; closeBtn.style.height = '30px'; closeBtn.style.lineHeight = '30px'; closeBtn.style.textAlign = 'center'; closeBtn.style.backgroundColor = '#fff'; closeBtn.style.borderRadius = '50%'; closeBtn.style.cursor = 'pointer'; closeBtn.style.fontSize = '20px'; closeBtn.style.color = '#000'; closeBtn.innerHTML = '×'; closeBtn.addEventListener('click', function() { container.parentNode.removeChild(container); }); container.appendChild(closeBtn); imgContainer.addEventListener('click', function(e) { e.stopPropagation(); container.parentNode.removeChild(container); }); document.body.appendChild(container); }, true); var ratio = targetWidth / img.naturalWidth; var height = Math.round(img.naturalHeight * ratio); img.style.width = targetWidth + 'px'; img.style.height = height + 'px'; } } // 图片查看模式 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秒后执行以上代码 } } })();