defuddle
Version:
Extract article content and metadata from web pages.
1 lines • 102 kB
JavaScript
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.Defuddle=e():t.Defuddle=e()}("undefined"!=typeof self?self:this,(()=>(()=>{"use strict";var t={0:(t,e,r)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.mathRules=e.createCleanMathEl=void 0;const o=r(282);e.createCleanMathEl=(t,e,r,o)=>{const n=t.createElement("math");if(n.setAttribute("xmlns","http://www.w3.org/1998/Math/MathML"),n.setAttribute("display",o?"block":"inline"),n.setAttribute("data-latex",r||""),null==e?void 0:e.mathml){const r=t.createElement("div");r.innerHTML=e.mathml;const o=r.querySelector("math");o&&(n.innerHTML=o.innerHTML)}else r&&(n.textContent=r);return n},e.mathRules=[{selector:o.mathSelectors,element:"math",transform:(t,r)=>{if(!function(t){return"classList"in t&&"getAttribute"in t&&"querySelector"in t}(t))return t;const n=(0,o.getMathMLFromElement)(t),i=(0,o.getBasicLatexFromElement)(t),a=(0,o.isBlockDisplay)(t),s=(0,e.createCleanMathEl)(r,n,i,a);if(t.parentElement){t.parentElement.querySelectorAll('\n\t\t\t\t\t/* MathJax scripts and previews */\n\t\t\t\t\tscript[type^="math/"],\n\t\t\t\t\t.MathJax_Preview,\n\n\t\t\t\t\t/* External math library scripts */\n\t\t\t\t\tscript[type="text/javascript"][src*="mathjax"],\n\t\t\t\t\tscript[type="text/javascript"][src*="katex"]\n\t\t\t\t').forEach((t=>t.remove()))}return s}}]},20:(t,e,r)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.GrokExtractor=void 0;const o=r(181);class n extends o.ConversationExtractor{constructor(t,e){super(t,e),this.messageContainerSelector=".relative.group.flex.flex-col.justify-center.w-full",this.messageBubbles=t.querySelectorAll(this.messageContainerSelector),this.footnotes=[],this.footnoteCounter=0}canExtract(){return!!this.messageBubbles&&this.messageBubbles.length>0}extractMessages(){const t=[];return this.footnotes=[],this.footnoteCounter=0,this.messageBubbles&&0!==this.messageBubbles.length?(this.messageBubbles.forEach((e=>{var r;const o=e.classList.contains("items-end"),n=e.classList.contains("items-start");if(!o&&!n)return;const i=e.querySelector(".message-bubble");if(!i)return;let a="",s="",l="";if(o)a=i.textContent||"",s="user",l="You";else if(n){s="assistant",l="Grok";const t=i.cloneNode(!0);null===(r=t.querySelector(".relative.border.border-border-l1.bg-surface-base"))||void 0===r||r.remove(),a=t.innerHTML,a=this.processFootnotes(a)}a.trim()&&t.push({author:l,content:a.trim(),metadata:{role:s}})})),t):t}getFootnotes(){return this.footnotes}getMetadata(){var t;const e=this.getTitle(),r=(null===(t=this.messageBubbles)||void 0===t?void 0:t.length)||0;return{title:e,site:"Grok",url:this.url,messageCount:r,description:`Grok conversation with ${r} messages`}}getTitle(){var t,e;const r=null===(t=this.document.title)||void 0===t?void 0:t.trim();if(r&&"Grok"!==r&&!r.startsWith("Grok by "))return r.replace(/\s-\s*Grok$/,"").trim();const o=this.document.querySelector(`${this.messageContainerSelector}.items-end`);if(o){const t=o.querySelector(".message-bubble");if(t){const r=(null===(e=t.textContent)||void 0===e?void 0:e.trim())||"";return r.length>50?r.slice(0,50)+"...":r}}return"Grok Conversation"}processFootnotes(t){return t.replace(/<a\s+(?:[^>]*?\s+)?href="([^"]*)"[^>]*>(.*?)<\/a>/gi,((t,e,r)=>{if(!e||e.startsWith("#")||!e.match(/^https?:\/\//i))return t;let o;if(this.footnotes.find((t=>t.url===e)))o=this.footnotes.findIndex((t=>t.url===e))+1;else{this.footnoteCounter++,o=this.footnoteCounter;let t=e;try{const r=new URL(e).hostname.replace(/^www\./,"");t=`<a href="${e}" target="_blank" rel="noopener noreferrer">${r}</a>`}catch(r){t=`<a href="${e}" target="_blank" rel="noopener noreferrer">${e}</a>`,console.warn(`GrokExtractor: Could not parse URL for footnote: ${e}`)}this.footnotes.push({url:e,text:t})}return`${r}<sup id="fnref:${o}" class="footnote-ref"><a href="#fn:${o}" class="footnote-link">${o}</a></sup>`}))}}e.GrokExtractor=n},181:(t,e,r)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.ConversationExtractor=void 0;const o=r(279),n=r(628);class i extends o.BaseExtractor{getFootnotes(){return[]}extract(){var t;const e=this.extractMessages(),r=this.getMetadata(),o=this.getFootnotes(),i=this.createContentHtml(e,o),a=document.implementation.createHTMLDocument(),s=a.createElement("article");s.innerHTML=i,a.body.appendChild(s);const l=new n.Defuddle(a).parse(),c=l.content;return{content:c,contentHtml:c,extractedContent:{messageCount:e.length.toString()},variables:{title:r.title||"Conversation",site:r.site,description:r.description||`${r.site} conversation with ${e.length} messages`,wordCount:(null===(t=l.wordCount)||void 0===t?void 0:t.toString())||""}}}createContentHtml(t,e){return`${t.map(((e,r)=>{const o=e.timestamp?`<div class="message-timestamp">${e.timestamp}</div>`:"",n=/<p[^>]*>[\s\S]*?<\/p>/i.test(e.content)?e.content:`<p>${e.content}</p>`,i=e.metadata?Object.entries(e.metadata).map((([t,e])=>`data-${t}="${e}"`)).join(" "):"";return`\n\t\t\t<div class="message message-${e.author.toLowerCase()}" ${i}>\n\t\t\t\t<div class="message-header">\n\t\t\t\t\t<p class="message-author"><strong>${e.author}</strong></p>\n\t\t\t\t\t${o}\n\t\t\t\t</div>\n\t\t\t\t<div class="message-content">\n\t\t\t\t\t${n}\n\t\t\t\t</div>\n\t\t\t</div>${r<t.length-1?"\n<hr>":""}`})).join("\n").trim()}\n${e.length>0?`\n\t\t\t<div id="footnotes">\n\t\t\t\t<ol>\n\t\t\t\t\t${e.map(((t,e)=>`\n\t\t\t\t\t\t<li class="footnote" id="fn:${e+1}">\n\t\t\t\t\t\t\t<p>\n\t\t\t\t\t\t\t\t<a href="${t.url}" target="_blank">${t.text}</a> <a href="#fnref:${e+1}" class="footnote-backref">\u21a9</a>\n\t\t\t\t\t\t\t</p>\n\t\t\t\t\t\t</li>\n\t\t\t\t\t`)).join("")}\n\t\t\t\t</ol>\n\t\t\t</div>`:""}`.trim()}}e.ConversationExtractor=i},248:(t,e,r)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.TwitterExtractor=void 0;const o=r(279);class n extends o.BaseExtractor{constructor(t,e){var r;super(t,e),this.mainTweet=null,this.threadTweets=[];const o=t.querySelector('[aria-label="Timeline: Conversation"]');if(!o){const e=t.querySelector('article[data-testid="tweet"]');return void(e&&(this.mainTweet=e))}const n=Array.from(o.querySelectorAll('article[data-testid="tweet"]')),i=null===(r=o.querySelector("section, h2"))||void 0===r?void 0:r.parentElement;i&&n.forEach(((t,e)=>{if(i.compareDocumentPosition(t)&Node.DOCUMENT_POSITION_FOLLOWING)return n.splice(e),!1})),this.mainTweet=n[0]||null,this.threadTweets=n.slice(1)}canExtract(){return!!this.mainTweet}extract(){const t=this.extractTweet(this.mainTweet),e=this.threadTweets.map((t=>this.extractTweet(t))).join("\n<hr>\n"),r=`\n\t\t\t<div class="tweet-thread">\n\t\t\t\t<div class="main-tweet">\n\t\t\t\t\t${t}\n\t\t\t\t</div>\n\t\t\t\t${e?`\n\t\t\t\t\t<hr>\n\t\t\t\t\t<div class="thread-tweets">\n\t\t\t\t\t\t${e}\n\t\t\t\t\t</div>\n\t\t\t\t`:""}\n\t\t\t</div>\n\t\t`.trim(),o=this.getTweetId(),n=this.getTweetAuthor();return{content:r,contentHtml:r,extractedContent:{tweetId:o,tweetAuthor:n},variables:{title:`Thread by ${n}`,author:n,site:"X (Twitter)",description:this.createDescription(this.mainTweet)}}}formatTweetText(t){if(!t)return"";const e=this.document.createElement("div");e.innerHTML=t,e.querySelectorAll("a").forEach((t=>{var e;const r=(null===(e=t.textContent)||void 0===e?void 0:e.trim())||"";t.replaceWith(r)})),e.querySelectorAll("span, div").forEach((t=>{t.replaceWith(...Array.from(t.childNodes))}));return e.innerHTML.split("\n").map((t=>t.trim())).filter((t=>t)).map((t=>`<p>${t}</p>`)).join("\n")}extractTweet(t){var e,r,o;if(!t)return"";const n=t.cloneNode(!0);n.querySelectorAll('img[src*="/emoji/"]').forEach((t=>{if("img"===t.tagName.toLowerCase()&&t.getAttribute("alt")){const e=t.getAttribute("alt");e&&t.replaceWith(e)}}));const i=(null===(e=n.querySelector('[data-testid="tweetText"]'))||void 0===e?void 0:e.innerHTML)||"",a=this.formatTweetText(i),s=this.extractImages(t),l=this.extractUserInfo(t),c=null===(o=null===(r=t.querySelector('[aria-labelledby*="id__"]'))||void 0===r?void 0:r.querySelector('[data-testid="User-Name"]'))||void 0===o?void 0:o.closest('[aria-labelledby*="id__"]'),u=c?this.extractTweet(c):"";return`\n\t\t\t<div class="tweet">\n\t\t\t\t<div class="tweet-header">\n\t\t\t\t\t<span class="tweet-author"><strong>${l.fullName}</strong> <span class="tweet-handle">${l.handle}</span></span>\n\t\t\t\t\t${l.date?`<a href="${l.permalink}" class="tweet-date">${l.date}</a>`:""}\n\t\t\t\t</div>\n\t\t\t\t${a?`<div class="tweet-text">${a}</div>`:""}\n\t\t\t\t${s.length?`\n\t\t\t\t\t<div class="tweet-media">\n\t\t\t\t\t\t${s.join("\n")}\n\t\t\t\t\t</div>\n\t\t\t\t`:""}\n\t\t\t\t${u?`\n\t\t\t\t\t<blockquote class="quoted-tweet">\n\t\t\t\t\t\t${u}\n\t\t\t\t\t</blockquote>\n\t\t\t\t`:""}\n\t\t\t</div>\n\t\t`.trim()}extractUserInfo(t){var e,r,o,n,i,a,s,l,c;const u=t.querySelector('[data-testid="User-Name"]');if(!u)return{fullName:"",handle:"",date:"",permalink:""};const d=u.querySelectorAll("a");let m=(null===(r=null===(e=null==d?void 0:d[0])||void 0===e?void 0:e.textContent)||void 0===r?void 0:r.trim())||"",h=(null===(n=null===(o=null==d?void 0:d[1])||void 0===o?void 0:o.textContent)||void 0===n?void 0:n.trim())||"";m&&h||(m=(null===(a=null===(i=u.querySelector('span[style*="color: rgb(15, 20, 25)"] span'))||void 0===i?void 0:i.textContent)||void 0===a?void 0:a.trim())||"",h=(null===(l=null===(s=u.querySelector('span[style*="color: rgb(83, 100, 113)"]'))||void 0===s?void 0:s.textContent)||void 0===l?void 0:l.trim())||"");const p=t.querySelector("time"),g=(null==p?void 0:p.getAttribute("datetime"))||"";return{fullName:m,handle:h,date:g?new Date(g).toISOString().split("T")[0]:"",permalink:(null===(c=null==p?void 0:p.closest("a"))||void 0===c?void 0:c.href)||""}}extractImages(t){var e,r;const o=['[data-testid="tweetPhoto"]','[data-testid="tweet-image"]','img[src*="media"]'],n=[],i=null===(r=null===(e=t.querySelector('[aria-labelledby*="id__"]'))||void 0===e?void 0:e.querySelector('[data-testid="User-Name"]'))||void 0===r?void 0:r.closest('[aria-labelledby*="id__"]');for(const e of o){t.querySelectorAll(e).forEach((t=>{var e,r;if(!(null==i?void 0:i.contains(t))&&"img"===t.tagName.toLowerCase()&&t.getAttribute("alt")){const o=(null===(e=t.getAttribute("src"))||void 0===e?void 0:e.replace(/&name=\w+$/,"&name=large"))||"",i=(null===(r=t.getAttribute("alt"))||void 0===r?void 0:r.replace(/\s+/g," ").trim())||"";n.push(`<img src="${o}" alt="${i}" />`)}}))}return n}getTweetId(){const t=this.url.match(/status\/(\d+)/);return(null==t?void 0:t[1])||""}getTweetAuthor(){var t,e,r;const o=null===(t=this.mainTweet)||void 0===t?void 0:t.querySelector('[data-testid="User-Name"]'),n=null==o?void 0:o.querySelectorAll("a"),i=(null===(r=null===(e=null==n?void 0:n[1])||void 0===e?void 0:e.textContent)||void 0===r?void 0:r.trim())||"";return i.startsWith("@")?i:`@${i}`}createDescription(t){var e;if(!t)return"";return((null===(e=t.querySelector('[data-testid="tweetText"]'))||void 0===e?void 0:e.textContent)||"").trim().slice(0,140).replace(/\s+/g," ")}}e.TwitterExtractor=n},258:(t,e,r)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.YoutubeExtractor=void 0;const o=r(279);class n extends o.BaseExtractor{constructor(t,e,r){super(t,e,r),this.videoElement=t.querySelector("video"),this.schemaOrgData=r}canExtract(){return!0}extract(){const t=this.getVideoData(),e=t.description||"",r=this.formatDescription(e),o=`<iframe width="560" height="315" src="https://www.youtube.com/embed/${this.getVideoId()}" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe><br>${r}`;return{content:o,contentHtml:o,extractedContent:{videoId:this.getVideoId(),author:t.author||""},variables:{title:t.name||"",author:t.author||"",site:"YouTube",image:Array.isArray(t.thumbnailUrl)&&t.thumbnailUrl[0]||"",published:t.uploadDate,description:e.slice(0,200).trim()}}}formatDescription(t){return`<p>${t.replace(/\n/g,"<br>")}</p>`}getVideoData(){if(!this.schemaOrgData)return{};return(Array.isArray(this.schemaOrgData)?this.schemaOrgData.find((t=>"VideoObject"===t["@type"])):"VideoObject"===this.schemaOrgData["@type"]?this.schemaOrgData:null)||{}}getVideoId(){const t=new URL(this.url);return"youtu.be"===t.hostname?t.pathname.slice(1):new URLSearchParams(t.search).get("v")||""}}e.YoutubeExtractor=n},279:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.BaseExtractor=void 0;e.BaseExtractor=class{constructor(t,e,r){this.document=t,this.url=e,this.schemaOrgData=r}}},282:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.mathSelectors=e.isBlockDisplay=e.getBasicLatexFromElement=e.getMathMLFromElement=void 0;e.getMathMLFromElement=t=>{if("math"===t.tagName.toLowerCase()){const e="block"===t.getAttribute("display");return{mathml:t.outerHTML,latex:t.getAttribute("alttext")||null,isBlock:e}}const e=t.getAttribute("data-mathml");if(e){const t=document.createElement("div");t.innerHTML=e;const r=t.querySelector("math");if(r){const t="block"===r.getAttribute("display");return{mathml:r.outerHTML,latex:r.getAttribute("alttext")||null,isBlock:t}}}const r=t.querySelector(".MJX_Assistive_MathML, mjx-assistive-mml");if(r){const t=r.querySelector("math");if(t){const e=t.getAttribute("display"),o=r.getAttribute("display"),n="block"===e||"block"===o;return{mathml:t.outerHTML,latex:t.getAttribute("alttext")||null,isBlock:n}}}const o=t.querySelector(".katex-mathml math");return o?{mathml:o.outerHTML,latex:null,isBlock:!1}:null};e.getBasicLatexFromElement=t=>{var e,r,o;const n=t.getAttribute("data-latex");if(n)return n;if("img"===t.tagName.toLowerCase()&&t.classList.contains("latex")){const e=t.getAttribute("alt");if(e)return e;const r=t.getAttribute("src");if(r){const t=r.match(/latex\.php\?latex=([^&]+)/);if(t)return decodeURIComponent(t[1]).replace(/\+/g," ").replace(/%5C/g,"\\")}}const i=t.querySelector('annotation[encoding="application/x-tex"]');if(null==i?void 0:i.textContent)return i.textContent.trim();if(t.matches(".katex")){const e=t.querySelector('.katex-mathml annotation[encoding="application/x-tex"]');if(null==e?void 0:e.textContent)return e.textContent.trim()}if(t.matches('script[type="math/tex"]')||t.matches('script[type="math/tex; mode=display"]'))return(null===(e=t.textContent)||void 0===e?void 0:e.trim())||null;if(t.parentElement){const e=t.parentElement.querySelector('script[type="math/tex"], script[type="math/tex; mode=display"]');if(e)return(null===(r=e.textContent)||void 0===r?void 0:r.trim())||null}return t.getAttribute("alt")||(null===(o=t.textContent)||void 0===o?void 0:o.trim())||null};e.isBlockDisplay=t=>{if("block"===t.getAttribute("display"))return!0;const e=t.className.toLowerCase();if(e.includes("display")||e.includes("block"))return!0;if(t.closest('.katex-display, .MathJax_Display, [data-display="block"]'))return!0;const r=t.previousElementSibling;if("p"===(null==r?void 0:r.tagName.toLowerCase()))return!0;if(t.matches(".mwe-math-fallback-image-display"))return!0;if(t.matches(".katex"))return null!==t.closest(".katex-display");if(t.hasAttribute("display"))return"true"===t.getAttribute("display");if(t.matches('script[type="math/tex; mode=display"]'))return!0;if(t.hasAttribute("display"))return"true"===t.getAttribute("display");const o=t.closest("[display]");return!!o&&"true"===o.getAttribute("display")},e.mathSelectors=['img.latex[src*="latex.php"]',"span.MathJax","mjx-container",'script[type="math/tex"]','script[type="math/tex; mode=display"]','.MathJax_Preview + script[type="math/tex"]',".MathJax_Display",".MathJax_SVG",".MathJax_MathML",".mwe-math-element",".mwe-math-fallback-image-inline",".mwe-math-fallback-image-display",".mwe-math-mathml-inline",".mwe-math-mathml-display",".katex",".katex-display",".katex-mathml",".katex-html","[data-katex]",'script[type="math/katex"]',"math","[data-math]","[data-latex]","[data-tex]",'script[type^="math/"]','annotation[encoding="application/x-tex"]'].join(",")},397:(t,e,r)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.ClaudeExtractor=void 0;const o=r(181);class n extends o.ConversationExtractor{constructor(t,e){super(t,e),this.articles=t.querySelectorAll('div[data-testid="user-message"], div[data-testid="assistant-message"], div.font-claude-message')}canExtract(){return!!this.articles&&this.articles.length>0}extractMessages(){const t=[];return this.articles?(this.articles.forEach((e=>{let r,o;if(e.hasAttribute("data-testid")){if("user-message"!==e.getAttribute("data-testid"))return;r="you",o=e.innerHTML}else{if(!e.classList.contains("font-claude-message"))return;r="assistant",o=e.innerHTML}o&&t.push({author:"you"===r?"You":"Claude",content:o.trim(),metadata:{role:r}})})),t):t}getMetadata(){const t=this.getTitle(),e=this.extractMessages();return{title:t,site:"Claude",url:this.url,messageCount:e.length,description:`Claude conversation with ${e.length} messages`}}getTitle(){var t,e,r,o,n;const i=null===(t=this.document.title)||void 0===t?void 0:t.trim();if(i&&"Claude"!==i)return i.replace(/ - Claude$/,"");const a=null===(r=null===(e=this.document.querySelector("header .font-tiempos"))||void 0===e?void 0:e.textContent)||void 0===r?void 0:r.trim();if(a)return a;const s=null===(n=null===(o=this.articles)||void 0===o?void 0:o.item(0))||void 0===n?void 0:n.querySelector('[data-testid="user-message"]');if(s){const t=s.textContent||"";return t.length>50?t.slice(0,50)+"...":t}return"Claude Conversation"}}e.ClaudeExtractor=n},458:(t,e,r)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.HackerNewsExtractor=void 0;const o=r(279);class n extends o.BaseExtractor{constructor(t,e){super(t,e),this.mainPost=t.querySelector(".fatitem"),this.isCommentPage=this.detectCommentPage(),this.mainComment=this.isCommentPage?this.findMainComment():null}detectCommentPage(){var t;return!!(null===(t=this.mainPost)||void 0===t?void 0:t.querySelector('.navs a[href*="parent"]'))}findMainComment(){var t;return(null===(t=this.mainPost)||void 0===t?void 0:t.querySelector(".comment"))||null}canExtract(){return!!this.mainPost}extract(){const t=this.getPostContent(),e=this.extractComments(),r=this.createContentHtml(t,e),o=this.getPostTitle(),n=this.getPostAuthor(),i=this.createDescription(),a=this.getPostDate();return{content:r,contentHtml:r,extractedContent:{postId:this.getPostId(),postAuthor:n},variables:{title:o,author:n,site:"Hacker News",description:i,published:a}}}createContentHtml(t,e){return`\n\t\t\t<div class="hackernews-post">\n\t\t\t\t<div class="post-content">\n\t\t\t\t\t${t}\n\t\t\t\t</div>\n\t\t\t\t${e?`\n\t\t\t\t\t<hr>\n\t\t\t\t\t<h2>Comments</h2>\n\t\t\t\t\t<div class="hackernews-comments">\n\t\t\t\t\t\t${e}\n\t\t\t\t\t</div>\n\t\t\t\t`:""}\n\t\t\t</div>\n\t\t`.trim()}getPostContent(){var t,e,r,o,n,i;if(!this.mainPost)return"";if(this.isCommentPage&&this.mainComment){const i=(null===(t=this.mainComment.querySelector(".hnuser"))||void 0===t?void 0:t.textContent)||"[deleted]",a=(null===(e=this.mainComment.querySelector(".commtext"))||void 0===e?void 0:e.innerHTML)||"",s=this.mainComment.querySelector(".age"),l=((null==s?void 0:s.getAttribute("title"))||"").split("T")[0]||"",c=(null===(o=null===(r=this.mainComment.querySelector(".score"))||void 0===r?void 0:r.textContent)||void 0===o?void 0:o.trim())||"",u=(null===(n=this.mainPost.querySelector('.navs a[href*="parent"]'))||void 0===n?void 0:n.getAttribute("href"))||"";return`\n\t\t\t\t<div class="comment main-comment">\n\t\t\t\t\t<div class="comment-metadata">\n\t\t\t\t\t\t<span class="comment-author"><strong>${i}</strong></span> \u2022\n\t\t\t\t\t\t<span class="comment-date">${l}</span>\n\t\t\t\t\t\t${c?` \u2022 <span class="comment-points">${c}</span>`:""}\n\t\t\t\t\t\t${u?` \u2022 <a href="https://news.ycombinator.com/${u}" class="parent-link">parent</a>`:""}\n\t\t\t\t\t</div>\n\t\t\t\t\t<div class="comment-content">${a}</div>\n\t\t\t\t</div>\n\t\t\t`.trim()}const a=this.mainPost.querySelector("tr.athing"),s=(null==a||a.nextElementSibling,(null===(i=null==a?void 0:a.querySelector(".titleline a"))||void 0===i?void 0:i.getAttribute("href"))||"");let l="";s&&(l+=`<p><a href="${s}" target="_blank">${s}</a></p>`);const c=this.mainPost.querySelector(".toptext");return c&&(l+=`<div class="post-text">${c.innerHTML}</div>`),l}extractComments(){const t=Array.from(this.document.querySelectorAll("tr.comtr"));return this.processComments(t)}processComments(t){var e,r,o,n;let i="";const a=new Set;let s=-1,l=[];for(const c of t){const t=c.getAttribute("id");if(!t||a.has(t))continue;a.add(t);const u=(null===(e=c.querySelector(".ind img"))||void 0===e?void 0:e.getAttribute("width"))||"0",d=parseInt(u)/40,m=c.querySelector(".commtext"),h=(null===(r=c.querySelector(".hnuser"))||void 0===r?void 0:r.textContent)||"[deleted]",p=c.querySelector(".age"),g=(null===(n=null===(o=c.querySelector(".score"))||void 0===o?void 0:o.textContent)||void 0===n?void 0:n.trim())||"";if(!m)continue;const f=`https://news.ycombinator.com/item?id=${t}`,v=((null==p?void 0:p.getAttribute("title"))||"").split("T")[0]||"";if(0===d){for(;l.length>0;)i+="</blockquote>",l.pop();i+="<blockquote>",l=[0],s=0}else if(d<s)for(;l.length>0&&l[l.length-1]>=d;)i+="</blockquote>",l.pop();else d>s&&(i+="<blockquote>",l.push(d));i+=`<div class="comment">\n\t<div class="comment-metadata">\n\t\t<span class="comment-author"><strong>${h}</strong></span> \u2022\n\t\t<a href="${f}" class="comment-link">${v}</a>\n\t\t${g?` \u2022 <span class="comment-points">${g}</span>`:""}\n\t</div>\n\t<div class="comment-content">${m.innerHTML}</div>\n</div>`,s=d}for(;l.length>0;)i+="</blockquote>",l.pop();return i}getPostId(){const t=this.url.match(/id=(\d+)/);return(null==t?void 0:t[1])||""}getPostTitle(){var t,e,r,o,n;if(this.isCommentPage&&this.mainComment){const r=(null===(t=this.mainComment.querySelector(".hnuser"))||void 0===t?void 0:t.textContent)||"[deleted]",o=(null===(e=this.mainComment.querySelector(".commtext"))||void 0===e?void 0:e.textContent)||"";return`Comment by ${r}: ${o.trim().slice(0,50)+(o.length>50?"...":"")}`}return(null===(n=null===(o=null===(r=this.mainPost)||void 0===r?void 0:r.querySelector(".titleline"))||void 0===o?void 0:o.textContent)||void 0===n?void 0:n.trim())||""}getPostAuthor(){var t,e,r;return(null===(r=null===(e=null===(t=this.mainPost)||void 0===t?void 0:t.querySelector(".hnuser"))||void 0===e?void 0:e.textContent)||void 0===r?void 0:r.trim())||""}createDescription(){const t=this.getPostTitle(),e=this.getPostAuthor();return this.isCommentPage?`Comment by ${e} on Hacker News`:`${t} - by ${e} on Hacker News`}getPostDate(){if(!this.mainPost)return"";const t=this.mainPost.querySelector(".age");return((null==t?void 0:t.getAttribute("title"))||"").split("T")[0]||""}}e.HackerNewsExtractor=n},552:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.isElement=function(t){return t.nodeType===r.ELEMENT_NODE},e.isTextNode=function(t){return t.nodeType===r.TEXT_NODE},e.isCommentNode=function(t){return t.nodeType===r.COMMENT_NODE},e.getComputedStyle=function(t){const e=o(t.ownerDocument);return e?e.getComputedStyle(t):null},e.getWindow=o,e.logDebug=function(t,...e){"undefined"!=typeof window&&window.defuddleDebug&&console.log("Defuddle:",t,...e)};const r={ELEMENT_NODE:1,ATTRIBUTE_NODE:2,TEXT_NODE:3,CDATA_SECTION_NODE:4,ENTITY_REFERENCE_NODE:5,ENTITY_NODE:6,PROCESSING_INSTRUCTION_NODE:7,COMMENT_NODE:8,DOCUMENT_NODE:9,DOCUMENT_TYPE_NODE:10,DOCUMENT_FRAGMENT_NODE:11,NOTATION_NODE:12};function o(t){return t.defaultView?t.defaultView:t.ownerWindow?t.ownerWindow:t.window?t.window:null}},588:(t,e,r)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.GitHubExtractor=void 0;const o=r(279);class n extends o.BaseExtractor{canExtract(){return['meta[name="expected-hostname"][content="github.com"]','meta[name="octolytics-url"]','meta[name="github-keyboard-shortcuts"]',".js-header-wrapper","#js-repo-pjax-container"].some((t=>null!==this.document.querySelector(t)))&&Object.values({issue:['[data-testid="issue-metadata-sticky"]','[data-testid="issue-title"]']}).some((t=>t.some((t=>null!==this.document.querySelector(t)))))}extract(){return this.extractIssue()}extractIssue(){const t=this.extractRepoInfo(),e=this.extractIssueNumber();let r="";const o=this.document.querySelector('[data-testid="issue-viewer-issue-container"]');if(o){const t=this.extractAuthor(o,['a[data-testid="issue-body-header-author"]',".IssueBodyHeaderAuthor-module__authorLoginLink--_S7aT",".ActivityHeader-module__AuthorLink--iofTU",'a[href*="/users/"][data-hovercard-url*="/users/"]','a[aria-label*="profile"]']),e=o.querySelector("relative-time"),n=(null==e?void 0:e.getAttribute("datetime"))||"",i=o.querySelector('[data-testid="issue-body-viewer"] .markdown-body');if(i){const e=this.cleanBodyContent(i);if(r+=`<div class="issue-author"><strong>${t}</strong>`,n){const t=new Date(n);r+=` opened this issue on ${t.toLocaleDateString()}`}r+="</div>\n\n",r+=`<div class="issue-body">${e}</div>\n\n`}}const n=Array.from(this.document.querySelectorAll("[data-wrapper-timeline-id]")),i=new Set;return n.forEach((t=>{const e=t.querySelector(".react-issue-comment");if(!e)return;const o=t.getAttribute("data-wrapper-timeline-id");if(!o||i.has(o))return;i.add(o);const n=this.extractAuthor(e,[".ActivityHeader-module__AuthorLink--iofTU",'a[data-testid="avatar-link"]','a[href^="/"][data-hovercard-url*="/users/"]']),a=e.querySelector("relative-time"),s=(null==a?void 0:a.getAttribute("datetime"))||"",l=e.querySelector(".markdown-body");if(l){const t=this.cleanBodyContent(l);if(t){if(r+='<div class="comment">\n',r+=`<div class="comment-header"><strong>${n}</strong>`,s){const t=new Date(s);r+=` commented on ${t.toLocaleDateString()}`}r+="</div>\n",r+=`<div class="comment-body">${t}</div>\n`,r+="</div>\n\n"}}})),{content:r,contentHtml:r,extractedContent:{type:"issue",issueNumber:e,repository:t.repo,owner:t.owner},variables:{title:this.document.title,author:"",site:`GitHub - ${t.owner}/${t.repo}`,description:this.createDescription(r)}}}extractAuthor(t,e){for(const r of e){const e=t.querySelector(r);if(e){const t=e.getAttribute("href");if(t){if(t.startsWith("/"))return t.substring(1);if(t.includes("github.com/")){const e=t.match(/github\.com\/([^\/\?#]+)/);if(e&&e[1])return e[1]}}}}return"Unknown"}cleanBodyContent(t){const e=t.cloneNode(!0);return e.querySelectorAll('button, [data-testid*="button"], [data-testid*="menu"]').forEach((t=>t.remove())),e.querySelectorAll(".js-clipboard-copy, .zeroclipboard-container").forEach((t=>t.remove())),e.innerHTML.trim()}extractIssueNumber(){var t;const e=this.url.match(/\/(issues|pull)\/(\d+)/);if(e)return e[2];const r=this.document.querySelector("h1"),o=null===(t=null==r?void 0:r.textContent)||void 0===t?void 0:t.match(/#(\d+)/);return o?o[1]:""}extractRepoInfo(){const t=this.url.match(/github\.com\/([^\/]+)\/([^\/]+)/);if(t)return{owner:t[1],repo:t[2]};const e=this.document.title.match(/([^\/\s]+)\/([^\/\s]+)/);return e?{owner:e[1],repo:e[2]}:{owner:"",repo:""}}createDescription(t){var e;if(!t)return"";const r=this.document.createElement("div");return r.innerHTML=t,(null===(e=r.textContent)||void 0===e?void 0:e.trim().slice(0,140).replace(/\s+/g," "))||""}}e.GitHubExtractor=n},608:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.MetadataExtractor=void 0;e.MetadataExtractor=class{static extract(t,e,r){var o,n;let i="",a="";try{if(a=(null===(o=t.location)||void 0===o?void 0:o.href)||"",a||(a=this.getMetaContent(r,"property","og:url")||this.getMetaContent(r,"property","twitter:url")||this.getSchemaProperty(e,"url")||this.getSchemaProperty(e,"mainEntityOfPage.url")||this.getSchemaProperty(e,"mainEntity.url")||this.getSchemaProperty(e,"WebSite.url")||(null===(n=t.querySelector('link[rel="canonical"]'))||void 0===n?void 0:n.getAttribute("href"))||""),a)try{i=new URL(a).hostname.replace(/^www\./,"")}catch(t){console.warn("Failed to parse URL:",t)}}catch(e){const r=t.querySelector("base[href]");if(r)try{a=r.getAttribute("href")||"",i=new URL(a).hostname.replace(/^www\./,"")}catch(t){console.warn("Failed to parse base URL:",t)}}return{title:this.getTitle(t,e,r),description:this.getDescription(t,e,r),domain:i,favicon:this.getFavicon(t,a,r),image:this.getImage(t,e,r),published:this.getPublished(t,e,r),author:this.getAuthor(t,e,r),site:this.getSite(t,e,r),schemaOrgData:e,wordCount:0,parseTime:0}}static getAuthor(t,e,r){let o;if(o=this.getMetaContent(r,"name","sailthru.author")||this.getMetaContent(r,"property","author")||this.getMetaContent(r,"name","author")||this.getMetaContent(r,"name","byl")||this.getMetaContent(r,"name","authorList"),o)return o;let n=this.getSchemaProperty(e,"author.name")||this.getSchemaProperty(e,"author.[].name");if(n){const t=n.split(",").map((t=>t.trim().replace(/,$/,"").trim())).filter(Boolean);if(t.length>0){let e=[...new Set(t)];return e.length>10&&(e=e.slice(0,10)),e.join(", ")}}const i=[];if(['[itemprop="author"]',".author",'[href*="author"]',".authors a"].forEach((e=>{t.querySelectorAll(e).forEach((t=>{var e;(e=t.textContent)&&e.split(",").forEach((t=>{const e=t.trim().replace(/,$/,"").trim(),r=e.toLowerCase();e&&"author"!==r&&"authors"!==r&&i.push(e)}))}))})),i.length>0){let t=[...new Set(i.map((t=>t.trim())).filter(Boolean))];if(t.length>0)return t.length>10&&(t=t.slice(0,10)),t.join(", ")}return o=this.getMetaContent(r,"name","copyright")||this.getSchemaProperty(e,"copyrightHolder.name")||this.getMetaContent(r,"property","og:site_name")||this.getSchemaProperty(e,"publisher.name")||this.getSchemaProperty(e,"sourceOrganization.name")||this.getSchemaProperty(e,"isPartOf.name")||this.getMetaContent(r,"name","twitter:creator")||this.getMetaContent(r,"name","application-name"),o||""}static getSite(t,e,r){return this.getSchemaProperty(e,"publisher.name")||this.getMetaContent(r,"property","og:site_name")||this.getSchemaProperty(e,"WebSite.name")||this.getSchemaProperty(e,"sourceOrganization.name")||this.getMetaContent(r,"name","copyright")||this.getSchemaProperty(e,"copyrightHolder.name")||this.getSchemaProperty(e,"isPartOf.name")||this.getMetaContent(r,"name","application-name")||this.getAuthor(t,e,r)||""}static getTitle(t,e,r){var o,n;const i=this.getMetaContent(r,"property","og:title")||this.getMetaContent(r,"name","twitter:title")||this.getSchemaProperty(e,"headline")||this.getMetaContent(r,"name","title")||this.getMetaContent(r,"name","sailthru.title")||(null===(n=null===(o=t.querySelector("title"))||void 0===o?void 0:o.textContent)||void 0===n?void 0:n.trim())||"";return this.cleanTitle(i,this.getSite(t,e,r))}static cleanTitle(t,e){if(!t||!e)return t;const r=e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),o=[`\\s*[\\|\\-\u2013\u2014]\\s*${r}\\s*$`,`^\\s*${r}\\s*[\\|\\-\u2013\u2014]\\s*`];for(const e of o){const r=new RegExp(e,"i");if(r.test(t)){t=t.replace(r,"");break}}return t.trim()}static getDescription(t,e,r){return this.getMetaContent(r,"name","description")||this.getMetaContent(r,"property","description")||this.getMetaContent(r,"property","og:description")||this.getSchemaProperty(e,"description")||this.getMetaContent(r,"name","twitter:description")||this.getMetaContent(r,"name","sailthru.description")||""}static getImage(t,e,r){return this.getMetaContent(r,"property","og:image")||this.getMetaContent(r,"name","twitter:image")||this.getSchemaProperty(e,"image.url")||this.getMetaContent(r,"name","sailthru.image.full")||""}static getFavicon(t,e,r){var o,n;const i=this.getMetaContent(r,"property","og:image:favicon");if(i)return i;const a=null===(o=t.querySelector("link[rel='icon']"))||void 0===o?void 0:o.getAttribute("href");if(a)return a;const s=null===(n=t.querySelector("link[rel='shortcut icon']"))||void 0===n?void 0:n.getAttribute("href");if(s)return s;if(e)try{return new URL("/favicon.ico",e).href}catch(t){console.warn("Failed to construct favicon URL:",t)}return""}static getPublished(t,e,r){var o,n;return this.getSchemaProperty(e,"datePublished")||this.getMetaContent(r,"name","publishDate")||this.getMetaContent(r,"property","article:published_time")||(null===(n=null===(o=t.querySelector('abbr[itemprop="datePublished"]'))||void 0===o?void 0:o.title)||void 0===n?void 0:n.trim())||this.getTimeElement(t)||this.getMetaContent(r,"name","sailthru.date")||""}static getMetaContent(t,e,r){var o,n;const i=t.find((t=>{const o="name"===e?t.name:t.property;return(null==o?void 0:o.toLowerCase())===r.toLowerCase()}));return i&&null!==(n=null===(o=i.content)||void 0===o?void 0:o.trim())&&void 0!==n?n:""}static getTimeElement(t){var e,r,o,n;const i=Array.from(t.querySelectorAll("time"))[0];return i&&null!==(n=null!==(r=null===(e=i.getAttribute("datetime"))||void 0===e?void 0:e.trim())&&void 0!==r?r:null===(o=i.textContent)||void 0===o?void 0:o.trim())&&void 0!==n?n:""}static getSchemaProperty(t,e,r=""){if(!t)return r;const o=(t,e,r,n=!0)=>{if("string"==typeof t)return 0===e.length?[t]:[];if(!t||"object"!=typeof t)return[];if(Array.isArray(t)){const i=e[0];if(/^\\[\\d+\\]$/.test(i)){const a=parseInt(i.slice(1,-1));return t[a]?o(t[a],e.slice(1),r,n):[]}return 0===e.length&&t.every((t=>"string"==typeof t||"number"==typeof t))?t.map(String):t.flatMap((t=>o(t,e,r,n)))}const[i,...a]=e;if(!i)return"string"==typeof t?[t]:"object"==typeof t&&t.name?[t.name]:[];if(t.hasOwnProperty(i))return o(t[i],a,r?`${r}.${i}`:i,!0);if(!n){const n=[];for(const i in t)if("object"==typeof t[i]){const a=o(t[i],e,r?`${r}.${i}`:i,!1);n.push(...a)}if(n.length>0)return n}return[]};try{let n=o(t,e.split("."),"",!0);0===n.length&&(n=o(t,e.split("."),"",!1));return n.length>0?n.filter(Boolean).join(", "):r}catch(t){return console.error(`Error in getSchemaProperty for ${e}:`,t),r}}}},610:(t,e,r)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.standardizeFootnotes=function(t){const e=t.ownerDocument;if(!e)return void console.warn("standardizeFootnotes: No document available");new n(e).standardizeFootnotes(t)};const o=r(640);class n{constructor(t){this.doc=t}createFootnoteItem(t,e,r){const o="string"==typeof e?this.doc:e.ownerDocument,n=o.createElement("li");if(n.className="footnote",n.id=`fn:${t}`,"string"==typeof e){const t=o.createElement("p");t.innerHTML=e,n.appendChild(t)}else{const t=Array.from(e.querySelectorAll("p"));if(0===t.length){const t=o.createElement("p");t.innerHTML=e.innerHTML,n.appendChild(t)}else t.forEach((t=>{const e=o.createElement("p");e.innerHTML=t.innerHTML,n.appendChild(e)}))}const i=n.querySelector("p:last-of-type")||n;return r.forEach(((t,e)=>{const n=o.createElement("a");n.href=`#${t}`,n.title="return to article",n.className="footnote-backref",n.innerHTML="\u21a9",e<r.length-1&&(n.innerHTML+=" "),i.appendChild(n)})),n}collectFootnotes(t){const e={};let r=1;const n=new Set;return t.querySelectorAll(o.FOOTNOTE_LIST_SELECTORS).forEach((t=>{if(t.matches('div.footnote[data-component-name="FootnoteToDOM"]')){const o=t.querySelector("a.footnote-number"),i=t.querySelector(".footnote-content");if(o&&i){const t=o.id.replace("footnote-","").toLowerCase();t&&!n.has(t)&&(e[r]={content:i,originalId:t,refs:[]},n.add(t),r++)}return}t.querySelectorAll('li, div[role="listitem"]').forEach((t=>{var o,i,a,s;let l="",c=null;const u=t.querySelector(".citations");if(null===(o=null==u?void 0:u.id)||void 0===o?void 0:o.toLowerCase().startsWith("r")){l=u.id.toLowerCase();const t=u.querySelector(".citation-content");t&&(c=t)}else{if(t.id.toLowerCase().startsWith("bib.bib"))l=t.id.replace("bib.bib","").toLowerCase();else if(t.id.toLowerCase().startsWith("fn:"))l=t.id.replace("fn:","").toLowerCase();else if(t.id.toLowerCase().startsWith("fn"))l=t.id.replace("fn","").toLowerCase();else if(t.hasAttribute("data-counter"))l=(null===(a=null===(i=t.getAttribute("data-counter"))||void 0===i?void 0:i.replace(/\.$/,""))||void 0===a?void 0:a.toLowerCase())||"";else{const e=null===(s=t.id.split("/").pop())||void 0===s?void 0:s.match(/cite_note-(.+)/);l=e?e[1].toLowerCase():t.id.toLowerCase()}c=t}l&&!n.has(l)&&(e[r]={content:c||t,originalId:l,refs:[]},n.add(l),r++)}))})),e}findOuterFootnoteContainer(t){let e=t,r=t.parentElement;for(;r&&("span"===r.tagName.toLowerCase()||"sup"===r.tagName.toLowerCase());)e=r,r=r.parentElement;return e}createFootnoteReference(t,e){const r=this.doc.createElement("sup");r.id=e;const o=this.doc.createElement("a");return o.href=`#fn:${t}`,o.textContent=t,r.appendChild(o),r}standardizeFootnotes(t){const e=this.collectFootnotes(t),r=t.querySelectorAll(o.FOOTNOTE_INLINE_REFERENCES),n=new Map;r.forEach((t=>{var r,o,i,a;if(!t)return;let s="",l="";if(t.matches('a[id^="ref-link"]'))s=(null===(r=t.textContent)||void 0===r?void 0:r.trim())||"";else if(t.matches('a[role="doc-biblioref"]')){const e=t.getAttribute("data-xml-rid");if(e)s=e;else{const e=t.getAttribute("href");(null==e?void 0:e.startsWith("#core-R"))&&(s=e.replace("#core-",""))}}else if(t.matches("a.footnote-anchor, span.footnote-hovercard-target a")){const e=(null===(o=t.id)||void 0===o?void 0:o.replace("footnote-anchor-",""))||"";e&&(s=e.toLowerCase())}else if(t.matches("cite.ltx_cite")){const e=t.querySelector("a");if(e){const t=e.getAttribute("href");if(t){const e=null===(i=t.split("/").pop())||void 0===i?void 0:i.match(/bib\.bib(\d+)/);e&&(s=e[1].toLowerCase())}}}else if(t.matches("sup.reference")){const e=t.querySelectorAll("a");Array.from(e).forEach((t=>{var e;const r=t.getAttribute("href");if(r){const t=null===(e=r.split("/").pop())||void 0===e?void 0:e.match(/(?:cite_note|cite_ref)-(.+)/);t&&(s=t[1].toLowerCase())}}))}else if(t.matches('sup[id^="fnref:"]'))s=t.id.replace("fnref:","").toLowerCase();else if(t.matches('sup[id^="fnr"]'))s=t.id.replace("fnr","").toLowerCase();else if(t.matches("span.footnote-reference"))s=t.getAttribute("data-footnote-id")||"";else if(t.matches("span.footnote-link"))s=t.getAttribute("data-footnote-id")||"",l=t.getAttribute("data-footnote-content")||"";else if(t.matches("a.citation"))s=(null===(a=t.textContent)||void 0===a?void 0:a.trim())||"",l=t.getAttribute("href")||"";else if(t.matches('a[id^="fnref"]'))s=t.id.replace("fnref","").toLowerCase();else{const e=t.getAttribute("href");if(e){const t=e.replace(/^[#]/,"");s=t.toLowerCase()}}if(s){const r=Object.entries(e).find((([t,e])=>e.originalId===s.toLowerCase()));if(r){const[e,o]=r,i=o.refs.length>0?`fnref:${e}-${o.refs.length+1}`:`fnref:${e}`;o.refs.push(i);const a=this.findOuterFootnoteContainer(t);if("sup"===a.tagName.toLowerCase()){n.has(a)||n.set(a,[]);n.get(a).push(this.createFootnoteReference(e,i))}else a.replaceWith(this.createFootnoteReference(e,i))}}})),n.forEach(((t,e)=>{if(t.length>0){const r=this.doc.createDocumentFragment();t.forEach((t=>{const e=t.querySelector("a");if(e){const o=this.doc.createElement("sup");o.id=t.id,o.appendChild(e.cloneNode(!0)),r.appendChild(o)}})),e.replaceWith(r)}}));const i=this.doc.createElement("div");i.id="footnotes";const a=this.doc.createElement("ol");Object.entries(e).forEach((([t,e])=>{const r=this.createFootnoteItem(parseInt(t),e.content,e.refs);a.appendChild(r)}));t.querySelectorAll(o.FOOTNOTE_LIST_SELECTORS).forEach((t=>t.remove())),a.children.length>0&&(i.appendChild(a),t.appendChild(i))}}},628:(t,e,r)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.Defuddle=void 0;const o=r(608),n=r(917),i=r(640),a=r(840),s=r(968),l=r(552);e.Defuddle=class{constructor(t,e={}){this.doc=t,this.options=e,this.debug=e.debug||!1}parse(){const t=this.parseInternal();if(t.wordCount<200){console.log("Initial parse returned very little content, trying again");const e=this.parseInternal({removePartialSelectors:!1});if(e.wordCount>t.wordCount)return this._log("Retry produced more content"),e}return t}parseInternal(t={}){var e,r,i;const l=Date.now(),c=Object.assign(Object.assign({removeExactSelectors:!0,removePartialSelectors:!0},this.options),t),u=this._extractSchemaOrgData(this.doc),d=[];this.doc.querySelectorAll("meta").forEach((t=>{const e=t.getAttribute("name"),r=t.getAttribute("property");let o=t.getAttribute("content");o&&d.push({name:e,property:r,content:this._decodeHTMLEntities(o)})}));const m=o.MetadataExtractor.extract(this.doc,u,d);c.removeImages&&this.removeImages(this.doc);try{const t=c.url||this.doc.URL,o=n.ExtractorRegistry.findExtractor(this.doc,t,u);if(o&&o.canExtract()){const t=o.extract(),n=Date.now();return{content:t.contentHtml,title:(null===(e=t.variables)||void 0===e?void 0:e.title)||m.title,description:m.description,domain:m.domain,favicon:m.favicon,image:m.image,published:(null===(r=t.variables)||void 0===r?void 0:r.published)||m.published,author:(null===(i=t.variables)||void 0===i?void 0:i.author)||m.author,site:m.site,schemaOrgData:m.schemaOrgData,wordCount:this.countWords(t.contentHtml),parseTime:Math.round(n-l),extractorType:o.constructor.name.replace("Extractor","").toLowerCase(),metaTags:d}}const h=this._evaluateMediaQueries(this.doc),p=this.findSmallImages(this.doc),g=this.doc.cloneNode(!0);this.applyMobileStyles(g,h);const f=this.findMainContent(g);if(!f){const t=Date.now();return Object.assign(Object.assign({content:this.doc.body.innerHTML},m),{wordCount:this.countWords(this.doc.body.innerHTML),parseTime:Math.round(t-l),metaTags:d})}this.removeSmallImages(g,p),this.removeHiddenElements(g),s.ContentScorer.scoreAndRemove(g,this.debug),(c.removeExactSelectors||c.removePartialSelectors)&&this.removeBySelector(g,c.removeExactSelectors,c.removePartialSelectors),(0,a.standardizeContent)(f,m,this.doc,this.debug);const v=f.outerHTML,b=Date.now();return Object.assign(Object.assign({content:v},m),{wordCount:this.countWords(v),parseTime:Math.round(b-l),metaTags:d})}catch(t){console.error("Defuddle","Error processing document:",t);const e=Date.now();return Object.assign(Object.assign({content:this.doc.body.innerHTML},m),{wordCount:this.countWords(this.doc.body.innerHTML),parseTime:Math.round(e-l),metaTags:d})}}countWords(t){const e=this.doc.createElement("div");e.innerHTML=t;return(e.textContent||"").trim().replace(/\s+/g," ").split(" ").filter((t=>t.length>0)).length}_log(...t){this.debug&&console.log("Defuddle:",...t)}_evaluateMediaQueries(t){const e=[],r=/max-width[^:]*:\s*(\d+)/;try{const o=Array.from(t.styleSheets).filter((t=>{try{return t.cssRules,!0}catch(t){return t instanceof DOMException&&t.name,!1}}));o.flatMap((t=>{try{return"undefined"==typeof CSSMediaRule?[]:Array.from(t.cssRules).filter((t=>t instanceof CSSMediaRule&&t.conditionText.includes("max-width")))}catch(t){return this.debug&&console.warn("Defuddle: Failed to process stylesheet:",t),[]}})).forEach((t=>{const o=t.conditionText.match(r);if(o){const r=parseInt(o[1]);if(i.MOBILE_WIDTH<=r){Array.from(t.cssRules).filter((t=>t instanceof CSSStyleRule)).forEach((t=>{try{e.push({selector:t.selectorText,styles:t.style.cssText})}catch(t){this.debug&&console.warn("Defuddle: Failed to process CSS rule:",t)}}))}}}))}catch(t){console.error("Defuddle: Error evaluating media queries:",t)}return e}applyMobileStyles(t,e){e.forEach((({selector:e,styles:r})=>{try{t.querySelectorAll(e).forEach((t=>{t.setAttribute("style",(t.getAttribute("style")||"")+r)}))}catch(t){console.error("Defuddle","Error applying styles for selector:",e,t)}}))}removeImages(t){const e=t.getElementsByTagName("img");Array.from(e).forEach((t=>{t.remove()}))}removeHiddenElements(t){let e=0;const r=new Set,o=Array.from(t.getElementsByTagName("*"));for(let n=0;n<o.length;n+=100){const i=o.slice(n,n+100),a=i.map((e=>{var r,o;try{return null===(r=e.ownerDocument.defaultView)||void 0===r?void 0:r.getComputedStyle(e)}catch(r){const n=e.getAttribute("style");if(!n)return null;const i=t.createElement("style");i.textContent=`* { ${n} }`,t.head.appendChild(i);const a=null===(o=e.ownerDocument.defaultView)||void 0===o?void 0:o.getComputedStyle(e);return t.head.removeChild(i),a}}));i.forEach(((t,o)=>{const n=a[o];!n||"none"!==n.display&&"hidden"!==n.visibility&&"0"!==n.opacity||(r.add(t),e++)}))}this._log("Removed hidden elements:",e)}removeBySelector(t,e=!0,r=!0){const o=Date.now();let n=0,a=0;const s=new Set;if(e){t.querySelectorAll(i.EXACT_SELECTORS.join(",")).forEach((t=>{(null==t?void 0:t.parentNode)&&(s.add(t),n++)}))}if(r){const e=i.PARTIAL_SELECTORS.join("|"),r=new RegExp(e,"i"),o=i.TEST_ATTRIBUTES.map((t=>`[${t}]`)).join(",");t.querySelectorAll(o).forEach((t=>{if(s.has(t))return;const e=i.TEST_ATTRIBUTES.map((e=>"class"===e?t.className&&"string"==typeof t.className?t.className:"":"id"===e?t.id||"":t.getAttribute(e)||"")).join(" ").toLowerCase();e.trim()&&r.test(e)&&(s.add(t),a++)}))}s.forEach((t=>t.remove()));const l=Date.now();this._log("Removed clutter elements:",{exactSelectors:n,partialSelectors:a,total:s.size,processingTime:`${(l-o).toFixed(2)}ms`})}findSmallImages(t){const e=new Set,r=/scale\(([\d.]+)\)/,o=Date.now();let n=0;const i=[...Array.from(t.getElementsByTagName("img")),...Array.from(t.getElementsByTagName("svg"))];if(0===i.length)return e;const a=i.map((t=>({element:t,naturalWidth:"img"===t.tagName.toLowerCase()&&parseInt(t.getAttribute("width")||"0")||0,naturalHeight:"img"===t.tagName.toLowerCase()&&parseInt(t.getAttribute("height")||"0")||0,attrWidth:parseInt(t.getAttribute("width")||"0"),attrHeight:parseInt(t.getAttribute("height")||"0")})));for(let t=0;t<a.length;t+=50){const o=a.slice(t,t+50);try{const t=o.map((({element:t})=>{var e;try{return null===(e=t.ownerDocument.defaultView)||void 0===e?void 0:e.getComputedStyle(t)}catch(t){return null}})),i=o.map((({element:t})=>{try{return t.getBoundingClientRect()}catch(t){return null}}));o.forEach(((o,a)=>{var s;try{const l=t[a],c=i[a];if(!l)return;const u=l.transform,d=u?parseFloat((null===(s=u.match(r))||void 0===s?void 0:s[1])||"1"):1,m=[o.naturalWidth,o.attrWidth,parseInt(l.width)||0,c?c.width*d:0].filter((t=>"number"==typeof t&&t>0)),h=[o.naturalHeight,o.attrHeight,parseInt(l.height)||0,c?c.height*d:0].filter((t=>"number"==typeof t&&t>0));if(m.length>0&&h.length>0){const t=Math.min(...m),r=Math.min(...h);if(t<33||r<33){const t=this.getElementIdentifier(o.element);t&&(e.add(t),n++)}}}catch(t){this.debug&&console.warn("Defuddle: Failed to process element dimensions:",t)}}))}catch(t){this.debug&&console.warn("Defuddle: Failed to process batch:",t)}}const s=Date.now();return this._log("Found small elements:",{count:n,processingTime:`${(s-o).toFixed(2)}ms`}),e}removeSmallImages(t,e){let r=0;["img","svg"].forEach((o=>{const n=t.getElementsByTagName(o);Array.from(n).forEach((t=>{const o=this.getElementIdentifier(t);o&&e.has(o)&&(t.remove(),r++)}))})),this._log("Removed small elements:",r)}getElementIdentifier(t){if("img"===t.tagName.toLowerCase()){const e=t.getAttribute("data-src");if(e)return`src:${e}`;const r=t.getAttribute("src")||"",o=t.getAttribute("srcset")||"",n=t.getAttribute("data-srcset");if(r)return`src:${r}`;if(o)return`srcset:${o}`;if(n)return`srcset:${n}`}const e=t.id||"",r=t.className||"",o="svg"===t.tagName.toLowerCase()&&t.getAttribute("viewBox")||"";return e?`id:${e}`:o?`viewBox:${o}`:r?`class:${r}`:null}findMainContent(t){const e=[];if(i.ENTRY_POINT_ELEMENTS.forEach(((r,o)=>{t.querySelectorAll(r).forEach((t=>{let r=40*(i.ENTRY_POINT_ELEMENTS.length-o);r+=s.ContentScorer.scoreElement(t),e.push({element:t,score:r})}))})),0===e.length)return this.findContentByScoring(t);if(e.sort(((t,e)=>e.score-t.score)),this.debug&&this._log("Content candidates:",e.map((t=>({element:t.element.tagName,selector:this.getElementSelector(t.element),score:t.score})))),1===e.length&&"body"===e[0].element.tagName.toLowerCase()){const e=this.findTableBasedContent(t);if(e)return e}return e[0].element}findTableBasedContent(t){if(!Array.from(t.getElementsByTagName("table")).some((t=>{const e=parseInt(t.getAttribute("width")||"0"),r=this.getComputedStyle(t);return e>400||(null==r?void 0:r.width.includes("px"))&&parseInt(r.width)>400||"center"===t.getAttribute("align")||t.className.toLowerCase().includes("content")||t.className.toLowerCase().includes("article")})))return null;const e=Array.from(t.getElementsByTagName("td"));return s.ContentScorer.findBestElement(e)}findContentByScoring(t){const e=[];return i.BLOCK_ELEMENTS.forEach((r=>{Array.from(t.getElementsByTagName(r)).forEach((t=>{const r=s.ContentScorer.scoreElement(t);r>0&&e.push({score:r,element:t})}))})),e.length>0?e.sort(((t,e)=>e.score-t.score))[0].element:null}getElementSelector(t){const e=[];let r=t;for(;r&&r!==this.doc.documentElement;){let t=r.tagName.toLowerCase();r.id?t+="#"+r.id:r.className&&"string"==typeof r.className&&(t+="."+r.className.trim().split(/\s+/).join(".")),e.unshift(t),r=r.parentElement}return e.join(" > ")}getComputedStyle(t){return(0,l.getComputedStyle)(t)}_extractSchemaOrgData(t){const e=t.querySelectorAll('script[type="application/ld+json"]'),r=[];e.forEach((t=>{let e=t.textContent||"";try{e=e.replace(/\/\*[\s\S]*?\*\/|^\s*\/\/.*$/gm,"").replace(/^\s*<!\[CDATA\[([\s\S]*?)\]\]>\s*$/,"$1").replace(/^\s*(\*\/|\/\*)\s*|\s*(\*\/|\/\*)\s*$/g,"").trim();const t=JSON.parse(e);t["@graph"]&&Array.isArray(t["@graph"])?r.push(...t["@graph"]):r.push(t)}catch(t){console.error("Defuddle: Error parsing schema.org data:",t),this.debug&&console.error("Defuddle: Problematic JSON content:",e)}}));const o=t=>{if("string"==typeof t)return this._decodeHTMLEntities(t);if(Array.isArray(t))return t.map(o);if("object"==typeof t&&null!==t){const e={};for(const r in t)Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=o(t[r]));return e}return t};return r.map(o)}_decodeHTMLEntities(t){const e=this.doc.createElement("textarea");return e.innerHTML=t,e.value}}},632:(t,e,r)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.ChatGPTExtractor=void 0;const o=r(181);class n extends o.ConversationExtractor{constructor(t,e){super(t,e),this.articles=t.querySelectorAll('article[data-testid^="conversation-turn-"]'),this.footnotes=[],this.footnoteCounter=0}canExtract(){return!!this.articles&&this.articles.length>0}extractMessages(){const t=[];return this.footnotes=[],this.footnoteCounter=0,this.articles?(this.articles.forEach((e=>{var r,o;const n=e.querySelector("h5.sr-only, h6.sr-only"),i=(null===(o=null===(r=null==n?void 0:n.textContent)||void 0===r?void 0:r.trim())||void 0===o?void 0:o.replace(/:\s*$/,""))||"";let a="";const s=e.getAtt