GameMale
登陆 / 注册 搜索

USERCENTER

SEARCHSITE

搜索

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

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

    [复制链接] |关注本帖

GM活动员

众志成城光之少女の魔法书福卡·曙红[5]福卡·澄黄[6]福卡·锰紫[8]Futūrum(未来)神奇宝贝大师球♬狂舞终乐章♬亭亭如盖

     楼主| 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活动员

    福卡·曙红[4]火玛瑙福卡·锰紫[7]鎏彩万幢男巫之歌女巫之路虚空之海的鲸業火死鬥实现梦想官复原职

      娱乐法师火布偶 发表于 2025-8-22 12:48:05 | 显示全部楼层 <
      回复

      使用道具 举报

      捡到了肥皂收到情书千杯不醉灵光补脑剂神秘商店贵宾卡变骚喷雾茉香啤酒咆哮诅咒火玛瑙福卡·曙红[1]

        赴约波波 发表于 2025-8-22 12:52:29 | 显示全部楼层 <
        这简直是个太实用的工具了吧,这样一来,搜索的时候也能够清晰的得到想要的答案,谢谢分享
        回复

        使用道具 举报

        福卡·澄黄[1]福卡·锰紫[1]福卡·曙红[7]骑兽之子守护者三角头卡利亚权杖邪恶圣杯破损的旧书龙血指环铁牛

          傲瑞龍兽 发表于 2025-8-22 13:03:40 | 显示全部楼层 <
          喂喂喂,這個工具也太好用吧,馬住
          回复

          使用道具 举报

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

            白色咸鱼 发表于 2025-8-22 13:06:01 | 显示全部楼层 <
            回复

            使用道具 举报

            金苹果极·龙の意小镇的站台火玛瑙

              reober3 发表于 2025-8-22 13:06:54 | 显示全部楼层 <
              回复

              使用道具 举报

              火玛瑙马上發捕猎之歌男巫之歌盗梦空间『落樱缤纷』You Can Pet Blaidd失去力量的白狼诺克提斯·路西斯·伽拉姆

                Yoichiqzuser 发表于 2025-8-22 13:09:11 | 显示全部楼层 <
                回复

                使用道具 举报

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

                  XLK 发表于 2025-8-22 13:10:59 | 显示全部楼层 <
                  回复

                  使用道具 举报

                  火玛瑙福卡·曙红[2]福卡·澄黄[0]福卡·锰紫[7]杰森‧斯坦森炽焰咆哮虎雷夜嘯聲高桥剑痴『炫目的铁塔』救命饮料

                    油漆王 发表于 2025-8-22 13:11:13 | 显示全部楼层 <
                    回复

                    使用道具 举报

                    GM論壇進階勛章香喷喷的烤鸡牧羊人黑龙幼崽瑞雪兆丰年,生灵万物新小小安全帽奇怪的宝箱

                      狮心疯 发表于 2025-8-22 13:13:15 | 显示全部楼层 <
                      回复

                      使用道具 举报

                      炼金之心『随时随地开启!』破损的旧书『随时随地开启!』雪王的心脏人鱼之泪苏格兰圆脸胖鸡[Pro Max]位面引航器不曾寄出的信件幽灵竹筒

                        凯诺斯 发表于 2025-8-22 13:17:54 | 显示全部楼层 <
                        回复

                        使用道具 举报

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

                          毛茸茸兽兽 发表于 2025-8-22 13:33:43 | 显示全部楼层 <
                          回复

                          使用道具 举报

                          马上發福卡·锰紫[9]福卡·澄黄[8]福卡·曙红[7]男巫之歌【夏日限定】夏日的泰凯斯裸体克里斯男用贞操带不曾寄出的信件破损的旧书

                            crino66666 发表于 2025-8-22 13:35:52 | 显示全部楼层 <
                            回复

                            使用道具 举报

                            福卡·曙红[3]福卡·澄黄[1]福卡·锰紫[7]攀缘藤可爱黑猫长花的蛋神奇四叶草『狄文卡德的残羽』

                              大上33 发表于 2025-8-22 13:38:57 | 显示全部楼层 <
                              回复

                              使用道具 举报

                              福卡·曙红[0]福卡·澄黄[0]福卡·锰紫[0]萨赫的蛋糕变骚喷雾火玛瑙

                                114514banana 发表于 2025-8-22 13:41:34 | 显示全部楼层 <
                                回复

                                使用道具 举报

                                【新春限定】果体 隆永远的克叔Broken【圣诞限定】心心念念小雪人金钱马车猎个痛快!月影狼幸福的小阿尔睡着的小伯纯真护剑 · 这把剑守护每个孩子无论他有没有被神选中

                                  小晨风 发表于 2025-8-22 13:56:45 | 显示全部楼层 <
                                  回复

                                  使用道具 举报

                                  福卡·曙红[0]福卡·澄黄[1]福卡·锰紫[5]永远的克叔【夏日限定】夏日的泰凯斯帅气的本・比格【圣诞限定】心心念念小雪人和你一起飞行的皮卡丘吃饱金币的Doge男巫之歌

                                    M小黑 发表于 2025-8-22 14:16:45 | 显示全部楼层 <
                                    回复

                                    使用道具 举报

                                    火玛瑙雄躯的昇格光耀为誓塞拉斯魔法迸发禁断秘典凛霜魔典历练人间和谐圣杯诺克提斯·路西斯·伽拉姆

                                      蓝灯 发表于 2025-8-22 14:17:12 | 显示全部楼层 <
                                      回复

                                      使用道具 举报

                                      但丁

                                        a153450 发表于 2025-8-22 14:17:37 | 显示全部楼层 <
                                        回复

                                        使用道具 举报

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

                                          suowo 发表于 2025-8-22 14:18:21 | 显示全部楼层 <
                                          回复

                                          使用道具 举报

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

                                          本版积分规则

                                          关闭

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

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

                                          GMT+8, 2026-3-2 17:12 , Processed in 0.264292 second(s), 151 queries , Redis On.

                                          Copyright © 2013-2026 GameMale

                                          All Rights Reserved.

                                          快速回复 返回列表