defuddle
Version:
Extract article content and metadata from web pages.
1 lines • 98 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 n=r(282);e.createCleanMathEl=(t,e,r,n)=>{const o=t.createElement("math");if(o.setAttribute("xmlns","http://www.w3.org/1998/Math/MathML"),o.setAttribute("display",n?"block":"inline"),o.setAttribute("data-latex",r||""),null==e?void 0:e.mathml){const r=t.createElement("div");r.innerHTML=e.mathml;const n=r.querySelector("math");n&&(o.innerHTML=n.innerHTML)}else r&&(o.textContent=r);return o},e.mathRules=[{selector:n.mathSelectors,element:"math",transform:(t,r)=>{if(!function(t){return"classList"in t&&"getAttribute"in t&&"querySelector"in t}(t))return t;const o=(0,n.getMathMLFromElement)(t),i=(0,n.getBasicLatexFromElement)(t),a=(0,n.isBlockDisplay)(t),s=(0,e.createCleanMathEl)(r,o,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 n=r(181);class o extends n.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 n=e.classList.contains("items-end"),o=e.classList.contains("items-start");if(!n&&!o)return;const i=e.querySelector(".message-bubble");if(!i)return;let a="",s="",l="";if(n)a=i.textContent||"",s="user",l="You";else if(o){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 n=this.document.querySelector(`${this.messageContainerSelector}.items-end`);if(n){const t=n.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 n;if(this.footnotes.find((t=>t.url===e)))n=this.footnotes.findIndex((t=>t.url===e))+1;else{this.footnoteCounter++,n=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:${n}" class="footnote-ref"><a href="#fn:${n}" class="footnote-link">${n}</a></sup>`}))}}e.GrokExtractor=o},181:(t,e,r)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.ConversationExtractor=void 0;const n=r(279),o=r(628);class i extends n.BaseExtractor{getFootnotes(){return[]}extract(){var t;const e=this.extractMessages(),r=this.getMetadata(),n=this.getFootnotes(),i=this.createContentHtml(e,n),a=document.implementation.createHTMLDocument(),s=a.createElement("article");s.innerHTML=i,a.body.appendChild(s);const l=new o.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 n=e.timestamp?`<div class="message-timestamp">${e.timestamp}</div>`:"",o=/<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${n}\n\t\t\t\t</div>\n\t\t\t\t<div class="message-content">\n\t\t\t\t\t${o}\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 n=r(279);class o extends n.BaseExtractor{constructor(t,e){var r;super(t,e),this.mainTweet=null,this.threadTweets=[];const n=t.querySelector('[aria-label="Timeline: Conversation"]');if(!n){const e=t.querySelector('article[data-testid="tweet"]');return void(e&&(this.mainTweet=e))}const o=Array.from(n.querySelectorAll('article[data-testid="tweet"]')),i=null===(r=n.querySelector("section, h2"))||void 0===r?void 0:r.parentElement;i&&o.forEach(((t,e)=>{if(i.compareDocumentPosition(t)&Node.DOCUMENT_POSITION_FOLLOWING)return o.splice(e),!1})),this.mainTweet=o[0]||null,this.threadTweets=o.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(),n=this.getTweetId(),o=this.getTweetAuthor();return{content:r,contentHtml:r,extractedContent:{tweetId:n,tweetAuthor:o},variables:{title:`Thread by ${o}`,author:o,site:"X (Twitter)",description:this.createDescription(this.mainTweet)}}}formatTweetText(t){if(!t)return"";const e=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,n;if(!t)return"";const o=t.cloneNode(!0);o.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=o.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===(n=null===(r=t.querySelector('[aria-labelledby*="id__"]'))||void 0===r?void 0:r.querySelector('[data-testid="User-Name"]'))||void 0===n?void 0:n.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,n,o,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===(o=null===(n=null==d?void 0:d[1])||void 0===n?void 0:n.textContent)||void 0===o?void 0:o.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 n=['[data-testid="tweetPhoto"]','[data-testid="tweet-image"]','img[src*="media"]'],o=[],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 n){t.querySelectorAll(e).forEach((t=>{var e,r;if(!(null==i?void 0:i.contains(t))&&"img"===t.tagName.toLowerCase()&&t.getAttribute("alt")){const n=(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())||"";o.push(`<img src="${n}" alt="${i}" />`)}}))}return o}getTweetId(){const t=this.url.match(/status\/(\d+)/);return(null==t?void 0:t[1])||""}getTweetAuthor(){var t,e,r;const n=null===(t=this.mainTweet)||void 0===t?void 0:t.querySelector('[data-testid="User-Name"]'),o=null==n?void 0:n.querySelectorAll("a"),i=(null===(r=null===(e=null==o?void 0:o[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=o},258:(t,e,r)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.YoutubeExtractor=void 0;const n=r(279);class o extends n.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),n=`<iframe width="560" height="315" src="https://www.youtube.com/embed/${this.getVideoId()}?si=_m0qv33lAuJFoGNh" 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:n,contentHtml:n,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(){return new URLSearchParams(new URL(this.url).search).get("v")||""}}e.YoutubeExtractor=o},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"),n=r.getAttribute("display"),o="block"===e||"block"===n;return{mathml:t.outerHTML,latex:t.getAttribute("alttext")||null,isBlock:o}}}const n=t.querySelector(".katex-mathml math");return n?{mathml:n.outerHTML,latex:null,isBlock:!1}:null};e.getBasicLatexFromElement=t=>{var e,r,n;const o=t.getAttribute("data-latex");if(o)return o;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===(n=t.textContent)||void 0===n?void 0:n.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 n=t.closest("[display]");return!!n&&"true"===n.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 n=r(181);class o extends n.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,n;if(e.hasAttribute("data-testid")){if("user-message"!==e.getAttribute("data-testid"))return;r="you",n=e.innerHTML}else{if(!e.classList.contains("font-claude-message"))return;r="assistant",n=e.innerHTML}n&&t.push({author:"you"===r?"You":"Claude",content:n.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,n,o;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===(o=null===(n=this.articles)||void 0===n?void 0:n.item(0))||void 0===o?void 0:o.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=o},458:(t,e,r)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.HackerNewsExtractor=void 0;const n=r(279);class o extends n.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),n=this.getPostTitle(),o=this.getPostAuthor(),i=this.createDescription(),a=this.getPostDate();return{content:r,contentHtml:r,extractedContent:{postId:this.getPostId(),postAuthor:o},variables:{title:n,author:o,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,n,o,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===(n=null===(r=this.mainComment.querySelector(".score"))||void 0===r?void 0:r.textContent)||void 0===n?void 0:n.trim())||"",u=(null===(o=this.mainPost.querySelector('.navs a[href*="parent"]'))||void 0===o?void 0:o.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,n,o;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===(o=null===(n=c.querySelector(".score"))||void 0===n?void 0:n.textContent)||void 0===o?void 0:o.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,n,o;if(this.isCommentPage&&this.mainComment){const r=(null===(t=this.mainComment.querySelector(".hnuser"))||void 0===t?void 0:t.textContent)||"[deleted]",n=(null===(e=this.mainComment.querySelector(".commtext"))||void 0===e?void 0:e.textContent)||"";return`Comment by ${r}: ${n.trim().slice(0,50)+(n.length>50?"...":"")}`}return(null===(o=null===(n=null===(r=this.mainPost)||void 0===r?void 0:r.querySelector(".titleline"))||void 0===n?void 0:n.textContent)||void 0===o?void 0:o.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=o},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=n(t.ownerDocument);return e?e.getComputedStyle(t):null},e.getWindow=n,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 n(t){return t.defaultView?t.defaultView:t.ownerWindow?t.ownerWindow:t.window?t.window:null}},608:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.MetadataExtractor=void 0;e.MetadataExtractor=class{static extract(t,e,r){var n,o;let i="",a="";try{if(a=(null===(n=t.location)||void 0===n?void 0:n.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===(o=t.querySelector('link[rel="canonical"]'))||void 0===o?void 0:o.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 n;if(n=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"),n)return n;let o=this.getSchemaProperty(e,"author.name")||this.getSchemaProperty(e,"author.[].name");if(o){const t=o.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 n=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"),n||""}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 n,o;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===(o=null===(n=t.querySelector("title"))||void 0===n?void 0:n.textContent)||void 0===o?void 0:o.trim())||"";return this.cleanTitle(i,this.getSite(t,e,r))}static cleanTitle(t,e){if(!t||!e)return t;const r=e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),n=[`\\s*[\\|\\-\u2013\u2014]\\s*${r}\\s*$`,`^\\s*${r}\\s*[\\|\\-\u2013\u2014]\\s*`];for(const e of n){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 n,o;const i=this.getMetaContent(r,"property","og:image:favicon");if(i)return i;const a=null===(n=t.querySelector("link[rel='icon']"))||void 0===n?void 0:n.getAttribute("href");if(a)return a;const s=null===(o=t.querySelector("link[rel='shortcut icon']"))||void 0===o?void 0:o.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 n,o;return this.getSchemaProperty(e,"datePublished")||this.getMetaContent(r,"name","publishDate")||this.getMetaContent(r,"property","article:published_time")||(null===(o=null===(n=t.querySelector('abbr[itemprop="datePublished"]'))||void 0===n?void 0:n.title)||void 0===o?void 0:o.trim())||this.getTimeElement(t)||this.getMetaContent(r,"name","sailthru.date")||""}static getMetaContent(t,e,r){var n,o;const i=t.find((t=>{const n="name"===e?t.name:t.property;return(null==n?void 0:n.toLowerCase())===r.toLowerCase()}));return i&&null!==(o=null===(n=i.content)||void 0===n?void 0:n.trim())&&void 0!==o?o:""}static getTimeElement(t){var e,r,n,o;const i=Array.from(t.querySelectorAll("time"))[0];return i&&null!==(o=null!==(r=null===(e=i.getAttribute("datetime"))||void 0===e?void 0:e.trim())&&void 0!==r?r:null===(n=i.textContent)||void 0===n?void 0:n.trim())&&void 0!==o?o:""}static getSchemaProperty(t,e,r=""){if(!t)return r;const n=(t,e,r,o=!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]?n(t[a],e.slice(1),r,o):[]}return 0===e.length&&t.every((t=>"string"==typeof t||"number"==typeof t))?t.map(String):t.flatMap((t=>n(t,e,r,o)))}const[i,...a]=e;if(!i)return"string"==typeof t?[t]:"object"==typeof t&&t.name?[t.name]:[];if(t.hasOwnProperty(i))return n(t[i],a,r?`${r}.${i}`:i,!0);if(!o){const o=[];for(const i in t)if("object"==typeof t[i]){const a=n(t[i],e,r?`${r}.${i}`:i,!1);o.push(...a)}if(o.length>0)return o}return[]};try{let o=n(t,e.split("."),"",!0);0===o.length&&(o=n(t,e.split("."),"",!1));return o.length>0?o.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 o(e).standardizeFootnotes(t)};const n=r(640);class o{constructor(t){this.doc=t}createFootnoteItem(t,e,r){const n="string"==typeof e?this.doc:e.ownerDocument,o=n.createElement("li");if(o.className="footnote",o.id=`fn:${t}`,"string"==typeof e){const t=n.createElement("p");t.innerHTML=e,o.appendChild(t)}else{const t=Array.from(e.querySelectorAll("p"));if(0===t.length){const t=n.createElement("p");t.innerHTML=e.innerHTML,o.appendChild(t)}else t.forEach((t=>{const e=n.createElement("p");e.innerHTML=t.innerHTML,o.appendChild(e)}))}const i=o.querySelector("p:last-of-type")||o;return r.forEach(((t,e)=>{const o=n.createElement("a");o.href=`#${t}`,o.title="return to article",o.className="footnote-backref",o.innerHTML="\u21a9",e<r.length-1&&(o.innerHTML+=" "),i.appendChild(o)})),o}collectFootnotes(t){const e={};let r=1;const o=new Set;return t.querySelectorAll(n.FOOTNOTE_LIST_SELECTORS).forEach((t=>{if(t.matches('div.footnote[data-component-name="FootnoteToDOM"]')){const n=t.querySelector("a.footnote-number"),i=t.querySelector(".footnote-content");if(n&&i){const t=n.id.replace("footnote-","").toLowerCase();t&&!o.has(t)&&(e[r]={content:i,originalId:t,refs:[]},o.add(t),r++)}return}t.querySelectorAll('li, div[role="listitem"]').forEach((t=>{var n,i,a,s;let l="",c=null;const u=t.querySelector(".citations");if(null===(n=null==u?void 0:u.id)||void 0===n?void 0:n.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&&!o.has(l)&&(e[r]={content:c||t,originalId:l,refs:[]},o.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 n=this.doc.createElement("a");return n.href=`#fn:${t}`,n.textContent=t,r.appendChild(n),r}standardizeFootnotes(t){const e=this.collectFootnotes(t),r=t.querySelectorAll(n.FOOTNOTE_INLINE_REFERENCES),o=new Map;r.forEach((t=>{var r,n,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===(n=t.id)||void 0===n?void 0:n.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,n]=r,i=n.refs.length>0?`fnref:${e}-${n.refs.length+1}`:`fnref:${e}`;n.refs.push(i);const a=this.findOuterFootnoteContainer(t);if("sup"===a.tagName.toLowerCase()){o.has(a)||o.set(a,[]);o.get(a).push(this.createFootnoteReference(e,i))}else a.replaceWith(this.createFootnoteReference(e,i))}}})),o.forEach(((t,e)=>{if(t.length>0){const r=this.doc.createDocumentFragment();t.forEach((t=>{const e=t.querySelector("a");if(e){const n=this.doc.createElement("sup");n.id=t.id,n.appendChild(e.cloneNode(!0)),r.appendChild(n)}})),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(n.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 n=r(608),o=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 n=t.getAttribute("content");n&&d.push({name:e,property:r,content:this._decodeHTMLEntities(n)})}));const m=n.MetadataExtractor.extract(this.doc,u,d);try{const t=c.url||this.doc.URL,n=o.ExtractorRegistry.findExtractor(this.doc,t,u);if(n&&n.canExtract()){const t=n.extract(),o=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(o-l),extractorType:n.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 n=Array.from(t.styleSheets).filter((t=>{try{return t.cssRules,!0}catch(t){return t instanceof DOMException&&t.name,!1}}));n.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 n=t.conditionText.match(r);if(n){const r=parseInt(n[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)}}))}removeHiddenElements(t){let e=0;const r=new Set,n=Array.from(t.getElementsByTagName("*"));for(let o=0;o<n.length;o+=100){const i=n.slice(o,o+100),a=i.map((e=>{var r,n;try{return null===(r=e.ownerDocument.defaultView)||void 0===r?void 0:r.getComputedStyle(e)}catch(r){const o=e.getAttribute("style");if(!o)return null;const i=t.createElement("style");i.textContent=`* { ${o} }`,t.head.appendChild(i);const a=null===(n=e.ownerDocument.defaultView)||void 0===n?void 0:n.getComputedStyle(e);return t.head.removeChild(i),a}}));i.forEach(((t,n)=>{const o=a[n];!o||"none"!==o.display&&"hidden"!==o.visibility&&"0"!==o.opacity||(r.add(t),e++)}))}this._log("Removed hidden elements:",e)}removeBySelector(t,e=!0,r=!0){const n=Date.now();let o=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),o++)}))}if(r){const e=i.PARTIAL_SELECTORS.join("|"),r=new RegExp(e,"i"),n=i.TEST_ATTRIBUTES.map((t=>`[${t}]`)).join(",");t.querySelectorAll(n).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:o,partialSelectors:a,total:s.size,processingTime:`${(l-n).toFixed(2)}ms`})}findSmallImages(t){const e=new Set,r=/scale\(([\d.]+)\)/,n=Date.now();let o=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 n=a.slice(t,t+50);try{const t=n.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=n.map((({element:t})=>{try{return t.getBoundingClientRect()}catch(t){return null}}));n.forEach(((n,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=[n.naturalWidth,n.attrWidth,parseInt(l.width)||0,c?c.width*d:0].filter((t=>"number"==typeof t&&t>0)),h=[n.naturalHeight,n.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(n.element);t&&(e.add(t),o++)}}}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:o,processingTime:`${(s-n).toFixed(2)}ms`}),e}removeSmallImages(t,e){let r=0;["img","svg"].forEach((n=>{const o=t.getElementsByTagName(n);Array.from(o).forEach((t=>{const n=this.getElementIdentifier(t);n&&e.has(n)&&(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")||"",n=t.getAttribute("srcset")||"",o=t.getAttribute("data-srcset");if(r)return`src:${r}`;if(n)return`srcset:${n}`;if(o)return`srcset:${o}`}const e=t.id||"",r=t.className||"",n="svg"===t.tagName.toLowerCase()&&t.getAttribute("viewBox")||"";return e?`id:${e}`:n?`viewBox:${n}`:r?`class:${r}`:null}findMainContent(t){const e=[];if(i.ENTRY_POINT_ELEMENTS.forEach(((r,n)=>{t.querySelectorAll(r).forEach((t=>{let r=40*(i.ENTRY_POINT_ELEMENTS.length-n);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 n=t=>{if("string"==typeof t)return this._decodeHTMLEntities(t);if(Array.isArray(t))return t.map(n);if("object"==typeof t&&null!==t){const e={};for(const r in t)Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=n(t[r]));return e}return t};return r.map(n)}_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 n=r(181);class o extends n.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,n;const o=e.querySelector("h5.sr-only, h6.sr-only"),i=(null===(n=null===(r=null==o?void 0:o.textContent)||void 0===r?void 0:r.trim())||void 0===n?void 0:n.replace(/:\s*$/,""))||"";let a="";const s=e.getAttribute("data-message-author-role");s&&(a=s);let l=e.innerHTML||"";l=l.replace(/\u200B/g,"");const c=document.createElement("div");c.innerHTML=l,c.querySelectorAll('h5.sr-only, h6.sr-only, span[data-state="closed"]').forEach((t=>t.remove())),l=c.innerHTML;l=l.replace(/(​)?(<span[^>]*?>\s*<a(?=[^>]*?href="([^"]+)")(?=[^>]*?target="_blank")(?=[^>]*?rel="noopener")[^>]*?>[\s\S]*?<\/a>\s*<\/span>)/gi,((t,e,r,n)=>{let o="",i="";try{o=new URL(n).hostname.replace(/^www\./,"");const t=n.split("#:~:text=");if(t.length>1){i=decodeURIComponent(t[1]),i=i.replace(/%2C/g,",");const e=i.split(",");i=e.length>1&&e[0].trim()?` \u2014 ${e[0].trim()}...`:e[0].trim()?` \u2014 ${i.trim()}`:""}}catch(t){console.error(`Failed to parse URL: ${n}`,t),o=n}let a,s=this.footnotes.findIndex((t=>t.url===n));return-1===s?(this.footnoteCounter++,a=this.footnoteCounter,this.footnotes.push({url:n,text:`<a href="${n}">${o}</a>${i}`})):a=s+1,`<sup id="fnref:${a}"><a href="#fn:${a}">${a}</a></sup>`})),l=l.replace(/<p[^>]*>\s*<\/p>/g,""),t.push({author:i,content:l.trim(),metadata:{role:a||"unknown"}})})),t):t}getFootnotes(){return this.footnotes}getMetadata(){const t=this.getTitle(),e=this.extractMessages();return{title:t,site:"ChatGPT",url:this.url,messageCount:e.length,description:`ChatGPT conversation with ${e.length} messages`}}getTitle(){var t,e,r;const n=null===(t=this.document.title)||void 0===t?void 0:t.trim();if(n&&"ChatGPT"!==n)return n;const o=null===(r=null===(e=this.articles)||void 0===e?void 0:e.item(0))||void 0===r?void 0:r.querySelector(".text-message");if(o){const t=o.textContent||"";return t.length>50?t.slice(0,50)+"...":t}return"ChatGPT Conversation"}}e.ChatGPTExtractor=o},640:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.ALLOWED_ATTRIBUTES_DEBUG=e.ALLOWED_ATTRIBUTES=e.ALLOWED_EMPTY_ELEMENTS=e.FOOTNOTE_LIST_SELECTORS=e.FOOTNOTE_INLINE_REFERENCES=e.PARTIAL_SELECTORS=e.TEST_ATTRIBUTES=e.EXACT_SELECTORS=e.INLINE_ELEMENTS=e.PRESERVE_ELEMENTS=e.BLOCK_ELEMENTS=e.MOBILE_WIDTH=e.ENTRY_POINT_ELEMENTS=void 0,e.ENTRY_POINT_ELEMENTS=["#post",".post-content",".article-content","#article-content",".article_post",".article-wrapper",".entry-content",".content-article",".post",".markdown-body","article",'[role="article"]',"main",'[role="main"]',"body"],e.MOBILE_WIDTH=600,e.BLOCK_ELEMENTS=["div","section","article","main","aside","header","footer","nav","content"],e.PRESERVE_ELEMENTS=new Set(["pre","code","table","thead","tbody","tr","td","th","ul","ol","li","dl","dt","dd","figure","figcaption","picture","details","summary","blockquote","form","fieldset"]),e.INLINE_ELEMENTS=new Set(["a","span","strong","em","i","b","u","code","br","small","sub","sup","mark","date","del","ins","q","abbr","cite","relative-time","time","font"]),e.EXACT_SELECTORS=["noscript",'script:not([type^="math/"])',"style","meta","link",'.ad:not([class*="gradient"])','[class^="ad-" i]','[class$="-ad" i]','[id^="ad-" i]','[id$="-ad" i]','[role="banner" i]','[alt*="advert" i]',".promo",".Promo","#barrier-page",".alert",'[id="comments" i]','[id="comment" i]',"header",".header:not(.banner)","#header","#Header","#banner","#Banner","nav",".navigation","#navigation",".hero",'[role="navigation" i]','[role="dialog" i]','[role*="complementary" i]','[class*="pagination" i]',".menu","#menu","#siteSub",".previous",".author",".Author",'[class$="_bio"]',"#categories",".contributor",".date","#date","[data-date]",".entry-meta",".meta",".tags","#tags",".toc",".Toc","#toc",".headline","#headline","#title","#Title","#articleTag",'[href*="/category"]','[href*="/categories"]','[href*="/tag/"]','[href*="/tags/"]','[href*="/topics"]','[href*="author"]','[href*="#toc"]','[href="#top"]','[href="#Top"]','[href="#page-header"]','[href="#content"]','[href="#site-content"]','[href="#main-content"]','[href