(()=>{"use strict";if(globalThis.__AHT_DOM_CONFIG_HELPER_LOADED__)return;globalThis.__AHT_DOM_CONFIG_HELPER_LOADED__=!0;const t=globalThis.__AHT_DOM_DUMP_DEFAULTS__&&"object"==typeof globalThis.__AHT_DOM_DUMP_DEFAULTS__?globalThis.__AHT_DOM_DUMP_DEFAULTS__:{version:1,storageKey:"aht_dom_dump_v1",sync:{endpoint:"https://sync.alpha-helper.date/api/tools/check",periodMinutes:5}},r=String(t.storageKey||"aht_dom_dump_v1"),e="data-aht-dom-dump",n="AHT_DOM_DUMP_UPDATED",o=new Set;let i=l(y()||t),c=null;function u(t){return!!t&&"object"==typeof t&&!Array.isArray(t)}function s(t){if(null==t||"object"!=typeof t)return t;try{if("function"==typeof structuredClone)return structuredClone(t)}catch{}try{return JSON.parse(JSON.stringify(t))}catch{return Array.isArray(t)?t.slice():{...t}}}function a(t,r){if(Array.isArray(t)||Array.isArray(r))return Array.isArray(r)?s(r):s(t);if(!u(t)||!u(r))return s(void 0===r?t:r);const e={...s(t)};for(const[t,n]of Object.entries(r))void 0!==n&&(e[t]=a(e[t],n));return e}function l(e){const n=u(e)?e:{},o=a(t,n),i=Number(n.version??o.version??t.version??1);return o.version=Number.isFinite(i)&&i>0?i:1,o.storageKey=String(o.storageKey||r),o}function f(){return document.documentElement||document.querySelector("html")}function y(){try{const t=f()?.getAttribute?.(e);if(!t)return null;const r=JSON.parse(t);return u(r)?r:null}catch{return null}}function _(t,r={}){const c=l(t),u=Number(i?.version||0),s=r.force?"":h(i),a=h(c);if(i=c,!1!==r.publish&&function(t){const r=f();if(r)try{const o=JSON.stringify(t);r.getAttribute(e)!==o&&r.setAttribute(e,o),document.dispatchEvent(new CustomEvent(n,{detail:o}))}catch{}}(i),r.force||s!==a||u!==Number(c.version||0))for(const t of Array.from(o))try{t(i)}catch(t){console.warn("[AHT DOM] listener failed:",t)}return i}function h(t){try{return JSON.stringify(t)}catch{return""}}function p(t,r,e){let n=t;for(const t of function(t){return Array.isArray(t)?t.map(String).filter(Boolean):String(t||"").split(".").map((t=>t.trim())).filter(Boolean)}(r)){if(null==n||"object"!=typeof n&&"function"!=typeof n||!(t in n))return e;n=n[t]}return void 0===n?e:n}function d(t,r=void 0){return p(i,t,r)}function A(t,r=""){const e=d(t,r);return"string"==typeof e&&e.trim()?e:String(r||"")}function g(){try{return"undefined"!=typeof chrome&&!!chrome?.storage?.local}catch{return!1}}async function m(){return g()?(c||(c=(async()=>{try{const e=await chrome.storage.local.get(r),n=e?.[r];return u(n)?_(n,{publish:!0}):_(t,{publish:!0})}catch(r){return console.warn("[AHT DOM] storage load failed:",r),_(t,{publish:!0})}})()),c):i}const b={STORAGE_KEY:r,ATTR_NAME:e,EVENT_NAME:n,DEFAULT_DUMP:t,getDump:()=>i,get:d,selector:A,list:function(t,r=[]){const e=d(t,r);return Array.isArray(e)?e.slice():"string"==typeof e&&e.trim()?[e]:Array.isArray(r)?r.slice():[]},number:function(t,r=0){const e=Number(d(t,r));return Number.isFinite(e)?e:r},template:function(t,r={},e=""){return A(t,e).replace(/\{([a-zA-Z0-9_.-]+)\}/g,((t,e)=>{const n=p(r,e,void 0);return null==n?"":String(n)}))},regex:function(t,r="",e=""){const n=A(t,r);try{return new RegExp(n,e)}catch{return new RegExp(String(r||"$.^"),e)}},reload:m,onChange:function(t){return"function"!=typeof t?()=>{}:(o.add(t),()=>o.delete(t))}};try{globalThis.AHT_DOM=b}catch{}try{document.addEventListener(n,(function(t){let r=null;try{r="string"==typeof t?.detail?JSON.parse(t.detail):t?.detail}catch{r=null}u(r)||(r=y()),r&&_(r,{publish:!1})}))}catch{}if(g()){_(i,{publish:!0,force:!0}),m().catch((()=>{}));try{chrome.storage.onChanged.addListener(((e,n)=>{if("local"!==n||!e||!Object.prototype.hasOwnProperty.call(e,r))return;const o=e[r]?.newValue;u(o)?_(o,{publish:!0}):_(t,{publish:!0})}))}catch{}}else{const t=y();t&&_(t,{publish:!1})}})();