nexus-web-assistant 1.0.1 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- (()=>{"use strict";const n={API_URL:"https://api.groq.com/openai/v1/chat/completions",API_KEY:"",MODEL:"meta-llama/llama-4-scout-17b-16e-instruct",BOT_NAME:"Nexus AI",GREETING:"Hey! I'm Nexus AI, your intelligent assistant. Ask me anything about this page!",SYSTEM_PROMPT:"\nYou are Nexus AI, a smart assistant. Use the page context provided in every response.\n\n**Rules:**\n- Always prioritize the given page context over general knowledge.\n- Quote specific details (headings, tables, code, lists, etc.) from the context.\n- Structure answers clearly with bullet points or headings where helpful.\n- Be crisp, professional, and friendly. Use Markdown.\n- If information is not in context, politely say so and offer to help with related topics.\n- Keep responses concise (under 600 tokens).\n ",COLORS:{bg:"#0a0a0a",panelBg:"rgba(12, 12, 12, 0.85)",border:"#2a2a2a",borderHover:"#444444",textPrimary:"#f5f5f5",textSecondary:"#a0a0a0",userBubble:"#1e1e1e",botBubble:"transparent"}},e=n=>document.getElementById(n);function t(n,t){if(!n)return!1;const o=void 0!==t?t:!n.classList.contains("open");return n.classList.toggle("open",o),o&&setTimeout(()=>e("aiInput")?.focus(),100),o}function o(n,e,t="bot",o=null){if(!n)return null;const a=document.createElement("div");if(a.className=`msg ${t}`,"bot"===t){const n=function(n){return"undefined"!=typeof marked&&marked.parse?marked.parse(n,{breaks:!0,gfm:!0}):n.replace(/\n/g,"<br>")}(e);a.innerHTML=n,"undefined"!=typeof hljs&&a.querySelectorAll("pre code").forEach(n=>{hljs.highlightElement(n)})}else{let n=e||"";o&&(n+=`<br><img src="${o}" class="image-preview" alt="attached">`),a.innerHTML=n}return n.appendChild(a),n.scrollTo({top:n.scrollHeight,behavior:"smooth"}),a}let a=null;function i(n,e){n&&(a&&(a.remove(),a=null),e&&(a=document.createElement("div"),a.className="typing-indicator",a.innerHTML="<span></span><span></span><span></span>",n.appendChild(a),n.scrollTo({top:n.scrollHeight,behavior:"smooth"})))}function r(n,e){if(!n)return;if(n.innerHTML="",!e)return;const t=document.createElement("div");t.className="image-preview-pill",t.innerHTML=`\n <img src="${e.dataUrl}" alt="preview">\n <span class="file-name">${e.name}</span>\n <button class="remove-file" id="aiRemoveFile"><i class="fas fa-times"></i></button>\n `,n.appendChild(t),document.getElementById("aiRemoveFile")?.addEventListener("click",()=>{})}const s={isOpen:!1,isProcessing:!1,attachedFile:null,conversationHistory:[]};function c(n){Object.assign(s,n)}const l="NexusAICache",d="pageData";let p=null;function u(){return new Promise((n,e)=>{if(p)return void n(p);const t=indexedDB.open(l,1);t.onupgradeneeded=n=>{const e=n.target.result;if(!e.objectStoreNames.contains(d)){const n=e.createObjectStore(d,{keyPath:"id"});n.createIndex("url","url",{unique:!1}),n.createIndex("timestamp","timestamp",{unique:!1}),console.log("šŸ“¦ IndexedDB store created")}},t.onsuccess=e=>{p=e.target.result,n(p)},t.onerror=n=>{e(n.target.error)}})}async function m(n){try{const e=(await u()).transaction(d,"readwrite").objectStore(d),t=window.location.href,o={id:t,url:t,data:n,timestamp:Date.now()};return new Promise((n,t)=>{const a=e.put(o);a.onsuccess=()=>{console.log("šŸ’¾ Data cached in IndexedDB"),n()},a.onerror=n=>{t(n.target.error)}})}catch(n){console.warn("IndexedDB write failed:",n)}}let g=null,f=null;function b(n){return new Promise((e,t)=>{const o=document.createElement("script");o.src=n,o.async=!0,o.onload=e,o.onerror=t,document.head.appendChild(o)})}function h(){console.log("šŸ•·ļø Advanced scraping started...");const n={title:document.title,url:window.location.href,timestamp:(new Date).toISOString(),pageType:x(),readability:null,structuredData:[],markdown:"",summary:"",metadata:{}};try{if(g){const e=document.cloneNode(!0),t=new g(e).parse();if(t){if(n.readability={title:t.title,byline:t.byline,excerpt:t.excerpt,content:t.content,textContent:t.textContent},f){const e=new f({headingStyle:"atx",codeBlockStyle:"fenced",emDelimiter:"*",bulletListMarker:"-"});e.addRule("strikethrough",{filter:["del","s","strike"],replacement:function(n){return"~~"+n+"~~"}}),n.markdown=e.turndown(t.content)}n.summary=t.excerpt||t.textContent.substring(0,300)}}}catch(e){console.warn("Readability failed, falling back to basic scraper:",e),n.readability=null}try{document.querySelectorAll('script[type="application/ld+json"]').forEach(e=>{try{const t=JSON.parse(e.textContent);n.structuredData.push(t)}catch(n){}})}catch(n){console.warn("JSON-LD extraction failed:",n)}if(n.metadata=function(){const n={},e=document.querySelector('meta[name="description"]');e&&(n.description=e.content);const t=document.querySelector('meta[name="keywords"]');t&&(n.keywords=t.content),["title","description","image","url","type","site_name"].forEach(e=>{const t=document.querySelector(`meta[property="og:${e}"]`);t&&(n[`og_${e}`]=t.content)}),["card","title","description","image"].forEach(e=>{const t=document.querySelector(`meta[name="twitter:${e}"]`);t&&(n[`twitter_${e}`]=t.content)});const o=document.querySelector('link[rel="canonical"]');return o&&(n.canonical=o.href),n}(),!n.readability){console.log("āš ļø Using fallback scraper");const e=function(){const n=document.body.cloneNode(!0);["nav","header","footer","aside",".sidebar",".navigation",".menu",".ads",".cookie-banner",".popup",".overlay","script","style","noscript","iframe"].forEach(e=>{n.querySelectorAll(e).forEach(n=>n.remove())});let e=n.textContent||"";e=e.replace(/\s+/g," ").trim();const t=e.substring(0,500)+"...";return{content:e,summary:t}}();n.markdown=e.content,n.summary=e.summary}return n.aiContext=y(n),console.log("āœ… Advanced scraping complete"),n}function x(){const n=window.location.href,e=document.title.toLowerCase(),t=document.querySelector('meta[property="og:type"]');if(t){const n=t.content;if(n.includes("article"))return"article";if(n.includes("product"))return"product";if(n.includes("website"))return"website"}return n.includes("/blog/")||n.includes("/post/")||e.includes("blog")?"blog":n.includes("/product/")||n.includes("/shop/")?"product":n.includes("/portfolio/")||n.includes("/project/")?"portfolio":n===window.location.origin+"/"||n===window.location.origin?"homepage":"general"}function y(n){let e="";if(e+=`# šŸ“„ ${n.title}\n\n`,e+=`**URL:** ${n.url}\n`,e+=`**Type:** ${n.pageType}\n`,e+=`**Scraped:** ${new Date(n.timestamp).toLocaleString()}\n\n`,Object.keys(n.metadata).length>0){e+="## šŸ“‹ Metadata\n";for(const[t,o]of Object.entries(n.metadata))o&&o.length>0&&(e+=`- **${t}:** ${o}\n`);e+="\n"}if(n.structuredData&&n.structuredData.length>0&&(e+="## šŸ“Š Structured Data (Schema.org)\n",n.structuredData.forEach((n,t)=>{e+=`\n### Schema ${t+1}\n`,e+=`\`\`\`json\n${JSON.stringify(n,null,2)}\n\`\`\`\n`}),e+="\n"),n.markdown){e+="## šŸ“ Main Content\n\n";const t=4e3,o=n.markdown.length>t?n.markdown.substring(0,t)+"... (truncated)":n.markdown;e+=o,e+="\n\n"}return n.summary&&(e+="## šŸ“Œ Summary\n\n",e+=n.summary,e+="\n\n"),e+="---\n",e+="*šŸ¤– AI Instructions: Use this context to answer user questions about this page. Be precise, reference specific details from the content, and maintain a friendly professional tone.*\n",e}async function w(e,t,a=null){if(s.isProcessing)return;c({isProcessing:!0});const r=document.getElementById("aiSendBtn"),l=document.getElementById("aiInput");r&&(r.disabled=!0),l&&(l.disabled=!0),i(e,!0);const p=[];if(t&&p.push({type:"text",text:t}),a&&p.push({type:"image_url",image_url:{url:a}}),s.conversationHistory.push({role:"user",content:t||"(image)"}),s.conversationHistory.length>11){const n=s.conversationHistory[0],e=s.conversationHistory.slice(-10);s.conversationHistory=[n,...e]}try{const t=await async function(){let n=await async function(){try{const n=(await u()).transaction(d,"readonly").objectStore(d),e=window.location.href;return new Promise((t,o)=>{const a=n.get(e);a.onsuccess=n=>{const o=n.target.result;if(!o)return void t(null);const a=Date.now();if(a-o.timestamp>864e5)return async function(n){try{(await u()).transaction(d,"readwrite").objectStore(d).delete(n)}catch(n){console.warn("IndexedDB delete failed:",n)}}(e),void t(null);console.log(`šŸ“¦ Cache hit! Age: ${Math.floor((a-o.timestamp)/6e4)} minutes`),t(o.data)},a.onerror=n=>{o(n.target.error)}})}catch(n){return console.warn("IndexedDB read failed:",n),null}}();if(n)return console.log("šŸ“¦ Using cached page data"),n;console.log("šŸ” Scraping page data...");const e=y(h());return await m(e),console.log("šŸ’¾ Page data cached"),e}(),a=window.__NEXUS_CONFIG||n,r=[{role:"system",content:`${a.SYSTEM_PROMPT}\n\n## Current Page Context\n${t}`}];for(let n=1;n<s.conversationHistory.length-1;n++)r.push({role:s.conversationHistory[n].role,content:s.conversationHistory[n].content});r.push({role:"user",content:p});const c=await fetch(a.API_URL,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${a.API_KEY}`},body:JSON.stringify({model:a.MODEL,messages:r,temperature:.7,max_tokens:600,stream:!1})});if(!c.ok){const n=await c.json().catch(()=>({}));throw new Error(`API error ${c.status}: ${n.error?.message||c.statusText}`)}const l=await c.json(),g=l.choices?.[0]?.message?.content||"Sorry, I didn't understand that.";s.conversationHistory.push({role:"assistant",content:g}),i(e,!1),o(e,g,"bot")}catch(n){console.error("Groq API Error:",n),i(e,!1),o(e,`āš ļø Oops! ${n.message||"Something went wrong."} Please try again.`,"bot")}finally{c({isProcessing:!1}),r&&(r.disabled=!1),l&&(l.disabled=!1,l.value="",l.focus())}}async function v(){const a=function(){const e=window.NexusConfig||{};return{API_URL:n.API_URL,API_KEY:e.apiKey||n.API_KEY,MODEL:e.model||n.MODEL,BOT_NAME:e.botName||n.BOT_NAME,GREETING:e.greeting||n.GREETING,SYSTEM_PROMPT:e.systemPrompt||n.SYSTEM_PROMPT,COLORS:n.COLORS}}();window.__NEXUS_CONFIG=a,await async function(){const n=document.createElement("link");n.href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.1/css/all.min.css",n.rel="stylesheet",document.head.appendChild(n);const e=document.createElement("link");e.href="https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@400;500;600;700&display=swap",e.rel="stylesheet",document.head.appendChild(e);const t=document.createElement("script");t.src="https://cdnjs.cloudflare.com/ajax/libs/marked/12.0.0/marked.min.js",t.async=!0,document.head.appendChild(t);const o=document.createElement("link");o.href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/styles/github-dark.min.css",o.rel="stylesheet",document.head.appendChild(o);const a=document.createElement("script");a.src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/highlight.min.js",a.async=!0,document.head.appendChild(a),await async function(){await Promise.all([b("https://cdnjs.cloudflare.com/ajax/libs/readability/0.4.4/Readability.min.js"),b("https://cdnjs.cloudflare.com/ajax/libs/turndown/7.1.2/turndown.min.js")]),g=window.Readability,f=window.TurndownService,console.log("šŸ“š Scraper libraries loaded")}()}(),function(){const e=document.createElement("style");e.id="ai-chat-widget-styles",e.textContent=`\n @keyframes slideUpFade {\n 0% { opacity: 0; transform: translateY(16px); }\n 100% { opacity: 1; transform: translateY(0); }\n }\n @keyframes pulseDot {\n 0%, 100% { transform: scale(0.8); opacity: 0.5; }\n 50% { transform: scale(1.2); opacity: 1; }\n }\n @keyframes typing {\n 0%, 80%, 100% { opacity: 0.3; }\n 40% { opacity: 1; }\n }\n\n #ai-widget-root {\n all: initial;\n font-family: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, sans-serif;\n position: fixed;\n bottom: 24px;\n right: 24px;\n z-index: 999999;\n display: flex;\n flex-direction: column;\n align-items: flex-end;\n pointer-events: none;\n }\n #ai-widget-root * { box-sizing: border-box; pointer-events: auto; }\n\n /* ===== FIX: Font Awesome icons ===== */\n #ai-widget-root .fas,\n #ai-widget-root .far,\n #ai-widget-root .fab {\n font-family: 'Font Awesome 6 Free', 'Font Awesome 6 Brands' !important;\n font-weight: 900 !important; /* solid icons use 900 */\n font-style: normal;\n font-variant: normal;\n text-rendering: auto;\n -webkit-font-smoothing: antialiased;\n }\n #ai-widget-root .far {\n font-weight: 400 !important; /* regular */\n }\n #ai-widget-root .fab {\n font-family: 'Font Awesome 6 Brands' !important;\n font-weight: 400 !important;\n }\n\n /* ===== FLOATING ORB (FAB) ===== */\n .ai-fab {\n width: 56px;\n height: 56px;\n border-radius: 50%;\n background: #ffffff;\n border: 1px solid rgba(255,255,255,0.1);\n cursor: pointer;\n display: flex;\n align-items: center;\n justify-content: center;\n color: #000000;\n transition: opacity 0.3s cubic-bezier(0.16, 1, 0.3, 1),\n transform 0.3s cubic-bezier(0.16, 1, 0.3, 1),\n box-shadow 0.25s ease;\n user-select: none;\n box-shadow: 0 8px 24px rgba(0,0,0,0.4);\n position: relative;\n z-index: 10;\n will-change: transform, opacity;\n }\n .ai-fab:hover {\n transform: scale(1.05);\n box-shadow: 0 12px 32px rgba(0,0,0,0.5);\n }\n .ai-fab .bot-icon i {\n color: #000000 !important;\n font-size: 24px !important;\n }\n\n /* Hide FAB when panel is open – smooth fade + scale */\n .ai-panel.open ~ .ai-fab {\n opacity: 0;\n transform: scale(0.8);\n pointer-events: none;\n }\n\n /* ===== CHAT PANEL ===== */\n .ai-panel {\n position: absolute;\n bottom: 0;\n right: 0;\n width: 400px;\n max-width: calc(100vw - 48px);\n height: 600px;\n max-height: calc(100vh - 48px);\n background: ${n.COLORS.panelBg};\n backdrop-filter: blur(20px);\n -webkit-backdrop-filter: blur(20px);\n border-radius: 20px;\n box-shadow: 0 24px 80px rgba(0,0,0,0.5), 0 0 0 1px ${n.COLORS.border};\n display: flex;\n flex-direction: column;\n overflow: hidden;\n opacity: 0;\n visibility: hidden;\n transform: translateY(20px);\n transition: opacity 0.3s ease, transform 0.3s cubic-bezier(0.16, 1, 0.3, 1), visibility 0.3s;\n }\n .ai-panel.open {\n opacity: 1;\n visibility: visible;\n transform: translateY(0);\n }\n\n /* ===== HEADER ===== */\n .ai-header {\n padding: 20px 24px;\n border-bottom: 1px solid ${n.COLORS.border};\n display: flex;\n justify-content: space-between;\n align-items: center;\n flex-shrink: 0;\n background: transparent;\n }\n .ai-header-title {\n display: flex;\n align-items: center;\n gap: 12px;\n color: ${n.COLORS.textPrimary};\n font-weight: 600;\n font-size: 16px;\n }\n .status-dot {\n width: 8px;\n height: 8px;\n border-radius: 50%;\n background: #10B981;\n box-shadow: 0 0 8px rgba(16, 185, 129, 0.5);\n }\n .ai-close-btn {\n background: transparent;\n border: none;\n color: ${n.COLORS.textSecondary};\n font-size: 20px;\n cursor: pointer;\n transition: color 0.2s;\n display: flex;\n align-items: center;\n justify-content: center;\n }\n .ai-close-btn:hover {\n color: ${n.COLORS.textPrimary};\n }\n\n /* ===== MESSAGES ===== */\n .ai-messages {\n flex: 1;\n padding: 24px;\n overflow-y: auto;\n display: flex;\n flex-direction: column;\n gap: 24px;\n scroll-behavior: smooth;\n }\n .ai-messages::-webkit-scrollbar { width: 6px; }\n .ai-messages::-webkit-scrollbar-track { background: transparent; }\n .ai-messages::-webkit-scrollbar-thumb {\n background: ${n.COLORS.border};\n border-radius: 10px;\n }\n\n /* ===== BUBBLES ===== */\n .msg {\n max-width: 85%;\n font-size: 14.5px;\n line-height: 1.6;\n word-break: break-word;\n animation: slideUpFade 0.4s cubic-bezier(0.16, 1, 0.3, 1) forwards;\n color: ${n.COLORS.textPrimary};\n }\n .msg.user {\n align-self: flex-end;\n background: ${n.COLORS.userBubble};\n padding: 12px 18px;\n border-radius: 16px;\n border-bottom-right-radius: 4px;\n border: 1px solid ${n.COLORS.border};\n }\n .msg.bot {\n align-self: flex-start;\n background: ${n.COLORS.botBubble};\n max-width: 95%;\n }\n .msg.bot .bot-label {\n font-size: 12px;\n color: ${n.COLORS.textSecondary};\n margin-bottom: 6px;\n font-weight: 500;\n display: flex;\n align-items: center;\n gap: 6px;\n }\n .msg .image-preview {\n max-width: 200px;\n border-radius: 12px;\n margin-top: 8px;\n border: 1px solid ${n.COLORS.border};\n }\n .msg.user .image-preview { max-width: 100%; }\n\n /* Markdown Cleanup */\n .msg.bot p { margin: 0 0 12px 0; }\n .msg.bot p:last-child { margin-bottom: 0; }\n .msg.bot code {\n background: #1e1e1e;\n padding: 2px 6px;\n border-radius: 4px;\n font-family: ui-monospace, monospace;\n font-size: 0.9em;\n border: 1px solid ${n.COLORS.border};\n }\n .msg.bot pre {\n background: #111111;\n padding: 16px;\n border-radius: 12px;\n overflow-x: auto;\n margin: 12px 0;\n border: 1px solid ${n.COLORS.border};\n }\n .msg.bot pre code { background: transparent; padding: 0; border: none; }\n .msg.bot ul, .msg.bot ol { margin: 8px 0 12px 20px; padding-left: 0; }\n .msg.bot li { margin-bottom: 6px; }\n .msg.bot a { color: #fff; text-decoration: underline; text-underline-offset: 4px; }\n\n /* ===== INPUT AREA ===== */\n .ai-input-area {\n padding: 16px 24px 24px;\n background: transparent;\n flex-shrink: 0;\n }\n .ai-input-container {\n display: flex;\n align-items: center;\n background: #161616;\n border: 1px solid ${n.COLORS.border};\n border-radius: 24px;\n padding: 6px 6px 6px 16px;\n transition: border-color 0.2s, background 0.2s;\n }\n .ai-input-container:focus-within {\n border-color: #555;\n background: #1a1a1a;\n }\n .ai-input-container input {\n flex: 1;\n background: transparent;\n border: none;\n color: ${n.COLORS.textPrimary};\n font-size: 14px;\n outline: none;\n font-family: inherit;\n padding: 8px 0;\n }\n .ai-input-container input::placeholder {\n color: ${n.COLORS.textSecondary};\n }\n .icon-btn {\n background: transparent;\n border: none;\n color: ${n.COLORS.textSecondary};\n width: 36px;\n height: 36px;\n border-radius: 50%;\n display: flex;\n align-items: center;\n justify-content: center;\n cursor: pointer;\n transition: color 0.2s, background 0.2s;\n }\n .icon-btn:hover {\n color: #fff;\n background: ${n.COLORS.borderHover};\n }\n .send-btn {\n background: #fff;\n color: #000;\n margin-left: 4px;\n }\n .send-btn:hover {\n background: #e0e0e0;\n color: #000;\n }\n .send-btn:disabled {\n background: #333;\n color: #666;\n cursor: not-allowed;\n }\n\n /* ===== PREVIEW PILL ===== */\n #aiPreviewContainer { margin-bottom: 12px; }\n .image-preview-pill {\n display: inline-flex;\n align-items: center;\n gap: 8px;\n background: #1e1e1e;\n border: 1px solid ${n.COLORS.border};\n border-radius: 8px;\n padding: 6px 12px 6px 6px;\n animation: slideUpFade 0.3s ease forwards;\n }\n .image-preview-pill img {\n width: 24px;\n height: 24px;\n border-radius: 4px;\n object-fit: cover;\n }\n .image-preview-pill .file-name {\n font-size: 12px;\n color: ${n.COLORS.textPrimary};\n max-width: 120px;\n overflow: hidden;\n text-overflow: ellipsis;\n white-space: nowrap;\n }\n .image-preview-pill .remove-file {\n background: none;\n border: none;\n color: ${n.COLORS.textSecondary};\n cursor: pointer;\n font-size: 14px;\n display: flex;\n align-items: center;\n }\n .image-preview-pill .remove-file:hover { color: #fff; }\n\n /* ===== TYPING INDICATOR ===== */\n .typing-indicator {\n display: flex;\n gap: 4px;\n padding: 8px 0;\n align-self: flex-start;\n }\n .typing-indicator span {\n width: 6px;\n height: 6px;\n border-radius: 50%;\n background: ${n.COLORS.textSecondary};\n animation: typing 1.4s infinite;\n }\n .typing-indicator span:nth-child(2) { animation-delay: 0.2s; }\n .typing-indicator span:nth-child(3) { animation-delay: 0.4s; }\n\n /* ===== RESPONSIVE ===== */\n @media (max-width: 480px) {\n .ai-panel {\n width: calc(100vw - 32px);\n right: 16px;\n height: 80vh;\n max-height: calc(100vh - 48px);\n }\n .ai-fab {\n width: 50px;\n height: 50px;\n }\n .ai-fab .bot-icon { font-size: 20px; }\n }\n `,document.head.appendChild(e)}(),function(){const e=window.__NEXUS_CONFIG?.BOT_NAME||n.BOT_NAME,t=window.__NEXUS_CONFIG?.GREETING||n.GREETING,o=document.createElement("div");o.id="ai-widget-root",o.innerHTML=`\n <div class="ai-panel" id="aiPanel">\n <div class="ai-header">\n <div class="ai-header-title">\n <span class="status-dot"></span>\n ${e}\n </div>\n <button class="ai-close-btn" id="aiCloseBtn" aria-label="Close chat">\n <i class="fas fa-xmark"></i>\n </button>\n </div>\n <div class="ai-messages" id="aiMessages">\n <div class="msg bot">\n ${t}\n </div>\n </div>\n <div class="ai-input-area" id="aiInputArea">\n <div id="aiPreviewContainer"></div>\n <div class="ai-input-container">\n <button class="icon-btn" id="aiAttachBtn" aria-label="Attach image">\n <i class="fas fa-paperclip"></i>\n </button>\n <input type="text" id="aiInput" placeholder="Message..." autocomplete="off">\n <button class="icon-btn send-btn" id="aiSendBtn">\n <i class="fas fa-arrow-up"></i>\n </button>\n </div>\n </div>\n </div>\n <button class="ai-fab" id="aiFab" aria-label="Open AI Chat">\n <span class="bot-icon">\n <i class="fas fa-robot" style="color: #000000 !important; font-size: 22px;"></i>\n </span>\n </button>\n `,document.body.appendChild(o)}();const i=e("aiPanel"),p=e("aiMessages"),x=e("aiFab"),v=e("aiCloseBtn"),S=e("aiSendBtn"),O=e("aiInput"),k=e("aiAttachBtn"),E=e("aiPreviewContainer");!function(n){let e=window.location.href;new MutationObserver(()=>{window.location.href!==e&&(e=window.location.href,console.log("šŸ”„ Page navigation detected"),n())}).observe(document,{subtree:!0,childList:!0});const t=history.pushState;history.pushState=function(){t.apply(this,arguments),setTimeout(()=>{window.location.href!==e&&(e=window.location.href,n())},500)}}(()=>{console.log("šŸ”„ Page changed, refreshing context..."),async function(){console.log("šŸ”„ Forcing page context refresh...");const n=y(h());await m(n),console.log("āœ… Page context refreshed")}(),o(p,"šŸ”„ Page context updated!","bot")});const C=document.createElement("input");C.type="file",C.accept="image/*",C.style.display="none",C.id="aiFileInput",document.body.appendChild(C),k?.addEventListener("click",()=>C.click()),C.addEventListener("change",n=>{const e=n.target.files?.[0];if(!e)return;if(!e.type.startsWith("image/"))return void alert("Please select an image file.");const t=new FileReader;t.onload=n=>{const t={dataUrl:n.target.result,name:e.name,type:e.type};c({attachedFile:t}),r(E,t);const o=document.getElementById("aiRemoveFile");o&&o.addEventListener("click",()=>{c({attachedFile:null}),r(E,null),O?.focus()}),O?.focus()},t.readAsDataURL(e),n.target.value=""}),x?.addEventListener("click",()=>{c({isOpen:t(i,!0)})}),v?.addEventListener("click",()=>{c({isOpen:t(i,!1)})}),document.addEventListener("click",n=>{const e=document.getElementById("ai-widget-root");e&&s.isOpen&&!e.contains(n.target)&&c({isOpen:t(i,!1)})});const L=()=>{const n=O?.value.trim();if(!n&&!s.attachedFile)return;if(s.isProcessing)return;const e=s.attachedFile?.dataUrl||null;o(p,n,"user",e),O.value="",r(E,null);const t=s.attachedFile?.dataUrl||null;c({attachedFile:null}),w(p,n,t)};S?.addEventListener("click",L),O?.addEventListener("keydown",n=>{"Enter"!==n.key||n.shiftKey||(n.preventDefault(),L())});const P=await async function(){try{const n=(await u()).transaction(d,"readonly").objectStore(d);return new Promise(e=>{const t=n.count();t.onsuccess=()=>{e({totalEntries:t.result,database:l,version:1})},t.onerror=()=>e(null)})}catch{return null}}();console.log("šŸ“Š Cache Stats:",P||"No cache yet"),console.log("✨ Nexus AI v2.0 initialized with advanced scraper!")}s.conversationHistory=[{role:"system",content:n.SYSTEM_PROMPT}],"loading"===document.readyState?document.addEventListener("DOMContentLoaded",v):v()})();
1
+ (()=>{"use strict";const n={API_URL:"https://api.groq.com/openai/v1/chat/completions",API_KEY:"",MODEL:"meta-llama/llama-4-scout-17b-16e-instruct",BOT_NAME:"Nexus AI",GREETING:"šŸ‘‹ Hey there! I'm **Nexus AI** – your smart assistant for this page.\n\nAsk me anything about the content you see here. I can:\n• šŸ“– Summarize articles\n• šŸ” Find specific details\n• šŸ“Š Explain tables and data\n• šŸ’” Answer questions instantly\n\nJust type your question below and I'll do my best to help! šŸš€",SYSTEM_PROMPT:"\nYou are Nexus AI, a smart assistant. Use the page context provided in every response.\n\n**Rules:**\n- Always prioritize the given page context over general knowledge.\n- Quote specific details (headings, tables, code, lists, etc.) from the context.\n- Structure answers clearly with bullet points or headings where helpful.\n- Be crisp, professional, and friendly. Use Markdown.\n- If information is not in context, politely say so and offer to help with related topics.\n- Keep responses concise (under 600 tokens).\n ",MAX_FILE_SIZE:5242880,ALLOWED_FILE_TYPES:["image/*","application/pdf","text/*","application/msword","application/vnd.openxmlformats-officedocument.wordprocessingml.document"],COLORS:{bg:"#0a0a0a",panelBg:"rgba(12, 12, 12, 0.85)",border:"#2a2a2a",borderHover:"#444444",textPrimary:"#f5f5f5",textSecondary:"#a0a0a0",userBubble:"#1e1e1e",botBubble:"transparent"}},e=n=>document.getElementById(n);function t(n){if(!n)return"";try{if("undefined"!=typeof marked&&marked.parse)return marked.parse(n,{breaks:!0,gfm:!0})}catch(n){console.warn("Markdown parse failed:",n)}return n.replace(/\n/g,"<br>")}function a(){const a=window.__NEXUS_CONFIG?.BOT_NAME||n.BOT_NAME,o=t(window.__NEXUS_CONFIG?.GREETING||n.GREETING),r=document.createElement("div");r.id="ai-widget-root",r.innerHTML=`\n <div class="ai-panel" id="aiPanel">\n <div class="ai-header">\n <div class="ai-header-title">\n <span class="status-dot"></span>\n ${a}\n </div>\n <div class="ai-header-actions">\n <button class="ai-theme-toggle" id="aiThemeToggle" aria-label="Toggle theme">\n <i class="fas fa-moon"></i>\n </button>\n <button class="ai-close-btn" id="aiCloseBtn" aria-label="Close chat">\n <i class="fas fa-xmark"></i>\n </button>\n </div>\n </div>\n <div class="ai-messages" id="aiMessages">\n <div class="msg bot">\n ${o}\n </div>\n </div>\n <div class="ai-input-area" id="aiInputArea">\n <div id="aiPreviewContainer"></div>\n <div class="ai-input-container">\n <button class="icon-btn" id="aiAttachBtn" aria-label="Attach image or file">\n <i class="fas fa-paperclip"></i>\n </button>\n <textarea \n id="aiInput" \n placeholder="Message..." \n rows="1"\n autocomplete="off"\n spellcheck="true"\n ></textarea>\n <button class="icon-btn send-btn" id="aiSendBtn">\n <i class="fas fa-arrow-up"></i>\n </button>\n </div>\n <div class="ai-input-footer">\n <span class="ai-char-count" id="aiCharCount">0</span>\n </div>\n </div>\n </div>\n <button class="ai-fab" id="aiFab" aria-label="Open AI Chat">\n <span class="bot-icon">\n <i class="fas fa-robot" style="color: #ffffff !important; font-size: 22px;"></i>\n </span>\n </button>\n `,document.body.appendChild(r);const i=e("aiInput");return i&&i.addEventListener("input",()=>{!function(n){n.style.height="auto",n.style.height=Math.min(n.scrollHeight,150)+"px"}(i),function(n){const t=e("aiCharCount");if(t){const e=n.value.length;t.textContent=e>0?`${e}`:"0",t.style.color=e>500?"#ef4444":"#a0a0a0"}}(i)}),r}function o(n,t){if(!n)return!1;const a=void 0!==t?t:!n.classList.contains("open");return n.classList.toggle("open",a),a&&setTimeout(()=>{const n=e("aiInput");n&&n.focus()},100),a}function r(n,e,a="bot",o=null){if(!n)return null;const r=document.createElement("div");if(r.className=`msg ${a}`,"bot"===a){const n=t(e);r.innerHTML=n,"undefined"!=typeof hljs&&r.querySelectorAll("pre code").forEach(n=>{hljs.highlightElement(n)})}else{let n=e||"";o&&(n+=`<br><img src="${o}" class="image-preview" alt="attached">`),r.innerHTML=n}return n.appendChild(r),n.scrollTo({top:n.scrollHeight,behavior:"smooth"}),r}let i=null;function s(n,e){n&&(i&&(i.remove(),i=null),e&&(i=document.createElement("div"),i.className="typing-indicator",i.innerHTML="<span></span><span></span><span></span>",n.appendChild(i),n.scrollTo({top:n.scrollHeight,behavior:"smooth"})))}function c(n,e){if(!n)return;if(n.innerHTML="",!e)return;const t=e.type?.startsWith("image/")||e.dataUrl?.startsWith("data:image"),a="application/pdf"===e.type||e.name?.endsWith(".pdf"),o=e.type?.includes("document")||e.name?.endsWith(".docx")||e.name?.endsWith(".txt"),r=document.createElement("div");r.className="image-preview-pill";let i="fa-file",s="rgba(255,255,255,0.04)";var c;t?(i="fa-image",s="rgba(255,255,255,0.04)"):a?(i="fa-file-pdf",s="rgba(255,255,255,0.04)"):o&&(i="fa-file-lines",s="rgba(255,255,255,0.04)"),r.innerHTML=`\n ${t?`<img src="${e.dataUrl}" alt="preview" class="preview-thumb">`:`<i class="fas ${i}" style="font-size: 20px; color: #888;"></i>`}\n <span class="file-name">${e.name||"file"}</span>\n <span class="file-size">${c=e.size||0,c<1024?c+" B":c<1048576?(c/1024).toFixed(1)+" KB":(c/1048576).toFixed(1)+" MB"}</span>\n <button class="remove-file" id="aiRemoveFile" aria-label="Remove file">\n <i class="fas fa-times"></i>\n </button>\n `,r.style.background=s,n.appendChild(r),document.getElementById("aiRemoveFile")?.addEventListener("click",()=>{n.innerHTML="";const e=new CustomEvent("file-removed");document.dispatchEvent(e)})}const l={isOpen:!1,isProcessing:!1,attachedFile:null,conversationHistory:[]};function d(n){Object.assign(l,n)}const p="NexusAICache",u="pageData";let m=null;function g(){return new Promise((n,e)=>{if(m)return void n(m);const t=indexedDB.open(p,1);t.onupgradeneeded=n=>{const e=n.target.result;if(!e.objectStoreNames.contains(u)){const n=e.createObjectStore(u,{keyPath:"id"});n.createIndex("url","url",{unique:!1}),n.createIndex("timestamp","timestamp",{unique:!1}),console.log("šŸ“¦ IndexedDB store created")}},t.onsuccess=e=>{m=e.target.result,n(m)},t.onerror=n=>{e(n.target.error)}})}async function b(n){try{const e=(await g()).transaction(u,"readwrite").objectStore(u),t=window.location.href,a={id:t,url:t,data:n,timestamp:Date.now()};return new Promise((n,t)=>{const o=e.put(a);o.onsuccess=()=>{console.log("šŸ’¾ Data cached in IndexedDB"),n()},o.onerror=n=>{t(n.target.error)}})}catch(n){console.warn("IndexedDB write failed:",n)}}let h=null,f=null;function x(n){return new Promise((e,t)=>{const a=document.createElement("script");a.src=n,a.async=!0,a.onload=e,a.onerror=t,document.head.appendChild(a)})}function w(){console.log("šŸ•·ļø Advanced scraping started...");const n={title:document.title,url:window.location.href,timestamp:(new Date).toISOString(),pageType:y(),readability:null,structuredData:[],markdown:"",summary:"",metadata:{}};try{if(h){const e=document.cloneNode(!0),t=new h(e).parse();if(t){if(n.readability={title:t.title,byline:t.byline,excerpt:t.excerpt,content:t.content,textContent:t.textContent},f){const e=new f({headingStyle:"atx",codeBlockStyle:"fenced",emDelimiter:"*",bulletListMarker:"-"});e.addRule("strikethrough",{filter:["del","s","strike"],replacement:function(n){return"~~"+n+"~~"}}),n.markdown=e.turndown(t.content)}n.summary=t.excerpt||t.textContent.substring(0,300)}}}catch(e){console.warn("Readability failed, falling back to basic scraper:",e),n.readability=null}try{document.querySelectorAll('script[type="application/ld+json"]').forEach(e=>{try{const t=JSON.parse(e.textContent);n.structuredData.push(t)}catch(n){}})}catch(n){console.warn("JSON-LD extraction failed:",n)}if(n.metadata=function(){const n={},e=document.querySelector('meta[name="description"]');e&&(n.description=e.content);const t=document.querySelector('meta[name="keywords"]');t&&(n.keywords=t.content),["title","description","image","url","type","site_name"].forEach(e=>{const t=document.querySelector(`meta[property="og:${e}"]`);t&&(n[`og_${e}`]=t.content)}),["card","title","description","image"].forEach(e=>{const t=document.querySelector(`meta[name="twitter:${e}"]`);t&&(n[`twitter_${e}`]=t.content)});const a=document.querySelector('link[rel="canonical"]');return a&&(n.canonical=a.href),n}(),!n.readability){console.log("āš ļø Using fallback scraper");const e=function(){const n=document.body.cloneNode(!0);["nav","header","footer","aside",".sidebar",".navigation",".menu",".ads",".cookie-banner",".popup",".overlay","script","style","noscript","iframe"].forEach(e=>{n.querySelectorAll(e).forEach(n=>n.remove())});let e=n.textContent||"";e=e.replace(/\s+/g," ").trim();const t=e.substring(0,500)+"...";return{content:e,summary:t}}();n.markdown=e.content,n.summary=e.summary}return n.aiContext=v(n),console.log("āœ… Advanced scraping complete"),n}function y(){const n=window.location.href,e=document.title.toLowerCase(),t=document.querySelector('meta[property="og:type"]');if(t){const n=t.content;if(n.includes("article"))return"article";if(n.includes("product"))return"product";if(n.includes("website"))return"website"}return n.includes("/blog/")||n.includes("/post/")||e.includes("blog")?"blog":n.includes("/product/")||n.includes("/shop/")?"product":n.includes("/portfolio/")||n.includes("/project/")?"portfolio":n===window.location.origin+"/"||n===window.location.origin?"homepage":"general"}function v(n){let e="";if(e+=`# šŸ“„ ${n.title}\n\n`,e+=`**URL:** ${n.url}\n`,e+=`**Type:** ${n.pageType}\n`,e+=`**Scraped:** ${new Date(n.timestamp).toLocaleString()}\n\n`,Object.keys(n.metadata).length>0){e+="## šŸ“‹ Metadata\n";for(const[t,a]of Object.entries(n.metadata))a&&a.length>0&&(e+=`- **${t}:** ${a}\n`);e+="\n"}if(n.structuredData&&n.structuredData.length>0&&(e+="## šŸ“Š Structured Data (Schema.org)\n",n.structuredData.forEach((n,t)=>{e+=`\n### Schema ${t+1}\n`,e+=`\`\`\`json\n${JSON.stringify(n,null,2)}\n\`\`\`\n`}),e+="\n"),n.markdown){e+="## šŸ“ Main Content\n\n";const t=4e3,a=n.markdown.length>t?n.markdown.substring(0,t)+"... (truncated)":n.markdown;e+=a,e+="\n\n"}return n.summary&&(e+="## šŸ“Œ Summary\n\n",e+=n.summary,e+="\n\n"),e+="---\n",e+="*šŸ¤– AI Instructions: Use this context to answer user questions about this page. Be precise, reference specific details from the content, and maintain a friendly professional tone.*\n",e}async function k(e,t,a=null){if(l.isProcessing)return;d({isProcessing:!0});const o=document.getElementById("aiSendBtn"),i=document.getElementById("aiInput");o&&(o.disabled=!0),i&&(i.disabled=!0),s(e,!0);const c=[];if(t&&c.push({type:"text",text:t}),a&&c.push({type:"image_url",image_url:{url:a}}),l.conversationHistory.push({role:"user",content:t||"(image)"}),l.conversationHistory.length>11){const n=l.conversationHistory[0],e=l.conversationHistory.slice(-10);l.conversationHistory=[n,...e]}try{const t=await async function(){let n=await async function(){try{const n=(await g()).transaction(u,"readonly").objectStore(u),e=window.location.href;return new Promise((t,a)=>{const o=n.get(e);o.onsuccess=n=>{const a=n.target.result;if(!a)return void t(null);const o=Date.now();if(o-a.timestamp>864e5)return async function(n){try{(await g()).transaction(u,"readwrite").objectStore(u).delete(n)}catch(n){console.warn("IndexedDB delete failed:",n)}}(e),void t(null);console.log(`šŸ“¦ Cache hit! Age: ${Math.floor((o-a.timestamp)/6e4)} minutes`),t(a.data)},o.onerror=n=>{a(n.target.error)}})}catch(n){return console.warn("IndexedDB read failed:",n),null}}();if(n)return console.log("šŸ“¦ Using cached page data"),n;console.log("šŸ” Scraping page data...");const e=v(w());return await b(e),console.log("šŸ’¾ Page data cached"),e}(),a=window.__NEXUS_CONFIG||n,o=[{role:"system",content:`${a.SYSTEM_PROMPT}\n\n## Current Page Context\n${t}`}];for(let n=1;n<l.conversationHistory.length-1;n++)o.push({role:l.conversationHistory[n].role,content:l.conversationHistory[n].content});o.push({role:"user",content:c});const i=await fetch(a.API_URL,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${a.API_KEY}`},body:JSON.stringify({model:a.MODEL,messages:o,temperature:.7,max_tokens:600,stream:!1})});if(!i.ok){const n=await i.json().catch(()=>({}));throw new Error(`API error ${i.status}: ${n.error?.message||i.statusText}`)}const d=await i.json(),p=d.choices?.[0]?.message?.content||"Sorry, I didn't understand that.";l.conversationHistory.push({role:"assistant",content:p}),s(e,!1),r(e,p,"bot")}catch(n){console.error("Groq API Error:",n),s(e,!1),r(e,`āš ļø Oops! ${n.message||"Something went wrong."} Please try again.`,"bot")}finally{d({isProcessing:!1}),o&&(o.disabled=!1),i&&(i.disabled=!1,i.value="",i.focus())}}function E(){const n=document.getElementById("ai-widget-root");if(!n)return;const e="dark"===(n.dataset.theme||"dark")?"light":"dark";n.dataset.theme=e,localStorage.setItem("nexus-theme",e),window.__NEXUS_CONFIG&&(window.__NEXUS_CONFIG.THEME=e);const t=document.getElementById("aiThemeToggle");t&&(t.innerHTML="dark"===e?'<i class="fas fa-moon"></i>':'<i class="fas fa-sun"></i>',t.title="dark"===e?"Switch to Light":"Switch to Dark"),console.log(`šŸŒ“ Theme switched to: ${e}`)}async function S(){const t=function(){const e=window.NexusConfig||{},t=function(){const n=window.NexusConfig||{};if(n.theme)return n.theme;const e=localStorage.getItem("nexus-theme");if(e)return e;const t=document.body;if(t.classList.contains("dark")||t.classList.contains("dark-theme")||t.classList.contains("dark-mode"))return"dark";if(t.classList.contains("light")||t.classList.contains("light-theme")||t.classList.contains("light-mode"))return"light";const a=document.documentElement.getAttribute("data-theme");if("dark"===a||"light"===a)return a;const o=document.querySelector('meta[name="theme-color"]');if(o){const n=o.content;if(n.startsWith("#")&&parseInt(n.slice(1,3),16)<100)return"dark"}return window.matchMedia&&window.matchMedia("(prefers-color-scheme: dark)").matches,"dark"}();return{API_URL:n.API_URL,API_KEY:e.apiKey||n.API_KEY,MODEL:e.model||n.MODEL,BOT_NAME:e.botName||n.BOT_NAME,GREETING:e.greeting||n.GREETING,SYSTEM_PROMPT:e.systemPrompt||n.SYSTEM_PROMPT,THEME:t,COLORS:n.COLORS}}();window.__NEXUS_CONFIG=t,await async function(){const n=document.createElement("link");n.href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.1/css/all.min.css",n.rel="stylesheet",document.head.appendChild(n);const e=document.createElement("link");e.href="https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@400;500;600;700&display=swap",e.rel="stylesheet",document.head.appendChild(e);const t=document.createElement("script");t.src="https://cdnjs.cloudflare.com/ajax/libs/marked/12.0.0/marked.min.js",t.async=!0,document.head.appendChild(t);const a=document.createElement("link");a.href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/styles/github-dark.min.css",a.rel="stylesheet",document.head.appendChild(a);const o=document.createElement("script");o.src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/highlight.min.js",o.async=!0,document.head.appendChild(o),await async function(){await Promise.all([x("https://cdnjs.cloudflare.com/ajax/libs/readability/0.4.4/Readability.min.js"),x("https://cdnjs.cloudflare.com/ajax/libs/turndown/7.1.2/turndown.min.js")]),h=window.Readability,f=window.TurndownService,console.log("šŸ“š Scraper libraries loaded")}()}(),function(){const n=document.createElement("style");n.id="ai-chat-widget-styles",n.textContent="\n /* ===== MONOCHROME THEME VARIABLES ===== */\n #ai-widget-root {\n /* Dark theme defaults */\n --bg-panel: rgba(10, 10, 10, 0.85);\n --bg-input: rgba(255, 255, 255, 0.03);\n --border-color: rgba(255, 255, 255, 0.08);\n --text-primary: #f0f0f0;\n --text-secondary: #999;\n --user-bubble-bg: #2a2a2a;\n --bot-bubble-bg: rgba(255, 255, 255, 0.04);\n --shadow-color: rgba(0, 0, 0, 0.6);\n --fab-bg: rgba(255, 255, 255, 0.05);\n --accent: #aaa;\n --send-bg: #f0f0f0;\n --send-color: #111;\n }\n\n /* ===== LIGHT THEME ===== */\n #ai-widget-root[data-theme=\"light\"] {\n --bg-panel: rgba(245, 245, 245, 0.92);\n --bg-input: rgba(0, 0, 0, 0.02);\n --border-color: rgba(0, 0, 0, 0.08);\n --text-primary: #111;\n --text-secondary: #555;\n --user-bubble-bg: #e0e0e0;\n --bot-bubble-bg: rgba(255, 255, 255, 0.5);\n --shadow-color: rgba(0, 0, 0, 0.05);\n --fab-bg: rgba(255, 255, 255, 0.6);\n --accent: #888;\n --send-bg: #222;\n --send-color: #fff;\n }\n\n /* ===== ANIMATIONS ===== */\n @keyframes slideUpFade {\n 0% { opacity: 0; transform: translateY(30px) scale(0.95); }\n 100% { opacity: 1; transform: translateY(0) scale(1); }\n }\n @keyframes pulseDot {\n 0%, 100% { transform: scale(0.8); opacity: 0.5; }\n 50% { transform: scale(1.3); opacity: 1; }\n }\n @keyframes typing {\n 0%, 80%, 100% { opacity: 0.3; transform: translateY(2px); }\n 40% { opacity: 1; transform: translateY(-2px); }\n }\n @keyframes previewPop {\n 0% { opacity: 0; transform: scale(0.8) translateY(10px); }\n 100% { opacity: 1; transform: scale(1) translateY(0); }\n }\n @keyframes fabPulse {\n 0% { box-shadow: 0 0 0 0 rgba(255,255,255,0.1); }\n 70% { box-shadow: 0 0 0 20px rgba(255,255,255,0); }\n 100% { box-shadow: 0 0 0 0 rgba(255,255,255,0); }\n }\n\n /* ===== ROOT ===== */\n #ai-widget-root {\n all: initial;\n font-family: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, sans-serif;\n position: fixed;\n bottom: 24px;\n right: 24px;\n z-index: 999999;\n display: flex;\n flex-direction: column;\n align-items: flex-end;\n pointer-events: none;\n color: var(--text-primary);\n }\n #ai-widget-root * { box-sizing: border-box; pointer-events: auto; }\n\n /* ===== ICONS FIX ===== */\n #ai-widget-root .fas,\n #ai-widget-root .far,\n #ai-widget-root .fab {\n font-family: 'Font Awesome 6 Free', 'Font Awesome 6 Brands' !important;\n font-weight: 900 !important;\n font-style: normal;\n font-variant: normal;\n text-rendering: auto;\n -webkit-font-smoothing: antialiased;\n }\n #ai-widget-root .far { font-weight: 400 !important; }\n #ai-widget-root .fab {\n font-family: 'Font Awesome 6 Brands' !important;\n font-weight: 400 !important;\n }\n\n /* ===== FLOATING ACTION BUTTON ===== */\n .ai-fab {\n width: 60px;\n height: 60px;\n border-radius: 50%;\n background: var(--fab-bg);\n backdrop-filter: blur(12px);\n -webkit-backdrop-filter: blur(12px);\n border: 1px solid var(--border-color);\n cursor: pointer;\n display: flex;\n align-items: center;\n justify-content: center;\n color: var(--text-primary);\n transition: all 0.4s cubic-bezier(0.16, 1, 0.3, 1);\n user-select: none;\n box-shadow: 0 8px 32px var(--shadow-color);\n position: relative;\n z-index: 10;\n will-change: transform, opacity;\n animation: fabPulse 3s infinite;\n }\n .ai-fab:hover {\n transform: scale(1.08) rotate(-5deg);\n box-shadow: 0 12px 40px var(--shadow-color);\n border-color: var(--accent);\n }\n .ai-fab .bot-icon i {\n color: var(--text-primary) !important;\n font-size: 26px !important;\n filter: drop-shadow(0 2px 8px rgba(0,0,0,0.2));\n }\n .ai-panel.open ~ .ai-fab {\n opacity: 0;\n transform: scale(0.8);\n pointer-events: none;\n animation: none;\n }\n\n /* ===== CHAT PANEL ===== */\n .ai-panel {\n position: absolute;\n bottom: 0;\n right: 0;\n width: 420px;\n max-width: calc(100vw - 48px);\n height: 620px;\n max-height: calc(100vh - 48px);\n background: var(--bg-panel);\n backdrop-filter: blur(32px);\n -webkit-backdrop-filter: blur(32px);\n border-radius: 28px;\n box-shadow: 0 32px 80px var(--shadow-color), 0 0 0 1px var(--border-color);\n display: flex;\n flex-direction: column;\n overflow: hidden;\n opacity: 0;\n visibility: hidden;\n transform: translateY(20px) scale(0.96);\n transition: all 0.35s cubic-bezier(0.16, 1, 0.3, 1);\n border: 1px solid var(--border-color);\n }\n .ai-panel.open {\n opacity: 1;\n visibility: visible;\n transform: translateY(0) scale(1);\n }\n\n /* ===== HEADER ===== */\n .ai-header {\n padding: 20px 24px;\n border-bottom: 1px solid var(--border-color);\n display: flex;\n justify-content: space-between;\n align-items: center;\n flex-shrink: 0;\n }\n .ai-header-actions {\n display: flex;\n align-items: center;\n gap: 8px;\n }\n .ai-header-title {\n display: flex;\n align-items: center;\n gap: 12px;\n color: var(--text-primary);\n font-weight: 600;\n font-size: 16px;\n letter-spacing: -0.3px;\n }\n .status-dot {\n width: 10px;\n height: 10px;\n border-radius: 50%;\n background: var(--accent);\n box-shadow: 0 0 12px rgba(128,128,128,0.4);\n animation: pulseDot 2s infinite;\n flex-shrink: 0;\n }\n .ai-theme-toggle,\n .ai-close-btn {\n background: transparent;\n border: 1px solid var(--border-color);\n color: var(--text-secondary);\n width: 32px;\n height: 32px;\n border-radius: 50%;\n font-size: 14px;\n cursor: pointer;\n transition: all 0.2s;\n display: flex;\n align-items: center;\n justify-content: center;\n }\n .ai-theme-toggle:hover,\n .ai-close-btn:hover {\n background: var(--border-color);\n color: var(--text-primary);\n transform: rotate(90deg);\n }\n .ai-theme-toggle:hover {\n transform: rotate(180deg) !important;\n }\n\n /* ===== MESSAGES ===== */\n .ai-messages {\n flex: 1;\n padding: 24px 24px 16px;\n overflow-y: auto;\n display: flex;\n flex-direction: column;\n gap: 20px;\n scroll-behavior: smooth;\n }\n .ai-messages::-webkit-scrollbar { width: 4px; }\n .ai-messages::-webkit-scrollbar-track { background: transparent; }\n .ai-messages::-webkit-scrollbar-thumb {\n background: var(--border-color);\n border-radius: 10px;\n }\n\n /* ===== MESSAGE BUBBLES ===== */\n .msg {\n max-width: 85%;\n font-size: 14.5px;\n line-height: 1.7;\n word-break: break-word;\n animation: slideUpFade 0.5s cubic-bezier(0.16, 1, 0.3, 1) forwards;\n color: var(--text-primary);\n padding: 12px 18px;\n border-radius: 18px;\n position: relative;\n box-shadow: 0 2px 8px var(--shadow-color);\n }\n /* User message – clearly distinguishable */\n .msg.user {\n align-self: flex-end;\n background: var(--user-bubble-bg);\n border: 1px solid var(--border-color);\n border-bottom-right-radius: 4px;\n }\n /* Bot message – different shade */\n .msg.bot {\n align-self: flex-start;\n background: var(--bot-bubble-bg);\n border: 1px solid var(--border-color);\n border-bottom-left-radius: 4px;\n max-width: 95%;\n }\n\n /* Small tail effects for clarity */\n .msg.user::after {\n content: '';\n position: absolute;\n bottom: 0;\n right: -6px;\n width: 12px;\n height: 12px;\n background: var(--user-bubble-bg);\n border-radius: 0 0 12px 0;\n clip-path: polygon(0 0, 100% 0, 100% 100%);\n }\n .msg.bot::before {\n content: '';\n position: absolute;\n bottom: 0;\n left: -6px;\n width: 12px;\n height: 12px;\n background: var(--bot-bubble-bg);\n border-radius: 0 0 0 12px;\n clip-path: polygon(0 0, 100% 100%, 100% 0);\n }\n\n /* ===== MARKDOWN RENDER ===== */\n .msg.bot p { margin: 0 0 12px 0; }\n .msg.bot p:last-child { margin-bottom: 0; }\n .msg.bot code {\n background: var(--border-color);\n padding: 2px 8px;\n border-radius: 6px;\n font-family: ui-monospace, monospace;\n font-size: 0.9em;\n border: 1px solid var(--border-color);\n }\n .msg.bot pre {\n background: var(--border-color);\n padding: 16px;\n border-radius: 14px;\n overflow-x: auto;\n margin: 12px 0;\n border: 1px solid var(--border-color);\n }\n .msg.bot pre code { background: transparent; padding: 0; border: none; }\n .msg.bot ul, .msg.bot ol { margin: 8px 0 12px 20px; padding-left: 0; }\n .msg.bot li { margin-bottom: 6px; }\n .msg.bot a { color: var(--accent); text-decoration: none; border-bottom: 1px dotted var(--accent); }\n .msg .image-preview {\n max-width: 200px;\n border-radius: 14px;\n margin-top: 8px;\n border: 1px solid var(--border-color);\n }\n\n /* ===== INPUT AREA ===== */\n .ai-input-area {\n padding: 12px 20px 20px;\n background: transparent;\n flex-shrink: 0;\n border-top: 1px solid var(--border-color);\n }\n .ai-input-container {\n display: flex;\n align-items: flex-end;\n gap: 8px;\n background: var(--bg-input);\n border: 1px solid var(--border-color);\n border-radius: 20px;\n padding: 4px 4px 4px 16px;\n transition: all 0.3s ease;\n min-height: 48px;\n box-shadow: inset 0 2px 6px rgba(0,0,0,0.02);\n }\n .ai-input-container:focus-within {\n border-color: var(--accent);\n background: var(--bg-input);\n box-shadow: 0 0 0 4px rgba(128,128,128,0.08);\n }\n .ai-input-container textarea {\n flex: 1;\n background: transparent;\n border: none;\n color: var(--text-primary);\n font-size: 14px;\n outline: none;\n font-family: inherit;\n padding: 10px 0;\n resize: none;\n max-height: 150px;\n line-height: 1.6;\n min-height: 28px;\n scrollbar-width: none;\n }\n .ai-input-container textarea::placeholder {\n color: var(--text-secondary);\n font-weight: 400;\n }\n\n .icon-btn {\n background: transparent;\n border: none;\n color: var(--text-secondary);\n width: 38px;\n height: 38px;\n border-radius: 50%;\n display: flex;\n align-items: center;\n justify-content: center;\n cursor: pointer;\n transition: all 0.2s ease;\n flex-shrink: 0;\n align-self: flex-end;\n margin-bottom: 2px;\n }\n .icon-btn:hover {\n color: var(--text-primary);\n background: var(--border-color);\n transform: scale(1.05);\n }\n .icon-btn:active { transform: scale(0.92); }\n\n .send-btn {\n background: var(--send-bg);\n color: var(--send-color);\n width: 38px;\n height: 38px;\n align-self: flex-end;\n margin-bottom: 2px;\n box-shadow: 0 4px 12px var(--shadow-color);\n transition: all 0.3s ease;\n border: none;\n }\n .send-btn:hover {\n transform: scale(1.08) rotate(-3deg);\n box-shadow: 0 6px 20px var(--shadow-color);\n }\n .send-btn:active { transform: scale(0.92); }\n .send-btn:disabled {\n background: var(--border-color);\n color: var(--text-secondary);\n cursor: not-allowed;\n transform: none;\n box-shadow: none;\n }\n\n .ai-input-footer {\n display: flex;\n justify-content: flex-end;\n padding: 4px 6px 0;\n min-height: 20px;\n }\n .ai-char-count {\n font-size: 11px;\n color: var(--text-secondary);\n font-weight: 500;\n transition: color 0.2s;\n opacity: 0.5;\n font-variant-numeric: tabular-nums;\n letter-spacing: 0.3px;\n }\n\n /* ===== PREVIEW PILL ===== */\n #aiPreviewContainer {\n margin-bottom: 8px;\n display: flex;\n flex-wrap: wrap;\n gap: 6px;\n }\n .image-preview-pill {\n display: inline-flex;\n align-items: center;\n gap: 10px;\n background: var(--bg-input);\n border: 1px solid var(--border-color);\n border-radius: 14px;\n padding: 6px 12px 6px 6px;\n animation: previewPop 0.3s cubic-bezier(0.16, 1, 0.3, 1) forwards;\n box-shadow: 0 4px 16px var(--shadow-color);\n transition: all 0.2s;\n max-width: 100%;\n }\n .image-preview-pill:hover {\n transform: translateY(-2px);\n box-shadow: 0 8px 24px var(--shadow-color);\n }\n .image-preview-pill .preview-thumb {\n width: 32px;\n height: 32px;\n border-radius: 10px;\n object-fit: cover;\n border: 1px solid var(--border-color);\n }\n .image-preview-pill .file-name {\n font-size: 12px;\n color: var(--text-primary);\n max-width: 150px;\n overflow: hidden;\n text-overflow: ellipsis;\n white-space: nowrap;\n font-weight: 500;\n }\n .image-preview-pill .file-size {\n font-size: 10px;\n color: var(--text-secondary);\n opacity: 0.6;\n }\n .image-preview-pill .remove-file {\n background: var(--border-color);\n border: none;\n color: var(--text-secondary);\n cursor: pointer;\n font-size: 14px;\n display: flex;\n align-items: center;\n justify-content: center;\n padding: 4px;\n border-radius: 50%;\n transition: all 0.2s;\n margin-left: 2px;\n width: 26px;\n height: 26px;\n }\n .image-preview-pill .remove-file:hover {\n color: #ef4444;\n background: rgba(239,68,68,0.15);\n transform: scale(1.1);\n }\n\n /* ===== TYPING INDICATOR ===== */\n .typing-indicator {\n display: flex;\n gap: 6px;\n padding: 12px 0;\n align-self: flex-start;\n background: var(--bot-bubble-bg);\n padding: 10px 16px;\n border-radius: 18px;\n border: 1px solid var(--border-color);\n }\n .typing-indicator span {\n width: 8px;\n height: 8px;\n border-radius: 50%;\n background: var(--text-secondary);\n animation: typing 1.4s infinite;\n box-shadow: 0 2px 6px rgba(0,0,0,0.02);\n }\n .typing-indicator span:nth-child(2) { animation-delay: 0.2s; }\n .typing-indicator span:nth-child(3) { animation-delay: 0.4s; }\n\n /* ===== RESPONSIVE ===== */\n @media (max-width: 480px) {\n .ai-panel {\n width: calc(100vw - 32px);\n right: 16px;\n height: 80vh;\n max-height: calc(100vh - 48px);\n border-radius: 20px;\n }\n .ai-fab {\n width: 52px;\n height: 52px;\n }\n .ai-fab .bot-icon { font-size: 22px; }\n .ai-input-area {\n padding: 8px 14px 14px;\n }\n .ai-input-container {\n border-radius: 16px;\n padding: 2px 2px 2px 12px;\n min-height: 42px;\n }\n .ai-input-container textarea { font-size: 13px; padding: 8px 0; }\n .icon-btn { width: 32px; height: 32px; }\n .send-btn { width: 32px; height: 32px; }\n .image-preview-pill .file-name { max-width: 100px; }\n }\n ",document.head.appendChild(n)}(),a();const i=document.getElementById("ai-widget-root");i&&(i.dataset.theme=t.THEME||"dark");const s=document.getElementById("aiThemeToggle");if(s){const n="dark"===t.THEME;s.innerHTML=n?'<i class="fas fa-moon"></i>':'<i class="fas fa-sun"></i>',s.title=n?"Switch to Light":"Switch to Dark",s.addEventListener("click",E)}const m=e("aiPanel"),y=e("aiMessages"),S=e("aiFab"),I=e("aiCloseBtn"),T=e("aiSendBtn"),L=e("aiInput"),P=e("aiAttachBtn"),O=e("aiPreviewContainer");!function(n){let e=window.location.href;new MutationObserver(()=>{window.location.href!==e&&(e=window.location.href,console.log("šŸ”„ Page navigation detected"),n())}).observe(document,{subtree:!0,childList:!0});const t=history.pushState;history.pushState=function(){t.apply(this,arguments),setTimeout(()=>{window.location.href!==e&&(e=window.location.href,n())},500)}}(()=>{console.log("šŸ”„ Page changed, refreshing context..."),async function(){console.log("šŸ”„ Forcing page context refresh...");const n=v(w());await b(n),console.log("āœ… Page context refreshed")}(),r(y,"šŸ”„ Page context updated!","bot")});const A=document.createElement("input");A.type="file",A.accept="image/*",A.style.display="none",A.id="aiFileInput",document.body.appendChild(A),P?.addEventListener("click",()=>A.click()),A.addEventListener("change",n=>{const e=n.target.files?.[0];if(!e)return;if(!e.type.startsWith("image/"))return void alert("Please select an image file.");const t=new FileReader;t.onload=n=>{const t={dataUrl:n.target.result,name:e.name,type:e.type};d({attachedFile:t}),c(O,t);const a=document.getElementById("aiRemoveFile");a&&a.addEventListener("click",()=>{d({attachedFile:null}),c(O,null),L?.focus()}),L?.focus()},t.readAsDataURL(e),n.target.value=""}),S?.addEventListener("click",()=>{d({isOpen:o(m,!0)})}),I?.addEventListener("click",()=>{d({isOpen:o(m,!1)})}),document.addEventListener("click",n=>{const e=document.getElementById("ai-widget-root");e&&l.isOpen&&!e.contains(n.target)&&d({isOpen:o(m,!1)})});const M=()=>{const n=L?.value.trim();if(!n&&!l.attachedFile)return;if(l.isProcessing)return;const e=l.attachedFile?.dataUrl||null;r(y,n,"user",e),L.value="",L.style.height="auto",c(O,null);const t=l.attachedFile?.dataUrl||null;d({attachedFile:null}),k(y,n,t)};T?.addEventListener("click",M),L?.addEventListener("keydown",n=>{"Enter"!==n.key||n.shiftKey||(n.preventDefault(),M())});const C=await async function(){try{const n=(await g()).transaction(u,"readonly").objectStore(u);return new Promise(e=>{const t=n.count();t.onsuccess=()=>{e({totalEntries:t.result,database:p,version:1})},t.onerror=()=>e(null)})}catch{return null}}();console.log("šŸ“Š Cache Stats:",C||"No cache yet"),console.log("✨ Nexus AI v2.0 initialized with theme:",t.THEME)}l.conversationHistory=[{role:"system",content:n.SYSTEM_PROMPT}],"loading"===document.readyState?document.addEventListener("DOMContentLoaded",S):S()})();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nexus-web-assistant",
3
- "version": "1.0.1",
3
+ "version": "1.2.0",
4
4
  "description": "AI-powered chatbot widget for any website",
5
5
  "main": "dist/nexus-assistant.min.js",
6
6
  "files": [