/* * (C) 2025 MARS FLAG Corporation * http://www.marsflag.com/ Version: 1.2.1 Build Time: 2026/3/2 14:14:33 Env: prd */ "use strict";(()=>{var u={JSON_BASE_URL:"https://s.mp.marsflag.com/config",CE_BASE_URL:"https://ce.mf.marsflag.com"},r=(n,e=null,o="debug")=>{if(!document.cookie.split("; ").find(a=>a.startsWith("mf_debug=")))return;let t={prefix:"color: yellow; background-color: black; font-size: 14px; font-weight: bold; padding: 2px;",message:"color: limegreen; background-color: black; font-size: 14px; padding: 2px;",error:"color: red; background-color: black; font-size: 14px; padding: 2px;",info:"color: cyan; background-color: black; font-size: 14px; padding: 2px;",data:"color: white; background-color: black; font-size: 14px; padding: 2px;"},l=o.toUpperCase(),s=o==="debug"?t.message:t[o];e?console[o](`%c${l}: %c${n}`,t.prefix,s,e):console[o](`%c${l}: %c${n}`,t.prefix,s)},p=()=>{let n=document.querySelector("mf-search-results"),e=document.querySelector("mf-search-box"),o=n||e,i=(n==null?void 0:n.getAttribute("ajax-url"))||(e==null?void 0:e.getAttribute("ajax-url"))||null;return o&&!i&&r("Elements exist but ajax-url attribute is missing",null,"error"),i},_=n=>{let e=n.match(/documents\/(.+?)\/search/),o=e?e[1]:null;return o||r(`Failed to get unique name from ajax-url: ${n}`,null,"error"),o},h=()=>{let n=window.location.search+window.location.hash;return new URLSearchParams(n.slice(1)).get("force_version")},f=()=>new URLSearchParams(window.location.search).get("preview"),g=(n,e)=>new Promise((o,i)=>{let t=document.createElement("script");t.async=!0,t.type=e,t.src=n,t.onload=()=>{r("Script loaded:",n),o()},t.onerror=()=>{r("Failed to load script:",n,"error"),i(new Error(`Failed to load script: ${n}`))},document.body.appendChild(t)}),m=()=>g(`${u.CE_BASE_URL}/v1/js/mf-search.js`,"text/javascript"),E=n=>{let e=`${u.CE_BASE_URL}/v2/js/mf-search.js`,o=n?`${e}?emotech_unique_name=${n}`:e;return g(o,"module")},v=async n=>{if(localStorage.getItem("use_test_json")==="true")return r("Using test JSON data",null,"info"),JSON.parse(localStorage.getItem("test_json_data")||"{}");try{let o=f()?`${n}-preview.json`:`${n}.json`,i=`${u.JSON_BASE_URL}/${o}`;r(`Fetching config from: ${i}`,null,"info");let t=await fetch(i);if(!t.ok)throw new Error(`JSON file not found: ${o}`);return await t.json()}catch(e){return e instanceof SyntaxError?r("JSON format error",e,"error"):r(e instanceof Error?e.message:String(e),null,"error"),{}}},S=(n,e,o)=>{var i,t,l,s;try{let a=o||((t=(i=n.mf3)==null?void 0:i.find(c=>c.unique_name===e))==null?void 0:t.setting.ce_version)||((s=(l=n.di)==null?void 0:l.find(c=>c.unique_name===e))==null?void 0:s.setting.ce_version);return a?Number(a):(r("Version not found in JSON data",null,"error"),2)}catch(a){return r("Error determining version",a,"error"),2}},b=(n,e)=>{var o,i;try{let t=(o=n.mf3)==null?void 0:o.find(c=>c.unique_name===e),l=(i=n.di)==null?void 0:i.find(c=>c.unique_name===e),s=t||l;if(r(`Using ${t?"mf3":"di"} entry for ${e}`,s),!s)return null;if(s.load!==void 0&&s.load!==1)return r("load is specified but not 1, stopping all script loading",s.load,"info"),"STOP_LOADING";if(Number(s.setting.ce_version)!==2||!s.setting.emotech_unique_name)return null;let a=s.setting.emotech_unique_name;return r("EmoTech in Finder is enabled",{searchUniqueName:e,emotechUniqueName:a},"info"),a}catch(t){return r("Error checking EmoTech in Finder status",t,"error"),null}},x=async()=>{try{let n=document.querySelector("mf-search-results"),e=document.querySelector("mf-search-box");!n&&!e&&r("No search components found on page",null,"info");let o=p();o||r("No ajax-url found",null,"error"),r("Element with ajax-url found:",o);let i=_(o);i||r("Unique name not found",null,"error"),r("Unique Name:",i);let t=h();r("Forced version:",t||"Not forced");let l=f();r("Preview query parameter:",l||"Not set");let s=await v(i);r("JSON Data:",s);let a=S(s,i,t);r("CE version:",a);let c=b(s,i);if(r("EmoTech Check Result:",c),c==="STOP_LOADING"){r("Stopping script loading due to mf3 load configuration",null,"info");return}if(a===1)r("Loading v1 code",a),await m();else{let d=c;r("Loading v2 code",{version:a,emotechUniqueName:d}),setTimeout(()=>{E(d||void 0)},0)}}catch(n){r("Error during initialization",n,"error");try{await m()}catch(e){r("Failed to load fallback script",e,"error")}}};x();})();