Greasy Fork

Greasy Fork is available in English.

小草简洁助手

为小草榴社区、1024、cl进行一些外科手术操作·回家不迷路,草榴最新地址 ·帖子内快速切换上下帖 ·预加载下一帖 ·限制页面宽度为1080 ·等比例无缝看图 ·图片查看模式 ·使用手机版面 ·帖子精简对于游客身份无关的内容·图片批量下载功能

当前为 2024-06-05 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         小草简洁助手
// @namespace    http://tampermonkey.net/
// @version      2.53
// @description  为小草榴社区、1024、cl进行一些外科手术操作·回家不迷路,草榴最新地址 ·帖子内快速切换上下帖 ·预加载下一帖 ·限制页面宽度为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*
// @match        *://*.163.com/*
// @connect      get.xunfs.com
// @grant        GM_setValue
// @grant        GM_getValue
// @grant        GM_registerMenuCommand
// @grant        GM_xmlhttpRequest
// @grant        GM_addStyle
// @run-at       document-body

// ==/UserScript==

(function() {
    'use strict';

    var links = [];
    // 回家不迷路
    var enableGoHome = GM_getValue('enableGoHome',true);
    // 上下帖导航
    var enableNavigationButton = GM_getValue('enableNavigationButton', true);
    // 预加载下一帖
    var enablePreloadnextpage = GM_getValue('enablePreloadnextpage', 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);
    // 图片批量下载功能
    var enableDownloadPic = GM_getValue('enableDownloadPic',true);
    // 屏蔽指定用户帖子
    var blockUserPosts = GM_getValue('blockUserPosts', true);

    function createButtonContainer() {
        var buttonContainer = document.createElement('div');
        buttonContainer.style.position = 'fixed';
        buttonContainer.style.width = '100%';
        buttonContainer.style.bottom = '10px';
        buttonContainer.style.left = '0';
        buttonContainer.style.right = '0';
        buttonContainer.style.display = 'flex';
        buttonContainer.style.justifyContent = 'center';
        buttonContainer.style.zIndex = '9999';
        document.body.appendChild(buttonContainer);

        return buttonContainer;
    }

    function createButton(text, action) {
        var button = document.createElement('button');
        button.innerHTML = text;
        button.style.height = '25px';
        button.style.margin = '0 10px';
        button.style.backgroundColor = '#0F7884';
        button.style.border = 'none';
        button.style.color = 'white'
        button.style.textAlign = 'center';
        button.style.textDecoration = 'none';
        button.style.fontSize = '14px';
        button.style.borderRadius = '4px';
        button.style.cursor = 'pointer';
        button.addEventListener('click', action);

        return button;
    }

    // 导航按钮
    if (enableNavigationButton) {
        var currentfid = 0;
        var page = 0;
        function getHrefLinks(){
            if (window.location.href.includes('/thread0806.php?fid=')) {
                currentfid = getFidFromURL(window.location.href);
                page = getCurrentPageFromURL(window.location.href);
                localStorage.setItem('currentPage', page);

                // 获取所有主题链接
                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/')) {
                // 从页面中提取 fid 值
                var headerDiv = document.getElementById('header');
                var fidButton = headerDiv.querySelector('input[value="<"]');
                if (fidButton) {
                    var onclickAttribute = fidButton.getAttribute('onclick');
                    var fid = extractFidValue(onclickAttribute);

                    // 创建当前版块的变量 currentfid 进行保存
                    currentfid = fid;
                }
                // 获取本地存储中的链接数组
                links = JSON.parse(localStorage.getItem('threadLinks')) || [];
                // 获取本地存储中的帖子列表值
                page = parseInt(localStorage.getItem('currentPage')) || 1;
            }
        }
        //↓↓↓↓↓↓↓↓↓↓↓↓↓导航按钮相关函数↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓
        // 从 URL 中获取 fid 值
        function getFidFromURL(url) {
            var fidRegex = /fid=(\d+)/;
            var matches = url.match(fidRegex);
            if (matches && matches.length > 1) {
                return matches[1];
            }
            return null;
        }

        // 从 URL 中获取当前页码page值
        function getCurrentPageFromURL(url) {
            var pageRegex = /page=(\d+)/;
            var matches = url.match(pageRegex);
            if (matches && matches.length > 1) {
                return parseInt(matches[1]);
            }
            return 1;
        }

        // 提取 fid 值的辅助函数
        function extractFidValue(onclickAttribute) {
            var startIndex = onclickAttribute.indexOf('fid=') + 4;
            var endIndex = onclickAttribute.indexOf("'", startIndex);

            return onclickAttribute.substring(startIndex, endIndex);
        }

        // 获取主题链接的函数
        function getThreadLinks(fid, page, callback) {
            var url = window.location.origin + '/thread0806.php?fid=' + fid + '&search=&page=' + page;
            GM_xmlhttpRequest({
                method: 'GET',
                url: url,
                onload: function(response) {
                    var html = response.responseText;
                    var doc = new DOMParser().parseFromString(html, 'text/html');

                    var threadDivs = doc.querySelectorAll('div.list.t_one'); // 选择具有特定 class 属性的 div 元素
                    var newLinks = [];
                    for (var i = 0; i < threadDivs.length; i++) {
                        var link = threadDivs[i].querySelector('a[href^="htm_mob"]'); // 在每个 div 元素中查找匹配的 a 元素
                        if (link) {
                            var href = link.getAttribute('href'); // 获取 href 属性的值
                            var fullLink = window.location.origin + '/' + href; // 拼接完整链接
                            newLinks.push(fullLink);
                        }
                    }
                    callback(newLinks);
                }
            });
        }
        //↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑导航按钮相关函数↑↑↑↑↑↑↑↑↑↑↑

        // 导航到上一篇帖子
        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;
            } else {
                var previousPage = page - 1;
                getThreadLinks(currentfid, previousPage, function(newLinks) {
                    var tempLinks = links.slice(); // 创建链接数组的副本

                    // 去除重复的链接
                    newLinks.forEach(function(link) {
                        if (!tempLinks.includes(link)) {
                            tempLinks.push(link);
                        }
                    });

                    links = tempLinks;

                    if (links.length > 0) {
                        var lastLinkIndex = links.length - 1;
                        window.location.href = links[lastLinkIndex];
                        // 将新的链接数组和更新后的page值存储在本地存储中
                        localStorage.setItem('threadLinks', JSON.stringify(links));
                        localStorage.setItem('currentPage', previousPage);
                    }
                });
            }
        }

        // 导航到下一篇帖子
        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;
            } else {
                var nextPage = page + 1;
                getThreadLinks(currentfid, nextPage, function(newLinks) {
                    var tempLinks = [];

                    // 去除与当前链接数组重复的链接
                    newLinks.forEach(function(link) {
                        if (!links.includes(link)) {
                            tempLinks.push(link);
                        }
                    });

                    links = tempLinks;

                    if (links.length > 0) {
                        window.location.href = links[0];
                        // 将新的链接数组和更新后的page值存储在本地存储中
                        localStorage.setItem('threadLinks', JSON.stringify(links));
                        localStorage.setItem('currentPage', nextPage);
                    }
                });
            }
        }

        getHrefLinks();

        if(window.location.href.includes('/htm_mob/') ){//|| window.location.href.includes('/htm_data/')){

            var buttonContainer = createButtonContainer();

            var previousButton = createButton('上一帖', navigateToPreviousPost);
            buttonContainer.appendChild(previousButton);

            var nextButton = createButton('下一帖', navigateToNextPost);
            buttonContainer.appendChild(nextButton);


        }
    }

            // 预加载下一帖图片功能
            if (enablePreloadnextpage && links.length>1){

                //↓↓↓↓↓↓↓↓↓↓↓↓↓预加载下一帖图片功能↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓

                // 提取图片链接
                function extractImageLinks(html) {
                    var parser = new DOMParser();
                    var doc = parser.parseFromString(html, 'text/html');
                    var divContainer = doc.getElementById('conttpc');
                    var images = divContainer.querySelectorAll('img[ess-data]');

                    var imageLinks = [];
                    for (var i = 0; i < images.length; i++) {
                        var image = images[i];
                        var imageLink = image.getAttribute('ess-data');
                        imageLinks.push(imageLink);
                    }

                    return imageLinks;
                }

                // 创建并显示图片容器
                function displayImageLinks(imageLinks) {
                    // 创建图片容器
                    var imageContainer = document.createElement('div');
                    imageContainer.className = 'image-container';
                    imageContainer.style.width = '90%';
                    imageContainer.style.height = '50px';
                    imageContainer.style.position = 'fixed';
                    imageContainer.style.bottom = '35px';
                    imageContainer.style.left = '50%';
                    imageContainer.style.transform = 'translateX(-50%)';
                    imageContainer.style.backgroundColor = 'rgba(0, 0, 0, 0.6)';
                    imageContainer.style.overflowX = 'scroll';
                    imageContainer.style.whiteSpace = 'nowrap';
                    imageContainer.style.zIndex = '9999';
                    imageContainer.style.opacity = '0';
                    imageContainer.style.transition = 'opacity 0.5s';

                    // 添加隐藏滚动条的样式
                    //imageContainer.style.overflow = 'hidden';
                    imageContainer.style.msOverflowStyle = 'none';
                    imageContainer.style.scrollbarWidth = 'none';

                    // 针对 Chrome 浏览器的滚动条隐藏样式
                    imageContainer.style.webkitOverflowScrolling = 'touch';
                    imageContainer.style.webkitOverflowScrolling = 'auto';
                    imageContainer.style.webkitOverflowScrolling = 'auto';
                    imageContainer.style.webkitScrollbar = 'none';
                    imageContainer.style.msOverflowStyle = 'none';

                    // 针对 Chrome 浏览器的滚动条隐藏样式
                    imageContainer.style.webkitScrollbar = 'none';
                    imageContainer.style.webkitScrollbarWidth = 'none';
                    imageContainer.style.webkitScrollbarColor = 'transparent';


                    // 添加图片到容器中
                    for (var i = 0; i < imageLinks.length; i++) {
                        var image = document.createElement('img');
                        image.src = imageLinks[i];
                        image.style.height = '47px';
                        image.style.width = 'auto';
                        image.style.display = 'inline-block';
                        image.style.margin = '0 1x';
                        imageContainer.appendChild(image);
                    }

                    // 监听图片加载完成事件
                    var images = imageContainer.querySelectorAll('img');
                    var loadedCount = 0;
                    for (var j = 0; j < images.length; j++) {
                        images[j].addEventListener('load', function() {
                            loadedCount++;
                            if (loadedCount === images.length) {
                                // 所有图片加载完成后设置容器透明度为20%
                                imageContainer.style.opacity = '0.2';
                                // 将下一帖按钮的标题改为"下一帖,预加载成功"
                                nextButton.innerHTML = '下一帖,预加载' + loadedCount + '张图成功';
                                //                    nextButton.style.left = '35%';
                            }
                        });
                    }

                    // 添加容器到页面
                    document.body.appendChild(imageContainer);
                }
                //↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑预加载下一帖图片功能↑↑↑↑↑↑↑↑↑↑↑


                // 获取当前页面的 URL
                var currentURL = window.location.href;
                // 获取当前页面在链接数组中的索引
                var currentIndex = links.indexOf(currentURL);
                // 如果启用导航按钮并且当前页面在链接数组中,且不是最后一个链接
                if (enableNavigationButton && currentIndex !== -1 && currentIndex < links.length - 1) {
                    var nextURL = links[currentIndex + 1];

                    // 获取下一帖的内容并提取图片链接
                    GM_xmlhttpRequest({
                        method: 'GET',
                        url: nextURL,
                        onload: function(response) {
                            var html = response.responseText;
                            var imageLinks = extractImageLinks(html);

                            // 创建图片容器并显示图片链接
                            //                    if (enablePreloadnextpage) {
                            displayImageLinks(imageLinks);
                            //                    }
                        }
                    });
                }
            }

    // 回家不迷路
    if (enableGoHome && window.location.href.includes('163.com')) {
        // 创建一个悬浮按钮
        const button = document.createElement('button');
        button.style.position = 'fixed';
        button.style.bottom = '40px';
        button.style.height = '50px';
        button.style.right = '30px';
        button.style.backgroundColor = '#0F7884';
        button.style.zIndex = '999';
        button.style.border = 'none';
        button.style.color = 'white'
        button.style.textAlign = 'center';
        button.style.textDecoration = 'none';
        button.innerText = '☞神秘入口☜';
        document.body.appendChild(button);

        // 给按钮添加点击事件监听器
        button.addEventListener('click', function() {
            // 创建POST请求的payload
            const payload = 'a=get18&system=android&v=2.2.7';

            // 发起POST请求
            GM_xmlhttpRequest({
                method: 'POST',
                url: 'https://get.xunfs.com/app/listapp.php',
                headers: {
                    'Content-Type': 'application/x-www-form-urlencoded',
                },
                data: payload,
                responseType: 'text',
                onload: function(response) {
                    // 解析响应中的JSON数据
                    const responseData = JSON.parse(response.responseText);

                    // 提取所需的URL
                    const url1 = responseData.url1;
                    const url2 = responseData.url2;
                    const url3 = responseData.url3;

                    // 创建一个悬浮div来显示URL
                    const urlDiv = document.createElement('div');
                    urlDiv.style.position = 'fixed';
                    urlDiv.style.bottom = '100px';
                    urlDiv.style.right = '20px';
                    urlDiv.style.zIndex = '999';
                    urlDiv.style.backgroundColor = '#fff';
                    urlDiv.style.padding = '20px';
                    urlDiv.style.border = '1px solid #ccc';

                    // 生成URL的内容
                    const urlsContent = `
                    最新地址为:
                    <br>地址1: <a href="https://${url1}/" target="_bank" style="text-decoration: underline; color: blue;">${url1}</a>
                    <br>地址2: <a href="https://${url2}/" style="text-decoration: underline; color: blue;">${url2}</a>
                    <br>地址3: <a href="https://${url3}/" style="text-decoration: underline; color: blue;">${url3}</a>
                    <br>
                    <br>进入论坛主页后,请手动在页面底下,切换为手机版页面,即能享受脚本最佳效果!!!
                `;

                    // 设置URL的内容到div中
                    urlDiv.innerHTML = urlsContent;

                    // 将div添加到文档中
                    document.body.appendChild(urlDiv);

                    // 为URL添加点击事件监听器
                   /* const urlLinks = urlDiv.querySelectorAll('a');
                    urlLinks.forEach(function(link) {
                        link.addEventListener('click', function(event) {
                            event.preventDefault();
                            const url = this.getAttribute('data-url');
                            copyToClipboard(url);
                            window.location.href = url;
                        });
                    });
                    */

                    // 复制文本到剪贴板的函数
                    function copyToClipboard(text) {
                        const tempInput = document.createElement('input');
                        tempInput.value = text;
                        document.body.appendChild(tempInput);
                        tempInput.select();
                        document.execCommand('copy');
                        document.body.removeChild(tempInput);
                        showAlert(text + ' 复制成功');
                    }

                    // 显示提示信息并在一段时间后隐藏
                    function showAlert(message) {
                        const alertDiv = document.createElement('div');
                        alertDiv.style.position = 'fixed';
                        alertDiv.style.bottom = '80px';
                        alertDiv.style.right = '20px';
                        alertDiv.style.zIndex = '9999';
                        alertDiv.style.backgroundColor = '#fff';
                        alertDiv.style.padding = '10px';
                        alertDiv.style.border = '1px solid #ccc';
                        alertDiv.innerText = message;
                        document.body.appendChild(alertDiv);
                        setTimeout(function() {
                            document.body.removeChild(alertDiv);
                        }, 2000);
                    }
                },
                onerror: function(error) {
                    console.error('POST请求失败:', error);
                }
            });
        });
    }

    // 限制页面宽度为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 (enableMobilePage) {
        var url = window.location.href;
        var regex = /\/htm_data\//;
        if (regex.test(url)) {
            window.location.href = url.replace(regex, '/htm_mob/');
        }
//         if (window.location.href.includes('/thread0806.php?fid')){
//             alert("test1");
//             var domain = window.location.hostname;
//             console.log(domain);
//             window.location.href = 'https://' + domain + '/mobile.php?ismobile=yes';
//         }
    }

    // 帖子页面简洁
    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秒后执行以上代码
        }
    }

    // 等比例无缝看图
    if (enableSeamlessView && window.location.href.includes('/htm_mob/')) {
        // 延迟执行函数
        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 && (node.nodeName === 'IMG' || node.nodeName === 'VIDEO')) {
                        // 最大化尺寸
                        node.style.width = '100%';
                        node.style.height = 'auto';
                    }

                    // 判断节点名称是否为br
                    if (node.nodeType === Node.ELEMENT_NODE && node.nodeName === 'BR') {
                        var nextNode = node.nextSibling;

                        // 判断br标签下的内容是否为文本节点
                        if (nextNode && nextNode.nodeType === Node.TEXT_NODE) {
                            // 如果br标签下的内容是文本节点,则保留br标签
                            continue;
                        } else {
                            // 删除br标签
                            tpcCont.removeChild(node);
                            continue;
                        }
                    }
                }

                // 删除整个div下的所有&nbsp;
                tpcCont.innerHTML = tpcCont.innerHTML.replace(/&nbsp;/g, '');
            }
        }

        // 延迟3秒后执行函数
        setTimeout(delayedExecution, 2000);

    }

    // 图片查看模式
    if (enableImagePreview && window.location.href.includes('/htm_mob/')) {
        function ImagePreview() {
            // 获取当前浏览器的宽度
            var browserWidth = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;

            // 定义要限制的图片的目标宽度(最大为1080px)
            var targetWidth = Math.min(browserWidth, 1080);

            // 获取所有图片元素
            var imgs = document.querySelectorAll('.tpc_cont img');

            // 遍历所有图片元素
            for (var i = 0; i < imgs.length; i++) {
                var img = imgs[i];

                // 添加点击事件,点击图片时进入查看模式
                img.addEventListener('click', function (e) {
                    // 删除原图片的链接
                    this.removeAttribute('href');

                    // 阻止事件冒泡
                    e.stopPropagation();

                    // 获取该div下的所有图片元素
                    var div = this.parentNode;
                    var imgs = div.querySelectorAll('img');

                    // 创建一个div用于显示所有图片
                    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.width = '100%'; // 设置图片宽度为100%(等比例缩放)
                        imgEl.style.height = 'auto'; // 设置图片高度为auto(根据宽度等比例缩放)
                        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 = '&times;';
                    closeBtn.addEventListener('click', function () {
                        container.parentNode.removeChild(container);
                    });
                    container.appendChild(closeBtn);

                    // 添加点击事件,点击拼接后的图片时关闭
                    imgContainer.addEventListener('click', function (e) {
                        // 阻止事件冒泡
                        e.stopPropagation();

                        // 关闭查看模式
                        container.parentNode.removeChild(container);
                    });

                    // 将div添加到页面中
                    document.body.appendChild(container);
                }, true);
            }
        }setTimeout(ImagePreview, 2500);
    }

    // 屏蔽指定用户帖子
    if (blockUserPosts && window.location.href.includes('thread0806.php?fid=')) {
        // 获取屏蔽名单,如果不存在则初始化为空数组
        let blockedUsers = GM_getValue('blockedUsers', []);

        // 屏蔽指定用户帖子
        if (GM_getValue('blockUserPosts', true) && window.location.href.includes('thread0806.php?fid=')) {
            function addBlockUserLink() {
                const userElements = document.querySelectorAll('.f10[onclick^="goUid("]');
                userElements.forEach(userElement => {
                    const userId = extractUserId(userElement.getAttribute('onclick'));
                    const usernameElement = userElement.childNodes[0];
                    const username = usernameElement.textContent.trim();
                    const blockLink = document.createElement('a');
                    blockLink.href = 'javascript:void(0)';
                    blockLink.textContent = '不看ta';
                    blockLink.style.textDecoration = 'underline';
                    blockLink.style.color = 'blue';
                    blockLink.addEventListener('click', function(event) {
                        event.preventDefault();
                        event.stopPropagation(); // 阻止点击事件冒泡到父元素
                        addToBlockedUsers(username, userId);
                    });
                    userElement.insertBefore(document.createTextNode(' '), usernameElement.nextSibling);
                    userElement.insertBefore(blockLink, usernameElement.nextSibling);
                });
            }

            function extractUserId(onclickValue) {
                const regex = /goUid\((\d+)\)/;
                const match = onclickValue.match(regex);
                return match ? match[1] : null;
            }

            function addToBlockedUsers(username, userId) {
                if (!blockedUsers.includes(username)) {
                    const confirmBlock = confirm(`确定要屏蔽用户 ${username} 吗?`);
                    if (confirmBlock) {
                        blockedUsers.push(username);
                        GM_setValue('blockedUsers', blockedUsers);
                        location.reload();
                    }
                }
            }

            function hideBlockedUsersPosts() {
                blockedUsers.forEach(username => {
                    const userElements = document.querySelectorAll(`span.f10:not([data-blocked])`);
                    userElements.forEach(userElement => {
                        const postUsernameElement = userElement.childNodes[0];
                        const postUsername = postUsernameElement.textContent.trim();
                        if (postUsername === username) {
                            userElement.closest('div').style.display = 'none';
                        }
                    });
                });
            }

            addBlockUserLink();
            hideBlockedUsersPosts();

            window.addEventListener('load', function() {
                hideBlockedUsersPosts();
            });
        }


    }
    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 = '300px'; // 调整设置窗口宽度
        settingsWindow.style.height = '420px'; // 调整设置窗口高度
        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 enableGoHomeCheckbox = createCheckbox('enableGoHome', '回家不迷路,进入163.com,右下角有神秘入口', enableGoHome);
        settingsWindow.appendChild(enableGoHomeCheckbox);

        var enableNavigationButtonCheckbox = createCheckbox('enableNavigationButton', '上下帖导航', enableNavigationButton);
        settingsWindow.appendChild(enableNavigationButtonCheckbox);

        var preloadnextpageCheckbox = createCheckbox('enablePreloadnextpage', '预加载下一帖', enablePreloadnextpage);
        settingsWindow.appendChild(preloadnextpageCheckbox);

        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 DownloadPicCheckbox = createCheckbox('enableDownloadPic','帖子批量图片下载(仅适用于安卓手机端,该功能涉及相关风险,有需要的请在反馈留言)',enableDownloadPic);
        settingsWindow.appendChild(DownloadPicCheckbox);


        var blockUserPostsCheckbox = document.createElement('input');
        blockUserPostsCheckbox.type = 'checkbox';
        blockUserPostsCheckbox.id = 'blockUserPosts';
        blockUserPostsCheckbox.checked = GM_getValue('blockUserPosts', false);
        var blockUserPostsLabel = document.createElement('label');
        blockUserPostsLabel.setAttribute('for', 'blockUserPosts');
        blockUserPostsLabel.innerHTML = '屏蔽指定用户帖子';
        settingsWindow.appendChild(blockUserPostsCheckbox);
        settingsWindow.appendChild(blockUserPostsLabel);

        var blockedUsersInput = document.createElement('textarea');
        blockedUsersInput.rows = '4'; // 调整文本框行数
        blockedUsersInput.cols = '25'; // 调整文本框列数
        blockedUsersInput.style.resize = 'both'; // 允许调整大小
        blockedUsersInput.style.width = '100%'; // 设置宽度
        blockedUsersInput.style.marginTop = '10px'; // 调整上边距
        blockedUsersInput.placeholder = '输入要屏蔽的用户名';
        blockedUsersInput.value = GM_getValue('blockedUsers', []).join(', '); // 获取并显示之前保存的屏蔽用户名单
        settingsWindow.appendChild(blockedUsersInput);



        var saveButton = document.createElement('button');
        saveButton.innerHTML = '保存';
        saveButton.addEventListener('click', function() {
            enableGoHome = document.getElementById('enableGoHome').checked;
            GM_setValue('enableGoHome',enableGoHome);

            enableNavigationButton = document.getElementById('enableNavigationButton').checked;
            GM_setValue('enableNavigationButton', enableNavigationButton);

            enablePreloadnextpage = document.getElementById('enablePreloadnextpage').checked;
            GM_setValue('enablePreloadnextpage', enablePreloadnextpage);

            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);

            enableDownloadPic = document.getElementById('enableDownloadPic').checked;
            GM_setValue('enableDownloadPic',enableDownloadPic);

            var blockUserPosts = document.getElementById('blockUserPosts').checked;
            GM_setValue('blockUserPosts', blockUserPosts);

            var blockedUsernames = blockedUsersInput.value.split(',').map(username => username.trim()).filter(username => username !== '');
            GM_setValue('blockedUsers', blockedUsernames);

            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;
    }



})();