GameMale
登陆 / 注册 搜索

USERCENTER

SEARCHSITE

搜索

查看: 5041|回复: 69
收起左侧

[实用工具] 【脚本】论坛列表显示图片0.5

    [复制链接] |关注本帖

GM活动员

法师 · I

Futūrum(未来)果体76裸体克里斯炙热的格拉迪欧拉斯凯登‧阿兰科亚瑟‧摩根永远的克叔【夏日限定】夏日的泰凯斯亭亭如盖

     楼主| Makima 发表于 2025-8-22 12:31:49 | 显示全部楼层 |阅读模式 |取消关注该作者的回复
    现在搜索页面也能预览图片了


    1. // ==UserScript==
    2. // @name        显示图片
    3. // @version      0.5
    4. // @description  论坛列表显示图片(适配搜索页面
    5. // @author       M&U
    6. // @match        https://www.gamemale.com/*
    7. // @exclude     https://www.gamemale.com/forum.php
    8. // @grant        GM_addStyle
    9. // @grant        GM_getValue
    10. // @grant        GM_setValue
    11. // @grant        GM_xmlhttpRequest
    12. // ==/UserScript==
    13. (function () {
    14.     'use strict';

    15.     const TYPE_HANDLERS = [
    16.         {
    17.             name: "discuz",
    18.             articleListSelector: 'tbody[id^="normalthread_"]:not([data-enhanced]',
    19.             articleLinkSelector: '.icn a',
    20.             postContentSelector: 'div[id^="post_"] .plc',
    21.             postImageLinkCallback: function (element) {
    22.                 return element.getAttribute('file') || element.getAttribute('src');
    23.             }
    24.         },
    25.         {
    26.             name: "discuz_search",
    27.             articleListSelector: '.slst.mtw li.pbw:not([data-enhanced])',
    28.             articleLinkSelector: 'h3.xs3 a',
    29.             postContentSelector: 'div[id^="post_"] .plc',
    30.             postImageLinkCallback: function (element) {
    31.                 return element.getAttribute('file') || element.getAttribute('src');
    32.             }
    33.         }
    34.     ];

    35.     const IGNORE_IMAGES = [
    36.         /smile|avatar|icon|face|emoji|emoticon/i,
    37.         /uc_server|static\/image|data\/avatar/i,
    38.         /\.gif(\?|$)/i
    39.     ];

    40.     let enabled = typeof GM_getValue !== 'undefined' ? GM_getValue('enabled', true) : true;

    41.     const toggleButton = document.createElement('button');
    42.     toggleButton.textContent = enabled ? '关闭预览' : '开启预览';
    43.     toggleButton.style.position = 'fixed';
    44.     toggleButton.style.bottom = '20px';
    45.     toggleButton.style.right = '20px';
    46.     toggleButton.style.zIndex = '9999';
    47.     toggleButton.style.padding = '5px 10px';
    48.     toggleButton.style.background = '#4CAF50';
    49.     toggleButton.style.color = 'white';
    50.     toggleButton.style.border = 'none';
    51.     toggleButton.style.borderRadius = '3px';
    52.     document.body.appendChild(toggleButton);

    53.     GM_addStyle(`
    54.         .image-row {
    55.             display: flex;
    56.             width: 100%;
    57.             margin: 10px 0;
    58.             flex-wrap: nowrap;
    59.             justify-content: flex-start;
    60.             gap: 10px;
    61.         }
    62.         .image-item {
    63.             flex: 0 0 auto;
    64.             height: 150px;
    65.         }
    66.         .preview-image {
    67.             height: 100%;
    68.             width: auto;
    69.             max-width: 300px;
    70.             object-fit: contain;
    71.             cursor: pointer;
    72.             border: 1px solid #ddd;
    73.             background: #f5f5f5;
    74.             border-radius: 3px;
    75.         }
    76.         .preview-image.zoomed {
    77.             position: fixed;
    78.             top: 50%;
    79.             left: 50%;
    80.             transform: translate(-50%, -50%);
    81.             max-width: 90vw;
    82.             max-height: 90vh;
    83.             width: auto;
    84.             height: auto;
    85.             z-index: 1000;
    86.             background: #fff;
    87.             box-shadow: 0 0 15px rgba(0,0,0,0.5);
    88.         }
    89.     `);

    90.     toggleButton.addEventListener('click', function() {
    91.         enabled = !enabled;
    92.         if (typeof GM_setValue !== 'undefined') {
    93.             GM_setValue('enabled', enabled);
    94.         }
    95.         window.location.reload(true); // 强制从服务器重新加载页面
    96.     });

    97.     function init() {
    98.         if (!enabled) return;

    99.         // 检查当前页面类型
    100.         if (location.href.includes('forum') && !location.href.includes('search')) {
    101.             handleForum('discuz');
    102.         } else if (location.href.includes('search')) {
    103.             handleForum('discuz_search');
    104.         }
    105.     }

    106.     function handleForum(type) {
    107.         const handler = TYPE_HANDLERS.find(h => h.name === type);
    108.         if (!handler) return;

    109.         document.querySelectorAll(handler.articleListSelector).forEach(post => {
    110.             if (post.hasAttribute('data-enhanced')) return;
    111.             post.setAttribute('data-enhanced', 'true');

    112.             const link = post.querySelector(handler.articleLinkSelector)?.href;
    113.             if (link) loadImages(link, handler, post);
    114.         });
    115.     }

    116.     function shouldIgnoreImage(src) {
    117.         return IGNORE_IMAGES.some(regex => regex.test(src));
    118.     }

    119.     async function loadImages(url, handler, post) {
    120.         try {
    121.             const html = await fetch(url).then(r => r.text());
    122.             const doc = new DOMParser().parseFromString(html, 'text/html');
    123.             const content = doc.querySelector(handler.postContentSelector);
    124.             if (!content) return;

    125.             const row = document.createElement('div');
    126.             row.className = 'image-row';

    127.             const images = Array.from(content.querySelectorAll('img'))
    128.                 .map(img => handler.postImageLinkCallback(img))
    129.                 .filter(src => src && !shouldIgnoreImage(src))
    130.                 .slice(0, 3);

    131.             images.forEach(src => {
    132.                 const item = document.createElement('div');
    133.                 item.className = 'image-item';

    134.                 const image = document.createElement('img');
    135.                 image.className = 'preview-image';
    136.                 image.src = src;
    137.                 image.loading = 'lazy';
    138.                 image.addEventListener('click', () => {
    139.                     document.querySelectorAll('.preview-image.zoomed').forEach(el => el.classList.remove('zoomed'));
    140.                     image.classList.add('zoomed');
    141.                 });

    142.                 item.appendChild(image);
    143.                 row.appendChild(item);
    144.             });

    145.             if (row.children.length > 0) {
    146.                 const description = post.querySelector('p.xg1');
    147.                 if (description && description.nextSibling) {
    148.                     description.parentNode.insertBefore(row, description.nextSibling);
    149.                 } else {
    150.                     post.appendChild(row);
    151.                 }
    152.             }
    153.         } catch (error) {
    154.             console.log('加载图片失败:', error);
    155.         }
    156.     }

    157.     init();

    158.     new MutationObserver(function(mutations) {
    159.         if (!enabled) return;
    160.         init();
    161.     }).observe(document.body, { childList: true, subtree: true });

    162.     document.addEventListener('click', function(e) {
    163.         if (e.target.classList.contains('zoomed')) {
    164.             e.target.classList.remove('zoomed');
    165.         }
    166.     });
    167. })();
    复制代码



    本帖子中包含更多资源

    您需要 登录 才可以下载或查看,没有账号?立即注册

    x

    评分

    参与人数 18血液 +36 追随 +18 堕落 +9 收起 理由
    书の妖怪 + 1 喜翻儿
    willans + 1
    rentoXSW + 1
    仰望星空的白熊 + 3 + 1 + 1
    PURO_ + 5 + 1 + 1
    安氏贵人鸟 + 5 + 1 + 1 谢谢分享
    Inari + 5 + 1 + 1 三连献上
    Floopa + 5 + 1 + 1 评分理由A
    克莱因蓝 + 1
    lonong + 1

    查看全部评分

    本帖被以下淘专辑推荐:

    回复

    使用道具 举报

    GM活动员

    法师 · I

    炉石与家猫咪合唱团(夏日)盈满心相元石法师I· 学识之章『召唤好运的角笛』雾港捞月鎏彩万幢男巫之歌女巫之路虚空之海的鲸

      回复

      使用道具 举报

      游侠 · I

      超能留声机茉香啤酒水泡术生金蛋的鹅收到情书灵光补脑剂晓月终焉萨赫的蛋糕神秘商店贵宾卡变骚喷雾

        这简直是个太实用的工具了吧,这样一来,搜索的时候也能够清晰的得到想要的答案,谢谢分享
        回复

        使用道具 举报

        骑兽之子守护者三角头卡利亚权杖龙血指环破损的旧书融灵​邪恶圣杯炽天使之拥月亮提灯

          喂喂喂,這個工具也太好用吧,馬住
          回复

          使用道具 举报

          驯化腐化龙幼崽牧羊人英雄联盟黄色就是俏皮【新手友好】昆進传说中的黑龙呆猫

            回复

            使用道具 举报

            法师I· 资深法师炽天使之拥被释放的灵魂雾港捞月

              回复

              使用道具 举报

              雾港捞月裸体克里斯『落樱缤纷』男巫之歌成年独角兽迁徙之歌You Can Pet Blaidd月光骑士

                回复

                使用道具 举报

                【新春限定】果体 隆小镇的站台新神的赐福黄金树的恩惠生金蛋的鹅【圣诞限定】心心念念小雪人永远的克叔男巫之歌亚瑟‧摩根虚空之海的鲸

                  XLK 发表于 2025-8-22 13:10:59 | 显示全部楼层 |取消关注该作者的回复
                  回复

                  使用道具 举报

                  紫粹露饮霉运小精灵[红]瑰香蜜露『开心果奶酥』雾港捞月裸体克里斯新神的赐福凯登‧阿兰科炽焰咆哮虎揄人者冠冕

                    回复

                    使用道具 举报

                    GM論壇進階勛章雾港捞月晓月终焉奇怪的宝箱小小安全帽瑞雪兆丰年,生灵万物新驯化黑龙幼崽

                      回复

                      使用道具 举报

                      『随时随地开启!』『随时随地开启!』小小舞台

                        回复

                        使用道具 举报

                        我的天使GM吸血伯爵吃饱金币的Doge苏格兰圆脸胖鸡小小舞台守卫: 坚守眼位永浴爱河肉垫手套御医神兔『搓粉团珠』

                          回复

                          使用道具 举报

                          男巫之歌【夏日限定】夏日的泰凯斯裸体克里斯灵魂之椅男用贞操带不曾寄出的信件破损的旧书雪王的心脏幽灵竹筒龙腾世纪:审判

                            回复

                            使用道具 举报

                            暗蚀魔典结晶火鹰幼崽不曾寄出的信件一只普通的鳄鱼『开心果奶酥』恩惠护符攀缘藤GM吸血伯爵

                              回复

                              使用道具 举报

                              河豚寿司『原味焦糖』雪王的心脏元素方舟神人的编制发星光彩虹小粉驼文森特‧瓦伦丁萨菲罗斯艾吉奥

                                回复

                                使用道具 举报

                                【新春限定】果体 隆『钟楼盐水棒冰』永远的克叔【圣诞限定】心心念念小雪人金钱马车咆哮虎的冠军之路雾港捞月丹雀衔五穗,人间始丰登崩朽之青铜龙王猫咪合唱团(夏日)

                                  回复

                                  使用道具 举报

                                  永远的克叔裸体克里斯里昂‧S‧甘乃迪帅气的本・比格【圣诞限定】心心念念小雪人和你一起飞行的皮卡丘吃饱金币的Doge生金蛋的鹅可鲁贝洛斯男巫之歌

                                    回复

                                    使用道具 举报

                                    猫咪合唱团(夏日)荧光水母Mr.Neon御医神兔网中的皮卡丘神奇宝贝大师球猪庇特Amicus守卫: 坚守眼位熔岩鹰

                                      回复

                                      使用道具 举报

                                      但丁

                                        回复

                                        使用道具 举报

                                        最终幻想XVI位面引航器虚空藤蔓破损的旧书虎克船长火柴 - Gamemale赛博朋克2077都市:天际线2

                                          回复

                                          使用道具 举报

                                          您需要登录后才可以回帖 登录 | 立即注册

                                          本版积分规则

                                          关闭

                                          站长公告上一条 /1 下一条

                                          文字版|手机版|小黑屋|GameMale

                                          GMT+8, 2026-8-7 00:25 , Processed in 0.249425 second(s), 151 queries , Redis On.

                                          Copyright © 2013-2026 GameMale

                                          All Rights Reserved.

                                          快速回复 返回列表