|
"use strict";(()=>{var k=class{constructor(e={}){this.namespace=e.namespace,this.prefix=[this.namespace,e.prefix].filter(Boolean).join(" "),this.enabled=e.enabled!==!1,this.timestamp=e.timestamp!==!1,this.timestampFormat=e.timestampFormat||"locale"}getTimestamp(){let e=new Date;return this.timestampFormat==="ISO"?e.toISOString():e.toLocaleString()}formatMessage(e,...n){let u=[this.prefix];return this.timestamp&&u.push(`[${this.getTimestamp()}]`),u.push(`[${e.toUpperCase()}]`),[u.join(" "),...n]}debug(...e){this.enabled&&console.debug(...this.formatMessage("debug",...e))}info(...e){this.enabled&&console.info(...this.formatMessage("info",...e))}warn(...e){this.enabled&&console.warn(...this.formatMessage("warn",...e))}error(...e){this.enabled&&console.error(...this.formatMessage("error",...e))}log(...e){this.enabled&&console.log(...this.formatMessage("log",...e))}custom(e,...n){this.enabled&&console.log(...this.formatMessage(e,...n))}group(e,n){if(!this.enabled)return n();console.group(`${this.prefix} ${e}`);try{n()}finally{console.groupEnd()}}groupCollapsed(e,n){if(!this.enabled)return n();console.groupCollapsed(`${this.prefix} ${e}`);try{n()}finally{console.groupEnd()}}table(e,n){this.enabled&&(this.info("Table data:"),console.table(e,n))}time(e){this.enabled&&console.time(`${this.prefix} ${e}`)}timeEnd(e){this.enabled&&console.timeEnd(`${this.prefix} ${e}`)}timeLog(e){this.enabled&&console.timeLog(`${this.prefix} ${e}`)}enable(){this.enabled=!0}disable(){this.enabled=!1}setPrefix(e){this.prefix=e}};function D(f={}){return new k(f)}function N(f,e){function n(u){return u.replace(/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi,"")}if(window.trustedTypes){let l=window.trustedTypes.createPolicy("myHTMLPolicy",{createHTML:n}).createHTML(e);f.innerHTML=l}else{let u=n(e);f.innerHTML=u}}async function B(f){let{tagName:e,id:n,attributes:u={},parentSelector:l="body",parentElement:p,textContent:s,innerHTML:h,innerElement:w,returnElement:H=!0,checkExisting:V=!0,replaceExisting:q=!1,insertionMethod:y="append",contextElement:g,waitTimeout:I=3e4,persistent:E=!1,autoRemove:x=!0,debounceDelay:A=500,observerConfig:b={childList:!0,subtree:!0,attributes:!1,attributeOldValue:!1,characterData:!1,characterDataOldValue:!1},namespace:F,onMount:v}=f,t=D({prefix:"[createElement]",namespace:F}),r={action:"create",tagName:e,id:n,parentMethod:l?"selector":"element",parentIdentifier:l||(p?p.tagName:"unknown"),waitTimeout:I,insertionMethod:y};if(t.info(`Starting element creation: <${e}> with ID="${n}"${g?" (conditional)":""} using ${y} insertion`),!e||typeof e!="string")return t.error("Element creation failed: Tag parameter is required and must be a string",r),null;if(!n||typeof n!="string")return t.error("Element creation failed: ID parameter is required and must be a non-empty string",r),null;if(!l&&!p)return t.error("Element creation failed: Either parentSelector or parentElement must be provided",r),null;if(y!=="append"&&y!=="insertBeforeElement"&&y!=="prepend")return t.error("Element creation failed: insertionMethod must be 'append', 'insertBeforeElement', or 'prepend'",r),null;function T(a,i,o){try{let m=new DOMParser().parseFromString(i,"text/html"),c=m.querySelector("parsererror");if(c)throw new Error(`HTML parsing error: ${c.textContent}`);let $=Array.from(m.body.childNodes);return $.length===0?(t.warn(`No valid elements found in HTML string: "${i.substring(0,50)}${i.length>50?"...":""}"`,o),!1):($.forEach(M=>{let O=a.ownerDocument.importNode(M,!0);a.appendChild(O)}),t.debug(`Created DOM elements programmatically: "${i.substring(0,50)}${i.length>50?"...":""}" (${$.length} elements)`,o),!0)}catch(d){t.warn(`DOMParser failed, attempting fallback method: ${d.message}`,o);try{return N(a,i),t.debug(`Successfully created DOM elements via fallback method: "${i.substring(0,50)}${i.length>50?"...":""}"`,o),!0}catch(m){return t.error(`DOM insertion failed: ${m.message}`,{...o,originalError:d.message,fallbackError:m.message}),!1}}}function C(){try{let a=null;if(V&&(a=document.getElementById(n),a))if(r.action="exists",q)t.info(`Found existing element with ID="${n}", replacing as requested`,r),a.remove(),r.action="replace";else return t.warn(`Element with ID="${n}" already exists, skipping creation. Use replaceExisting=true to replace.`,r),H?a:null;let i=p;if(!i&&l){let c=document.querySelector(l);if(!c)return t.error(`Element creation failed: Parent element not found with selector: ${l}`,r),null;i=c,t.debug(`Found parent element with selector: ${l}`,r)}if(!i)return t.error("Element creation failed: No valid parent element found",r),null;let o=document.createElement(e);t.debug(`Created DOM element: <${e}>`,r),o.setAttribute("id",n),t.debug(`Set required ID attribute: id="${n}"`,r);let d=Object.keys(u).length;if(d>0&&(Object.entries(u).forEach(([c,$])=>{$!=null&&(o.setAttribute(c,String($)),t.debug(`Set attribute: ${c}="${$}"`,r))}),t.debug(`Applied ${d} additional attributes to element`,r)),w&&typeof w=="function")try{let c=w();c instanceof HTMLElement?(o.appendChild(c),t.debug("Inserted child element via innerElement callback",r)):(t.warn("innerElement callback did not return a valid HTMLElement, falling back to other content methods",r),s!==void 0?(o.textContent=s,t.debug(`Set textContent: "${s.substring(0,100)}${s.length>100?"...":""}"`,r)):h!==void 0&&T(o,h,r))}catch(c){t.error("Error executing innerElement callback, falling back to other content methods:",c,r),s!==void 0?(o.textContent=s,t.debug(`Set textContent: "${s.substring(0,100)}${s.length>100?"...":""}"`,r)):h!==void 0&&T(o,h,r)}else s!==void 0?(o.textContent=s,t.debug(`Set textContent: "${s.substring(0,100)}${s.length>100?"...":""}"`,r)):h!==void 0&&T(o,h,r);if(y==="insertBeforeElement")if(i.parentElement)i.parentElement.insertBefore(o,i),t.debug("Inserted element before parent",r);else return t.error("Element insertion failed: Parent element has no parent to insert before",r),null;else y==="prepend"?(i.insertBefore(o,i.firstChild),t.debug("Prepended element as first child of parent",r)):(i.appendChild(o),t.debug("Appended element to end of parent",r));if(v&&typeof v=="function")try{v(o),t.debug(`Successfully called onMount callback for element ID="${n}"`,r)}catch(c){t.warn(`Error in onMount callback for element ID="${n}":`,c,r)}let m=`Element creation successful: <${e}> (ID="${n}") ${r.action==="replace"?"replaced and ":""}${y}ed to ${r.parentMethod==="selector"?`parent selected by "${l}"`:"provided parent element"}${g?" (after content element)":""}`;return t.info(m,{...r,success:!0,hasAttributes:d>0,hasContent:!!(s||h||w),parentTagName:i.tagName,elementPath:o.tagName+"#"+o.id+(o.className?`.${o.className.replace(/\s+/g,".")}`:"")}),H?o:null}catch(a){let i=`Element creation failed with exception: ${a.message||"Unknown error"}`;return t.error(i,{...r,success:!1,error:a.message||"Unknown error",stack:a.stack||"No stack trace available"}),null}}async function L(){try{if(typeof g=="function"){let a=await g();return a instanceof HTMLElement&&document.contains(a)}else if(typeof g=="string")return document.querySelector(g)!==null}catch(a){t.warn(`Error checking content element for element ID="${n}":`,a)}return!1}function P(){if(!E&&!x)return;t.info(`Setting up ${E?"persistent":""}${E&&x?" and ":""}${x?"auto-removal":""} monitoring for element ID="${n}"`);let a=null,i=new MutationObserver(async()=>{a&&clearTimeout(a),a=setTimeout(async()=>{t.debug(`Persistent monitoring check triggered for element ID="${n}"`);let d=await L(),m=document.getElementById(n);d?E&&!m?(t.info(`Context element found but managed element missing, recreating element ID="${n}"`),C()):t.debug(`Both context and managed elements exist for ID="${n}"`):x&&m?(t.info(`Context element no longer present, removing managed element ID="${n}"`),m.remove()):t.debug(`Context element no longer present for element ID="${n}"`)},A)}),o={childList:b.childList===!0,subtree:b.subtree===!0,attributes:b.attributes===!0,attributeOldValue:b.attributeOldValue===!0,characterData:b.characterData===!0,characterDataOldValue:b.characterDataOldValue===!0};i.observe(document.documentElement||document.body,o),t.debug(`Started persistent MutationObserver for element ID="${n}"`)}if(!g)return C();if(t.info(`Checking initial condition for element ID="${n}"`,{...r,waitCondition:typeof g=="function"?"callback":g,persistent:E}),await L()){t.info(`Initial content element already satisfied for element ID="${n}"`,r);let a=C();return(E||x)&&P(),a}return new Promise(a=>{let i=Date.now(),o=null,d=null,m=!1;function c(M){m||x&&(m=!0,o&&(clearTimeout(o),o=null),d&&(d.disconnect(),d=null,t.debug(`Disconnected MutationObserver for element ID="${n}"`,r)),a(M))}o=setTimeout(()=>{t.error(`Element creation failed: Wait condition timeout after ${I}ms for element ID="${n}"`,{...r,success:!1,timeoutReached:!0,waitCondition:typeof g=="function"?"callback":g}),c(null)},I),t.info(`Setting up MutationObserver for element ID="${n}"`,{...r,observerConfig:b,waitCondition:typeof g=="function"?"callback":g}),d=new MutationObserver(async M=>{if(!m&&(t.debug(`MutationObserver detected ${M.length} mutations for element ID="${n}"`,r),await L())){let O=Date.now()-i;t.info(`Wait condition satisfied via MutationObserver for element ID="${n}" after DOM changes`,{...r,elapsedTime:O});let _=C();(E||x)&&P(),c(_)}});let $={childList:b.childList===!0,subtree:b.subtree===!0,attributes:b.attributes===!0,attributeOldValue:b.attributeOldValue===!0,characterData:b.characterData===!0,characterDataOldValue:b.characterDataOldValue===!0};d.observe(document.documentElement||document.body,$),t.debug(`Started MutationObserver monitoring for element ID="${n}"`,{...r,target:"document.documentElement"})})}function S({selector:f,timeout:e=5e3,pollInterval:n=100}){return new Promise(u=>{let l=n,p=0,s=setInterval(()=>{let h=document.querySelector(f);h?(clearInterval(s),u(h)):p>=e&&(clearInterval(s),u(null)),p+=l},l)})}(async function(){"use strict";GM_addStyle(` |