tanhuazu-helper

tanhuazu.com 探花族论坛助手

As of 2023-03-11. See the latest version.

// ==UserScript==
// @name         tanhuazu-helper
// @namespace    tanhuazu-helper.xyjtyskfydhqss.none
// @version      0.1.0
// @author       xyjtyskfydhqss
// @description  tanhuazu.com 探花族论坛助手
// @license      MIT
// @icon         https://www.tanhuazu.com/favicon.ico
// @include      https://www.tanhuazu.com/*
// @include      https://tanhuazu.com/*
// @require      https://unpkg.com/react@18.2.0/umd/react.production.min.js
// @require      https://unpkg.com/react-dom@18.2.0/umd/react-dom.production.min.js
// @grant        GM.xmlHttpRequest
// @grant        GM_notification
// @grant        GM_openInTab
// ==/UserScript==

(e=>{const t=document.createElement("style");t.dataset.source="vite-plugin-monkey",t.innerText=e,document.head.appendChild(t)})(` ._preview-img-wrapper_1v8wn_1{z-index:500}._preview-img-wrapper_1v8wn_1 img{max-height:100%;max-width:100%}.tanhuazu-download-btn{position:relative;display:inline-block;font-weight:400;white-space:nowrap;text-align:center;background-image:none;background-color:transparent;border:1px solid transparent;cursor:pointer;transition:all .2s cubic-bezier(.645,.045,.355,1);user-select:none;touch-action:manipulation;line-height:1.57142857;font-size:16px;height:40px;border-radius:8px;color:#fff;background-color:#1677ff;outline:none;position:absolute;left:calc(100% + 10px);width:100px;top:0;height:auto;width:auto;font-size:30px;padding:5px;display:flex;align-items:center;justify-content:center;text-decoration:none}.tanhuazu-download-btn:hover,.tanhuazu-download-btn:visited{text-decoration:none}.tanhuazu .block-body .message:first-child .message-attribution{font-size:30px}.tanhuazu .structItem.structItem--thread.last-clicked{background-color:#ff8c00;color:#fff}.tanhuazu .structItem.structItem--thread.last-clicked a{color:#fff}
 `);

(function(v,Te){"use strict";function Oe(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var S={},Pe={get exports(){return S},set exports(e){S=e}};const xe=(e,t)=>Math.floor(Math.random()*(t-e+1)+e),oe=()=>{const e=new Error("Delay aborted");return e.name="AbortError",e},se=({clearTimeout:e,setTimeout:t,willResolve:o})=>(r,{value:s,signal:n}={})=>{if(n&&n.aborted)return Promise.reject(oe());let i,c,u;const a=e||clearTimeout,l=()=>{a(i),u(oe())},w=()=>{n&&n.removeEventListener("abort",l)},h=new Promise((y,m)=>{c=()=>{w(),o?y(s):m(s)},u=m,i=(t||setTimeout)(c,r)});return n&&n.addEventListener("abort",l,{once:!0}),h.clear=()=>{a(i),i=null,c()},h},ne=e=>{const t=se({...e,willResolve:!0});return t.reject=se({...e,willResolve:!1}),t.range=(o,r,s)=>t(xe(o,r),s),t},H=ne();H.createWithTimers=ne,Pe.exports=H,S.default=H;function Ae(){return new Promise(e=>{requestIdleCallback(()=>e(void 0))})}async function ke(){for(;;)await Me(),await S(1e3)}async function Me(){let e,t,o="",r="";const s=async()=>{var i,c,u;if(await Ae(),e=document.querySelector(".overlay-container.is-active .overlay"),!!e&&(o=((c=(i=e.querySelector(".overlay-title"))==null?void 0:i.textContent)==null?void 0:c.trim())??"",t=e==null?void 0:e.querySelector(".overlay-content .blockMessage"),r=((u=t==null?void 0:t.textContent)==null?void 0:u.trim())??"",o==="哎呀!我们遇到了一些问题。"&&r&&r.includes("您必须等待")&&r.includes("后才可以继续执行此操作")))return!0};for(;!await s();)await S(500);let n=Number(/您必须等待 (\d+) 秒后才可以继续执行此操作。/.exec(r)[1]);if(!(!n||isNaN(n))){for(;n>0;){if(!document.querySelector(".overlay-container.is-active .overlay"))return;await S(1e3),n--;const i=n>=60?`${Math.floor(n/60)} 分 ${n%60} 秒`:`${n} 秒`;t.textContent=`您必须等待 ${i} 后才可以继续执行此操作。`}await S(1e3),GM_notification({title:"tanhuazu.com 可以继续操作了",text:document.title,onclick(){GM_openInTab(location.href,{active:!0,insert:!0})}})}}function De(e){const t=e.trim();if(!t)return new Headers;const o=t.split(`\r
`).map(r=>{let s=r.split(":");return[s[0].trim(),s[1].trim()]});return new Headers(o)}function Le(e){const t=new Response(e.response,{statusText:e.statusText,status:e.status,headers:De(e.responseHeaders)});return Object.defineProperty(t,"url",{value:e.finalUrl}),t}async function je(e,t){const o=new Request(e,t);let r;return t!=null&&t.body&&(r=await o.text()),await qe(o,t,r)}function qe(e,t,o){return new Promise((r,s)=>{if(e.signal&&e.signal.aborted)return s(new DOMException("Aborted","AbortError"));GM.xmlHttpRequest({url:e.url,method:Ue(e.method.toUpperCase()),headers:Object.fromEntries(new Headers(t==null?void 0:t.headers).entries()),data:o,responseType:"blob",onload(n){r(Le(n))},onabort(){s(new DOMException("Aborted","AbortError"))},ontimeout(){s(new TypeError("Network request failed, timeout"))},onerror(n){s(new TypeError("Failed to fetch: "+n.finalUrl))}})})}const Ce=["GET","POST","PUT","DELETE","PATCH","HEAD","TRACE","OPTIONS","CONNECT"];function Ie(e,t){return e.includes(t)}function Ue(e){if(Ie(Ce,e))return e;throw new Error(`unsupported http method ${e}`)}class ae extends Error{constructor(t,o,r){const s=t.status||t.status===0?t.status:"",n=t.statusText||"",i=`${s} ${n}`.trim(),c=i?`status code ${i}`:"an unknown error";super(`Request failed with ${c}`),Object.defineProperty(this,"response",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"request",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"options",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.name="HTTPError",this.response=t,this.request=o,this.options=r}}class ie extends Error{constructor(t){super("Request timed out"),Object.defineProperty(this,"request",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.name="TimeoutError",this.request=t}}const q=e=>e!==null&&typeof e=="object",C=(...e)=>{for(const t of e)if((!q(t)||Array.isArray(t))&&typeof t<"u")throw new TypeError("The `options` argument must be an object");return V({},...e)},ce=(e={},t={})=>{const o=new globalThis.Headers(e),r=t instanceof globalThis.Headers,s=new globalThis.Headers(t);for(const[n,i]of s.entries())r&&i==="undefined"||i===void 0?o.delete(n):o.set(n,i);return o},V=(...e)=>{let t={},o={};for(const r of e)if(Array.isArray(r))Array.isArray(t)||(t=[]),t=[...t,...r];else if(q(r)){for(let[s,n]of Object.entries(r))q(n)&&s in t&&(n=V(t[s],n)),t={...t,[s]:n};q(r.headers)&&(o=ce(o,r.headers),t.headers=o)}return t},We=(()=>{let e=!1,t=!1;return typeof globalThis.ReadableStream=="function"&&(t=new globalThis.Request("https://a.com",{body:new globalThis.ReadableStream,method:"POST",get duplex(){return e=!0,"half"}}).headers.has("Content-Type")),e&&!t})(),Ne=typeof globalThis.AbortController=="function",Be=typeof globalThis.ReadableStream=="function",He=typeof globalThis.FormData=="function",ue=["get","post","put","patch","head","delete"],Ve={json:"application/json",text:"text/*",formData:"multipart/form-data",arrayBuffer:"*/*",blob:"*/*"},z=2147483647,le=Symbol("stop"),ze=e=>ue.includes(e)?e.toUpperCase():e,Fe=["get","put","head","delete","options","trace"],$e=[408,413,429,500,502,503,504],fe=[413,429,503],he={limit:2,methods:Fe,statusCodes:$e,afterStatusCodes:fe,maxRetryAfter:Number.POSITIVE_INFINITY,backoffLimit:Number.POSITIVE_INFINITY},Ge=(e={})=>{if(typeof e=="number")return{...he,limit:e};if(e.methods&&!Array.isArray(e.methods))throw new Error("retry.methods must be an array");if(e.statusCodes&&!Array.isArray(e.statusCodes))throw new Error("retry.statusCodes must be an array");return{...he,...e,afterStatusCodes:fe}};async function Ke(e,t,o){return new Promise((r,s)=>{const n=setTimeout(()=>{t&&t.abort(),s(new ie(e))},o.timeout);o.fetch(e).then(r).catch(s).then(()=>{clearTimeout(n)})})}const Je=Boolean(globalThis.DOMException);function de(e){if(Je)return new DOMException((e==null?void 0:e.reason)??"The operation was aborted.","AbortError");const t=new Error((e==null?void 0:e.reason)??"The operation was aborted.");return t.name="AbortError",t}async function Ye(e,{signal:t}){return new Promise((o,r)=>{if(t){if(t.aborted){r(de(t));return}t.addEventListener("abort",s,{once:!0})}function s(){r(de(t)),clearTimeout(n)}const n=setTimeout(()=>{t==null||t.removeEventListener("abort",s),o()},e)})}class I{static create(t,o){const r=new I(t,o),s=async()=>{if(r._options.timeout>z)throw new RangeError(`The \`timeout\` option cannot be greater than ${z}`);await Promise.resolve();let c=await r._fetch();for(const u of r._options.hooks.afterResponse){const a=await u(r.request,r._options,r._decorateResponse(c.clone()));a instanceof globalThis.Response&&(c=a)}if(r._decorateResponse(c),!c.ok&&r._options.throwHttpErrors){let u=new ae(c,r.request,r._options);for(const a of r._options.hooks.beforeError)u=await a(u);throw u}if(r._options.onDownloadProgress){if(typeof r._options.onDownloadProgress!="function")throw new TypeError("The `onDownloadProgress` option must be a function");if(!Be)throw new Error("Streams are not supported in your environment. `ReadableStream` is missing.");return r._stream(c.clone(),r._options.onDownloadProgress)}return c},i=r._options.retry.methods.includes(r.request.method.toLowerCase())?r._retry(s):s();for(const[c,u]of Object.entries(Ve))i[c]=async()=>{r.request.headers.set("accept",r.request.headers.get("accept")||u);const l=(await i).clone();if(c==="json"){if(l.status===204||(await l.clone().arrayBuffer()).byteLength===0)return"";if(o.parseJson)return o.parseJson(await l.text())}return l[c]()};return i}constructor(t,o={}){if(Object.defineProperty(this,"request",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"abortController",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_retryCount",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"_input",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_options",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this._input=t,this._options={credentials:this._input.credentials||"same-origin",...o,headers:ce(this._input.headers,o.headers),hooks:V({beforeRequest:[],beforeRetry:[],beforeError:[],afterResponse:[]},o.hooks),method:ze(o.method??this._input.method),prefixUrl:String(o.prefixUrl||""),retry:Ge(o.retry),throwHttpErrors:o.throwHttpErrors!==!1,timeout:typeof o.timeout>"u"?1e4:o.timeout,fetch:o.fetch??globalThis.fetch.bind(globalThis)},typeof this._input!="string"&&!(this._input instanceof URL||this._input instanceof globalThis.Request))throw new TypeError("`input` must be a string, URL, or Request");if(this._options.prefixUrl&&typeof this._input=="string"){if(this._input.startsWith("/"))throw new Error("`input` must not begin with a slash when using `prefixUrl`");this._options.prefixUrl.endsWith("/")||(this._options.prefixUrl+="/"),this._input=this._options.prefixUrl+this._input}if(Ne){if(this.abortController=new globalThis.AbortController,this._options.signal){const r=this._options.signal;this._options.signal.addEventListener("abort",()=>{this.abortController.abort(r.reason)})}this._options.signal=this.abortController.signal}if(We&&(this._options.duplex="half"),this.request=new globalThis.Request(this._input,this._options),this._options.searchParams){const s="?"+(typeof this._options.searchParams=="string"?this._options.searchParams.replace(/^\?/,""):new URLSearchParams(this._options.searchParams).toString()),n=this.request.url.replace(/(?:\?.*?)?(?=#|$)/,s);(He&&this._options.body instanceof globalThis.FormData||this._options.body instanceof URLSearchParams)&&!(this._options.headers&&this._options.headers["content-type"])&&this.request.headers.delete("content-type"),this.request=new globalThis.Request(new globalThis.Request(n,{...this.request}),this._options)}this._options.json!==void 0&&(this._options.body=JSON.stringify(this._options.json),this.request.headers.set("content-type",this._options.headers.get("content-type")??"application/json"),this.request=new globalThis.Request(this.request,{body:this._options.body}))}_calculateRetryDelay(t){if(this._retryCount++,this._retryCount<this._options.retry.limit&&!(t instanceof ie)){if(t instanceof ae){if(!this._options.retry.statusCodes.includes(t.response.status))return 0;const r=t.response.headers.get("Retry-After");if(r&&this._options.retry.afterStatusCodes.includes(t.response.status)){let s=Number(r);return Number.isNaN(s)?s=Date.parse(r)-Date.now():s*=1e3,typeof this._options.retry.maxRetryAfter<"u"&&s>this._options.retry.maxRetryAfter?0:s}if(t.response.status===413)return 0}const o=.3;return Math.min(this._options.retry.backoffLimit,o*2**(this._retryCount-1)*1e3)}return 0}_decorateResponse(t){return this._options.parseJson&&(t.json=async()=>this._options.parseJson(await t.text())),t}async _retry(t){try{return await t()}catch(o){const r=Math.min(this._calculateRetryDelay(o),z);if(r!==0&&this._retryCount>0){await Ye(r,{signal:this._options.signal});for(const s of this._options.hooks.beforeRetry)if(await s({request:this.request,options:this._options,error:o,retryCount:this._retryCount})===le)return;return this._retry(t)}throw o}}async _fetch(){for(const t of this._options.hooks.beforeRequest){const o=await t(this.request,this._options);if(o instanceof Request){this.request=o;break}if(o instanceof Response)return o}return this._options.timeout===!1?this._options.fetch(this.request.clone()):Ke(this.request.clone(),this.abortController,this._options)}_stream(t,o){const r=Number(t.headers.get("content-length"))||0;let s=0;return t.status===204?(o&&o({percent:1,totalBytes:r,transferredBytes:s},new Uint8Array),new globalThis.Response(null,{status:t.status,statusText:t.statusText,headers:t.headers})):new globalThis.Response(new globalThis.ReadableStream({async start(n){const i=t.body.getReader();o&&o({percent:0,transferredBytes:0,totalBytes:r},new Uint8Array);async function c(){const{done:u,value:a}=await i.read();if(u){n.close();return}if(o){s+=a.byteLength;const l=r===0?0:s/r;o({percent:l,transferredBytes:s,totalBytes:r},a)}n.enqueue(a),await c()}await c()}}),{status:t.status,statusText:t.statusText,headers:t.headers})}}/*! MIT License © Sindre Sorhus */const F=e=>{const t=(o,r)=>I.create(o,C(e,r));for(const o of ue)t[o]=(r,s)=>I.create(r,C(e,s,{method:o}));return t.create=o=>F(C(o)),t.extend=o=>F(C(e,o)),t.stop=le,t},pe=F(),Xe=pe.extend({fetch:je});async function Qe(){var b,R,g;const e=()=>document.querySelector('.block-body article.message .message-body a[href*="obdown.com"][href*=".torrent"]'),t=performance.now()+5e3;for(;!e()&&performance.now()<t;)await S(500);const o=e();if(!o)return;const r=o.getAttribute("href");if(!r)return;console.log("[tanhuazu-helper]: torrent download page %s",r);const s=await Xe.get(r,{retry:5}).text(),i=new DOMParser().parseFromString(s,"text/html"),c=Array.from(i.querySelectorAll("span.text-secondary")).filter(E=>{var L;return((L=E.textContent)==null?void 0:L.trim())==="MAGENT"})[0],u=(R=(b=c==null?void 0:c.nextElementSibling)==null?void 0:b.querySelector('a[href^="magnet:?xt="]'))==null?void 0:R.getAttribute("href");if(console.log("[tanhuazu-helper]: magnet link %s",u),!u)return;const a=document.querySelector(".block-body article.message");a.style.position="relative";const l=(g=a.querySelector('a[aria-label="分享"]'))==null?void 0:g.parentElement,w=document.createElement("li");w.innerHTML=`
    <a href="${u}" class="message-attribution-gadget" title="磁力链接">
      <svg viewBox="64 64 896 896" focusable="false" data-icon="download" width="1em" height="1em" fill="currentColor" aria-hidden="true"><path d="M505.7 661a8 8 0 0012.6 0l112-141.7c4.1-5.2.4-12.9-6.3-12.9h-74.1V168c0-4.4-3.6-8-8-8h-60c-4.4 0-8 3.6-8 8v338.3H400c-6.7 0-10.4 7.7-6.3 12.9l112 141.8zM878 626h-60c-4.4 0-8 3.6-8 8v154H214V634c0-4.4-3.6-8-8-8h-60c-4.4 0-8 3.6-8 8v198c0 17.7 14.3 32 32 32h684c17.7 0 32-14.3 32-32V634c0-4.4-3.6-8-8-8z"></path></svg>
    </a>
  `,l==null||l.insertAdjacentElement("afterend",w),l==null||l.remove();const h=()=>{const E=document.createElement("a");return E.href=u,E.innerHTML=`
      <svg viewBox="64 64 896 896" focusable="false" data-icon="download" width="1em" height="1em" fill="currentColor" aria-hidden="true"><path d="M505.7 661a8 8 0 0012.6 0l112-141.7c4.1-5.2.4-12.9-6.3-12.9h-74.1V168c0-4.4-3.6-8-8-8h-60c-4.4 0-8 3.6-8 8v338.3H400c-6.7 0-10.4 7.7-6.3 12.9l112 141.8zM878 626h-60c-4.4 0-8 3.6-8 8v154H214V634c0-4.4-3.6-8-8-8h-60c-4.4 0-8 3.6-8 8v198c0 17.7 14.3 32 32 32h684c17.7 0 32-14.3 32-32V634c0-4.4-3.6-8-8-8z"></path></svg>
      <span>下载</span>
    `,E.className="tanhuazu-download-btn",E},y=h();a.appendChild(y);const m=h();m.style.top="unset",m.style.bottom="0",a.appendChild(m)}var $={},Ze={get exports(){return $},set exports(e){$=e}},U={};/**
 * @license React
 * react-jsx-runtime.production.min.js
 *
 * Copyright (c) Facebook, Inc. and its affiliates.
 *
 * This source code is licensed under the MIT license found in the
 * LICENSE file in the root directory of this source tree.
 */var et=v,tt=Symbol.for("react.element"),rt=Symbol.for("react.fragment"),ot=Object.prototype.hasOwnProperty,st=et.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,nt={key:!0,ref:!0,__self:!0,__source:!0};function ye(e,t,o){var r,s={},n=null,i=null;o!==void 0&&(n=""+o),t.key!==void 0&&(n=""+t.key),t.ref!==void 0&&(i=t.ref);for(r in t)ot.call(t,r)&&!nt.hasOwnProperty(r)&&(s[r]=t[r]);if(e&&e.defaultProps)for(r in t=e.defaultProps,t)s[r]===void 0&&(s[r]=t[r]);return{$$typeof:tt,type:e,key:n,ref:i,props:s,_owner:st.current}}U.Fragment=rt,U.jsx=ye,U.jsxs=ye,function(e){e.exports=U}(Ze);const G=$.jsx;var me,be=Te;me=be.createRoot,be.hydrateRoot;const at=Symbol(),K=Symbol(),k="a",M="w";let it=(e,t)=>new Proxy(e,t);const J=Object.getPrototypeOf,Y=new WeakMap,we=e=>e&&(Y.has(e)?Y.get(e):J(e)===Object.prototype||J(e)===Array.prototype),W=e=>typeof e=="object"&&e!==null,ct=e=>{if(Array.isArray(e))return Array.from(e);const t=Object.getOwnPropertyDescriptors(e);return Object.values(t).forEach(o=>{o.configurable=!0}),Object.create(J(e),t)},X=e=>e[K]||e,ge=(e,t,o,r)=>{if(!we(e))return e;let s=r&&r.get(e);if(!s){const u=X(e);s=(a=>Object.values(Object.getOwnPropertyDescriptors(a)).some(l=>!l.configurable&&!l.writable))(u)?[u,ct(u)]:[u],r==null||r.set(e,s)}const[n,i]=s;let c=o&&o.get(n);return c&&c[1].f===!!i||(c=((u,a)=>{const l={f:a};let w=!1;const h=(m,b)=>{if(!w){let R=l[k].get(u);if(R||(R={},l[k].set(u,R)),m===M)R[M]=!0;else{let g=R[m];g||(g=new Set,R[m]=g),g.add(b)}}},y={get:(m,b)=>b===K?u:(h("k",b),ge(Reflect.get(m,b),l[k],l.c)),has:(m,b)=>b===at?(w=!0,l[k].delete(u),!0):(h("h",b),Reflect.has(m,b)),getOwnPropertyDescriptor:(m,b)=>(h("o",b),Reflect.getOwnPropertyDescriptor(m,b)),ownKeys:m=>(h(M),Reflect.ownKeys(m))};return a&&(y.set=y.deleteProperty=()=>!1),[y,l]})(n,!!i),c[1].p=it(i||n,c[0]),o&&o.set(n,c)),c[1][k]=t,c[1].c=o,c[1].p},Re=(e,t,o,r)=>{if(Object.is(e,t))return!1;if(!W(e)||!W(t))return!0;const s=o.get(X(e));if(!s)return!0;if(r){const i=r.get(e);if(i&&i.n===t)return i.g;r.set(e,{n:t,g:!1})}let n=null;try{for(const i of s.h||[])if(n=Reflect.has(e,i)!==Reflect.has(t,i),n)return n;if(s[M]===!0){if(n=((i,c)=>{const u=Reflect.ownKeys(i),a=Reflect.ownKeys(c);return u.length!==a.length||u.some((l,w)=>l!==a[w])})(e,t),n)return n}else for(const i of s.o||[])if(n=!!Reflect.getOwnPropertyDescriptor(e,i)!=!!Reflect.getOwnPropertyDescriptor(t,i),n)return n;for(const i of s.k||[])if(n=Re(e[i],t[i],o,r),n)return n;return n===null&&(n=!0),n}finally{r&&r.set(e,{n:t,g:n})}},ut=e=>we(e)&&e[K]||null,_e=(e,t=!0)=>{Y.set(e,t)},lt=(e,t,o)=>{const r=[],s=new WeakSet,n=(i,c)=>{if(s.has(i))return;W(i)&&s.add(i);const u=W(i)&&t.get(X(i));if(u){var a,l;if((a=u.h)==null||a.forEach(h=>{const y=`:has(${String(h)})`;r.push(c?[...c,y]:[y])}),u[M]===!0){const h=":ownKeys";r.push(c?[...c,h]:[h])}else{var w;(w=u.o)==null||w.forEach(h=>{const y=`:hasOwn(${String(h)})`;r.push(c?[...c,y]:[y])})}(l=u.k)==null||l.forEach(h=>{o&&!("value"in(Object.getOwnPropertyDescriptor(i,h)||{}))||n(i[h],c?[...c,h]:[h])})}else c&&r.push(c)};return n(e),r},Q=e=>typeof e=="object"&&e!==null,T=new WeakMap,D=new WeakSet,ft=(e=Object.is,t=(a,l)=>new Proxy(a,l),o=a=>Q(a)&&!D.has(a)&&(Array.isArray(a)||!(Symbol.iterator in a))&&!(a instanceof WeakMap)&&!(a instanceof WeakSet)&&!(a instanceof Error)&&!(a instanceof Number)&&!(a instanceof Date)&&!(a instanceof String)&&!(a instanceof RegExp)&&!(a instanceof ArrayBuffer),r=a=>{switch(a.status){case"fulfilled":return a.value;case"rejected":throw a.reason;default:throw a}},s=new WeakMap,n=(a,l,w=r)=>{const h=s.get(a);if((h==null?void 0:h[0])===l)return h[1];const y=Array.isArray(a)?[]:Object.create(Object.getPrototypeOf(a));return _e(y,!0),s.set(a,[l,y]),Reflect.ownKeys(a).forEach(m=>{if(Object.getOwnPropertyDescriptor(y,m))return;const b=Reflect.get(a,m),R={value:b,enumerable:!0,configurable:!0};if(D.has(b))_e(b,!1);else if(b instanceof Promise)delete R.value,R.get=()=>w(b);else if(T.has(b)){const[g,E]=T.get(b);R.value=n(g,E(),w)}Object.defineProperty(y,m,R)}),y},i=new WeakMap,c=[1,1],u=a=>{if(!Q(a))throw new Error("object required");const l=i.get(a);if(l)return l;let w=c[0];const h=new Set,y=(p,d=++c[0])=>{w!==d&&(w=d,h.forEach(f=>f(p,d)))};let m=c[1];const b=(p=++c[1])=>(m!==p&&!h.size&&(m=p,g.forEach(([d])=>{const f=d[1](p);f>w&&(w=f)})),w),R=p=>(d,f)=>{const _=[...d];_[1]=[p,..._[1]],y(_,f)},g=new Map,E=(p,d)=>{if(({BASE_URL:"/",MODE:"production",DEV:!1,PROD:!0,SSR:!1}&&"production")!=="production"&&g.has(p))throw new Error("prop listener already exists");if(h.size){const f=d[3](R(p));g.set(p,[d,f])}else g.set(p,[d])},L=p=>{var d;const f=g.get(p);f&&(g.delete(p),(d=f[1])==null||d.call(f))},Wt=p=>(h.add(p),h.size===1&&g.forEach(([f,_],A)=>{if(({BASE_URL:"/",MODE:"production",DEV:!1,PROD:!0,SSR:!1}&&"production")!=="production"&&_)throw new Error("remove already exists");const j=f[3](R(A));g.set(A,[f,j])}),()=>{h.delete(p),h.size===0&&g.forEach(([f,_],A)=>{_&&(_(),g.set(A,[f]))})}),re=Array.isArray(a)?[]:Object.create(Object.getPrototypeOf(a)),N=t(re,{deleteProperty(p,d){const f=Reflect.get(p,d);L(d);const _=Reflect.deleteProperty(p,d);return _&&y(["delete",[d],f]),_},set(p,d,f,_){const A=Reflect.has(p,d),j=Reflect.get(p,d,_);if(A&&(e(j,f)||i.has(f)&&e(j,i.get(f))))return!0;L(d),Q(f)&&(f=ut(f)||f);let B=f;if(f instanceof Promise)f.then(P=>{f.status="fulfilled",f.value=P,y(["resolve",[d],P])}).catch(P=>{f.status="rejected",f.reason=P,y(["reject",[d],P])});else{!T.has(f)&&o(f)&&(B=u(f));const P=!D.has(B)&&T.get(B);P&&E(d,P)}return Reflect.set(p,d,B,_),y(["set",[d],f,j]),!0}});i.set(a,N);const Nt=[re,b,n,Wt];return T.set(N,Nt),Reflect.ownKeys(a).forEach(p=>{const d=Object.getOwnPropertyDescriptor(a,p);"value"in d&&(N[p]=a[p],delete d.value,delete d.writable),Object.defineProperty(re,p,d)}),N})=>[u,T,D,e,t,o,r,s,n,i,c],[ht]=ft();function dt(e={}){return ht(e)}function pt(e,t,o){const r=T.get(e);({BASE_URL:"/",MODE:"production",DEV:!1,PROD:!0,SSR:!1}&&"production")!=="production"&&!r&&console.warn("Please use proxy object");let s;const n=[],i=r[3];let c=!1;const a=i(l=>{if(n.push(l),o){t(n.splice(0));return}s||(s=Promise.resolve().then(()=>{s=void 0,c&&t(n.splice(0))}))});return c=!0,()=>{c=!1,a()}}function ve(e,t){const o=T.get(e);({BASE_URL:"/",MODE:"production",DEV:!1,PROD:!0,SSR:!1}&&"production")!=="production"&&!o&&console.warn("Please use proxy object");const[r,s,n]=o;return n(r,s(),t)}function yt(e){return D.add(e),e}var Z={},mt={get exports(){return Z},set exports(e){Z=e}},Ee={};/**
 * @license React
 * use-sync-external-store-shim.production.min.js
 *
 * Copyright (c) Facebook, Inc. and its affiliates.
 *
 * This source code is licensed under the MIT license found in the
 * LICENSE file in the root directory of this source tree.
 */var x=v;function bt(e,t){return e===t&&(e!==0||1/e===1/t)||e!==e&&t!==t}var wt=typeof Object.is=="function"?Object.is:bt,gt=x.useState,Rt=x.useEffect,_t=x.useLayoutEffect,vt=x.useDebugValue;function Et(e,t){var o=t(),r=gt({inst:{value:o,getSnapshot:t}}),s=r[0].inst,n=r[1];return _t(function(){s.value=o,s.getSnapshot=t,ee(s)&&n({inst:s})},[e,o,t]),Rt(function(){return ee(s)&&n({inst:s}),e(function(){ee(s)&&n({inst:s})})},[e]),vt(o),o}function ee(e){var t=e.getSnapshot;e=e.value;try{var o=t();return!wt(e,o)}catch{return!0}}function St(e,t){return t()}var Tt=typeof window>"u"||typeof window.document>"u"||typeof window.document.createElement>"u"?St:Et;Ee.useSyncExternalStore=x.useSyncExternalStore!==void 0?x.useSyncExternalStore:Tt,function(e){e.exports=Ee}(mt);const Ot=Oe(Z),{use:Se}=v,{useSyncExternalStore:Pt}=Ot,xt=(e,t)=>{const o=v.useRef();v.useEffect(()=>{o.current=lt(e,t,!0)}),v.useDebugValue(o.current)},At=new WeakMap;function kt(e,t){const o=t==null?void 0:t.sync,r=v.useRef(),s=v.useRef();let n=!0;const i=Pt(v.useCallback(a=>{const l=pt(e,a,o);return a(),l},[e,o]),()=>{const a=ve(e,Se);try{if(!n&&r.current&&s.current&&!Re(r.current,a,s.current,new WeakMap))return r.current}catch{}return a},()=>ve(e,Se));n=!1;const c=new WeakMap;v.useEffect(()=>{r.current=i,s.current=c}),({BASE_URL:"/",MODE:"production",DEV:!1,PROD:!0,SSR:!1}&&"production")!=="production"&&xt(i,c);const u=v.useMemo(()=>new WeakMap,[]);return ge(i,c,u,At)}const Mt={previewImgWrapper:"_preview-img-wrapper_1v8wn_1"};function Dt(){const e=document.querySelector(".block-body");e&&(e.onmouseover=async t=>{const o=t.target;if(o.tagName.toLowerCase()!=="a"||!new URL(o.href,location.href).pathname.startsWith("/threads/"))return;const s=o.href.replace(/unread/,"");console.log("hover: %s",s),O.a=yt(o),O.threadUrl=s;const n=await Lt(s);if(console.log(n),O.threadUrl===s&&(O.imgs=n),!te){const i=document.createElement("div");i.classList.add("preview-img-root"),document.body.appendChild(i),te=me(i),te.render(G(jt,{}))}},e.onmouseout=function(t){O.a=void 0,O.threadUrl="",O.imgs=[]})}async function Lt(e){const t=await pe.get(e,{cache:"force-cache"}).text(),r=new DOMParser().parseFromString(t,"text/html");return Array.from(r.querySelectorAll(".block-body .message:first-child .bbImageWrapper img")).map(n=>n.src)}const O=dt({threadUrl:"",a:void 0,imgs:[]});function jt(){const{imgs:e,a:t}=kt(O),o=v.useMemo(()=>{const r=t==null?void 0:t.getBoundingClientRect();return((r==null?void 0:r.right)||0)+50},[t]);return e.length?G("div",{className:Mt.previewImgWrapper,style:{position:"fixed",left:o,top:10,width:`calc(100vw - ${o}px - 20px)`,height:"calc(100vh - 20px)",overflow:"hidden"},children:e.slice(0,1).map(r=>G("img",{src:r,alt:""},r))}):null}let te;function qt(){const e=document.querySelector(".block-body");e&&(e.onclick=t=>{It(t),Ct(t)},Dt())}function Ct(e){const t=e.target;if(t.tagName.toLowerCase()!=="a")return;const o=new URL(t.href,location.href);if(o.pathname.startsWith("/threads/")&&o.pathname.includes("unread")){e.preventDefault();const r=t.href.replace(/unread/,"");GM_openInTab(r)}}function It(e){const t=e.target.closest(".structItem.structItem--thread");t==null||t.classList.add("last-clicked"),document.querySelectorAll(".block-body .structItem.structItem--thread").forEach(o=>{o!==t&&o.classList.remove("last-clicked")})}const Vt="";Ut();function Ut(){if(document.body.classList.add("tanhuazu"),location.pathname.startsWith("/threads/")){ke(),Qe();return}if(location.pathname.startsWith("/forums/"))return qt()}})(React,ReactDOM);