Repository navigation
Expand file tree
/
Copy pathcontent.js
More file actions
1 lines (1 loc) · 15.8 KB
/
Copy pathcontent.js
File metadata and controls
1 lines (1 loc) · 15.8 KB
1
(()=>{"use strict";const e=/^[^\p{L}\p{N}]+|[^\p{L}\p{N}]+$/gu,n=/^[\p{L}\p{N}'-]+$/u;function t(e,n){let t=0;const o=/ [.!?] /;for(;t<320;){const a=e.toString();try{"backward"===n?e.setStart(e.startContainer,Math.max(0,e.startOffset-1)):e.setEnd(e.endContainer,e.endOffset+1)}catch{break}const r=e.toString();if(t+=Math.abs(r.length-a.length)||1,o.test("backward"===n?r.slice(0,4):r.slice(-4)))break}}async function o(e){try{return await chrome.runtime.sendMessage({type:e.type,payload:e.payload})}catch(e){return{ok:!1,code:"SW_DEAD",message:`Could not reach service worker: ${e.message}`}}}new Map;const a={price:99,guaranteeDays:30,trialDays:7,reframe:"",utm:{source:"definedict",medium:"extension",campaign:"upgrade"},checkoutUrl:"https://zovo.one/pricing"};function r(){const e=a.utm,n=a.checkoutUrl.includes("?")?"&":"?";return a.checkoutUrl+n+`utm_source=${e.source}&utm_medium=${e.medium}&utm_campaign=${e.campaign}`}function i(e,n){try{return"undefined"!=typeof chrome&&chrome.i18n&&chrome.i18n.getMessage?chrome.i18n.getMessage(e,n):""}catch{return""}}let d=!1;function l(){const e=document.createElement("div");return e.className="defif0f1-paywall-mount",document.body.appendChild(e),function(e){!function(){if(!d)try{const e=document.createElement("style");e.textContent="\n.defif0f1-paywall-overlay {\n position: fixed; inset: 0; z-index: 2147483647;\n display: flex; align-items: center; justify-content: center;\n background: rgba(0,0,0,0.55);\n backdrop-filter: blur(2px);\n}\n.defif0f1-paywall-card {\n width: 340px; max-width: 90vw;\n background: var(--defif0f1-bg, #fff);\n border: 1px solid var(--defif0f1-border, #E5E7EB);\n border-radius: var(--defif0f1-radius-card, 12px);\n box-shadow: var(--defif0f1-shadow-lg, 0 24px 48px -12px rgba(0,0,0,0.28));\n padding: 28px 24px 24px;\n font-family: var(--defif0f1-font, 'Inter', sans-serif);\n color: var(--defif0f1-text, #1A1A2E);\n}\n.defif0f1-paywall-head {\n display: flex; align-items: center; gap: 8px;\n margin-bottom: 12px;\n}\n.defif0f1-paywall-title {\n flex: 1; margin: 0; font-size: 22px; font-weight: 700;\n letter-spacing: -0.02em;\n}\n.defif0f1-paywall-close {\n background: none; border: none; font-size: 24px; line-height: 1;\n cursor: pointer; color: var(--defif0f1-text-secondary, #6B7280);\n padding: 4px 8px; border-radius: 6px;\n}\n.defif0f1-paywall-close:hover { background: var(--defif0f1-surface-2, #F1F2F4); }\n.defif0f1-paywall-reframe {\n font-size: 15px; font-weight: 600; color: var(--defif0f1-pro, #F59E0B);\n margin: 0 0 16px;\n}\n.defif0f1-paywall-features {\n list-style: none; margin: 0 0 20px; padding: 0;\n display: flex; flex-direction: column; gap: 8px;\n}\n.defif0f1-paywall-features li {\n font-size: 14px; line-height: 1.5; color: var(--defif0f1-text, #1A1A2E);\n padding-left: 24px; position: relative;\n}\n.defif0f1-paywall-features li::before {\n content: '\\2713'; position: absolute; left: 0; top: 0;\n color: var(--defif0f1-success, #10B981); font-weight: 700;\n}\n.defif0f1-paywall-pricing {\n display: flex; align-items: baseline; gap: 8px; margin-bottom: 12px;\n}\n.defif0f1-paywall-orig {\n font-size: 18px; text-decoration: line-through;\n color: var(--defif0f1-text-secondary, #6B7280);\n}\n.defif0f1-paywall-price {\n font-size: 40px; font-weight: 700; letter-spacing: -0.03em;\n color: var(--defif0f1-text, #1A1A2E);\n}\n.defif0f1-paywall-once {\n font-size: 13px; font-weight: 500;\n color: var(--defif0f1-text-secondary, #6B7280);\n}\n.defif0f1-paywall-socialproof {\n font-size: 13px; color: var(--defif0f1-text-secondary, #6B7280);\n margin: 0 0 4px;\n}\n.defif0f1-paywall-socialproof strong { color: var(--defif0f1-text, #1A1A2E); }\n.defif0f1-paywall-guarantee {\n font-size: 12px; color: var(--defif0f1-text-secondary, #6B7280);\n margin: 0 0 20px;\n}\n.defif0f1-paywall-cta { font-size: 16px; min-height: 48px; text-decoration: none; }\n",document.head.appendChild(e),d=!0}catch{}}(),e.innerHTML=function(){const e=a,n=i("paywallReframe")||"$99 once vs $9/mo forever",t="One-time payment",o="no subscription",d=i("paywallGuarantee",[String(e.guaranteeDays)])||`${e.guaranteeDays}-day money-back guarantee`,l=i("paywallTrial",[String(e.trialDays)])||`${e.trialDays}-day free trial, no card needed`;return['<div class="defif0f1-paywall-overlay" role="dialog"',' aria-modal="true" aria-label="Upgrade to Define Pro">',"",' <div class="defif0f1-paywall-card">',"",' <div class="defif0f1-paywall-head">',' <span class="defif0f1-badge defif0f1-badge--pro">PRO</span>',' <h2 class="defif0f1-paywall-title">Define Pro</h2>',' <button class="defif0f1-paywall-close" aria-label="Close">×</button>'," </div>","",` <p class="defif0f1-paywall-reframe">${n}</p>`,"",' <ul class="defif0f1-paywall-features">'," <li>Unlimited saved words</li>"," <li>Spaced-repetition flashcards</li>",' <li>BYOK "Explain in context" (OpenAI, Anthropic, Groq)</li>'," <li>Translate mode (30+ languages)</li>"," <li>Export to CSV & Anki</li>"," <li>Multi-dictionary source selector</li>"," </ul>","",' <div class="defif0f1-paywall-pricing">',"",` <span class="defif0f1-paywall-price">$${e.price}</span>`,' <span class="defif0f1-paywall-once">one-time</span>'," </div>","",' <p class="defif0f1-paywall-socialproof">',` <strong>${t}</strong> ·`,` <strong>${o}</strong>`," </p>","",' <p class="defif0f1-paywall-guarantee">',` ${d}`," </p>","",' <a class="defif0f1-btn defif0f1-btn--pro defif0f1-btn--block defif0f1-paywall-cta"',' href="'+r()+'" target="_blank"',' rel="noopener noreferrer">Upgrade to Pro</a>',""," </div>","</div>"].join("\n")}();const n=e.querySelector(".defif0f1-paywall-overlay");if(!n)return;const t=e.querySelector(".defif0f1-paywall-close"),o=()=>{try{e.removeChild(n)}catch{}};t&&t.addEventListener("click",o),n.addEventListener("click",e=>{e.target===n&&o()})}(e),e}let c=null,s=null,p=null,u=!1,m="";function f(a){const r=a.target;if(r instanceof HTMLInputElement||r instanceof HTMLTextAreaElement||r instanceof HTMLElement&&r.isContentEditable)return;const i=window.getSelection();if(!i||i.isCollapsed)return;const d=function(t){if("string"!=typeof t)return null;const o=t.trim();if(0===o.length)return null;if(/\s/.test(o))return null;if(o.length>100)return null;e.lastIndex=0;const a=o.replace(e,"");if(0===a.length)return null;const r=a.toLowerCase();return n.test(r)?r:null}(i.toString());if(!d)return void h(a.clientX,a.clientY,0,chrome.i18n.getMessage("cardNotFound")||"Select a single word to define.");const l=function(e){const n=e.toString().trim();if(0===n.length)return"";let o=null;try{o=e.getRangeAt(0).cloneRange()}catch{return n.slice(0,240)}try{return t(o,"backward"),t(o,"forward"),o.toString().replace(/\s+/g," ").trim().slice(0,240)}catch{return n.slice(0,240)}}(i);m=l,function(e,n){v(),function(e,n){if(!s)return;const t=window.innerHeight,o=n>t-t/3?Math.max(16,n-280):n+16,a=Math.max(16,Math.min(e-170,window.innerWidth-340-16));s.style.top=`${o}px`,s.style.left=`${a}px`,s.style.width="340px"}(e,n),w();const t=p,o=document.createElement("div");o.textContent="Looking up…",o.style.cssText="padding:16px;font:14px/1.5 Inter,sans-serif;color:#6B7280;",t.appendChild(o)}(a.clientX,a.clientY),o({type:"DEFIF0F1_DEFINE",payload:{word:d,sentence:l}}).then(e=>{if(e){if("ok"in e&&e.ok&&"result"in e)y(e.result);else if("ok"in e&&!e.ok){const n=e;h(a.clientX,a.clientY,n.code,n.message)}}else h(a.clientX,a.clientY,0,chrome.i18n.getMessage("cardNetworkErr")||"Could not reach the dictionary.")})}function x(e){"Escape"===e.key&&z()}function g(e){if(!e||"object"!=typeof e)return;const n=e;if("DEFIF0F1_DEFINE_RESULT"===n.type&&n.payload)y(n.payload);else if("DEFIF0F1_DEFINE_ERROR"===n.type&&n.payload){const e=n.payload;h(0,0,e.code,e.message)}}function y(e){v(),w();const n=p;if(b(),n.appendChild(function(e){const n=document.createElement("div");n.className="dd-header";const t=document.createElement("h3");if(t.textContent=e.word,t.className="dd-word",n.appendChild(t),e.phonetic){const t=document.createElement("span");t.textContent=e.phonetic,t.className="dd-ipa",n.appendChild(t)}return n}(e)),e.audioUrl){const t=document.createElement("button");t.textContent=chrome.i18n.getMessage("cardPlayAudio")||"▶ Pronounce",t.className="dd-audio-btn",t.addEventListener("click",()=>function(e){try{new Audio(e).play().catch(()=>{})}catch{}}(e.audioUrl)),n.appendChild(t)}if(function(e,n){for(const t of n){const n=document.createElement("div");n.className="dd-sense";const o=document.createElement("em");o.textContent=t.partOfSpeech,o.className="dd-pos",n.appendChild(o);const a=document.createElement("p");if(a.textContent=t.definition,a.className="dd-definition",n.appendChild(a),t.example){const e=document.createElement("p");e.textContent=`"${t.example}"`,e.className="dd-example",n.appendChild(e)}e.appendChild(n)}}(n,e.definitions),e.synonyms&&e.synonyms.length>0){const t=document.createElement("p");t.textContent=`Synonyms: ${e.synonyms.join(", ")}`,t.className="dd-synonyms",n.appendChild(t)}n.appendChild(function(e){const n=document.createElement("div");n.className="dd-actions";const t=document.createElement("button");t.textContent=chrome.i18n.getMessage("cardSave")||"Save word",t.className="dd-save-btn",t.addEventListener("click",()=>async function(e){const n={id:`${e.word}-${Date.now()}`,word:e.word,definition:e.definitions[0]?.definition||"",partOfSpeech:e.definitions[0]?.partOfSpeech||"",phonetic:e.phonetic,savedAt:Date.now(),source:e.source,url:location.href};try{const e=await o({type:"DEFIF0F1_SAVE_WORD",payload:{word:n}});if(e&&"ok"in e&&!e.ok&&"capHit"in e&&e.capHit){try{l()}catch{}h(0,0,0,"Study list is full (Free tier limit: 50 words). Upgrade for unlimited words.")}}catch{}}(e)),n.appendChild(t);const a=document.createElement("button");a.textContent=chrome.i18n.getMessage("cardExplainContext")||"Explain in context",a.className="dd-explain-btn",a.setAttribute("aria-label","Explain in context (Pro feature)"),a.addEventListener("click",()=>{!async function(e){try{const n=await o({type:"DEFIF0F1_GET_TIER",payload:{}});if("pro"!==(n?.tier??"free"))return void l();const t=await o({type:"DEFIF0F1_BYOK_EXPLAIN",payload:{word:e.word,sentence:m}});if(t&&"ok"in t&&t.ok&&"explanation"in t)!function(e){if(!p)return;const n=document.createElement("div");n.className="dd-explanation";const t=document.createElement("p");t.className="dd-explanation__label",t.textContent="In context",n.appendChild(t);const o=document.createElement("p");o.className="dd-explanation__body",o.textContent=e,n.appendChild(o),p.appendChild(n)}(t.explanation);else if(t&&"ok"in t&&!t.ok){const e=t.code;h(0,0,0,"BYOK_MISSING"===e?chrome.i18n.getMessage("cardByokMissing")||"Add your BYOK API key in Settings to use explain-in-context.":t.message||"Explain-in-context failed.")}}catch{}}(e)}),n.appendChild(a);const r=document.createElement("button");return r.textContent=chrome.i18n.getMessage("cardClose")||"Close",r.className="dd-close-btn",r.addEventListener("click",z),n.appendChild(r),n}(e))}function h(e,n,t,o){v(),w(),b();const a=p,r=document.createElement("div");r.textContent=o,r.style.cssText="padding:16px;font:14px/1.5 Inter,sans-serif;color:#EF4444;",a.appendChild(r);const i=document.createElement("button");i.textContent=chrome.i18n.getMessage("cardClose")||"Close",i.className="dd-close-btn",i.addEventListener("click",z),a.appendChild(i)}function v(){s&&p||(s=document.createElement("div"),s.id="defif0f1-define-card-host",s.style.cssText="position:absolute;z-index:2147483647;all:initial;",document.body.appendChild(s),p=s.attachShadow({mode:"closed"}),setTimeout(()=>{document.addEventListener("mousedown",E,!0)},100))}function b(){if(!p)return;const e=document.createElement("style");e.textContent=C,p.appendChild(e)}function w(){if(p)for(;p.firstChild;)p.removeChild(p.firstChild)}function E(e){u||s&&(e.target instanceof Node&&s.contains(e.target)||(u=!0,setTimeout(()=>{u=!1},250),z()))}function z(){s&&s.parentNode&&s.parentNode.removeChild(s),s=null,p=null;try{document.removeEventListener("mousedown",E,!0)}catch{}}!async function(){if(!document.contentType||"text/html"===document.contentType){try{if(!chrome.runtime?.id)return}catch{return}try{const e=await o({type:"DEFIF0F1_GET_PREFS",payload:{}});e&&"prefs"in e&&(c=e.prefs)}catch{}if(c||(c=null),"dblclick"===c?.triggerMode||"selection"===c?.triggerMode)try{document.addEventListener("dblclick",f,{passive:!0})}catch{}try{document.addEventListener("keydown",x)}catch{}try{chrome.runtime.onMessage.addListener(g)}catch{}}}();const C="\n :host { all: initial; }\n * { box-sizing: border-box; font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; }\n :host {\n all: initial;\n display: block;\n background: #FFFFFF;\n border: 1px solid #E5E7EB;\n border-radius: 8px;\n box-shadow: 0 4px 6px -1px rgba(0,0,0,0.1), 0 2px 4px -1px rgba(0,0,0,0.06);\n padding: 0;\n color: #1A1A2E;\n font-size: 14px;\n line-height: 1.5;\n max-height: 400px;\n overflow-y: auto;\n animation: dd-fade 150ms ease-in-out;\n }\n @media (prefers-reduced-motion: reduce) {\n :host { animation: none; }\n }\n @keyframes dd-fade {\n from { opacity: 0; transform: translateY(4px); }\n to { opacity: 1; transform: translateY(0); }\n }\n .dd-header { padding: 12px 16px 4px; }\n .dd-word { margin: 0; font-size: 20px; font-weight: 600; color: #1A1A2E; display: inline; }\n .dd-ipa { margin-left: 8px; font-size: 12px; color: #6B7280; }\n .dd-audio-btn {\n margin: 4px 16px; padding: 4px 12px;\n background: transparent; border: 1px solid #E5E7EB; border-radius: 6px;\n color: #6C5CE7; font-size: 12px; cursor: pointer; transition: 150ms;\n }\n .dd-audio-btn:hover { background: #F8F9FA; }\n .dd-sense { padding: 8px 16px; }\n .dd-pos { font-style: italic; font-size: 12px; color: #6B7280; }\n .dd-definition { margin: 4px 0 0; font-size: 14px; color: #1A1A2E; }\n .dd-example { margin: 4px 0 0; font-size: 12px; color: #6B7280; font-style: italic; }\n .dd-synonyms { padding: 4px 16px; font-size: 12px; color: #6B7280; }\n .dd-actions { padding: 8px 16px 12px; display: flex; gap: 8px; flex-wrap: wrap; }\n .dd-save-btn {\n padding: 6px 14px; background: #6C5CE7; color: #FFFFFF;\n border: none; border-radius: 6px; font-size: 13px; font-weight: 500;\n cursor: pointer; transition: background 150ms;\n }\n .dd-save-btn:hover { background: #5A4BD1; }\n .dd-explain-btn {\n padding: 6px 14px; background: transparent; color: #D97706;\n border: 1px solid #F59E0B; border-radius: 6px; font-size: 12px; font-weight: 500;\n cursor: pointer; transition: background 150ms, border-color 150ms;\n }\n .dd-explain-btn:hover { background: rgba(245, 158, 11, 0.08); border-color: #D97706; }\n .dd-explanation { padding: 8px 16px 12px; border-top: 1px solid #E5E7EB; margin-top: 4px; }\n .dd-explanation__label {\n margin: 0 0 4px; font-size: 10px; font-weight: 600;\n text-transform: uppercase; letter-spacing: 0.06em; color: #D97706;\n }\n .dd-explanation__body { margin: 0; font-size: 13px; color: #1A1A2E; line-height: 1.5; }\n .dd-close-btn {\n padding: 6px 14px; background: transparent; color: #6B7280;\n border: 1px solid #E5E7EB; border-radius: 6px; font-size: 13px;\n cursor: pointer; transition: 150ms;\n }\n .dd-close-btn:hover { background: #F8F9FA; }\n @media (prefers-color-scheme: dark) {\n :host { background: #0F0F1A; color: #F5F5FA; border-color: #2E2E45; }\n .dd-word { color: #F5F5FA; }\n .dd-ipa, .dd-pos, .dd-example, .dd-synonyms { color: #A1A1AA; }\n .dd-definition { color: #F5F5FA; }\n .dd-close-btn { border-color: #2E2E45; color: #A1A1AA; }\n .dd-close-btn:hover { background: #232338; }\n .dd-audio-btn { border-color: #2E2E45; color: #8B7CF0; }\n .dd-audio-btn:hover { background: #232338; }\n .dd-explain-btn { border-color: #F59E0B; color: #F59E0B; }\n .dd-explain-btn:hover { background: rgba(245, 158, 11, 0.12); }\n .dd-explanation { border-color: #2E2E45; }\n .dd-explanation__body { color: #F5F5FA; }\n }\n"})();