// ==UserScript==
// @name 2048-预览
// @version 1.2.3
// @namespace https://sleazyfork.org/zh-CN/users/1461640-%E6%98%9F%E5%AE%BF%E8%80%81%E9%AD%94
// @author 星宿老魔
// @description 为2048核基地论坛帖子添加图片、链接预览
// @match https://hjd2048.com/2048/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=hjd2048.com
// @license MIT
// @grant GM_xmlhttpRequest
// @grant GM_setValue
// @grant GM_getValue
// @run-at document-start
// ==/UserScript==
(function(){"use strict";const CONFIG={PREVIEW_IMAGE_HEIGHT:300,DEFAULT_PREVIEW_COUNT:4,getPreviewCount(){try{
return GM_getValue("PREVIEW_COUNT",this.DEFAULT_PREVIEW_COUNT)}catch(e){return this.DEFAULT_PREVIEW_COUNT}},
setPreviewCount(e){try{GM_setValue("PREVIEW_COUNT",e)}catch(t){void 0}},getExcludedForums(){try{
return GM_getValue("EXCLUDED_FORUMS",[])}catch(e){return[]}},setExcludedForums(e){try{GM_setValue("EXCLUDED_FORUMS",e)
}catch(t){void 0}},selectors:{threadRows:"tr.tr3.t_one",threadLinks:'a[target="_self"], a[target="_blank"]',
contentSelectors:["#read_tpc",".tpc_content",".f14.cc",'div[id="read_tpc"]',".t_f"],
searchLink:'#nav-pc a[href="/search.php"]',navSearch:"#nav-s",searchResultTable:".t table",
searchResultRows:'tr[id^="search_"]',searchResultHeader:".t table .h",previewRows:"tr.imagePreviewTr",
imgSelectors:["#read_tpc img",".tpc_content img",".f14.cc img",'div[id="read_tpc"] img'],
magnetTextarea:"textarea[readonly], textarea#copytext",magnetLink:'a[href^="magnet:?xt=urn:btih:"]',
ed2kLink:'a[href^="ed2k://"]',btLink:'a[href*="bt.ivcbt.com/list.php?name="], a[href*="bt.bxmho.cn/list.php?name="]'},
regex:{threadUrl:/read\.php\?tid=/,searchUrl:/search\.php/,searchRowId:/^search_(\d+)_(\d+)$/,
magnetHash:/([A-F0-9]{40})/i,thunder:/thunder:\/\/[A-Za-z0-9+\/=]+/i,
ed2k:/ed2k:\/\/\|file\|[^|]+\|\d+\|[A-F0-9]{32}\|\//i,magnetLink:/magnet:\?xt=urn:btih:[a-zA-Z0-9]+/,
copyText:/magnet:\?xt=urn:btih:/},btSites:[{name:"bxmho",
pattern:/(?:\/\/bt\.bxmho\.cn\/list\.php\?name=|userscript\.html\?name=)([0-9a-z]+)/i,
url:"https://bt.bxmho.cn/list.php",method:"GET",getHash:e=>{const t=e.match(/([0-9a-z]+)$/i);return t?t[1]:""}},{
name:"82bt",pattern:/\/\/www\.82bt\.com\/(?:cao\.php|dlink\.php)\?hash=([0-9a-z]+)/i,
url:"https://www.82bt.com/downt-m.php",method:"POST",paramName:"code",referer:"https://www.82bt.com",getHash:e=>{
const t=e.match(/hash=([0-9a-z]+)/i);return t?t[1]:""}}]};const e={copyToClipboard(e,t){
navigator.clipboard.writeText(e).then(()=>{this.showClickTip("已复制",t)}).catch(()=>{this.fallbackCopyTextToClipboard(e,t)
})},fallbackCopyTextToClipboard(e,t){const n=document.createElement("textarea");n.value=e;n.style.position="fixed"
;n.style.top="-1000px";n.style.left="-1000px";document.body.appendChild(n);n.focus();n.select();try{
document.execCommand("copy");this.showClickTip("已复制",t)}catch(a){void 0;this.showClickTip("复制失败",t)}
document.body.removeChild(n)},showClickTip(e,t){const n=t;let a=document.querySelector(".click-tip");if(a)a.remove()
;a=document.createElement("div");a.className="click-tip";a.textContent=e;document.body.appendChild(a)
;a.style.left=`${n.clientX}px`;a.style.top=`${n.clientY}px`;setTimeout(()=>{a.style.opacity="1"},10);setTimeout(()=>{
a.style.opacity="0";setTimeout(()=>{if(a.parentElement)a.remove()},200)},1e3)},removeRules(){try{
const e=document.querySelector(".collapse-header");if(e){
const t=e.closest("div, section, .rule-container, .collapse-container");if(t)t.remove()}}catch(e){void 0}},
isContentPage(){return CONFIG.regex.threadUrl.test(window.location.href)},safeQuerySelector(e,t=document){try{
return t.querySelector(e)}catch(n){return null}},safeQuerySelectorAll(e,t=document){try{
return Array.from(t.querySelectorAll(e))}catch(n){return[]}}};const t=class _ForumData{static getForumById(e){
return this.FORUM_SECTIONS.find(t=>t.id===e)}static getChildForums(e){return this.FORUM_SECTIONS.filter(t=>t.parent===e)
}static getMainCategories(){return this.FORUM_SECTIONS.filter(e=>2===e.level&&"1"===e.parent)}static getDisplayName(e){
const t=" ".repeat(Math.max(0,e.level-2));return`${t}${e.name}`}static getForumTree(){const e=[]
;const t=this.getMainCategories();t.forEach(t=>{e.push(t);const n=this.getChildForums(t.id);n.forEach(t=>{e.push(t)
;const n=this.getChildForums(t.id);n.forEach(t=>{e.push(t);const n=this.getChildForums(t.id);e.push(...n)})})});return e
}};t.FORUM_SECTIONS=[{id:"all",name:"全部版块分类",level:0},{id:"1",name:"总板块",level:1},{id:"2",name:"新片速递",level:2,parent:"1"
},{id:"3",name:"最新合集",level:3,parent:"2"},{id:"4",name:"亞洲無碼",level:3,parent:"2"},{id:"5",name:"日本騎兵",level:3,parent:"2"
},{id:"13",name:"歐美新片",level:3,parent:"2"},{id:"15",name:"國內原創",level:3,parent:"2"},{id:"16",name:"中字原創",level:3,
parent:"2"},{id:"18",name:"三級寫真",level:3,parent:"2"},{id:"343",name:"实时BT",level:3,parent:"2"},{id:"326",name:"本站高清影院",
level:3,parent:"2"},{id:"7",name:"图片专区",level:2,parent:"1"},{id:"23",name:"網友自拍",level:3,parent:"7"},{id:"24",
name:"亞洲激情",level:3,parent:"7"},{id:"25",name:"歐美激情",level:3,parent:"7"},{id:"26",name:"熟女专图",level:3,parent:"7"},{
id:"27",name:"高跟絲襪",level:3,parent:"7"},{id:"28",name:"卡通漫畫",level:3,parent:"7"},{id:"345",name:"图你所图",level:3,
parent:"7"},{id:"135",name:"原創达人",level:3,parent:"7"},{id:"273",name:"美图秀秀",level:2,parent:"1"},{id:"21",name:"唯美清純",
level:3,parent:"273"},{id:"275",name:"亞洲正妹",level:3,parent:"273"},{id:"276",name:"素人正妹",level:3,parent:"273"},{id:"277",
name:"角色扮演",level:3,parent:"273"},{id:"278",name:"A I 智能",level:3,parent:"273"},{id:"320",name:"优质图片",level:3,
parent:"273"},{id:"333",name:"明星合成",level:3,parent:"273"},{id:"29",name:"动态图片",level:3,parent:"273"},{id:"92",
name:"精品收录",level:2,parent:"1"},{id:"295",name:"原创首发",level:3,parent:"92"},{id:"94",name:"稀有首發",level:3,parent:"92"},{
id:"329",name:"藏精阁 — 2017-2024",level:4,parent:"94"},{id:"283",name:"网络见闻",level:3,parent:"92"},{id:"111",name:"主播實錄",
level:3,parent:"92"},{id:"99",name:"國產主播",level:4,parent:"111"},{id:"324",name:"自购主播区",level:4,parent:"111"},{id:"323",
name:"国产主播2区",level:4,parent:"111"},{id:"322",name:"国产主播3区",level:4,parent:"111"},{id:"131",name:"名站同步",level:3,
parent:"92"},{id:"314",name:"真实街拍",level:3,parent:"92"},{id:"341",name:"原档115",level:3,parent:"92"},{id:"213",
name:"国产主播同步",level:4,parent:"341"},{id:"342",name:"VR視頻2023-2025",level:4,parent:"341"},{id:"290",name:"日本4K超清",
level:4,parent:"341"},{id:"303",name:"高清有碼",level:4,parent:"341"},{id:"302",name:"AI視界",level:4,parent:"341"},{id:"304",
name:"外掛字幕",level:4,parent:"341"},{id:"306",name:"FC2視頻",level:4,parent:"341"},{id:"307",name:"S-cute / Mywife",level:4,
parent:"341"},{id:"305",name:"亞洲SM",level:4,parent:"341"},{id:"321",name:"补档申请",level:3,parent:"92"},{id:"75",
name:"免空網盤",level:2,parent:"1"},{id:"72",name:"网盘二区",level:3,parent:"75"},{id:"272",name:"网盘三区",level:3,parent:"75"},{
id:"195",name:"优质 B T",level:3,parent:"75"},{id:"280",name:"国产精选",level:3,parent:"75"},{id:"76",name:"多挂原创",level:3,
parent:"75"},{id:"55",name:"有声小说",level:3,parent:"75"},{id:"180",name:"实用漫画",level:3,parent:"75"},{id:"113",name:"原档收藏",
level:3,parent:"75"},{id:"116",name:"有碼.HD",level:4,parent:"113"},{id:"114",name:"亞洲SM.HD",level:4,parent:"113"},{
id:"96",name:"日韓VR/3D",level:4,parent:"113"},{id:"119",name:"S-cute / Mywife / G-area",level:4,parent:"113"},{id:"41",
name:"綜合資源",level:2,parent:"1"},{id:"43",name:"E D 2 K",level:3,parent:"41"},{id:"315",name:"原档字幕",level:3,parent:"41"
},{id:"318",name:"磁链迅雷",level:3,parent:"41"},{id:"316",name:"包罗万象",level:3,parent:"41"},{id:"271",name:"聚合1区",level:4,
parent:"316"},{id:"281",name:"聚合2区",level:4,parent:"316"},{id:"284",name:"聚合3区",level:4,parent:"316"},{id:"313",
name:"远古资源",level:4,parent:"316"},{id:"319",name:"聚合5区",level:4,parent:"316"},{id:"325",name:"聚合6区 WK",level:4,
parent:"316"},{id:"327",name:"聚合7区",level:4,parent:"316"},{id:"332",name:"司机社",level:4,parent:"316"},{id:"335",
name:"套图学院",level:4,parent:"316"},{id:"334",name:"游戏下载",level:4,parent:"316"},{id:"340",name:"韩国主播",level:4,parent:"316"
},{id:"344",name:"美足踩踏",level:4,parent:"316"},{id:"346",name:"套图百晓生",level:4,parent:"316"},{id:"348",name:"街拍精品",
level:4,parent:"316"},{id:"67",name:"正片大片",level:3,parent:"41"},{id:"66",name:"H-GAME",level:3,parent:"41"},{id:"291",
name:"快播影院",level:3,parent:"41"},{id:"293",name:"快播1号",level:4,parent:"291"},{id:"294",name:"快播2号",level:4,parent:"291"
},{id:"296",name:"快播3号",level:4,parent:"291"},{id:"299",name:"快播4号",level:4,parent:"291"},{id:"300",name:"快播5号",level:4,
parent:"291"},{id:"301",name:"快播6号",level:4,parent:"291"},{id:"308",name:"快播7号",level:4,parent:"291"},{id:"309",
name:"快播频道",level:4,parent:"291"},{id:"311",name:"快播10号",level:4,parent:"291"},{id:"312",name:"快播11号",level:4,
parent:"291"},{id:"331",name:"本站破解资源",level:3,parent:"41"},{id:"102",name:"文学欣赏",level:2,parent:"1"},{id:"328",
name:"在线速听",level:3,parent:"102"},{id:"48",name:"综合小说",level:3,parent:"102"},{id:"49",name:"激情都市",level:4,parent:"48"},{
id:"51",name:"青春校园",level:4,parent:"48"},{id:"52",name:"武侠虚幻",level:4,parent:"48"},{id:"105",name:"另类其他",level:4,
parent:"48"},{id:"103",name:"人妻意淫",level:3,parent:"102"},{id:"50",name:"乱伦迷情",level:3,parent:"102"},{id:"54",
name:"长篇连载",level:3,parent:"102"},{id:"100",name:"文学作者",level:3,parent:"102"},{id:"109",name:"TXT小说打包",level:3,
parent:"102"},{id:"297",name:"2008-2024大集合",level:4,parent:"109"},{id:"110",name:"TXT小说綜合一区",level:4,parent:"109"},{
id:"189",name:"TXT小说綜合二区",level:4,parent:"109"},{id:"193",name:"同人小说",level:4,parent:"109"},{id:"336",name:"耽美小说",
level:4,parent:"109"},{id:"192",name:"言情小说",level:4,parent:"109"},{id:"338",name:"常规小说",level:4,parent:"109"},{id:"190",
name:"都市校园",level:4,parent:"109"},{id:"191",name:"武侠小说",level:4,parent:"109"},{id:"93",name:"TXT小说網盤區",level:4,
parent:"109"},{id:"56",name:"网友互动",level:2,parent:"1"},{id:"57",name:"聚友客栈",level:3,parent:"56"},{id:"61",name:"求片专版",
level:3,parent:"56"},{id:"206",name:"重金求片区(米粒悬赏)限侠客以上",level:4,parent:"61"},{id:"218",name:"成人信息",level:3,parent:"56"},{
id:"220",name:"北京性息",level:4,parent:"218"},{id:"237",name:"上海性息",level:4,parent:"218"},{id:"238",name:"广州性息",level:4,
parent:"218"},{id:"239",name:"深圳性息",level:4,parent:"218"},{id:"287",name:"赚米专区",level:3,parent:"56"},{id:"136",
name:"坛友自售",level:3,parent:"56"},{id:"289",name:"破解软件",level:3,parent:"56"},{id:"339",name:"包养情报",level:3,parent:"56"},{
id:"128",name:"问题建议/举报申诉",level:3,parent:"56"},{id:"292",name:"解禁忏悔区/丢失找回",level:4,parent:"128"}];let n=t
;const a=class _ModernSettingsPanel{static init(){if(this.initialized)return;this.removeSearchButton()
;this.addSimpleButtons();this.initialized=true}static removeSearchButton(){try{
const e=document.getElementById("td_ID141");if(e){const t=e.closest("li");if(t){t.remove();return}}
const t=document.querySelectorAll('a[href="/search.php"]');t.forEach(e=>{const t=e.closest("li");if(t)t.remove()})
}catch(e){void 0}}static addSimpleButtons(){const e=document.getElementById("nav-pc");if(e){
const t=document.createElement("li");const n=document.createElement("a");n.href="javascript:;"
;n.className="simple-toggle-btn";n.onclick=()=>false;this.updatePreviewButtonText(n);t.appendChild(n);e.appendChild(t)
;n.addEventListener("click",e=>{e.preventDefault();this.togglePreviewCount()});const a=document.createElement("li")
;const i=document.createElement("a");i.href="javascript:;";i.textContent="搜索过滤";i.onclick=()=>false;a.appendChild(i)
;e.appendChild(a);const r=this.createSearchFilterPanel();i.addEventListener("click",e=>{e.preventDefault();r.show()})
}else this.addFallbackSimpleButton()}static addFallbackSimpleButton(){const e=document.getElementById("nav-s");if(e){
const t=document.createElement("a");t.href="javascript:;";t.style.color="#fff";t.style.marginRight="15px"
;t.className="fr";this.updatePreviewButtonText(t);e.insertBefore(t,e.firstChild);t.addEventListener("click",e=>{
e.preventDefault();this.togglePreviewCount()})}}static updatePreviewButtonText(e){const t=CONFIG.getPreviewCount()
;e.textContent=`预览${t}张图`}static togglePreviewCount(){const e=CONFIG.getPreviewCount();const t=4===e?5:4
;CONFIG.setPreviewCount(t);window.location.reload()}static createSearchFilterPanel(){
const e=`\n <dialog id="search-filter-panel" class="clean-search-panel script-container">\n <header>\n <span>搜索过滤设置</span>\n <button id="search-close-settings-btn" class="close-x">×</button>\n </header>\n <main id="search-forum-list" class="clean-forum-tree"></main>\n <footer>\n <div class="filter-controls">\n <button id="search-clear-all-filters" class="secondary">清除全部</button>\n <button id="search-select-all-forums" class="secondary">全选</button>\n </div>\n <button id="search-save-settings-btn">保存设置</button>\n </footer>\n </dialog>\n <div id="search-filter-overlay" style="display:none; position:fixed; inset:0; background:rgba(0,0,0,0.5); z-index:10000;"></div>\n `
;document.body.insertAdjacentHTML("beforeend",e);const t=document.getElementById("search-filter-panel")
;const n=document.getElementById("search-filter-overlay");this.generateCleanSearchForumList()
;this.loadSearchFilterSettings();setTimeout(()=>{if(n)this.setupSearchFilterEventListeners(t,n)},50);return{show:()=>{
t.style.display="block";n.style.display="block"}}}static generateCleanSearchForumList(){
const e=document.getElementById("search-forum-list");if(!e)return;const t=n.getForumTree()
;const a=t.filter(e=>2===e.level);a.forEach(n=>{const a=document.createElement("div");a.className="clean-forum-card"
;const i=document.createElement("div");i.className="clean-card-header";const r=document.createElement("input")
;r.type="checkbox";r.id=`search-forum-${n.id}`;r.value=n.id;r.className="main-forum-checkbox"
;const l=document.createElement("span");l.className="main-forum-title";l.textContent=n.name;i.appendChild(r)
;i.appendChild(l);a.appendChild(i);const s=document.createElement("div");s.className="clean-card-content"
;this.addCleanSubForums(t,n.id,s,n.id);a.appendChild(s);e.appendChild(a);r.addEventListener("change",()=>{
this.handleSearchFilterParentToggle(n.id,r.checked)})})}static addCleanSubForums(e,t,n,a){
const i=e.filter(e=>e.parent===t&&3===e.level);if(0===i.length)return
;const r=i.some(t=>e.some(e=>4===e.level&&e.parent===t.id));if(r)i.forEach(t=>{const i=document.createElement("div")
;i.className="clean-sub-section";const r=document.createElement("div");r.className="clean-sub-header"
;const l=document.createElement("input");l.type="checkbox";l.id=`search-forum-${t.id}`;l.value=t.id
;l.className="sub-forum-checkbox";l.dataset.parent=a;const s=document.createElement("span")
;s.className="sub-forum-title";s.textContent=t.name;r.appendChild(l);r.appendChild(s);i.appendChild(r)
;l.addEventListener("change",()=>{this.handleLevel3Toggle(t.id,l.checked)})
;const o=e.filter(e=>4===e.level&&e.parent===t.id);if(o.length>0){const e=document.createElement("div")
;e.className="clean-level4-grid";o.forEach(n=>{const i=document.createElement("label");i.className="clean-level4-item"
;const r=document.createElement("input");r.type="checkbox";r.id=`search-forum-${n.id}`;r.value=n.id
;r.className="level4-forum-checkbox";r.dataset.parent=a;r.dataset.level3Parent=t.id
;const l=document.createElement("span");l.textContent=n.name;i.appendChild(r);i.appendChild(l);e.appendChild(i)})
;i.appendChild(e)}n.appendChild(i)});else{const e=document.createElement("div");e.className="clean-compact-grid"
;i.forEach(t=>{const n=document.createElement("label");n.className="clean-compact-item"
;const i=document.createElement("input");i.type="checkbox";i.id=`search-forum-${t.id}`;i.value=t.id
;i.className="compact-forum-checkbox";i.dataset.parent=a;const r=document.createElement("span");r.textContent=t.name
;n.appendChild(i);n.appendChild(r);e.appendChild(n)});n.appendChild(e)}}static loadSearchFilterSettings(){
const e=CONFIG.getExcludedForums();e.forEach(e=>{const t=document.getElementById(`search-forum-${e}`)
;if(t)t.checked=true})}static setupSearchFilterEventListeners(e,t){
const n=document.getElementById("search-save-settings-btn")
;if(n)n.addEventListener("click",()=>this.saveSearchFilterSettings());const closePanel=()=>{e.style.display="none"
;t.style.display="none"};const a=document.getElementById("search-close-settings-btn")
;if(a)a.addEventListener("click",closePanel);t.addEventListener("click",closePanel)
;const i=document.getElementById("search-clear-all-filters");const r=document.getElementById("search-select-all-forums")
;if(i)i.addEventListener("click",()=>this.clearAllSearchFilters())
;if(r)r.addEventListener("click",()=>this.selectAllSearchForums())}static saveSearchFilterSettings(){
const e=document.querySelectorAll('.clean-search-panel input[type="checkbox"]:checked')
;const t=Array.from(e).map(e=>e.value);CONFIG.setExcludedForums(t);window.location.reload()}
static handleSearchFilterParentToggle(e,t){const n=document.querySelectorAll(`[data-parent="${e}"]`);n.forEach(e=>{
e.checked=t})}static handleLevel3Toggle(e,t){const n=document.querySelectorAll(`[data-level3-parent="${e}"]`)
;n.forEach(e=>{e.checked=t})}static clearAllSearchFilters(){
const e=document.querySelectorAll('.clean-search-panel input[type="checkbox"]');e.forEach(e=>e.checked=false)}
static selectAllSearchForums(){const e=document.querySelectorAll('.clean-search-panel input[type="checkbox"]')
;e.forEach(e=>e.checked=true)}};a.initialized=false;let i=a;const r=class _LightboxManager{static init(){
this.createLightbox();this.setupEventListeners()}static createLightbox(){if(this.lightbox)return
;this.lightbox=document.createElement("div");this.lightbox.className="lightbox"
;this.lightboxContent=document.createElement("div");this.lightboxContent.className="lightbox-content"
;this.lightboxImg=document.createElement("img");this.lightboxImg.className="lightbox-image"
;const e=document.createElement("div");e.className="lightbox-close";e.innerHTML="×"
;const t=document.createElement("div");t.className="lightbox-prev";t.innerHTML="‹";const n=document.createElement("div")
;n.className="lightbox-next";n.innerHTML="›";this.loadingText=document.createElement("div")
;this.loadingText.className="lightbox-loading";this.loadingText.textContent="加载中..."
;this.lightboxContent.appendChild(this.loadingText);this.lightboxContent.appendChild(this.lightboxImg)
;this.lightbox.appendChild(this.lightboxContent);this.lightbox.appendChild(e);this.lightbox.appendChild(t)
;this.lightbox.appendChild(n);document.body.appendChild(this.lightbox);this.closeBtn=e;this.prevBtn=t;this.nextBtn=n}
static setupEventListeners(){if(!this.closeBtn||!this.prevBtn||!this.nextBtn||!this.lightbox)return
;this.closeBtn.addEventListener("click",()=>this.closeLightbox());this.prevBtn.addEventListener("click",e=>{
e.stopPropagation();this.currentIndex=(this.currentIndex-1+this.currentImages.length)%this.currentImages.length
;this.updateLightboxImage()});this.nextBtn.addEventListener("click",e=>{e.stopPropagation()
;this.currentIndex=(this.currentIndex+1)%this.currentImages.length;this.updateLightboxImage()})
;this.lightbox.addEventListener("click",e=>{if(e.target===this.lightbox)this.closeLightbox()})
;document.addEventListener("keydown",e=>{if(!this.lightbox?.classList.contains("active"))return
;if("Escape"===e.key)this.closeLightbox();else if("ArrowLeft"===e.key)this.prevBtn?.click();else if("ArrowRight"===e.key)this.nextBtn?.click()
})}static updateLightboxImage(){if(!this.lightboxImg||!this.loadingText||!this.lightboxContent)return
;const e=this.currentImages[this.currentIndex];this.loadingText.textContent="加载中..."
;this.loadingText.style.display="block";this.lightboxImg.style.display="none";this.lightboxImg.style.width=""
;this.lightboxImg.style.height="";this.lightboxImg.style.maxWidth="";this.lightboxImg.style.maxHeight=""
;this.lightboxContent.classList.remove("landscape","portrait");this.lightboxImg.src=e;this.lightboxImg.onload=()=>{
if(!this.lightboxImg||!this.loadingText||!this.lightboxContent)return;this.loadingText.style.display="none"
;this.lightboxImg.style.display="block";const e=.9*window.innerWidth;const t=.9*window.innerHeight
;const n=this.lightboxImg.naturalWidth;const a=this.lightboxImg.naturalHeight;if(n<300&&a<300){const i=2*n;const r=2*a
;if(i<=e&&r<=t){this.lightboxImg.style.width=i+"px";this.lightboxImg.style.height=r+"px"
}else this.scaleImageToFit(i,r,e,t)}else if(n>e||a>t)this.scaleImageToFit(n,a,e,t);else{
this.lightboxImg.style.width=n+"px";this.lightboxImg.style.height=a+"px"}};this.lightboxImg.onerror=()=>{
if(this.loadingText)this.loadingText.textContent="图片加载失败"}}static scaleImageToFit(e,t,n,a){if(!this.lightboxImg)return
;const i=n/e;const r=a/t;const l=Math.min(i,r);const s=e*l;const o=t*l;this.lightboxImg.style.width=s+"px"
;this.lightboxImg.style.height=o+"px"}static showLightbox(e,t){if(!this.lightbox)return;this.currentImages=e
;this.currentIndex=t;this.updateLightboxImage();this.lightbox.classList.add("active")}static closeLightbox(){
if(this.lightbox)this.lightbox.classList.remove("active")}};r.lightbox=null;r.lightboxImg=null;r.lightboxContent=null
;r.loadingText=null;r.currentImages=[];r.currentIndex=0;r.closeBtn=null;r.prevBtn=null;r.nextBtn=null;let l=r
;const s=class _UltraMinimalStyleManager{static injectStyles(){const e=document.getElementById(this.styleElementId)
;if(e)e.remove();const t=document.createElement("style");t.id=this.styleElementId
;t.textContent=`.click-tip{position:fixed;background:rgba(0,0,0,0.8);color:#fff;padding:6px 12px;border-radius:4px;font-size:13px;z-index:10000}.thread-title-highlighted{background:#e8f4fd!important;border-radius:4px 4px 0 0}.preview-container{margin:0 0 10px 0;border:1px solid #dee2e6;border-top:none;border-radius:0 0 4px 4px;padding:16px;background:#f8f9fa}.preview-images{display:flex;gap:12px;margin-bottom:16px}.preview-image-wrapper{height:300px;flex:0 0 auto;border-radius:4px;cursor:pointer;overflow:hidden}.preview-image{width:100%;height:100%;object-fit:cover}.preview-magnet{font-size:13px;word-break:break-all;cursor:pointer;padding:10px 12px;background:#f0f9ff;border:1px solid #e0f2fe;border-radius:4px;margin-bottom:10px}.lightbox{position:fixed;inset:0;background:rgba(0,0,0,0.9);display:flex;align-items:center;justify-content:center;z-index:9999;opacity:0;visibility:hidden}.lightbox.active{opacity:1;visibility:visible}.lightbox-image{border-radius:8px;display:block;object-fit:contain}.lightbox-prev,.lightbox-next,.lightbox-close{position:absolute;color:#fff;cursor:pointer;background:rgba(0,0,0,0.5);border-radius:50%;display:flex;align-items:center;justify-content:center}.lightbox-prev,.lightbox-next{top:50%;transform:translateY(-50%);font-size:36px;width:60px;height:60px}.lightbox-close{top:20px;right:20px;font-size:24px;width:40px;height:40px}.lightbox-prev{left:20px}.lightbox-next{right:20px}.simple-toggle-btn{color:#007bff;text-decoration:none;font-size:13px;cursor:pointer}.simple-toggle-btn:hover{color:#0056b3;text-decoration:underline}.clean-search-panel{position:fixed;top:50%;left:50%;transform:translate(-50%,-50%);z-index:10001;background:#fff;border:1px solid #ddd;border-radius:8px;font-family:system-ui,sans-serif;width:750px;max-height:80vh;overflow:hidden;box-shadow:0 4px 16px rgba(0,0,0,0.2)}.clean-search-panel header{position:relative;padding:16px 20px;border-bottom:1px solid #e5e7eb;background:#f8f9fa;border-radius:8px 8px 0 0;font-size:15px;font-weight:600;color:#374151}.clean-forum-tree{padding:20px;max-height:500px;overflow-y:auto}.clean-forum-card{margin-bottom:20px;border:1px solid #e5e7eb;border-radius:8px;overflow:hidden;background:#fff}.clean-forum-card:last-child{margin-bottom:0}.clean-card-header{padding:12px 16px;background:#f1f5f9;border-bottom:1px solid #e5e7eb;display:flex;align-items:center;gap:10px}.main-forum-title{font-weight:600;font-size:14px;color:#1f2937;cursor:pointer}.main-forum-checkbox{margin:0;transform:scale(1.1)}.clean-card-content{padding:16px}.clean-sub-section{margin-bottom:16px;border-left:3px solid #e5e7eb;padding-left:12px}.clean-sub-section:last-child{margin-bottom:0}.clean-sub-header{display:flex;align-items:center;gap:8px;margin-bottom:12px}.sub-forum-title{font-weight:500;font-size:13px;color:#4b5563;cursor:pointer}.sub-forum-checkbox{margin:0}.clean-level4-grid{display:grid;grid-template-columns:repeat(auto-fit,minmax(160px,1fr));gap:8px;margin-left:20px}.clean-level4-item{display:flex;align-items:center;gap:6px;padding:8px 12px;background:#f9fafb;border:1px solid #f3f4f6;border-radius:6px;cursor:pointer;font-size:12px;color:#6b7280}.clean-level4-item:hover{background:#f3f4f6}.level4-forum-checkbox{margin:0;transform:scale(0.9)}.clean-compact-grid{display:grid;grid-template-columns:repeat(auto-fit,minmax(140px,1fr));gap:8px;padding:12px}.clean-compact-item{display:flex;align-items:center;gap:6px;padding:10px 12px;background:#fff;border:1px solid #e5e7eb;border-radius:6px;cursor:pointer;font-size:13px;color:#4b5563}.clean-compact-item:hover{background:#f9fafb}.compact-forum-checkbox{margin:0;transform:scale(1.05)}.filter-controls{display:flex;gap:10px}.clean-search-panel footer{padding:16px 20px;background:#f8f9fa;border-top:1px solid #e5e7eb;border-radius:0 0 8px 8px;display:flex;justify-content:space-between;align-items:center}.clean-search-panel button{padding:8px 16px;border:1px solid #d1d5db;border-radius:6px;background:#fff;color:#374151;cursor:pointer;font-size:13px;font-weight:500}.clean-search-panel button.secondary{background:#f9fafb}.clean-search-panel #search-save-settings-btn{background:#3b82f6;border-color:#3b82f6;color:#fff}.flex{display:flex}.items-center{align-items:center}.justify-center{justify-content:center}.gap-2{gap:0.5rem}.mb-3{margin-bottom:0.75rem}.p-3{padding:0.75rem}.text-center{text-align:center}.cursor-pointer{cursor:pointer}.close-x{position:absolute;top:12px;right:16px;width:24px;height:24px;border:none;background:none;color:#999;font-size:18px;cursor:pointer;display:flex;align-items:center;justify-content:center;line-height:1}.close-x:hover{color:#666}`
;document.head.appendChild(t)}static setImageGridWidth(e,t){let n;if(1===t)n="50%";else{const e=12*(t-1)
;n=`calc((100% - ${e}px) / ${t})`}Array.from(e.children).forEach(e=>{e.style.width=n;e.style.flex="0 0 auto"})}}
;s.styleElementId="ultra-minimal-styles";let o=s;class AdRemover{static removeAds(){
const e=document.querySelectorAll(CONFIG.selectors.threadRows);e.forEach(e=>{const t=e.querySelector("td.tal")
;if(t&&t.innerHTML.includes("headtopic_3.gif"))e.remove()});this.removeAdButtons()}static removeGlobalAds(){
this.removeAdButtons()}static removeAdButtons(){const e=["td_ID144","td_ID86","td_ID139"];e.forEach(e=>{
const t=document.getElementById(e);if(t){const e=t.closest("li");if(e)e.remove();else t.remove()}})}}
class DataExtractor{static extractImages(e){const t=CONFIG.getPreviewCount();let n=[]
;for(const l of CONFIG.selectors.imgSelectors){n=Array.from(e.querySelectorAll(l));if(n.length>0)break}
const a=n.filter(e=>{const t=e.getAttribute("style")||""
;if(t.includes("display: none")||t.includes("display:none"))return false;return true});let i=a.map(e=>({
src:e.getAttribute("data-original")||e.getAttribute("src")||"",img:e})).filter(e=>{
if(!e.src||e.src.length<4)return false;return true});i.sort((e,t)=>{const n=/\.(jpg|jpeg|png)$/i.test(e.src)
;const a=/\.(jpg|jpeg|png)$/i.test(t.src);if(n&&!a)return-1;if(!n&&a)return 1;return 0})
;const r=i.map(e=>e.src).slice(0,t);return r}static extractMagnet(e){let t=""
;let n=e.querySelector(CONFIG.selectors.magnetTextarea);if(n)t=n.value.trim();else{
let n=e.querySelector(CONFIG.selectors.magnetLink);if(n)t=n.getAttribute("href")||"";else{const n=e.body.innerHTML
;const a=n.match(CONFIG.regex.magnetHash);if(a&&a[1])t=`magnet:?xt=urn:btih:${a[1]}`}}return t}static extractEd2k(e){
let t="";const n=e.querySelector(CONFIG.selectors.ed2kLink);if(n)t=n.getAttribute("href")||"";else{
const n=e.body.innerHTML;const a=n.match(CONFIG.regex.ed2k);if(a&&a[0])t=a[0]}return t}static extractThunder(e){let t=""
;const n=e.body.innerHTML;const a=n.match(CONFIG.regex.thunder);if(a&&a[0])t=a[0];return t}}
class ExternalMagnetExtractor{static async extractFromPage(e){try{for(const t of CONFIG.btSites){
const n=e.match(t.pattern);if(n){const e=t.getHash(n[0]);const a=await this.fetchFromBtSite(t,e);if(a){
const e=this.cleanMagnetLink(a);return e}}}return null}catch(t){void 0;return null}}static cleanMagnetLink(e){
const t=e.match(/magnet:\?xt=urn:btih:([a-f0-9]{40})/i);if(t)return`magnet:?xt=urn:btih:${t[1]}`;return e}
static async fetchFromBtSite(e,t){try{return new Promise(n=>{const a={method:e.method,
url:"GET"===e.method?`${e.url}?name=${t}`:e.url,headers:{
Accept:"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8",
"User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36",
"Accept-Language":"zh-CN,zh;q=0.9,en;q=0.8",DNT:"1",Connection:"keep-alive","Upgrade-Insecure-Requests":"1"},onload:e=>{
if(e.status>=200&&e.status<300)try{const t=(new DOMParser).parseFromString(e.responseText,"text/html")
;const a=t.querySelector("#magnetInput");if(a){const e=a.value||a.getAttribute("value");if(e){
const t=e.replace(/&/g,"&");n(t);return}}const i=t.querySelector(".magnet-box input");if(i){
const e=i.getAttribute("value")||i.value;if(e){const t=e.replace(/&/g,"&");n(t);return}}
const r=e.responseText.match(/magnet:\?xt=urn:btih:[a-f0-9]{40}[^"'\s]*/i);if(r){const e=r[0].replace(/&/g,"&");n(e)
;return}n(null)}catch(t){void 0;n(null)}else n(null)},onerror:()=>n(null),ontimeout:()=>n(null)};if("POST"===e.method){
a.headers["Content-Type"]="application/x-www-form-urlencoded";a.headers["Referer"]=e.referer
;a.headers["Origin"]=e.referer;const n={};n[e.paramName]=t;a.data=new URLSearchParams(n).toString()}GM_xmlhttpRequest(a)
})}catch(n){void 0;return null}}}class UIComponents{static buildPreviewUI(e,t){
const{imgSrcs:n,magnet:a,ed2k:i,thunder:r}=t
;if(e.nextElementSibling&&e.nextElementSibling.classList.contains("imagePreviewTr"))return
;e.classList.add("thread-title-highlighted");const l=document.createElement("tr");l.className="imagePreviewTr"
;const s=document.createElement("td");s.colSpan=e.children.length;const o=document.createElement("div")
;o.className="preview-container";o.style.borderTop="none";if(n.length)o.appendChild(this.createImageSection(n))
;if(a)o.appendChild(this.createInfoSection(a));if(i)o.appendChild(this.createEd2kSection(i))
;if(r)o.appendChild(this.createThunderSection(r));s.appendChild(o);l.appendChild(s)
;e.parentNode.insertBefore(l,e.nextSibling)}static createImageSection(e){const t=document.createElement("div")
;t.className="preview-images";e.forEach((n,a)=>{if(n&&n.startsWith("http")){const i=document.createElement("div")
;i.className="preview-image-wrapper";const r=document.createElement("img");r.src=n;r.className="preview-image"
;r.onerror=()=>{i.style.display="none"};r.onload=()=>{if(r.naturalHeight>r.naturalWidth){
const e=r.naturalHeight/r.naturalWidth
;if(e>1.9&&r.naturalHeight>1800)r.style.objectPosition="top";else r.style.objectFit="contain"}}
;i.addEventListener("click",()=>l.showLightbox(e,a));i.appendChild(r);t.appendChild(i)}})
;if(t.children.length>0)o.setImageGridWidth(t,t.children.length);return t}static createInfoSection(t){
const n=document.createElement("div");n.className="preview-magnet";n.textContent=t;n.title="点击链接可复制"
;n.onclick=function(n){e.copyToClipboard(t,n)};return n}static createEd2kSection(t){
const n=document.createElement("div");n.className="preview-magnet";n.textContent=t;n.title="点击ed2k链接可复制"
;n.onclick=function(n){e.copyToClipboard(t,n)};return n}static createThunderSection(t){
const n=document.createElement("div");n.className="preview-magnet";n.textContent=t;n.title="点击迅雷链接可复制"
;n.onclick=function(n){e.copyToClipboard(t,n)};return n}}const c=class _SearchFilter{static init(){
if(this.initialized)return;if(!this.isSearchResultPage())return;this.filterSearchResults();this.updateResultStats()
;this.initialized=true}static isSearchResultPage(){if(!window.location.href.includes("search.php"))return false
;const e=document.querySelector(".t table");const t=document.querySelectorAll('tr[id^="search_"]')
;return!!(e&&t.length>0)}static extractForumId(e){const t=e.getAttribute("id");if(t&&t.startsWith("search_")){
const e=t.split("_");if(e.length>=2)return e[1]}return null}static getExcludedForums(){return CONFIG.getExcludedForums()
}static filterSearchResults(){const e=this.getExcludedForums();if(0===e.length)return
;const t=document.querySelectorAll('tr[id^="search_"]');this.totalCount=t.length;let n=0;t.forEach(t=>{
const a=this.extractForumId(t);if(a&&e.includes(a)){t.style.display="none";const e=t.nextElementSibling
;if(e&&e.classList.contains("imagePreviewTr"))e.style.display="none";n++}});this.filteredCount=n;if(n>0)void 0}
static updateResultStats(){if(0===this.filteredCount)return;const e=document.querySelector(".t table .h");if(e){
const t=e.textContent||"主题列表";const n=this.totalCount-this.filteredCount
;e.textContent=`${t} (显示 ${n}/${this.totalCount} 条结果,已过滤 ${this.filteredCount} 条)`
;e.setAttribute("title",`已根据设置隐藏${this.filteredCount}条不相关结果`)}}static reapplyFilter(){
if(!this.isSearchResultPage())return;const e=document.querySelectorAll('tr[id^="search_"], tr.imagePreviewTr')
;e.forEach(e=>{e.style.display=""});this.filteredCount=0;this.filterSearchResults();this.updateResultStats()}
static getFilterStats(){return{total:this.totalCount,filtered:this.filteredCount,
visible:this.totalCount-this.filteredCount}}static clearAllFilters(){CONFIG.setExcludedForums([]);this.reapplyFilter()}
static addExcludedForum(e){const t=this.getExcludedForums();if(!t.includes(e)){t.push(e);CONFIG.setExcludedForums(t)
;this.reapplyFilter()}}static removeExcludedForum(e){const t=this.getExcludedForums();const n=t.filter(t=>t!==e)
;CONFIG.setExcludedForums(n);this.reapplyFilter()}static toggleForumExclusion(e){const t=this.getExcludedForums()
;if(t.includes(e))this.removeExcludedForum(e);else this.addExcludedForum(e)}static shouldFilterRow(e){
const t=this.extractForumId(e);const n=this.getExcludedForums();return t?n.includes(t):false}};c.initialized=false
;c.filteredCount=0;c.totalCount=0;let d=c;class PreviewProcessor{static async processThreadLink(e){const t=e.href
;if(!t||!CONFIG.regex.threadUrl.test(t))return;const n=e.closest("tr")
;if(!n||n.querySelector('img[src*="headtopic"]'))return;if(d.shouldFilterRow(n))return;try{const e=await fetch(t)
;const a=await e.text();const i=new DOMParser;const r=i.parseFromString(a,"text/html")
;let l=DataExtractor.extractMagnet(r);if(!l){const e=await ExternalMagnetExtractor.extractFromPage(a);l=e||""}const s={
imgSrcs:DataExtractor.extractImages(r),magnet:l||"",ed2k:DataExtractor.extractEd2k(r),
thunder:DataExtractor.extractThunder(r)};if(!s.imgSrcs.length&&!s.magnet&&!s.ed2k&&!s.thunder)return
;UIComponents.buildPreviewUI(n,s)}catch(a){void 0}}}class App2048{static async displayThreadImages(){
if(e.isContentPage())return;e.removeRules();l.init();const t=e.safeQuerySelectorAll(CONFIG.selectors.threadLinks)
;if(t.length)await Promise.all(t.map(e=>PreviewProcessor.processThreadLink(e)))}static isSearchPage(){
return CONFIG.regex.searchUrl.test(window.location.href)&&null!==document.querySelector(CONFIG.selectors.searchResultTable)
}static async main(){try{i.init();o.injectStyles();if(e.isContentPage())return;if(this.isSearchPage()){d.init()
;await this.displayThreadImages()}else{AdRemover.removeAds();await this.displayThreadImages()}}catch(t){void 0}}}
AdRemover.removeGlobalAds();if("loading"===document.readyState)document.addEventListener("DOMContentLoaded",()=>{
AdRemover.removeGlobalAds();App2048.main()});else{AdRemover.removeGlobalAds();App2048.main()}
window.addEventListener("load",()=>{AdRemover.removeGlobalAds()})})();