Sid Gifari File Manager
🏠 Root
/
home
/
genremedia08
/
thepassage.overlookedtracks.com
/
wp-content9
/
plugins
/
echo-knowledge-base
/
js
/
ai
/
Editing: admin-ai-util.min.js
(function(){"use strict";const{apiFetch:t}=wp;const{__:e}=wp.i18n;window.EPKB_AI_Util_React=window.EPKB_AI_Util_React||{};document.addEventListener("DOMContentLoaded",(function(){const e=document.getElementById("epkb-ai-admin-react-root");if(e&&e.dataset.epkbAiSettings){try{const n=JSON.parse(e.dataset.epkbAiSettings);if(n.nonce){t.use(t.createNonceMiddleware(n.nonce));window.epkbNonceInitialized=true}}catch(t){console.error("Failed to initialize nonce middleware",t)}}}));const n=(t,e="info",n=1e4)=>{o(t,e,n)};const o=(t,n,o)=>{const a=s();const i=a.querySelectorAll(`.epkb-ai-notification-${n}`);for(const e of i){const n=e.querySelector(".epkb-ai-notification-message");if(n&&n.textContent===t){e.style.animation="none";setTimeout((()=>{e.style.animation="slideDown 0.3s ease-out"}),10);return}}const r=document.createElement("div");let c="";let l="";switch(n){case"error":c="dashicons-warning";l="#dc3545";break;case"success":c="dashicons-yes-alt";l="#28a745";break;case"warning":c="dashicons-info";l="#ffc107";break;default:c="dashicons-info-outline";l="#007cba"}r.className=`epkb-ai-notification epkb-ai-notification-${n}`;r.style.borderLeft=`4px solid ${l}`;r.innerHTML=`\n\t\t\t<div class="epkb-ai-notification-content" style="\n\t\t\t\tdisplay: flex;\n\t\t\t\talign-items: center;\n\t\t\t\tpadding: 20px 24px;\n\t\t\t\tmin-height: 80px;\n\t\t\t">\n\t\t\t\t<span class="dashicons ${c}" style="\n\t\t\t\t\tfont-size: 48px;\n\t\t\t\t\tcolor: ${l};\n\t\t\t\t\tmargin-right: 34px;\n\t\t\t\t\tflex-shrink: 0;\n\t\t\t\t\tdisplay: flex;\n\t\t\t\t\talign-items: center;\n\t\t\t\t"></span>\n\t\t\t\t<span class="epkb-ai-notification-message" style="\n\t\t\t\t\tflex: 1;\n\t\t\t\t\tfont-size: 16px;\n\t\t\t\t\tline-height: 1.5;\n\t\t\t\t\tcolor: #333;\n\t\t\t\t\tfont-weight: 500;\n\t\t\t\t">${p(t)}</span>\n\t\t\t\t<button class="epkb-ai-notification-close" aria-label="${e("Close","echo-knowledge-base")}" style="\n\t\t\t\t\tbackground: none;\n\t\t\t\t\tborder: none;\n\t\t\t\t\tcursor: pointer;\n\t\t\t\t\tpadding: 8px;\n\t\t\t\t\tmargin-left: 16px;\n\t\t\t\t\topacity: 0.6;\n\t\t\t\t\ttransition: opacity 0.2s;\n\t\t\t\t" onmouseover="this.style.opacity='1'" onmouseout="this.style.opacity='0.6'">\n\t\t\t\t\t<span class="dashicons dashicons-dismiss" style="\n\t\t\t\t\t\tfont-size: 24px;\n\t\t\t\t\t\tcolor: #666;\n\t\t\t\t\t"></span>\n\t\t\t\t</button>\n\t\t\t</div>\n\t\t`;if(!document.querySelector("#epkb-notification-styles")){const t=document.createElement("style");t.id="epkb-notification-styles";t.innerHTML=`\n\t\t\t\t@keyframes slideDown {\n\t\t\t\t\tfrom {\n\t\t\t\t\t\ttransform: translateY(-20px);\n\t\t\t\t\t\topacity: 0;\n\t\t\t\t\t}\n\t\t\t\t\tto {\n\t\t\t\t\t\ttransform: translateY(0);\n\t\t\t\t\t\topacity: 1;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\t.epkb-ai-notification-fade-out {\n\t\t\t\t\tanimation: fadeOut 0.3s ease-out forwards;\n\t\t\t\t}\n\t\t\t\t@keyframes fadeOut {\n\t\t\t\t\tfrom {\n\t\t\t\t\t\topacity: 1;\n\t\t\t\t\t\ttransform: translateY(0);\n\t\t\t\t\t}\n\t\t\t\t\tto {\n\t\t\t\t\t\topacity: 0;\n\t\t\t\t\t\ttransform: translateY(-10px);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t`;document.head.appendChild(t)}const d=r.querySelector(".epkb-ai-notification-close");d.addEventListener("click",(()=>{r.classList.add("epkb-ai-notification-fade-out");setTimeout((()=>r.remove()),300)}));a.appendChild(r);if(o>0){setTimeout((()=>{if(r.parentNode){r.classList.add("epkb-ai-notification-fade-out");setTimeout((()=>r.remove()),300)}}),o)}};const s=()=>{let t=document.getElementById("epkb-ai-notifications");if(!t){t=document.createElement("div");t.id="epkb-ai-notifications";t.className="epkb-ai-notifications-container";const e=document.querySelector(".epkb-ai-tabs-nav");if(e&&e.parentNode){e.parentNode.insertBefore(t,e.nextSibling)}else{document.body.appendChild(t)}}return t};const a=(t,e=1e4)=>{n(t,"success",e)};const i=(t,e=0)=>{n(t,"error",e);window.scrollTo({top:0,behavior:"smooth"})};const r=(t,e=1e4)=>{n(t,"info",e)};const c=(t,e=1e4)=>{n(t,"warning",e)};const l={activeRequests:new Map,cancelRequest(t){const e=this.activeRequests.get(t);if(e){e.abort();this.activeRequests.delete(t)}},registerRequest(t){this.cancelRequest(t);const e=new AbortController;this.activeRequests.set(t,e);return e},completeRequest(t){this.activeRequests.delete(t)}};const d=async(n,o={})=>{const{suppressNotifications:s=false,...a}=o;const r=document.getElementById("epkb-ai-admin-react-root");if(r&&r.dataset.epkbAiSettings){try{const e=JSON.parse(r.dataset.epkbAiSettings);if(e.nonce&&!window.epkbNonceInitialized){t.use(t.createNonceMiddleware(e.nonce));window.epkbNonceInitialized=true}}catch(t){console.error("Failed to ensure nonce middleware",t)}}const c={path:`/epkb-admin/v1/${n}`,method:"GET",headers:{"Content-Type":"application/json"}};const d={...c,...a};let p=null;let f=null;if(n==="sync-progress"&&!o.allowConcurrent){p="sync-progress";f=l.registerRequest(p);d.signal=f.signal}else if(o.signal){d.signal=o.signal}if(d.params&&d.method==="GET"){const t=new URLSearchParams(d.params).toString();d.path+=`?${t}`;delete d.params}if(d.data&&["POST","PUT","PATCH","DELETE"].includes(d.method)){d.body=JSON.stringify(d.data);delete d.data}try{const e=await t(d);if(e.new_token){u(e.new_token)}return e}catch(t){if(t.name==="AbortError"){throw t}if(!s){if(t.code==="invalid_session"||t.code==="no_session"){i(e("Your session has expired. Please refresh the page.","echo-knowledge-base"))}else if(t.code==="rate_limit_exceeded"){i(e("Too many requests. Please wait a moment and try again.","echo-knowledge-base"))}else if(t.message&&t.code!="invalid_json"){i(t.message)}else{i(e("An unexpected error occurred. Please try again.","echo-knowledge-base"))}}throw t}finally{if(p){l.completeRequest(p)}}};const u=e=>{t.use(t.createNonceMiddleware(e));window.epkbNonceInitialized=true;const n=document.getElementById("epkb-ai-admin-react-root");if(n&&n.dataset.epkbAiSettings){try{const t=JSON.parse(n.dataset.epkbAiSettings);t.nonce=e;n.dataset.epkbAiSettings=JSON.stringify(t)}catch(t){console.error("Failed to update nonce in settings",t)}}};const p=t=>{const e={"&":"&","<":"<",">":">",'"':""","'":"'"};return t.replace(/[&<>"']/g,(t=>e[t]))};const f=(t,e)=>{let n;return function o(...s){const a=()=>{clearTimeout(n);t(...s)};clearTimeout(n);n=setTimeout(a,e)}};const g=(t,e)=>{let n;return function(...o){if(!n){t.apply(this,o);n=true;setTimeout((()=>n=false),e)}}};const m=(t,e="default")=>{const n=t instanceof Date?t:new Date(t);if(isNaN(n.getTime())){return""}const o={default:{year:"numeric",month:"short",day:"numeric"},short:{month:"numeric",day:"numeric",year:"2-digit"},long:{weekday:"long",year:"numeric",month:"long",day:"numeric"},time:{hour:"2-digit",minute:"2-digit"},datetime:{year:"numeric",month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"},full:{year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",second:"2-digit",hour12:true},compact:{month:"short",day:"numeric",hour:"numeric",minute:"2-digit",hour12:true}};if(e==="datetime"||e==="full"||e==="compact"){return n.toLocaleString(undefined,o[e]||o.default)}return n.toLocaleDateString(undefined,o[e]||o.default)};const b=(t,e="-")=>{if(!t||t==="Never"){return e}let n;if(t.includes("T")){n=new Date(t)}else{const e=t.replace(" ","T")+"Z";n=new Date(e)}if(isNaN(n.getTime())){return t}const o=n;const s=new Date;const a=o.toDateString()===s.toDateString();let i=o.getHours();const r=o.getMinutes();const c=i>=12?"pm":"am";i=i%12;i=i?i:12;const l=r<10?"0"+r:r;const d=`${i}:${l}${c}`;if(a){return`today at ${d}`}const u=new Date(s);u.setDate(u.getDate()-1);if(o.toDateString()===u.toDateString()){return`yesterday at ${d}`}const p=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];const f=p[o.getMonth()];const g=o.getDate();return`${f} ${g} at ${d}`};const h=(t,e)=>{const n=Object.assign({},t);if(y(t)&&y(e)){Object.keys(e).forEach((o=>{if(y(e[o])){if(!(o in t)){Object.assign(n,{[o]:e[o]})}else{n[o]=h(t[o],e[o])}}else{Object.assign(n,{[o]:e[o]})}}))}return n};const y=t=>t&&typeof t==="object"&&!Array.isArray(t);const k=(t,e,n=undefined)=>e.split(".").reduce(((t,e)=>t&&t[e]!==undefined?t[e]:n),t);const w=(t,e,n)=>{const o=e.split(".");const s=o.pop();const a=o.reduce(((t,e)=>{if(!t[e]||typeof t[e]!=="object"){t[e]={}}return t[e]}),t);a[s]=n;return t};const x=t=>{const e=/^[^\s@]+@[^\s@]+\.[^\s@]+$/;return e.test(t)};const S=(t="epkb")=>`${t}_${Date.now()}_${Math.random().toString(36).substr(2,9)}`;const _=async(t={})=>{const{title:n=e("Confirm Action","echo-knowledge-base"),message:o=e("Are you sure you want to proceed?","echo-knowledge-base"),confirmText:s=e("Confirm","echo-knowledge-base"),cancelText:a=e("Cancel","echo-knowledge-base"),confirmButtonClass:i="epkb-ai-button-primary",requireInput:r=false,inputPlaceholder:c="",inputMatch:l=""}=t;return new Promise((t=>{const e=document.createElement("div");e.className="epkb-ai-confirm-dialog-overlay";e.style.cssText=`\n\t\t\t\tposition: fixed;\n\t\t\t\ttop: 0;\n\t\t\t\tleft: 0;\n\t\t\t\tright: 0;\n\t\t\t\tbottom: 0;\n\t\t\t\tbackground: rgba(0, 0, 0, 0.5);\n\t\t\t\tdisplay: flex;\n\t\t\t\talign-items: center;\n\t\t\t\tjustify-content: center;\n\t\t\t\tz-index: 9999999;\n\t\t\t`;const d=document.createElement("div");d.className="epkb-ai-confirm-dialog";d.style.cssText=`\n\t\t\t\tbackground: white;\n\t\t\t\tborder-radius: 8px;\n\t\t\t\tpadding: 24px;\n\t\t\t\tmax-width: 500px;\n\t\t\t\twidth: 90%;\n\t\t\t\tbox-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);\n\t\t\t\tposition: relative;\n\t\t\t\tz-index: 9999999;\n\t\t\t`;let u=`\n\t\t\t\t<h3 style="margin: 0 0 16px 0; font-size: 18px; font-weight: 600;">${p(n)}</h3>\n\t\t\t\t<p style="margin: 0 0 20px 0; color: #555; line-height: 1.5;">${p(o)}</p>\n\t\t\t`;if(r){u+=`\n\t\t\t\t\t<input type="text" \n\t\t\t\t\t\t id="epkb-dialog-input" \n\t\t\t\t\t\t class="epkb-ai-input" \n\t\t\t\t\t\t placeholder="${p(c)}"\n\t\t\t\t\t\t style="width: 100%; margin-bottom: 20px; padding: 8px 12px; border: 1px solid #ddd; border-radius: 4px;">\n\t\t\t\t`}u+=`\n\t\t\t\t<div style="display: flex; justify-content: flex-end; gap: 10px;">\n\t\t\t\t\t<button class="epkb-ai-button epkb-ai-button-secondary" id="epkb-dialog-cancel">\n\t\t\t\t\t\t${p(a)}\n\t\t\t\t\t</button>\n\t\t\t\t\t<button class="epkb-ai-button ${i}" id="epkb-dialog-confirm">\n\t\t\t\t\t\t${p(s)}\n\t\t\t\t\t</button>\n\t\t\t\t</div>\n\t\t\t`;d.innerHTML=u;e.appendChild(d);document.body.appendChild(e);const f=d.querySelector("#epkb-dialog-confirm");const g=d.querySelector("#epkb-dialog-cancel");const m=d.querySelector("#epkb-dialog-input");if(m){m.focus()}const b=()=>{if(r){const e=m.value.trim();if(l&&e!==l){m.style.borderColor="#e74c3c";m.focus();return}y();t(e)}else{y();t(true)}};const h=()=>{y();t(false)};const y=()=>{document.body.removeChild(e)};f.addEventListener("click",b);g.addEventListener("click",h);e.addEventListener("click",(t=>{if(t.target===e){h()}}));if(m){m.addEventListener("keypress",(t=>{if(t.key==="Enter"){b()}}))}document.addEventListener("keydown",(function t(e){if(e.key==="Escape"){document.removeEventListener("keydown",t);h()}}))}))};let v=null;const N=({setupSteps:t,onTabSwitch:n,docLink:o})=>{const{createElement:s}=wp.element;if(!t||t.all_completed){return null}const a=t.steps||[];if(a.length===0){return null}const i=t.doc_link||o;const r=(t,n,o=null,s=true)=>{const a=t(n.target);if(!a.length){console.warn("Target element not found:",n.target);if(o){o()}return}if(v){try{const e=t(v);if(e.data("wp-pointer")){e.pointer("destroy")}}catch(t){}v=null}try{if(a.data("wp-pointer")){a.pointer("destroy")}}catch(t){}t(".wp-pointer").remove();const i="<h3>"+n.title+'</h3><div style="padding: 5px;">'+n.content+"</div>";a.pointer({content:i,position:{edge:"top",align:"center"},buttons:function(n,a){const i=t('<div style="display: flex; gap: 8px;"></div>');const r=s?e("Got it!","echo-knowledge-base"):e("Close","echo-knowledge-base");const c=t('<button type="button" class="button">'+r+"</button>");c.on("click",(function(){a.element.pointer("destroy");v=null}));i.append(c);if(o&&!s){const n=t('<button type="button" class="button button-primary">'+e("Next","echo-knowledge-base")+" →</button>");n.on("click",(function(){a.element.pointer("destroy");v=null;o()}));i.append(n)}return i}}).pointer("open");v=n.target};const c=(t,e,n=0)=>{if(n>=e.length){return}const o=e[n];const s=n===e.length-1;const a=s?null:()=>c(t,e,n+1);r(t,o,a,s)};const l=t=>{if(typeof jQuery==="undefined"){return}const e=jQuery;const n=t.pointer_sequence&&t.pointer_sequence.length>0;const o=t.pointer_target;if(!n&&!o){return}if(t.pointer_sub_tab){const o=e(".epkb-ai-sub-tab-"+t.pointer_sub_tab);if(o.length&&!o.hasClass("active")){o.trigger("click");setTimeout((()=>{if(n){c(e,t.pointer_sequence)}else{r(e,{target:t.pointer_target,title:t.pointer_title||t.title,content:t.pointer_content||t.description})}}),100);return}}if(n){c(e,t.pointer_sequence)}else{r(e,{target:t.pointer_target,title:t.pointer_title||t.title,content:t.pointer_content||t.description})}};return s("div",{className:"epkb-ai-setup-guide"},s("div",{className:"epkb-ai-setup-guide-header"},s("h3",null,e("Setup Steps","echo-knowledge-base"))),s("div",{className:"epkb-ai-setup-steps"},a.map(((t,o)=>{const a=o+1;const i=t.completed;const r=t.disabled;return s("div",{key:o,className:"epkb-ai-setup-step"+(r?" epkb-ai-setup-step-disabled":"")},s("span",{className:"epkb-ai-setup-step-number"+(i?" completed":"")},i?s("span",{className:"epkbfa epkbfa-check"}):a),s("div",{className:"epkb-ai-setup-step-content"},s("h4",null,t.title),s("p",null,t.description)),s("div",{className:"epkb-ai-setup-step-actions"},(t.pointer_target||t.pointer_sequence&&t.pointer_sequence.length>0)&&s("button",{type:"button",className:"epkb-ai-setup-step-show-me",onClick:e=>{e.stopPropagation();l(t)}},s("span",{className:"epkbfa epkbfa-hand-pointer-o"})," ",e("Show Me","echo-knowledge-base")),!i&&!r&&t.link_tab&&n&&s("button",{type:"button",className:"epkb-ai-setup-step-button",onClick:()=>n(t.link_tab)},e("Go to Settings","echo-knowledge-base")),!r&&t.link&&!t.link_tab&&s("a",{href:t.link,className:"epkb-ai-setup-step-button",target:t.link_external?"_blank":undefined,rel:t.link_external?"noopener noreferrer":undefined},t.link_label||e("Go to Settings","echo-knowledge-base")),o===0&&t.doc_link&&s("a",{href:t.doc_link,target:"_blank",rel:"noopener noreferrer",className:"epkb-ai-setup-step-doc-link"},e("Documentation","echo-knowledge-base"))))}))))};const T=({onAccept:t,i18n:n})=>{const{createElement:o}=wp.element;return o("div",{className:"epkb-ai-disabled-content"},o("div",{className:"epkb-ai-notice epkb-ai-notice-warning",style:{padding:"12px 15px",marginBottom:"20px",borderLeft:"4px solid #ffba00",backgroundColor:"#fff8e5"}},o("p",{style:{margin:"0"}},o("span",{className:"dashicons dashicons-info",style:{marginRight:"8px",color:"#ffba00"}}),e("To use AI features, please configure your API key and accept the data privacy agreement in ","echo-knowledge-base"),o("a",{href:"#",onClick:e=>{e.preventDefault();t()},style:{fontWeight:"bold",textDecoration:"underline"}},e("General Settings","echo-knowledge-base")),".")),o("div",{className:"epkb-ai-features-promo",style:{marginTop:"20px",textAlign:"center"}},o("img",{src:"https://www.echoknowledgebase.com/wp-content/uploads/2025/08/AI-Pro-Features-List.jpg",alt:e("AI Features","echo-knowledge-base"),style:{maxWidth:"100%",height:"auto",borderRadius:"8px",boxShadow:"0 2px 8px rgba(0, 0, 0, 0.1)"}})))};const E=async t=>{if(t.responseJSON&&t.responseJSON.error&&t.responseJSON.message){const n=document.createElement("div");n.innerHTML=t.responseJSON.message;const o=n.textContent||n.innerText||"";if(o.includes("Login")||o.includes("refresh")||o.includes("E03")){const t=await _({title:e("Session Expired","echo-knowledge-base"),message:o.trim(),confirmText:e("Refresh Page","echo-knowledge-base"),cancelText:e("Close","echo-knowledge-base"),confirmButtonClass:"epkb-ai-button-primary"});if(t){window.location.reload()}return true}}return false};const A=(t=e("Loading...","echo-knowledge-base"))=>{const n=document.createElement("div");n.className="epkb-ai-dialog-overlay";n.style.cssText=`\n\t\t\tposition: fixed;\n\t\t\ttop: 0;\n\t\t\tleft: 0;\n\t\t\tright: 0;\n\t\t\tbottom: 0;\n\t\t\tbackground: rgba(0, 0, 0, 0.5);\n\t\t\tdisplay: flex;\n\t\t\talign-items: center;\n\t\t\tjustify-content: center;\n\t\t\tz-index: 999999;\n\t\t`;const o=document.createElement("div");o.className="epkb-ai-dialog epkb-ai-loading-dialog";o.style.cssText=`\n\t\t\tbackground: white;\n\t\t\tpadding: 30px;\n\t\t\tborder-radius: 8px;\n\t\t\tbox-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);\n\t\t\tmax-width: 400px;\n\t\t\ttext-align: center;\n\t\t`;o.innerHTML=`\n\t\t\t<div class="epkb-loading-spinner" style="margin: 0 auto 20px; width: 40px; height: 40px;"></div>\n\t\t\t<p style="margin: 0; color: #555; font-size: 16px;">${p(t)}</p>\n\t\t`;n.appendChild(o);document.body.appendChild(n);return()=>{n.remove()}};const C=(t={})=>{const{data:n=[],allData:o=null,onServerSearch:s=null,searchFields:a=["title","name","query","message","user_name","url","item_id"],debounceDelay:i=500}=t;const{useState:r,useEffect:c,useCallback:l,useRef:d}=wp.element;const[u,p]=r("");const[f,g]=r(n);const[m,b]=r(false);const[h,y]=r("");const k=d(null);const w=d("");c((()=>{if(s||!u){g(n)}}),[n,u,s]);const x=l(((t,i=null)=>{if(!t){g(n);y("");return n}const r=t.toLowerCase();const c=i||o||n;const l=c.filter((t=>a.some((e=>{const n=t[e];if(n===null||n===undefined)return false;return n.toString().toLowerCase().includes(r)}))));g(l);if(!i){if(l.length===0&&!s){y(e("No results found","echo-knowledge-base"))}else{y("")}}return l}),[n,o,a,s]);const S=l((t=>{p(t);w.current=t;if(k.current){clearTimeout(k.current);k.current=null}if(!t){g(n);b(false);y("");if(s){s("")}return}if(s){b(true);k.current=setTimeout((async()=>{if(w.current!==t)return;try{await s(t)}catch(t){console.error("Server search error:",t)}finally{if(w.current===t){b(false);y("")}}}),i)}else{x(t)}}),[n,o,x,s,i]);const _=l((()=>{p("");w.current="";g(n);b(false);y("");if(k.current){clearTimeout(k.current);k.current=null}}),[n]);c((()=>()=>{if(k.current){clearTimeout(k.current)}}),[]);return{searchTerm:u,displayedData:f,isSearching:m,searchMessage:h,handleSearchChange:S,clearSearch:_}};const D=(t={})=>{const{errorText:e="Sorry, I couldn't get a response. Please reload your page and try again.",persistText:n="If the issue persists, please",linkText:o="contact support",linkUrl:s="https://www.echoknowledgebase.com/contact-us/",h:a=wp.element.createElement}=t;return a("p",null,e," ",n," ",a("a",{href:s,target:"_blank",rel:"noopener noreferrer",style:{color:"#007cba",textDecoration:"underline"}},o),".")};const $=(t={})=>{const{errorText:e="Sorry, I couldn't get a response. Please reload your page and try again.",persistText:n="If the issue persists, please",linkText:o="contact support",linkUrl:s="https://www.echoknowledgebase.com/contact-us/"}=t;return`${p(e)} ${p(n)} <a href="${p(s)}" target="_blank" rel="noopener noreferrer" style="color: #007cba; text-decoration: underline;">${p(o)}</a>.`};const I=()=>{try{const t=["epkb_new_collection_id"];const e=[];for(let n=0;n<sessionStorage.length;n++){const o=sessionStorage.key(n);if(o&&(o.startsWith("epkb_")||o.includes("epkb"))&&!t.includes(o)){e.push(o)}}e.forEach((t=>sessionStorage.removeItem(t)))}catch(t){}};const q="epkb_analysis_details";const L=5;const M=200*1024;const O=100*1024;const F=t=>`${q}_${t}`;const R=()=>{const t=[];try{for(let e=0;e<sessionStorage.length;e++){const n=sessionStorage.key(e);if(n&&n.startsWith(q+"_")){const e=n.replace(q+"_","");if(e){t.push(e)}}}}catch(t){}return t};const P=t=>new Blob([t]).size;const z=(t,e)=>{if(!t||typeof t!=="string"){return t}const n=P(t);if(n<=e){return t}let o=0;let s=t.length;let a=t;while(o<=s){const n=Math.floor((o+s)/2);const i=t.substring(0,n);const r=P(i);if(r<=e){a=i;o=n+1}else{s=n-1}}return a};const j=t=>{const e=R();const n=new Set(t.map(String));let o=0;e.forEach((t=>{if(!n.has(String(t))){try{sessionStorage.removeItem(F(t));o++}catch(e){console.error("Failed to remove storage for article:",t,e)}}}));return o};const J=()=>{const t=1024*1024;let e=0;try{const t=R();t.forEach((t=>{const n=sessionStorage.getItem(F(t));if(n){e+=P(n)}}))}catch(e){return t}return Math.max(0,t-e)};const B=(t,e)=>{if(t.includes(String(e))){return{allowed:true,reason:"already_open"}}if(t.length>=L){return{allowed:false,reason:"tab_limit",message:`Maximum ${L} article tabs can be open at once. Please close another tab first.`}}return{allowed:true,reason:"ok"}};const H=(t,e,n)=>{j(n);let o={...e};let s=false;let a=false;if(o.data&&o.data.processed_content&&typeof o.data.processed_content==="string"){const t=P(o.data.processed_content);if(t>M){o.data.processed_content=z(o.data.processed_content,O);o.data._content_truncated=true;o.data._full_content_size=t;s=true;a=true}}try{const e=F(t);sessionStorage.setItem(e,JSON.stringify(o));return{stored:true,truncated:s,needsFullFetch:a}}catch(e){console.error("Failed to store article data:",e);if(e.name==="QuotaExceededError"){j(n);if(o.data&&o.data.processed_content){o.data.processed_content=z(o.data.processed_content,O/2);o.data._content_truncated=true;s=true;a=true;try{const e=F(t);sessionStorage.setItem(e,JSON.stringify(o));return{stored:true,truncated:s,needsFullFetch:a}}catch(t){console.error("Failed to store article data after retry:",t);return{stored:false,truncated:false,needsFullFetch:true}}}}return{stored:false,truncated:false,needsFullFetch:true}}};const G=t=>{try{const e=F(t);const n=sessionStorage.getItem(e);if(n){return JSON.parse(n)}}catch(t){console.error("Failed to get article data:",t)}return null};const U=t=>{try{const e=F(t);sessionStorage.removeItem(e);return true}catch(t){console.error("Failed to remove article data:",t);return false}};const W=()=>{const t=R();let e=0;let n=0;let o=0;t.forEach((t=>{try{const s=sessionStorage.getItem(F(t));if(s){e+=P(s);n++;const t=JSON.parse(s);if(t.data&&t.data._content_truncated){o++}}}catch(t){}}));return{articleCount:n,totalSize:e,truncatedCount:o,availableSpace:J(),maxTabs:L,maxContentSize:M}};Object.assign(window.EPKB_AI_Util_React,{showNotification:n,showSuccess:a,showError:i,showInfo:r,showWarning:c,makeApiRequest:d,updateNonce:u,escapeHtml:p,debounce:f,throttle:g,formatDate:m,formatServerDateTime:b,deepMerge:h,isObject:y,getNestedValue:k,setNestedValue:w,isValidEmail:x,generateId:S,showConfirmDialog:_,handleSessionError:E,showLoadingDialog:A,SetupStepsGuide:N,DisclaimerRequiredMessage:T,useTableSearch:C,createAIErrorMessageElement:D,createAIErrorMessageHTML:$,clearAllEPKBSessionStorage:I,canAddArticleTab:B,storeArticleAnalysisData:H,getArticleAnalysisData:G,removeArticleAnalysisData:U,cleanupArticleStorage:j,getArticleStorageStats:W})})();
Save
Cancel