sis001-预览

sis001第一会所综合社区,帖子图片预览,板块收纳,搜索优化

// ==UserScript==
// @name         sis001-预览
// @version      1.0.0
// @namespace    https://sleazyfork.org/zh-CN/users/1461640-%E6%98%9F%E5%AE%BF%E8%80%81%E9%AD%94
// @author       星宿老魔
// @description  sis001第一会所综合社区,帖子图片预览,板块收纳,搜索优化
// @match        https://sis001.com/*
// @match        https://*.sis001.com/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=sis001.com
// @license      MIT
// @grant        none
// @run-at       document-start
// ==/UserScript==

(function(){"use strict";const s={select(p){return document.querySelector(p)},selectAll(p){return document.querySelectorAll(p)},create(p,e={},t={}){const n=document.createElement(p);return Object.entries(e).forEach(([o,r])=>{n.setAttribute(o,r)}),Object.entries(t).forEach(([o,r])=>{n.style[o]=r}),n},addStyle(p,e){const t=document.createElement("style");return e&&(t.id=e),t.textContent=p,document.head.appendChild(t),t}};async function L(p,e,t=8){const n=[...p],o=new Set,r=[];async function a(){if(n.length===0)return;const c=n.shift(),i=e(c).then(l=>{r.push(l)}).finally(()=>{o.delete(i)});return o.add(i),o.size>=t&&await Promise.race(Array.from(o)),a()}return await a(),await Promise.all(Array.from(o)),r}const x={resolve(p,e){try{return new URL(e,p).href}catch(t){return console.warn("[URL] 解析 URL 失败:",t),e}},isHttp(p){return/^https?:\/\//i.test(p)}},h={applyButtonStyle(p,e={}){const{primary:t=!1}=e;p.style.cssText=["display:inline-flex","align-items:center","justify-content:center","height:28px","padding:0 12px","border-radius:6px","font-size:12px","line-height:1","cursor:pointer","user-select:none","white-space:nowrap","box-sizing:border-box","background:#fff;color:#2c3e50;border:1px solid #e3e6ea"].join(";"),p.addEventListener("mouseenter",()=>{p.style.background="#f5f5f5"}),p.addEventListener("mouseleave",()=>{p.style.background="#fff"})},ensureToggleStyles(){if(document.querySelector('style[data-sis-toggle-style="1"]'))return;s.addStyle(`
      .sis-toggle {
        display:inline-flex;
        align-items:center;
        gap:6px;
        cursor:pointer;
        user-select:none;
        height:28px;
        padding:0 12px;
        border:1px solid #e3e6ea;
        border-radius:6px;
        background:#fff;
        box-shadow:0 2px 6px rgba(0,0,0,.08);
        vertical-align:middle;
        box-sizing:border-box;
      }
      .sis-toggle:hover { background:#f5f5f5; }
      .sis-toggle .sis-input { position:absolute; opacity:0; width:0; height:0; }
      .sis-toggle .sis-switch {
        position:relative;
        width:30px;
        height:16px;
        background:#e5e7eb;
        border-radius:999px;
        box-shadow: inset 0 0 0 1px #d1d5db;
        transition: background .2s ease;
        flex:0 0 30px;
      }
      .sis-toggle .sis-switch::before {
        content:"";
        position:absolute;
        top:2px;
        left:2px;
        width:12px;
        height:12px;
        background:#fff;
        border-radius:50%;
        box-shadow:0 1px 2px rgba(0,0,0,.2);
        transition: transform .2s ease;
      }
      .sis-toggle .sis-input:checked + .sis-text + .sis-switch {
        background:#00599F;
      }
      .sis-toggle .sis-input:checked + .sis-text + .sis-switch::before {
        transform: translateX(14px);
      }
      .sis-toggle .sis-text {
        color:#333;
        font-size:12px;
      }
    `,"sis-toggle-styles").setAttribute("data-sis-toggle-style","1")}},B={waitForDOMContentLoaded(){return document.readyState==="loading"?new Promise(p=>{document.addEventListener("DOMContentLoaded",()=>p(),{once:!0})}):Promise.resolve()},waitForWindowLoad(){return document.readyState!=="complete"?new Promise(p=>{window.addEventListener("load",()=>p(),{once:!0})}):Promise.resolve()}},I=class I{static init(){console.log("[MagnetConverter] 初始化磁力链接转换..."),this.setupMagnetLinks()}static setupMagnetLinks(){if(!s.select(".t_msgfont"))return;s.selectAll(".t_msgfont").forEach(t=>{this.processPost(t)})}static processPost(e){if(this.processed.has(e))return;const t=/([a-fA-F0-9]{40})/g;t.test(e.innerHTML)&&(e.innerHTML=e.innerHTML.replace(t,n=>`magnet:?xt=urn:btih:${n}`)),this.processed.add(e)}static refresh(){this.setupMagnetLinks()}};I.processed=new WeakSet;let w=I;class T{static init(){console.log("[UICollapse] 初始化界面折叠功能..."),this.injectEarlyCollapseCSS(),this.setupRulesCollapse(),this.setupPublicMessageCollapse(),this.setupSpecialTopicsCollapse(),setTimeout(()=>{console.log("[UICollapse] 延迟重试折叠功能..."),this.setupRulesCollapse(),this.setupPublicMessageCollapse(),this.setupSpecialTopicsCollapse()},2e3)}static injectEarlyCollapseCSS(){if(s.select('style[data-sis-early-collapse="1"]'))return;s.addStyle(`
      /* 公共消息默认收起 - 使用可被JavaScript覆盖的样式 */
      #pmprompt table:not(.sis-expanded) { display: none; }
      /* 本版规则默认收起:隐藏除 span/h3 外的直接子元素 - 使用可被JavaScript覆盖的样式 */
      #rules:not(.sis-expanded) > :not(span):not(h3) { display: none; }
    `).setAttribute("data-sis-early-collapse","1")}static setupRulesCollapse(){const e=s.select("#rules");if(!e){console.log("[UICollapse] 未找到 #rules 元素");return}if(console.log("[UICollapse] 找到 #rules 元素,开始设置折叠功能"),e.dataset.sisCollapsedSetup)return;e.dataset.sisCollapsedSetup="true";const t=Array.from(e.children).filter(r=>r.tagName!=="SPAN"&&r.tagName!=="H3");if(t.length===0)return;let n=!0;const o=s.select("#rules_img");o?this.setupImageToggle(o,e,t,n):this.setupTitleToggle(e,t,n)}static setupImageToggle(e,t,n,o){e.src="images/green001/collapsed_yes.gif",e.style.cursor="pointer",e.addEventListener("click",()=>{o=this.toggleElements(t,n,o,{expandedIcon:"images/green001/collapsed_no.gif",collapsedIcon:"images/green001/collapsed_yes.gif"}),e.src=o?"images/green001/collapsed_yes.gif":"images/green001/collapsed_no.gif"})}static setupTitleToggle(e,t,n){const o=e.querySelector("span")||e.querySelector("h3");o&&(this.setupClickableTitle(o),!o.textContent?.includes("[点击展开]")&&!o.textContent?.includes("[点击收起]")&&(o.innerHTML+=' <span class="sis-toggle-hint" style="font-size: 12px; color: #666; margin-left: 10px;">[点击展开]</span>'),o.addEventListener("click",()=>{const r=o.querySelector(".sis-toggle-hint");n=this.toggleElements(e,t,n),r&&(r.textContent=n?"[点击展开]":"[点击收起]"),o.style.backgroundColor=n?"":"#f0f0f0"}))}static setupPublicMessageCollapse(){const e=s.select("#pmprompt");if(!e){console.log("[UICollapse] 未找到 #pmprompt 元素");return}if(console.log("[UICollapse] 找到 #pmprompt 元素,开始设置折叠功能"),e.dataset.sisCollapsedSetup)return;e.dataset.sisCollapsedSetup="true";const t=e.querySelector("table"),n=e.querySelector("h4");if(!t||!n)return;let o=!0;this.setupClickableTitle(n),!n.textContent?.includes("[点击展开]")&&!n.textContent?.includes("[点击收起]")&&(n.innerHTML+=' <span class="sis-toggle-hint" style="font-size: 12px; color: #666;">[点击展开]</span>'),n.addEventListener("click",()=>{const r=n.querySelector(".sis-toggle-hint");o?(e.classList.add("sis-expanded"),t.style.display="table",r&&(r.textContent="[点击收起]"),n.style.backgroundColor="#f0f0f0",o=!1):(e.classList.remove("sis-expanded"),t.style.display="none",r&&(r.textContent="[点击展开]"),n.style.backgroundColor="",o=!0)}),n.addEventListener("mouseenter",()=>{o&&(n.style.backgroundColor="#f5f5f5")}),n.addEventListener("mouseleave",()=>{o&&(n.style.backgroundColor="")})}static setupSpecialTopicsCollapse(){const e=s.selectAll("thead.separation");console.log(`[UICollapse] 找到 ${e.length} 个 thead.separation 元素`),e.forEach(t=>{if(t.dataset.sisCollapsedSetup)return;const n=t.querySelectorAll("font");let o=!1,r="";n.forEach(a=>{const c=a.textContent||"";c.includes("重要主題")?(o=!0,r="重要主題"):c.includes("固定主題")?(o=!0,r="固定主題"):c.includes("推荐主题")&&(o=!0,r="推荐主题")}),o&&this.setupSpecialTopicCollapse(t,r)})}static setupSpecialTopicCollapse(e,t){e.dataset.sisCollapsedSetup="true";const n=e.querySelector("tr");if(!n)return;let o=e.nextElementSibling;const r=[];for(;o&&o.tagName==="TBODY";)r.push(o),o=o.nextElementSibling;if(r.length===0)return;let a=!0;r.forEach(i=>{i.style.display="none"}),n.style.cursor="pointer",n.style.userSelect="none",n.style.transition="background-color 0.2s";const c=n.querySelector('td[colspan="4"]');if(c){const i=c.innerHTML;!c.textContent?.includes("[点击展开]")&&!c.textContent?.includes("[点击收起]")&&(c.innerHTML=i+' <span class="sis-toggle-hint" style="font-size: 12px; color: #666; margin-left: 10px;">[点击展开]</span>'),n.addEventListener("click",()=>{const l=c.querySelector(".sis-toggle-hint");a?(r.forEach(g=>g.style.display=""),l&&(l.textContent="[点击收起]"),n.style.backgroundColor="#f0f0f0",a=!1):(r.forEach(g=>g.style.display="none"),l&&(l.textContent="[点击展开]"),n.style.backgroundColor="",a=!0)}),n.addEventListener("mouseenter",()=>{a&&(n.style.backgroundColor="#f5f5f5")}),n.addEventListener("mouseleave",()=>{a&&(n.style.backgroundColor="")})}}static setupClickableTitle(e){e.style.cursor="pointer",e.style.userSelect="none",e.style.padding="5px",e.style.borderRadius="3px",e.style.transition="background-color 0.2s"}static toggleElements(e,t,n,o){return n?(e.classList.add("sis-expanded"),t.forEach(r=>r.style.display=""),!1):(e.classList.remove("sis-expanded"),t.forEach(r=>r.style.display="none"),!0)}}const u={collectNames:"sis_board_collect_names",favoriteNames:"sis_board_favorite_names",collectionOpen:"sis_board_collection_open",favoriteOpen:"sis_board_favorite_open",searchFavForums:"sis_search_fav_forums",searchFavAuto:"sis_search_fav_auto",previewCache:"sis_preview_cache_v1",previewMaxImages:"sis_preview_max_images",previewConcurrency:"sis_preview_concurrency"},k={MAX_PREVIEW_CONCURRENCY:9,MAX_IMAGES_PER_POST:3,PREVIEW_CACHE_TTL_MS:900*1e3};class d{static getMaxPreviewConcurrency(){const e=parseInt(localStorage.getItem(u.previewConcurrency)||"",10);return Number.isFinite(e)&&e>=1&&e<=100?e:k.MAX_PREVIEW_CONCURRENCY}static setMaxPreviewConcurrency(e){try{localStorage.setItem(u.previewConcurrency,String(e))}catch(t){console.warn("[Config] 保存预览并发数失败:",t)}}static getMaxImagesPerPost(){const e=parseInt(localStorage.getItem(u.previewMaxImages)||"",10);return Number.isFinite(e)&&e>=1&&e<=20?e:k.MAX_IMAGES_PER_POST}static setMaxImagesPerPost(e){try{localStorage.setItem(u.previewMaxImages,String(e)),this.clearPreviewCache()}catch(t){console.warn("[Config] 保存图片数量配置失败:",t)}}static clearPreviewCache(){try{localStorage.removeItem(u.previewCache),console.log("[Config] 已清除预览缓存")}catch(e){console.warn("[Config] 清除预览缓存失败:",e)}}static getPreviewCache(){try{return JSON.parse(localStorage.getItem(u.previewCache)||"{}")}catch(e){return console.warn("[Config] 解析预览缓存失败:",e),{}}}static setPreviewCache(e){try{localStorage.setItem(u.previewCache,JSON.stringify(e))}catch(t){console.warn("[Config] 保存预览缓存失败:",t)}}static getPreviewCacheEntry(e){const n=this.getPreviewCache()[e];return!n||Date.now()-n.ts>k.PREVIEW_CACHE_TTL_MS?null:Array.isArray(n.urls)?n.urls:null}static savePreviewCacheEntry(e,t){const n=this.getPreviewCache();n[e]={ts:Date.now(),urls:t.slice(0,this.getMaxImagesPerPost())};const o=Object.keys(n);if(o.length>200){o.sort((r,a)=>(n[r].ts||0)-(n[a].ts||0));for(let r=0;r<o.length-200;r++)delete n[o[r]]}this.setPreviewCache(n)}static getCollectedBoardNames(){try{const e=localStorage.getItem(u.collectNames);if(!e)return[];const t=JSON.parse(e);return Array.isArray(t)?t:[]}catch(e){return console.warn("[Config] 获取收纳板块列表失败:",e),[]}}static setCollectedBoardNames(e){try{localStorage.setItem(u.collectNames,JSON.stringify(e||[]))}catch(t){console.warn("[Config] 保存收纳板块列表失败:",t)}}static getFavoriteBoardNames(){try{const e=localStorage.getItem(u.favoriteNames);if(!e)return[];const t=JSON.parse(e);return Array.isArray(t)?t:[]}catch(e){return console.warn("[Config] 获取收藏板块列表失败:",e),[]}}static setFavoriteBoardNames(e){try{localStorage.setItem(u.favoriteNames,JSON.stringify(e||[]))}catch(t){console.warn("[Config] 保存收藏板块列表失败:",t)}}static getCollectionOpen(){try{return localStorage.getItem(u.collectionOpen)==="1"}catch(e){return console.warn("[Config] 获取收纳区状态失败:",e),!1}}static setCollectionOpen(e){try{localStorage.setItem(u.collectionOpen,e?"1":"0")}catch(t){console.warn("[Config] 保存收纳区状态失败:",t)}}static getFavoriteOpen(){try{return localStorage.getItem(u.favoriteOpen)==="1"}catch(e){return console.warn("[Config] 获取收藏区状态失败:",e),!1}}static setFavoriteOpen(e){try{localStorage.setItem(u.favoriteOpen,e?"1":"0")}catch(t){console.warn("[Config] 保存收藏区状态失败:",t)}}static getSearchFavForums(){try{const e=localStorage.getItem(u.searchFavForums);return e?JSON.parse(e):[]}catch(e){return console.warn("[Config] 获取搜索收藏论坛失败:",e),[]}}static setSearchFavForums(e){try{localStorage.setItem(u.searchFavForums,JSON.stringify(e||[]))}catch(t){console.warn("[Config] 保存搜索收藏论坛失败:",t)}}static getSearchFavAuto(){try{return localStorage.getItem(u.searchFavAuto)==="1"}catch(e){return console.warn("[Config] 获取搜索自动记忆状态失败:",e),!1}}static setSearchFavAuto(e){try{localStorage.setItem(u.searchFavAuto,e?"1":"0")}catch(t){console.warn("[Config] 保存搜索自动记忆状态失败:",t)}}}class F{static async init(){console.log("[ImagePreview] 初始化图片预览..."),await this.displayThreadImages()}static async displayThreadImages(){if(s.select(".postmessage")||s.select("#postlist")||s.select(".plhin"))return;const e=window.location.href.includes("/search.php"),t=window.location.href.includes("/tag.php");let n=[];if(e||t){const r=s.selectAll("tbody");n=Array.from(r).filter(a=>{const c=a.querySelector('a[href*="thread-"]'),i=a.querySelector(".icon");return c&&i})}else{const r=s.selectAll('tbody[id^="normalthread_"]');n=Array.from(r)}const o=n.map(r=>async()=>{if(r.id&&r.id.startsWith("stickthread_")||r.querySelector(".new-post-layout"))return;const a=r.querySelector('a[href*="thread-"]');if(!a)return;const c=a.href;let i=a.textContent?.trim()||"";if(!i){const l=r.querySelector('span[id^="thread_"]');l&&(i=l.textContent?.trim()||"")}await this.transformPostLayout(r,c,i)});await L(o,r=>r(),d.getMaxPreviewConcurrency())}static async transformPostLayout(e,t,n){e.innerHTML="";const o=s.create("tr"),r=s.create("td",{colspan:"6"},{padding:"4px !important",border:"none !important",background:"transparent !important"}),a=this.createPostContainer(),c=this.createTitleSection(t,n),i=this.createImageSection();a.appendChild(c),a.appendChild(i),r.appendChild(a),o.appendChild(r),e.appendChild(o),await this.loadImagesForPost(t,i)}static createPostContainer(){const e=s.create("div",{class:"new-post-layout"},{background:"linear-gradient(135deg, #ffffff 0%, #f8f9fa 100%)",border:"1px solid #e3e6ea",borderRadius:"12px",boxShadow:"0 3px 12px rgba(0,0,0,0.08)",overflow:"hidden",transition:"all 0.3s ease"});return e.addEventListener("mouseenter",()=>{e.style.transform="translateY(-2px)",e.style.boxShadow="0 6px 20px rgba(0,0,0,0.12)"}),e.addEventListener("mouseleave",()=>{e.style.transform="translateY(0)",e.style.boxShadow="0 3px 12px rgba(0,0,0,0.08)"}),e}static createTitleSection(e,t){const n=s.create("div",{},{padding:"12px 16px",background:"rgba(255,255,255,0.9)",borderBottom:"1px solid #e9ecef"}),o=s.create("a",{href:e},{fontWeight:"500",color:"#2c3e50",fontSize:"15px",lineHeight:"1.3",textDecoration:"none",transition:"color 0.2s ease",display:"block",wordBreak:"break-word"});return o.textContent=t||"无标题",o.addEventListener("mouseenter",()=>{o.style.color="#667eea"}),o.addEventListener("mouseleave",()=>{o.style.color="#2c3e50"}),n.appendChild(o),n}static createImageSection(){const e=s.create("div",{},{padding:"8px 16px",background:"rgba(248,249,250,0.6)",display:"flex",gap:"10px",minHeight:"200px",flexWrap:"nowrap",alignItems:"stretch",overflow:"auto"}),t=s.create("div",{},{color:"#666",fontSize:"14px"});return t.textContent="正在加载图片预览...",e.appendChild(t),e}static async loadImagesForPost(e,t){try{const n=d.getPreviewCacheEntry(e);if(n&&n.length>0){this.renderCachedImages(t,n,e);return}const r=await(await fetch(e)).text(),c=new DOMParser().parseFromString(r,"text/html"),i=this.extractValidImages(c);if(t.innerHTML="",i.length===0){this.showNoImagesMessage(t);return}const l=i.map(g=>x.resolve(e,this.selectImageSource(g)));d.savePreviewCacheEntry(e,l),this.renderImages(t,i,l,e)}catch(n){console.warn("[ImagePreview] 加载图片失败:",n),t.innerHTML='<div style="color: #999; font-size: 14px;">图片加载失败</div>'}}static renderCachedImages(e,t,n){e.innerHTML="",t.slice(0,d.getMaxImagesPerPost()).forEach((o,r)=>{const a=this.createImageContainer(),c=this.createLoadingPlaceholder(),i=this.createImageElement(o);i.onerror=()=>this.handleImageError(i,o);const l=i.onload;i.onload=g=>{l&&l.call(i,g),c.remove()},this.setupImageInteraction(a,t,r,n),a.appendChild(c),a.appendChild(i),e.appendChild(a)})}static renderImages(e,t,n,o){t.forEach((r,a)=>{const c=this.createImageContainer(),i=this.createLoadingPlaceholder(),l=this.createImageElement(n[a]);l.onerror=()=>this.handleImageErrorWithFallback(l,r,o,n[a]);const g=l.onload;l.onload=m=>{g&&g.call(l,m),i.remove()},this.setupImageInteraction(c,n,a,o),c.appendChild(i),c.appendChild(l),e.appendChild(c)})}static createImageContainer(){return s.create("div",{},{position:"relative",flex:"1",minWidth:"120px",cursor:"pointer",transition:"all 0.2s ease",borderRadius:"8px",overflow:"hidden",boxShadow:"0 2px 8px rgba(0,0,0,0.12)",height:"184px",backgroundColor:"#f8f9fa"})}static createImageElement(e){const t=s.create("img",{src:e,loading:"lazy"},{width:"100%",height:"100%",objectFit:"cover",display:"block",transition:"opacity 0.3s ease, transform 0.2s ease",opacity:"0"});return t.onload=()=>{t.style.opacity="1"},t}static createLoadingPlaceholder(){const e=s.create("div",{},{position:"absolute",top:"0",left:"0",width:"100%",height:"100%",display:"flex",alignItems:"center",justifyContent:"center",backgroundColor:"#f8f9fa",color:"#6c757d",fontSize:"12px",zIndex:"1"});return e.textContent="加载中...",e}static setupImageInteraction(e,t,n,o){e.addEventListener("mouseenter",()=>{e.style.transform="translateY(-2px)",e.style.boxShadow="0 4px 12px rgba(0,0,0,0.15)"}),e.addEventListener("mouseleave",()=>{e.style.transform="translateY(0)",e.style.boxShadow="0 2px 6px rgba(0,0,0,0.1)"}),e.addEventListener("click",()=>{const r=t.map(a=>s.create("img",{src:a}));this.showImageViewer(r,n,o)})}static extractValidImages(e){return Array.from(e.querySelectorAll("img")).filter(n=>{const o=this.selectImageSource(n);if(!o)return!1;const r=x.isHttp(o),a=/(^|\/)attachments\//i.test(o);return!r&&!a?!1:!["images/common/","images/attachicons/","images/smilies/","static","hrline","back.gif","thanks.gif","icon"].some(i=>o.includes(i))}).slice(0,d.getMaxImagesPerPost())}static selectImageSource(e){const t=["images/common/","images/attachicons/","images/smilies/","static","hrline","back.gif","thanks.gif","icon"],n=i=>t.some(l=>i&&i.includes(l)),o=(i,l)=>/\.gif(\?|$)/i.test(i)?!(l.getAttribute("onclick")||"").includes("zoom(this)"):!1,r=[],a=["file","data-original","original","data-src","src"];for(const i of a){const l=e.getAttribute(i);x.isHttp(l||"")&&!n(l||"")&&r.push(l)}for(let i=0;i<e.attributes.length;i++){const l=e.attributes[i].value;x.isHttp(l)&&!n(l)&&!r.includes(l)&&r.push(l)}return r.length===0?e.getAttribute("src")||"":r.find(i=>!o(i,e))||r[0]}static handleImageError(e,t){parseInt(e.dataset.attempts||"0",10)===0?(e.dataset.attempts="1",e.referrerPolicy="no-referrer",setTimeout(()=>{e.src=t},300)):this.showImageLoadError(e)}static handleImageErrorWithFallback(e,t,n,o){const r=parseInt(e.dataset.attempts||"0",10);if(r>=2){this.showImageLoadError(e);return}if(e.dataset.attempts=String(r+1),r===0){e.referrerPolicy="no-referrer",setTimeout(()=>{e.src=o},300);return}if(r===1){const a=t.getAttribute("file");if(a){const c=x.resolve(n,a);if(c!==e.src){e.referrerPolicy="",e.src=c;return}}}this.showImageLoadError(e)}static showImageLoadError(e){e.style.background="#f0f0f0",e.style.opacity="1",e.alt="图片加载失败";const t=e.parentElement?.querySelector('div[style*="position: absolute"]');t&&t.remove()}static showNoImagesMessage(e){const t=s.create("div",{},{color:"#999",fontSize:"14px",fontStyle:"italic"});t.textContent="暂无图片预览",e.appendChild(t)}static showImageViewer(e,t,n){const o=this.createViewerOverlay(),{container:r,img:a,info:c,prevBtn:i,nextBtn:l}=this.createViewerElements();let g=t;const m=()=>{const f=this.selectImageSource(e[g]);a.src=x.resolve(n||location.href,f),c.textContent=`${g+1} / ${e.length}`};i.addEventListener("click",()=>{g=(g-1+e.length)%e.length,m()}),l.addEventListener("click",()=>{g=(g+1)%e.length,m()});const y=f=>{f.key==="ArrowLeft"?i.click():f.key==="ArrowRight"?l.click():f.key==="Escape"&&(o.remove(),document.removeEventListener("keydown",y))};o.addEventListener("click",f=>{f.target===o&&(o.remove(),document.removeEventListener("keydown",y))}),r.appendChild(c),r.appendChild(i),r.appendChild(l),r.appendChild(a),o.appendChild(r),document.body.appendChild(o),document.addEventListener("keydown",y),m()}static createViewerOverlay(){return s.create("div",{},{position:"fixed",top:"0",left:"0",width:"100%",height:"100%",background:"rgba(0,0,0,0.9)",zIndex:"10000",display:"flex",alignItems:"center",justifyContent:"center"})}static createViewerElements(){const e=s.create("div",{},{position:"relative",maxWidth:"90%",maxHeight:"90%",textAlign:"center"}),t=s.create("img",{},{maxWidth:"100%",maxHeight:"100%",objectFit:"contain",borderRadius:"8px",boxShadow:"0 4px 20px rgba(0,0,0,0.5)"}),n=s.create("div",{},{position:"absolute",top:"-40px",left:"50%",transform:"translateX(-50%)",color:"white",fontSize:"16px",fontWeight:"bold",background:"rgba(0,0,0,0.7)",padding:"8px 16px",borderRadius:"20px"}),o={position:"absolute",top:"50%",transform:"translateY(-50%)",background:"rgba(255,255,255,0.2)",color:"white",border:"none",fontSize:"24px",width:"44px",height:"44px",borderRadius:"50%",display:"flex",alignItems:"center",justifyContent:"center",cursor:"pointer",transition:"background 0.3s"},r=s.create("button",{},{...o,left:"-60px"});r.innerHTML="&#10094;";const a=s.create("button",{},{...o,right:"-60px"});return a.innerHTML="&#10095;",[r,a].forEach(c=>{c.addEventListener("mouseenter",()=>{c.style.background="rgba(255,255,255,0.4)"}),c.addEventListener("mouseleave",()=>{c.style.background="rgba(255,255,255,0.2)"})}),{container:e,img:t,info:n,prevBtn:r,nextBtn:a}}}class M{static init(){console.log("[BoardManager] 初始化板块管理..."),this.normalizeExclusiveLists(),this.setupBoardCollectionCollapse(),this.setupBoardFavoriteSection(),this.setupBoardHotkeys()}static normalizeExclusiveLists(){const e=new Set(d.getFavoriteBoardNames()),t=new Set(d.getCollectedBoardNames());let n=!1;e.forEach(o=>{t.has(o)&&(t.delete(o),n=!0)}),n&&d.setCollectedBoardNames(Array.from(t))}static findBoardElementsMap(){const e=new Map;return s.selectAll("div.mainbox.forumlist").forEach(n=>{const r=n.querySelector("h3 > a")?.textContent?.trim()||"";r&&!e.has(r)&&e.set(r,n)}),e}static moveBoardsToContainer(e,t){const n=this.findBoardElementsMap(),o=[];return e.forEach(r=>{const a=n.get(r);a&&(t.appendChild(a),o.push(r))}),o}static setupBoardCollectionCollapse(){if(s.select("#board-collection-container"))return;const e=new Set(d.getCollectedBoardNames()),t=Array.from(s.selectAll("div.mainbox.forumlist"));if(t.length===0)return;const n=t.filter(i=>{const g=i.querySelector("h3 > a")?.textContent?.trim()||"";return g&&e.has(g)}),o=this.createBoardContainer("board-collection-container","板块收纳区",n.length),{header:r,content:a,toggleHint:c}=this.setupContainerElements(o,{isOpen:d.getCollectionOpen(),onToggle:i=>d.setCollectionOpen(i),onSettings:()=>this.openBoardCollectSettings(),title:"板块收纳区",count:n.length});if(this.insertContainer(o),n.length===0)this.showEmptyMessage(a,'未选择任何板块,可点击右侧"设置"进行选择。');else{const i=n.map(l=>l.querySelector("h3 > a")?.textContent?.trim()||"");this.moveBoardsToContainer(i,a)}}static setupBoardFavoriteSection(){if(s.select("#board-favorite-container"))return;const e=new Set(d.getFavoriteBoardNames()),t=Array.from(s.selectAll("div.mainbox.forumlist"));if(t.length===0)return;const n=t.filter(i=>{const g=i.querySelector("h3 > a")?.textContent?.trim()||"";return g&&e.has(g)}),o=this.createBoardContainer("board-favorite-container","板块收藏区",n.length),{header:r,content:a,toggleHint:c}=this.setupContainerElements(o,{isOpen:d.getFavoriteOpen(),onToggle:i=>d.setFavoriteOpen(i),onSettings:()=>this.openBoardFavoriteSettings(),title:"板块收藏区",count:n.length});if(this.insertFavoriteContainer(o),n.length===0)this.showEmptyMessage(a,'未选择任何收藏板块,可点击右侧"设置"进行选择。');else{const i=n.map(l=>l.querySelector("h3 > a")?.textContent?.trim()||"");this.moveBoardsToContainer(i,a)}}static createBoardContainer(e,t,n){return s.create("div",{id:e},{margin:"12px 0",border:"1px solid #e3e6ea",borderRadius:"10px",boxShadow:"0 3px 12px rgba(0,0,0,0.08)",overflow:"hidden",background:"#fff"})}static setupContainerElements(e,t){const n=s.create("div",{},{padding:"10px 14px",background:t.isOpen?"#e9ecef":"linear-gradient(135deg, #ffffff 0%, #f8f9fa 100%)",borderBottom:"1px solid #e9ecef",cursor:"pointer",userSelect:"none",display:"flex",alignItems:"center",justifyContent:"space-between"}),o=s.create("span",{},{fontWeight:"600",color:"#2c3e50",fontSize:"14px"});o.textContent=`${t.title}(共 ${t.count} 个)`;const r=s.create("span",{},{fontSize:"12px",color:"#666"});r.textContent=t.isOpen?"[点击收起]":"[点击展开]";const a=s.create("button");a.textContent="设置",a.title="选择需要管理的板块",h.applyButtonStyle(a),a.addEventListener("click",l=>{l.stopPropagation(),t.onSettings()});const c=s.create("div",{},{display:"flex",alignItems:"center",gap:"10px"});c.appendChild(r),c.appendChild(a),n.appendChild(o),n.appendChild(c);const i=s.create("div",{},{padding:"10px",background:"rgba(248,249,250,0.6)",display:t.isOpen?"":"none"});return n.addEventListener("click",()=>{const l=i.style.display==="none";i.style.display=l?"":"none",r.textContent=l?"[点击收起]":"[点击展开]",n.style.background=l?"#e9ecef":"linear-gradient(135deg, #ffffff 0%, #f8f9fa 100%)",t.onToggle(l)}),e.appendChild(n),e.appendChild(i),{header:n,content:i,toggleHint:r}}static insertContainer(e){const t=s.select('table.portalbox[summary="HeadBox"]')||s.select("#hottags")?.closest("table")||s.select("#hottags");if(t?.parentNode){const n=t.parentNode;t.nextSibling?n.insertBefore(e,t.nextSibling):n.appendChild(e)}else document.body.appendChild(e)}static insertFavoriteContainer(e){const t=s.select("#board-collection-container");if(t?.parentNode){const n=t.parentNode;t.nextSibling?n.insertBefore(e,t.nextSibling):n.appendChild(e)}else this.insertContainer(e)}static showEmptyMessage(e,t){const n=s.create("div",{},{color:"#666",fontSize:"12px"});n.textContent=t,e.appendChild(n)}static openBoardCollectSettings(){const e=this.getAllBoardNames();this.openBoardSettings(e,d.getCollectedBoardNames(),"板块收纳设置","勾选需要收纳到顶部的板块:",t=>{const n=new Set(d.getFavoriteBoardNames());t.forEach(o=>n.delete(o)),d.setFavoriteBoardNames(Array.from(n)),d.setCollectedBoardNames(t),location.reload()})}static openBoardFavoriteSettings(){const e=this.getAllBoardNames();this.openBoardSettings(e,d.getFavoriteBoardNames(),"板块收藏设置",'勾选需要加入"板块收藏区"的板块:',t=>{const n=new Set(d.getCollectedBoardNames());t.forEach(o=>n.delete(o)),d.setCollectedBoardNames(Array.from(n)),d.setFavoriteBoardNames(t),location.reload()})}static getAllBoardNames(){const e=Array.from(s.selectAll("div.mainbox.forumlist > h3 > a")).map(t=>t.textContent?.trim()||"").filter(Boolean);return Array.from(new Set(e))}static openBoardSettings(e,t,n,o,r){const a=s.create("div",{},{position:"fixed",inset:"0",background:"rgba(0,0,0,0.4)",zIndex:"10001",display:"flex",alignItems:"center",justifyContent:"center"}),c=s.create("div",{},{width:"520px",maxWidth:"92vw",maxHeight:"80vh",overflow:"auto",background:"#fff",borderRadius:"10px",boxShadow:"0 10px 30px rgba(0,0,0,.2)"}),i=s.create("div",{},{padding:"12px 16px",borderBottom:"1px solid #e9ecef",fontWeight:"600",display:"flex",justifyContent:"space-between",alignItems:"center"});i.textContent=n;const l=s.create("button");l.textContent="×",h.applyButtonStyle(l),l.onclick=()=>a.remove(),i.appendChild(l);const g=s.create("div",{},{padding:"12px 16px"}),m=s.create("div",{},{color:"#666",marginBottom:"8px"});m.textContent=o,g.appendChild(m);const y=s.create("div",{},{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"6px"}),f=new Set(t);e.forEach(b=>{const P=s.create("label",{},{display:"flex",alignItems:"center",gap:"6px",padding:"6px",border:"1px solid #eee",borderRadius:"6px"}),S=s.create("input",{type:"checkbox"});S.checked=f.has(b),S.onchange=()=>{S.checked?f.add(b):f.delete(b)};const A=s.create("span");A.textContent=b,P.appendChild(S),P.appendChild(A),y.appendChild(P)}),g.appendChild(y);const E=s.create("div",{},{padding:"12px 16px",borderTop:"1px solid #e9ecef",display:"flex",justifyContent:"flex-end",gap:"10px"}),C=s.create("button");C.textContent="取消",h.applyButtonStyle(C),C.onclick=()=>a.remove();const v=s.create("button");v.textContent="保存并刷新",h.applyButtonStyle(v),v.onclick=()=>{r(Array.from(f))},E.appendChild(C),E.appendChild(v),c.appendChild(i),c.appendChild(g),c.appendChild(E),a.appendChild(c),document.body.appendChild(a)}static setupBoardHotkeys(){window.__sisBoardHotkeysReady||(window.__sisBoardHotkeysReady=!0,document.addEventListener("keydown",e=>{if(e.altKey)if(e.key.toLowerCase()==="b"){const t=s.select("#board-collection-content"),n=s.select("#board-collection-container > div");if(!t||!n)return;const o=t.style.display==="none";t.style.display=o?"":"none";const r=n.querySelector("span:last-child");r&&(r.textContent=o?"[点击收起]":"[点击展开]"),n.style.background=o?"#f0f2f5":"linear-gradient(135deg, #ffffff 0%, #f8f9fa 100%)"}else e.key.toLowerCase()==="m"&&this.openBoardCollectSettings()}))}}class _{static init(){console.log("[SearchOptimizer] 初始化搜索优化..."),this.setupSearchFavorites()}static setupSearchFavorites(){if(!/\/search\.php(\?|$)/.test(location.pathname+location.search))return;const e=s.select("#srchfid");!e||e.tagName!=="SELECT"||!e.multiple||(this.createSearchTools(e),this.setupTopGrouping(e),this.setupAutoRemember(e))}static createSearchTools(e){const t=s.create("div",{},{margin:"6px 0",display:"flex",gap:"12px",alignItems:"center"}),n=s.create("button",{type:"button"},{height:"30px"});n.textContent="置顶设置",h.applyButtonStyle(n),n.addEventListener("click",a=>{a.preventDefault(),a.stopPropagation(),this.openSearchFavSettings(e)}),h.ensureToggleStyles();const{switchWrap:o,switchInput:r}=this.createToggleSwitch();t.appendChild(n),t.appendChild(o),e.parentNode?.insertBefore(t,e)}static createToggleSwitch(){const e=s.create("label",{class:"sis-toggle"}),t=s.create("input",{type:"checkbox",class:"sis-input"});t.checked=d.getSearchFavAuto();const n=s.create("span",{class:"sis-text"});n.textContent="多选记忆";const o=s.create("span",{class:"sis-switch"});return e.appendChild(t),e.appendChild(n),e.appendChild(o),t.addEventListener("change",()=>{if(d.setSearchFavAuto(t.checked),t.checked){const r=s.select("#srchfid");if(r){const a=Array.from(r.selectedOptions).map(c=>c.value).filter(Boolean);a.length>0&&d.setSearchFavForums(a)}}}),{switchWrap:e,switchInput:t}}static setupTopGrouping(e){const t=d.getSearchFavForums();if(t.length===0)return;const n=s.create("optgroup",{label:"常用置顶"});e.insertBefore(n,e.firstChild);const o=Array.from(e.querySelectorAll("option"));t.forEach(r=>{const a=o.find(c=>c.value===r);a&&n.appendChild(a)}),d.getSearchFavAuto()&&(Array.from(e.options).forEach(r=>r.selected=!1),Array.from(n.querySelectorAll("option")).forEach(r=>r.selected=!0))}static setupAutoRemember(e){d.getSearchFavAuto()&&e.addEventListener("change",()=>{const t=Array.from(e.selectedOptions).map(n=>n.value).filter(Boolean);d.setSearchFavForums(t)})}static openSearchFavSettings(e){const t=Array.from(e.querySelectorAll("option")).filter(l=>l.value),n=s.create("div",{},{position:"fixed",inset:"0",background:"rgba(0,0,0,0.4)",zIndex:"10001",display:"flex",alignItems:"center",justifyContent:"center"}),o=s.create("div",{},{width:"1100px",maxWidth:"96vw",maxHeight:"90vh",overflow:"auto",background:"#fff",borderRadius:"10px",boxShadow:"0 10px 30px rgba(0,0,0,.2)"}),r=this.createPanelHeader(n),{body:a,favSet:c}=this.createPanelBody(e,t),i=this.createPanelFooter(n,c);o.appendChild(r),o.appendChild(a),o.appendChild(i),n.appendChild(o),document.body.appendChild(n)}static createPanelHeader(e){const t=s.create("div",{},{padding:"12px 16px",borderBottom:"1px solid #e9ecef",fontWeight:"600",display:"flex",justifyContent:"space-between",alignItems:"center"});t.textContent="置顶设置";const n=s.create("button",{type:"button"});return n.textContent="×",h.applyButtonStyle(n),n.onclick=()=>e.remove(),t.appendChild(n),t}static createPanelBody(e,t){const n=s.create("div",{},{padding:"12px 16px",display:"grid",gridTemplateColumns:"repeat(auto-fit,minmax(260px,1fr))",gap:"12px"}),o=new Set(d.getSearchFavForums());return this.organizeOptions(e,t).forEach(a=>{const c=this.createGroupCard(a,o);n.appendChild(c)}),{body:n,favSet:o}}static organizeOptions(e,t){const n=[];Array.from(e.querySelectorAll("optgroup")).forEach(a=>{const c=Array.from(a.querySelectorAll("option")).filter(i=>i.value);c.length>0&&n.push({label:a.label||"分组",options:c})});const r=Array.from(e.children).filter(a=>a.tagName==="OPTION"&&a.value&&a.value!=="all");return r.length>0&&n.unshift({label:"其他",options:r}),n}static createGroupCard(e,t){const n=s.create("div",{},{border:"1px solid #e9ecef",borderRadius:"8px",overflow:"hidden",background:"#fff"}),o=s.create("div",{},{padding:"8px 10px",background:"#f8f9fa",borderBottom:"1px solid #e9ecef",fontWeight:"600",color:"#2c3e50",fontSize:"12px"});o.textContent=e.label;const r=s.create("div",{},{padding:"8px 10px",display:"flex",flexDirection:"column",gap:"6px"});return e.options.forEach(a=>{const c=s.create("label",{},{display:"flex",alignItems:"center",gap:"6px",padding:"6px",border:"1px solid #eee",borderRadius:"6px"}),i=s.create("input",{type:"checkbox"});i.checked=t.has(a.value),i.onchange=()=>{i.checked?t.add(a.value):t.delete(a.value)};const l=s.create("span");l.textContent=a.textContent?.trim()||"",c.appendChild(i),c.appendChild(l),r.appendChild(c)}),n.appendChild(o),n.appendChild(r),n}static createPanelFooter(e,t){const n=s.create("div",{},{padding:"12px 16px",borderTop:"1px solid #e9ecef",display:"flex",justifyContent:"flex-end",gap:"10px"}),o=s.create("button",{type:"button"});o.textContent="取消",h.applyButtonStyle(o),o.onclick=()=>e.remove();const r=s.create("button",{type:"button"});return r.textContent="保存并刷新",h.applyButtonStyle(r),r.onclick=()=>{d.setSearchFavForums(Array.from(t)),location.reload()},n.appendChild(o),n.appendChild(r),n}}class N{static init(){console.log("[SettingsPanel] 初始化设置面板..."),this.injectScriptConfigMenuButton()}static injectScriptConfigMenuButton(){const e=s.select("#menu ul");if(!e||e.querySelector("#sis-script-settings"))return;const t=s.create("li",{id:"sis-script-settings"}),n=s.create("a",{href:"javascript:void(0)"});n.textContent="脚本配置",n.addEventListener("click",o=>{o.preventDefault(),this.openScriptSettingsPanel()}),t.appendChild(n),e.appendChild(t)}static openScriptSettingsPanel(){const e=s.create("div",{},{position:"fixed",inset:"0",background:"rgba(0,0,0,0.4)",zIndex:"10001",display:"flex",alignItems:"center",justifyContent:"center"}),t=s.create("div",{},{width:"480px",maxWidth:"92vw",maxHeight:"80vh",overflow:"auto",background:"#fff",borderRadius:"10px",boxShadow:"0 10px 30px rgba(0,0,0,.2)"}),n=this.createPanelHeader(e),o=this.createPanelBody(),r=this.createPanelFooter(e,o);t.appendChild(n),t.appendChild(o),t.appendChild(r),e.appendChild(t),document.body.appendChild(e)}static createPanelHeader(e){const t=s.create("div",{},{padding:"12px 16px",borderBottom:"1px solid #e9ecef",fontWeight:"600",display:"flex",justifyContent:"space-between",alignItems:"center"});t.textContent="脚本配置";const n=s.create("button");return n.textContent="×",h.applyButtonStyle(n),n.onclick=()=>e.remove(),t.appendChild(n),t}static createPanelBody(){const e=s.create("div",{},{padding:"12px 16px",display:"flex",flexDirection:"column",gap:"12px"}),t=this.createSettingRow("预览图数量","number",String(d.getMaxImagesPerPost()),{min:"1",max:"20",step:"1"}),n=this.createSettingRow("加载并发上限","number",String(d.getMaxPreviewConcurrency()),{min:"1",max:"100",step:"1"}),o=s.create("div",{},{color:"#777",fontSize:"12px"});return o.textContent="提示:并发过大会增加服务器和本机负载,建议 5-20 之间。",e.appendChild(t),e.appendChild(n),e.appendChild(o),e}static createSettingRow(e,t,n,o={}){const r=s.create("label",{},{display:"flex",alignItems:"center",justifyContent:"space-between",gap:"12px",padding:"8px 10px",border:"1px solid #e9ecef",borderRadius:"8px"}),a=s.create("span",{},{fontSize:"13px",color:"#2c3e50"});a.textContent=e;const c=s.create("input",{type:t,value:n,...o},{width:"100px",padding:"6px 8px",border:"1px solid #e3e6ea",borderRadius:"6px"});return r.__input=c,r.appendChild(a),r.appendChild(c),r}static createPanelFooter(e,t){const n=s.create("div",{},{padding:"12px 16px",borderTop:"1px solid #e9ecef",display:"flex",justifyContent:"flex-end",gap:"10px"}),o=s.create("button");o.textContent="取消",h.applyButtonStyle(o),o.onclick=()=>e.remove();const r=s.create("button");return r.textContent="保存并刷新",h.applyButtonStyle(r),r.onclick=()=>this.saveSettings(t),n.appendChild(o),n.appendChild(r),n}static saveSettings(e){const t=Array.from(e.children).filter(n=>n.__input);if(t.length>=2){const n=t[0].__input,o=t[1].__input;let r=parseInt(n.value,10),a=parseInt(o.value,10);Number.isFinite(r)||(r=d.getMaxImagesPerPost()),Number.isFinite(a)||(a=d.getMaxPreviewConcurrency()),r=Math.min(20,Math.max(1,r)),a=Math.min(100,Math.max(1,a)),console.log(`[SettingsPanel] 保存配置: 图片数量=${r}, 并发数=${a}`),d.setMaxImagesPerPost(r),d.setMaxPreviewConcurrency(a);const c=d.getMaxImagesPerPost(),i=d.getMaxPreviewConcurrency();console.log(`[SettingsPanel] 验证保存结果: 图片数量=${c}, 并发数=${i}`),location.reload()}}}/**
 * 第一会所-预览脚本 主入口
 * SIS001 第一会所综合社区,帖子图片预览,板块收纳,搜索优化
 *
 * @version 1.0.0
 * @author 星宿老魔
 * @license MIT
 */console.log("[SIS001 Preview] 脚本开始加载 v1.0.0");async function O(){try{H(),T.init(),document.readyState==="loading"&&await B.waitForDOMContentLoaded(),w.init(),await B.waitForWindowLoad(),await F.init(),M.init(),_.init(),N.init(),console.log("[SIS001 Preview] 所有功能模块初始化完成")}catch(p){console.error("[SIS001 Preview] 初始化失败:",p)}}function H(){const p=document.querySelectorAll("a");for(let e=0;e<p.length;e++){const t=p[e];if(t.textContent&&t.textContent.includes("电脑版")){window.location.href=t.href;break}}}O()})();