(()=>{let e=(location.pathname||"").split("/").filter(Boolean).map(e=>e.toLowerCase());if(e.length&&"trades"===e[e.length-1]&&!window.__nru_trade_detail_cache_bridge_loaded){window.__nru_trade_detail_cache_bridge_loaded=!0;let s=500,c=18e5,f=new Map,m=new Map;function t(e,t){for(f.has(e)&&f.delete(e),f.set(e,{v:t,t:Date.now()});f.size>s;){let e=f.keys().next().value;f.delete(e)}}function r(e){if("string"!=typeof e)return e&&"object"==typeof e?e:null;try{return JSON.parse(e)}catch{return null}}function n(){return document.documentElement?.getAttribute("data-nru-trade-list-request-patch-loaded")||""}function i(e){let t=String(e||"").trim().toLowerCase();return"bundlethumbnail"===t||"bundle"===t?"BundleThumbnail":"Asset"}function l(e,t="Asset"){let r=parseInt(e,10);return r>0?`${i(t)}:${r}`:""}function u(e,t="",r="Asset"){let n=parseInt(e,10);if(!(n>0))return"";let l=i(r);return t||`${n}:undefined:${l}:150x150:webp:regular:0:`}function a(e,t="Asset"){let r=parseInt(e,10);if(!(r>0))return[];let n=[l(r,t),String(r)];return n.filter((e,t)=>e&&n.indexOf(e)===t)}function d(e){if(!e||"object"!=typeof e)return null;let t=i(e.type||""),r=String(e.size||"").trim(),n=String(e.format||"").trim().toLowerCase(),u=String(e.targetId||"").trim();return"150x150"===r&&"webp"===n&&u?{requestId:String(e.requestId||""),targetId:u,type:t,key:l(u,t)}:null}function o(e){let r=String(e||"").trim();if(!r)return Promise.resolve(null);let n=function(e){let t=f.get(e);if(t){if(!(Date.now()-t.t>c))return f.delete(e),f.set(e,t),t.v;f.delete(e)}}(r);if(void 0!==n)return Promise.resolve(n);let i=function(e){let r=String(e||"").trim();if(!r)return null;let n=window.__nte_trade_row_raw_cache;if(!n||"object"!=typeof n)return null;let i=n[r];if(!i||"object"!=typeof i)return null;if(!i.participantAOffer&&!i.participantBOffer&&!Array.isArray(i.offers))return null;let l=null==i.tradeId?{...i,tradeId:parseInt(r,10)||r}:i;return t(r,l),l}(r);if(i)return Promise.resolve(i);if(m.has(r))return m.get(r);let l=(u={type:"getCachedTrade",tradeId:r},new Promise(e=>{let t=!1,r=r=>{t||(t=!0,e(r))};try{let e=chrome.runtime.sendMessage(u,e=>{if(chrome.runtime.lastError)return r(null);r(e)});e&&"function"==typeof e.then&&e.then(r,()=>r(null))}catch{r(null)}})).then(e=>{if(!e||"object"!=typeof e)return null;if(!e.participantAOffer&&!e.participantBOffer&&!Array.isArray(e.offers))return null;let n=null==e.tradeId?{...e,tradeId:parseInt(r,10)||r}:e;return t(r,n),n}).catch(()=>null).finally(()=>{m.delete(r)});var u;return m.set(r,l),l}document.addEventListener("nru_trade_detail_cache_request",e=>{let t=r(e.detail),n=String(t?.request_id||"").trim(),i=String(t?.trade_id||"").trim();n&&i&&o(i).then(e=>{document.dispatchEvent(new CustomEvent("nru_trade_detail_cache_response",{detail:JSON.stringify({request_id:n,trade_id:i,trade:e||null})}))}).catch(()=>{document.dispatchEvent(new CustomEvent("nru_trade_detail_cache_response",{detail:JSON.stringify({request_id:n,trade_id:i,trade:null})}))})}),document.addEventListener("nru_trade_thumb_cache_request",e=>{let t=r(e.detail),n=String(t?.request_id||"").trim(),l=function(e){if(!Array.isArray(e)||!e.length)return null;let t=window.__nte_trade_thumb_meta_cache;if(!t||"object"!=typeof t)return null;let r=[];for(let n of e){let e=d(n);if(!e)return null;let l=null;for(let r of a(e.targetId,e.type)){let e=t[r];if(e&&"object"==typeof e&&e.imageUrl){l=e;break}}if(!l||"object"!=typeof l||!l.imageUrl)return null;r.push({requestId:u(e.targetId,e.requestId,e.type),errorCode:Number(l.errorCode)||0,errorMessage:String(l.errorMessage||""),targetId:parseInt(e.targetId,10)||e.targetId,type:i(l.type||e.type),state:String(l.state||"Completed"),imageUrl:String(l.imageUrl||""),version:String(l.version||"")})}return r}(Array.isArray(t?.requests)?t.requests:null);n&&document.dispatchEvent(new CustomEvent("nru_trade_thumb_cache_response",{detail:JSON.stringify({request_id:n,thumbs:l||null})}))}),async function(){if("1"===n())return!0;let e="";try{let t=await fetch(chrome.runtime.getURL("scripts/trade_list_request_patch.js"));e=t.ok?await t.text():""}catch{}if(!e)return!1;let t=document.createElement("script"),r=document.querySelector("script[nonce]"),i=r?.nonce||r?.getAttribute?.("nonce")||"",l=document.head||document.documentElement;return!!l&&(i&&t.setAttribute("nonce",i),t.textContent=`${e}\n;document.documentElement&&document.documentElement.setAttribute("data-nru-trade-list-request-patch-loaded","1");`,l.appendChild(t),t.remove(),"1"===n())}().catch(()=>{})}})();