defuddle 0.2.1 → 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.Defuddle=t():e.Defuddle=t()}("undefined"!=typeof self?self:this,(()=>(()=>{"use strict";var e={608:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.MetadataExtractor=void 0,t.MetadataExtractor=class{static extract(e,t){var r,o;let n="",a="";try{a=(null===(r=e.location)||void 0===r?void 0:r.href)||"",a||(a=this.getMetaContent(e,"property","og:url")||this.getMetaContent(e,"property","twitter:url")||this.getSchemaProperty(t,"url")||this.getSchemaProperty(t,"mainEntityOfPage.url")||this.getSchemaProperty(t,"mainEntity.url")||this.getSchemaProperty(t,"WebSite.url")||(null===(o=e.querySelector('link[rel="canonical"]'))||void 0===o?void 0:o.getAttribute("href"))||""),a&&(n=new URL(a).hostname.replace(/^www\./,""))}catch(t){const r=e.querySelector("base[href]");if(r)try{a=r.getAttribute("href")||"",n=new URL(a).hostname.replace(/^www\./,"")}catch(e){console.warn("Failed to parse base URL:",e)}}return{title:this.getTitle(e,t),description:this.getDescription(e,t),domain:n,favicon:this.getFavicon(e,a),image:this.getImage(e,t),published:this.getPublished(e,t),author:this.getAuthor(e,t),site:this.getSite(e,t),schemaOrgData:t}}static getAuthor(e,t){return this.getMetaContent(e,"name","sailthru.author")||this.getSchemaProperty(t,"author.name")||this.getMetaContent(e,"property","author")||this.getMetaContent(e,"name","byl")||this.getMetaContent(e,"name","author")||this.getMetaContent(e,"name","authorList")||this.getMetaContent(e,"name","copyright")||this.getSchemaProperty(t,"copyrightHolder.name")||this.getMetaContent(e,"property","og:site_name")||this.getSchemaProperty(t,"publisher.name")||this.getSchemaProperty(t,"sourceOrganization.name")||this.getSchemaProperty(t,"isPartOf.name")||this.getMetaContent(e,"name","twitter:creator")||this.getMetaContent(e,"name","application-name")||""}static getSite(e,t){return this.getSchemaProperty(t,"publisher.name")||this.getMetaContent(e,"property","og:site_name")||this.getSchemaProperty(t,"sourceOrganization.name")||this.getMetaContent(e,"name","copyright")||this.getSchemaProperty(t,"copyrightHolder.name")||this.getSchemaProperty(t,"isPartOf.name")||this.getMetaContent(e,"name","application-name")||""}static getTitle(e,t){var r,o;return this.getMetaContent(e,"property","og:title")||this.getMetaContent(e,"name","twitter:title")||this.getSchemaProperty(t,"headline")||this.getMetaContent(e,"name","title")||this.getMetaContent(e,"name","sailthru.title")||(null===(o=null===(r=e.querySelector("title"))||void 0===r?void 0:r.textContent)||void 0===o?void 0:o.trim())||""}static getDescription(e,t){return this.getMetaContent(e,"name","description")||this.getMetaContent(e,"property","description")||this.getMetaContent(e,"property","og:description")||this.getSchemaProperty(t,"description")||this.getMetaContent(e,"name","twitter:description")||this.getMetaContent(e,"name","sailthru.description")||""}static getImage(e,t){return this.getMetaContent(e,"property","og:image")||this.getMetaContent(e,"name","twitter:image")||this.getSchemaProperty(t,"image.url")||this.getMetaContent(e,"name","sailthru.image.full")||""}static getFavicon(e,t){var r,o;const n=this.getMetaContent(e,"property","og:image:favicon");if(n)return n;const a=null===(r=e.querySelector("link[rel='icon']"))||void 0===r?void 0:r.getAttribute("href");if(a)return a;const i=null===(o=e.querySelector("link[rel='shortcut icon']"))||void 0===o?void 0:o.getAttribute("href");if(i)return i;if(t)try{return new URL("/favicon.ico",t).href}catch(e){console.warn("Failed to construct favicon URL:",e)}return""}static getPublished(e,t){return this.getSchemaProperty(t,"datePublished")||this.getMetaContent(e,"name","publishDate")||this.getMetaContent(e,"property","article:published_time")||this.getTimeElement(e)||this.getMetaContent(e,"name","sailthru.date")||""}static getMetaContent(e,t,r){var o,n;const a=`meta[${t}]`,i=Array.from(e.querySelectorAll(a)).find((e=>{var o;return(null===(o=e.getAttribute(t))||void 0===o?void 0:o.toLowerCase())===r.toLowerCase()})),s=i&&null!==(n=null===(o=i.getAttribute("content"))||void 0===o?void 0:o.trim())&&void 0!==n?n:"";return this.decodeHTMLEntities(s)}static getTimeElement(e){var t,r,o,n;const a=Array.from(e.querySelectorAll("time"))[0],i=a&&null!==(n=null!==(r=null===(t=a.getAttribute("datetime"))||void 0===t?void 0:t.trim())&&void 0!==r?r:null===(o=a.textContent)||void 0===o?void 0:o.trim())&&void 0!==n?n:"";return this.decodeHTMLEntities(i)}static decodeHTMLEntities(e){const t=document.createElement("textarea");return t.innerHTML=e,t.value}static getSchemaProperty(e,t,r=""){if(!e)return r;const o=(e,t,r,n=!0)=>{if("string"==typeof e)return 0===t.length?[e]:[];if(!e||"object"!=typeof e)return[];if(Array.isArray(e)){const a=t[0];if(/^\[\d+\]$/.test(a)){const i=parseInt(a.slice(1,-1));return e[i]?o(e[i],t.slice(1),r,n):[]}return 0===t.length&&e.every((e=>"string"==typeof e||"number"==typeof e))?e.map(String):e.flatMap((e=>o(e,t,r,n)))}const[a,...i]=t;if(!a)return"string"==typeof e?[e]:"object"==typeof e&&e.name?[e.name]:[];if(e.hasOwnProperty(a))return o(e[a],i,r?`${r}.${a}`:a,!0);if(!n){const n=[];for(const a in e)if("object"==typeof e[a]){const i=o(e[a],t,r?`${r}.${a}`:a,!1);n.push(...i)}if(n.length>0)return n}return[]};try{let n=o(e,t.split("."),"",!0);0===n.length&&(n=o(e,t.split("."),"",!1));const a=n.length>0?n.filter(Boolean).join(", "):r;return this.decodeHTMLEntities(a)}catch(e){return console.error(`Error in getSchemaProperty for ${t}:`,e),r}}static extractSchemaOrgData(e){const t=e.querySelectorAll('script[type="application/ld+json"]'),r=[];return t.forEach((e=>{let t=e.textContent||"";try{t=t.replace(/\/\*[\s\S]*?\*\/|^\s*\/\/.*$/gm,"").replace(/^\s*<!\[CDATA\[([\s\S]*?)\]\]>\s*$/,"$1").replace(/^\s*(\*\/|\/\*)\s*|\s*(\*\/|\/\*)\s*$/g,"").trim();const e=JSON.parse(t);e["@graph"]&&Array.isArray(e["@graph"])?r.push(...e["@graph"]):r.push(e)}catch(e){console.error("Error parsing schema.org data:",e),console.error("Problematic JSON content:",t)}})),r}}},628:(e,t,r)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.Defuddle=void 0;const o=r(608),n=["article",'[role="article"]','[itemprop="articleBody"]',".post-content",".article-content","#article-content",".content-article","main",'[role="main"]',"body"],a=["div","section","article","main"],i=["[hidden]",'[aria-hidden="true"]','[style*="visibility: hidden"]','[style*="visibility:hidden"]',".hidden",".invisible"].join(","),s=["noscript","script","style",'.ad:not([class*="gradient"])','[class^="ad-" i]','[class$="-ad" i]','[id^="ad-" i]','[id$="-ad" i]','[role="banner" i]',".promo",".Promo",'[id="comments" i]',"header","#header","nav",".navigation","#navigation",'[role="navigation" i]','[role="dialog" i]','[role*="complementary" i]','[class*="pagination" i]',".author",".Author",".contributor",".date",".meta",".toc",".Toc","#toc","#title","#Title",'[href*="/category"]','[href*="/categories"]','[href*="/tag/"]','[href*="/tags/"]','[href*="/topics"]','[href*="author"]','[href="#site-content"]','[src*="author"]',"footer","aside","button","canvas","dialog","fieldset","form","input","label","link","option","select","textarea","time","instaread-player",'iframe:not([src*="youtube"]):not([src*="youtu.be"]):not([src*="vimeo"]):not([src*="twitter"])','[class="logo" i]',"#logo","#Logo","#newsletter","#Newsletter",".noprint",'[data-link-name*="skip" i]','[data-print-layout="hide" i]','[data-block="donotprint" i]','[class*="clickable-icon" i]','li span[class*="ltx_tag" i][class*="ltx_tag_item" i]','a[href^="#"][class*="anchor" i]','a[href^="#"][class*="ref" i]','[data-container*="most-viewed" i]',".sidebar",".Sidebar","#sidebar","#Sidebar","#sitesub","table.infobox",".pencraft:not(.pc-display-contents)",'[data-optimizely="related-articles-section" i]'],l=["access-wall","activitypub","appendix","avatar","advert","-ad-","_ad_","allterms","around-the-web","article__copy","article_date","article-end ","article_header","article__header","article__info","article-info","article__meta","article-subject","article_subject","article-snippet","article-tags","article_tags","article-title","article_title","articletopics","article-topics","article-type","article--lede","associated-people","back-to-top","backlinks-section","banner","bio-block","blog-pager","bottom-of-article","brand-bar","breadcrumb","button-wrapper","btn-","-btn","byline","captcha","cat_header","catlinks","chapter-list","collections","comments","comment-count","comment-content","comment-form","comment-respond","comment-thread","complementary","consent","content-card","content-topics","contentpromo","core-collateral","_cta","-cta","cta-","cta_","current-issue","custom-list-number","dateline","dateheader","date-header","date_header-","disclaimer","disclosure","discussion","discuss_","disqus","donate","dropdown","eletters","emailsignup","engagement-widget","entry-author-info","entry-date","entry-meta","entry-title","entry-utility","eyebrow","expand-reduce","externallinkembedwrapper","facebook","favorite","feedback","feed-links","field-site-sections","fixed","follow","footer","footnote-back","footnoteback","for-you","frontmatter","further-reading","gist-meta","google","goog-","header-logo","header-pattern","hero-list","hide-for-print","hide-print","hidden-sidenote","interlude","interaction","jumplink","kicker","-labels","language-name","latest-content","-ledes-","-license","link-box","links-grid","links-title","listing-dynamic-terms","loading","loa-info","logo_container","ltx_role_refnum","ltx_tag_bibitem","ltx_error","marketing","media-inquiry","menu-","meta-","metadata","might-like","_modal","-modal","more-","morenews","morestories","mw-editsection","mw-cite-backlink","mw-indicators","mw-jump-link","nav-","nav_","navbar","navigation","next-","news-story-title","newsletter_","newsletter-signup","newslettersignup","newsletterwidget","newsletterwrapper","not-found","nomobile","noprint","originally-published","overlay","page-title","-partners","plea","popular","pop-up","popover","post-bottom","post__category","postcomment","postdate","post-date","post_date","post-feeds","postinfo","post-info","post_info","post-inline-date","post-links","post-meta","postmeta","postsnippet","post_snippet","post-snippet","posttitle","post-title","post_title","posttax","post-tax","post_tax","posttag","post_tag","post-tag","prevnext","previousnext","print-none","print-header","profile","pubdate","pub_date","pub-date","publication-date","publicationName","qr-code","qr_code","_rail","readmore","read-next","read_next","read_time","read-time","reading_time","reading-time","reading-list","recentpost","recent_post","recent-post","recommend","redirectedfrom","recirc","register","related","reversefootnote","screen-reader-text","share-box","share-icons","sharelinks","share-section","sidebartitle","sidebar_","similar-","similar_","similars-","sideitems","side-box","site-index","site-header","site-logo","site-name","skip-link","social","speechify-ignore","sponsor","_stats","sticky","storyreadtime","storypublishdate","subject-label","subscribe","_tags","tags__item","tag_list","taxonomy","table-of-contents","tabs-","terminaltout","time-rubric","timestamp","tip_off","tiptout","-toc","topic-list","toolbar","tooltip","top-wrapper","tree-item","trending","trust-feat","trust-badge","twitter","visually-hidden","welcomebox"],c=["sup.reference","cite.ltx_cite",'sup[id^="fnr"]','sup[id^="fnref:"]',"span.footnote-link","a.citation",'a[id^="ref-link"]','a[href^="#fn"]','a[href^="#cite"]','a[href^="#reference"]','a[href^="#footnote"]','a[href^="#r"]','a[href^="#b"]','a[href*="cite_note"]','a[href*="cite_ref"]',"a.footnote-anchor","span.footnote-hovercard-target a",'a[role="doc-biblioref"]','a[id^="fnref"]','a[id^="ref-link"]'].join(","),d=["div.footnote ol","div.footnotes ol",'div[role="doc-endnotes"]','div[role="doc-footnotes"]',"ol.footnotes-list","ol.footnotes","ol.references",'ol[class*="article-references"]',"section.footnotes ol",'section[role="doc-endnotes"]','section[role="doc-footnotes"]','section[role="doc-bibliography"]',"ul.footnotes-list","ul.ltx_biblist",'div.footnote[data-component-name="FootnoteToDOM"]'].join(","),m=new Set(["area","audio","base","br","circle","col","defs","ellipse","embed","figure","g","hr","iframe","img","input","line","link","mask","meta","object","param","path","pattern","picture","polygon","polyline","rect","source","stop","svg","td","th","track","use","video","wbr"]),h=new Set(["alt","allow","allowfullscreen","aria-label","class","colspan","controls","data-src","data-srcset","data-lang","dir","frameborder","headers","height","href","id","lang","role","rowspan","src","srcset","title","type","width"]),u=new Set(["markup","html","xml","svg","mathml","ssml","atom","rss","javascript","js","jsx","typescript","ts","tsx","webassembly","wasm","python","java","csharp","cs","dotnet","aspnet","cpp","c++","c","objc","ruby","rb","php","golang","rust","swift","kotlin","scala","dart","bash","shell","sh","powershell","batch","json","jsonp","yaml","yml","toml","dockerfile","gitignore","sql","mysql","postgresql","graphql","mongodb","sparql","markdown","md","latex","tex","asciidoc","adoc","jsdoc","haskell","hs","elm","elixir","erlang","ocaml","fsharp","scheme","lisp","elisp","clojure","matlab","fortran","cobol","pascal","perl","lua","julia","groovy","crystal","nim","zig","regex","gradle","cmake","makefile","nix","terraform","solidity","glsl","hlsl","nasm","masm","armasm","gdscript","unrealscript","abap","actionscript","ada","agda","antlr4","applescript","arduino","coffeescript","django","erlang","fortran","haxe","idris","kotlin","livescript","matlab","nginx","pascal","prolog","puppet","scala","scheme","tcl","verilog","vhdl"]),p=[{selector:"pre",element:"pre",transform:e=>{if(!(e instanceof HTMLElement))return e;const t=e=>{const t=e.getAttribute("data-lang");if(t)return t.toLowerCase();const r=[/^language-(\w+)$/,/^lang-(\w+)$/,/^(\w+)-code$/,/^code-(\w+)$/,/^syntax-(\w+)$/,/^code-snippet__(\w+)$/,/^highlight-(\w+)$/,/^(\w+)-snippet$/];if(e.className&&"string"==typeof e.className){for(const t of r){const r=e.className.toLowerCase().match(t);if(r)return r[1].toLowerCase()}if(u.has(e.className.toLowerCase()))return e.className.toLowerCase()}const o=Array.from(e.classList);for(const e of o)for(const t of r){const r=e.match(t);if(r)return r[1].toLowerCase()}for(const e of o)if(u.has(e.toLowerCase()))return e.toLowerCase();return""};let r="",o=e;for(;o&&!r;)r=t(o),!r&&o.querySelector("code")&&(r=t(o.querySelector("code"))),o=o.parentElement;const n=e=>{if(e.nodeType===Node.TEXT_NODE)return e.textContent||"";let t="";if(e instanceof HTMLElement){if("BR"===e.tagName)return"\n";e.childNodes.forEach((e=>{t+=n(e)})),"CODE"===e.tagName&&(t+="\n")}return t};let a=n(e);a=a.replace(/^\n+/,"").replace(/\n+$/,"").replace(/\n{3,}/g,"\n\n");const i=document.createElement("pre");Array.from(e.attributes).forEach((e=>{h.has(e.name)&&i.setAttribute(e.name,e.value)}));const s=document.createElement("code");return r&&(s.setAttribute("data-lang",r),s.setAttribute("class",`language-${r}`)),s.textContent=a,i.appendChild(s),i}},{selector:"h1, h2, h3, h4, h5, h6",element:"keep",transform:e=>{var t,r,o,n,a;if(1===e.children.length&&"A"===(null===(t=e.firstElementChild)||void 0===t?void 0:t.tagName)&&((null===(r=e.firstElementChild.getAttribute("href"))||void 0===r?void 0:r.includes("#"))||(null===(o=e.firstElementChild.getAttribute("href"))||void 0===o?void 0:o.startsWith("#")))){const t=document.createElement(e.tagName);return Array.from(e.attributes).forEach((e=>{h.has(e.name)&&t.setAttribute(e.name,e.value)})),t.textContent=(null===(n=e.textContent)||void 0===n?void 0:n.trim())||"",t}if(e.querySelectorAll("button").length>0){const t=document.createElement(e.tagName);return Array.from(e.attributes).forEach((e=>{h.has(e.name)&&t.setAttribute(e.name,e.value)})),t.textContent=(null===(a=e.textContent)||void 0===a?void 0:a.trim())||"",t}return e}},{selector:'div[data-testid^="paragraph"], div[role="paragraph"]',element:"p",transform:e=>{const t=document.createElement("p");return t.innerHTML=e.innerHTML,Array.from(e.attributes).forEach((e=>{h.has(e.name)&&t.setAttribute(e.name,e.value)})),t}},{selector:'div[role="list"]',element:"ul",transform:e=>{var t;const r=e.querySelector('div[role="listitem"] .label'),o=((null===(t=null==r?void 0:r.textContent)||void 0===t?void 0:t.trim())||"").match(/^\d+\)/),n=document.createElement(o?"ol":"ul");return e.querySelectorAll('div[role="listitem"]').forEach((e=>{const t=document.createElement("li"),r=e.querySelector(".content");r&&(r.querySelectorAll('div[role="paragraph"]').forEach((e=>{const t=document.createElement("p");t.innerHTML=e.innerHTML,e.replaceWith(t)})),r.querySelectorAll('div[role="list"]').forEach((e=>{var t;const r=e.querySelector('div[role="listitem"] .label'),o=((null===(t=null==r?void 0:r.textContent)||void 0===t?void 0:t.trim())||"").match(/^\d+\)/),n=document.createElement(o?"ol":"ul");e.querySelectorAll('div[role="listitem"]').forEach((e=>{const t=document.createElement("li"),r=e.querySelector(".content");r&&(r.querySelectorAll('div[role="paragraph"]').forEach((e=>{const t=document.createElement("p");t.innerHTML=e.innerHTML,e.replaceWith(t)})),t.innerHTML=r.innerHTML),n.appendChild(t)})),e.replaceWith(n)})),t.innerHTML=r.innerHTML),n.appendChild(t)})),n}},{selector:'div[role="listitem"]',element:"li",transform:e=>{const t=e.querySelector(".content");return t?(t.querySelectorAll('div[role="paragraph"]').forEach((e=>{const t=document.createElement("p");t.innerHTML=e.innerHTML,e.replaceWith(t)})),t):e}}];t.Defuddle=class{constructor(e,t={}){this.doc=e,this.options=t,this.debug=t.debug||!1}parse(){const e=o.MetadataExtractor.extractSchemaOrgData(this.doc),t=o.MetadataExtractor.extract(this.doc,e);try{const e=this._evaluateMediaQueries(this.doc),r=this.findSmallImages(this.doc),o=this.doc.cloneNode(!0);this.applyMobileStyles(o,e);const n=this.findMainContent(o);return n?(this.removeSmallImages(o,r),this.removeHiddenElements(o),this.removeClutter(o),this.cleanContent(n,t),Object.assign({content:n?n.outerHTML:this.doc.body.innerHTML},t)):Object.assign({content:this.doc.body.innerHTML},t)}catch(e){return console.error("Defuddle","Error processing document:",e),Object.assign({content:this.doc.body.innerHTML},t)}}_log(...e){this.debug&&console.log("Defuddle:",...e)}_evaluateMediaQueries(e){const t=[],r=/max-width[^:]*:\s*(\d+)/;try{Array.from(e.styleSheets).filter((e=>{try{return e.cssRules,!0}catch(e){if(e instanceof DOMException&&"SecurityError"===e.name)return!1;throw e}})).flatMap((e=>{try{return Array.from(e.cssRules).filter((e=>e instanceof CSSMediaRule&&e.conditionText.includes("max-width")))}catch(e){return this.debug&&console.warn("Defuddle: Failed to process stylesheet:",e),[]}})).forEach((e=>{const o=e.conditionText.match(r);o&&600<=parseInt(o[1])&&Array.from(e.cssRules).filter((e=>e instanceof CSSStyleRule)).forEach((e=>{try{t.push({selector:e.selectorText,styles:e.style.cssText})}catch(e){this.debug&&console.warn("Defuddle: Failed to process CSS rule:",e)}}))}))}catch(e){console.error("Defuddle: Error evaluating media queries:",e)}return t}applyMobileStyles(e,t){t.forEach((({selector:t,styles:r})=>{try{e.querySelectorAll(t).forEach((e=>{e.setAttribute("style",(e.getAttribute("style")||"")+r)}))}catch(e){console.error("Defuddle","Error applying styles for selector:",t,e)}}))}removeHiddenElements(e){let t=0;const r=new Set,o=e.querySelectorAll(i);o.forEach((e=>r.add(e))),t+=o.length;const n=document.createTreeWalker(e.body,NodeFilter.SHOW_ELEMENT,{acceptNode:e=>r.has(e)?NodeFilter.FILTER_REJECT:NodeFilter.FILTER_ACCEPT}),a=[];let s;for(;s=n.nextNode();)a.push(s);for(let e=0;e<a.length;e+=100){const o=a.slice(e,e+100),n=o.map((e=>window.getComputedStyle(e)));o.forEach(((e,o)=>{const a=n[o];"none"!==a.display&&"hidden"!==a.visibility&&"0"!==a.opacity||(r.add(e),t++)}))}r.forEach((e=>e.remove())),this._log("Removed hidden elements:",t)}removeClutter(e){const t=performance.now();let r=0,o=0;const n=new Set;e.querySelectorAll(s.join(",")).forEach((e=>{(null==e?void 0:e.parentNode)&&(n.add(e),r++)}));const a=l.join("|"),i=new RegExp(a,"i");e.querySelectorAll("[class],[id],[data-testid],[data-qa],[data-cy]").forEach((e=>{if(n.has(e))return;const t=[e.className&&"string"==typeof e.className?e.className:"",e.id||"",e.getAttribute("data-testid")||"",e.getAttribute("data-qa")||"",e.getAttribute("data-cy")||""].join(" ").toLowerCase();t.trim()&&i.test(t)&&(n.add(e),o++)})),n.forEach((e=>e.remove()));const c=performance.now();this._log("Removed clutter elements:",{exactSelectors:r,partialSelectors:o,total:n.size,processingTime:`${(c-t).toFixed(2)}ms`})}cleanContent(e,t){this.removeHtmlComments(e),this.handleHeadings(e,t.title),this.standardizeFootnotes(e),this.handleLazyImages(e),this.standardizeElements(e),this.stripUnwantedAttributes(e),this.removeEmptyElements(e),this.removeTrailingHeadings(e)}removeTrailingHeadings(e){let t=0;const r=t=>{let o="",n=t.nextSibling;for(;n;)(n.nodeType===Node.TEXT_NODE||n.nodeType===Node.ELEMENT_NODE)&&(o+=n.textContent||""),n=n.nextSibling;if(o.trim())return!0;const a=t.parentElement;return!(!a||a===e)&&r(a)};Array.from(e.querySelectorAll("h1, h2, h3, h4, h5, h6")).reverse().forEach((e=>{r(e)||(e.remove(),t++)})),t>0&&this._log("Removed trailing headings:",t)}handleHeadings(e,t){var r;const o=e.getElementsByTagName("h1");Array.from(o).forEach((e=>{var t;const r=document.createElement("h2");r.innerHTML=e.innerHTML,Array.from(e.attributes).forEach((e=>{h.has(e.name)&&r.setAttribute(e.name,e.value)})),null===(t=e.parentNode)||void 0===t||t.replaceChild(r,e)}));const n=e.getElementsByTagName("h2");if(n.length>0){const e=n[0],o=(null===(r=e.textContent)||void 0===r?void 0:r.trim().toLowerCase())||"",a=t.toLowerCase().trim();a&&a===o&&e.remove()}}removeHtmlComments(e){const t=[],r=document.createTreeWalker(e,NodeFilter.SHOW_COMMENT,null);let o;for(;o=r.nextNode();)t.push(o);t.forEach((e=>{e.remove()})),this._log("Removed HTML comments:",t.length)}stripUnwantedAttributes(e){let t=0;const r=e=>{e instanceof SVGElement||Array.from(e.attributes).forEach((r=>{const o=r.name.toLowerCase();h.has(o)||o.startsWith("data-")||(e.removeAttribute(r.name),t++)}))};r(e),e.querySelectorAll("*").forEach(r),this._log("Stripped attributes:",t)}removeEmptyElements(e){let t=0,r=0,o=!0;for(;o;){r++,o=!1;const n=Array.from(e.getElementsByTagName("*")).filter((e=>{if(m.has(e.tagName.toLowerCase()))return!1;const t=e.textContent||"",r=0===t.trim().length,o=t.includes(" "),n=!e.hasChildNodes()||Array.from(e.childNodes).every((e=>{if(e.nodeType===Node.TEXT_NODE){const t=e.textContent||"";return 0===t.trim().length&&!t.includes(" ")}return!1}));return r&&!o&&n}));n.length>0&&(n.forEach((e=>{e.remove(),t++})),o=!0)}this._log("Removed empty elements:",{count:t,iterations:r})}createFootnoteItem(e,t,r){const o=document.createElement("li");if(o.className="footnote",o.id=`fn:${e}`,"string"==typeof t){const e=document.createElement("p");e.innerHTML=t,o.appendChild(e)}else{const e=Array.from(t.querySelectorAll("p"));if(0===e.length){const e=document.createElement("p");e.innerHTML=t.innerHTML,o.appendChild(e)}else e.forEach((e=>{const t=document.createElement("p");t.innerHTML=e.innerHTML,o.appendChild(t)}))}const n=o.querySelector("p:last-of-type")||o;return r.forEach(((e,t)=>{const o=document.createElement("a");o.href=`#${e}`,o.title="return to article",o.className="footnote-backref",o.innerHTML="↩",t<r.length-1&&(o.innerHTML+=" "),n.appendChild(o)})),o}collectFootnotes(e){const t={};let r=1;const o=new Set;return e.querySelectorAll(d).forEach((e=>{if(e.matches('div.footnote[data-component-name="FootnoteToDOM"]')){const n=e.querySelector("a.footnote-number"),a=e.querySelector(".footnote-content");if(n&&a){const e=n.id.replace("footnote-","").toLowerCase();e&&!o.has(e)&&(t[r]={content:a,originalId:e,refs:[]},o.add(e),r++)}}else e.querySelectorAll('li, div[role="listitem"]').forEach((e=>{var n,a,i,s;let l="",c=null;const d=e.querySelector(".citations");if(null===(n=null==d?void 0:d.id)||void 0===n?void 0:n.toLowerCase().startsWith("r")){l=d.id.toLowerCase();const e=d.querySelector(".citation-content");e&&(c=e)}else{if(e.id.toLowerCase().startsWith("bib.bib"))l=e.id.replace("bib.bib","").toLowerCase();else if(e.id.toLowerCase().startsWith("fn:"))l=e.id.replace("fn:","").toLowerCase();else if(e.id.toLowerCase().startsWith("fn"))l=e.id.replace("fn","").toLowerCase();else if(e.hasAttribute("data-counter"))l=(null===(i=null===(a=e.getAttribute("data-counter"))||void 0===a?void 0:a.replace(/\.$/,""))||void 0===i?void 0:i.toLowerCase())||"";else{const t=null===(s=e.id.split("/").pop())||void 0===s?void 0:s.match(/cite_note-(.+)/);l=t?t[1].toLowerCase():e.id.toLowerCase()}c=e}l&&!o.has(l)&&(t[r]={content:c||e,originalId:l,refs:[]},o.add(l),r++)}))})),t}findOuterFootnoteContainer(e){let t=e,r=e.parentElement;for(;r&&("span"===r.tagName.toLowerCase()||"sup"===r.tagName.toLowerCase());)t=r,r=r.parentElement;return t}createFootnoteReference(e,t){const r=document.createElement("sup");r.id=t;const o=document.createElement("a");return o.href=`#fn:${e}`,o.textContent=e,r.appendChild(o),r}standardizeFootnotes(e){const t=this.collectFootnotes(e),r=e.querySelectorAll(c),o=new Map;r.forEach((e=>{var r,n,a,i;if(!(e instanceof HTMLElement))return;let s="",l="";if(e.matches('a[id^="ref-link"]'))s=(null===(r=e.textContent)||void 0===r?void 0:r.trim())||"";else if(e.matches('a[role="doc-biblioref"]')){const t=e.getAttribute("data-xml-rid");if(t)s=t;else{const t=e.getAttribute("href");(null==t?void 0:t.startsWith("#core-R"))&&(s=t.replace("#core-",""))}}else if(e.matches("a.footnote-anchor, span.footnote-hovercard-target a")){const t=(null===(n=e.id)||void 0===n?void 0:n.replace("footnote-anchor-",""))||"";t&&(s=t.toLowerCase())}else if(e.matches("cite.ltx_cite")){const t=e.querySelector("a");if(t){const e=t.getAttribute("href");if(e){const t=null===(a=e.split("/").pop())||void 0===a?void 0:a.match(/bib\.bib(\d+)/);t&&(s=t[1].toLowerCase())}}}else if(e.matches("sup.reference")){const t=e.querySelectorAll("a");Array.from(t).forEach((e=>{var t;const r=e.getAttribute("href");if(r){const e=null===(t=r.split("/").pop())||void 0===t?void 0:t.match(/(?:cite_note|cite_ref)-(.+)/);e&&(s=e[1].toLowerCase())}}))}else if(e.matches('sup[id^="fnref:"]'))s=e.id.replace("fnref:","").toLowerCase();else if(e.matches('sup[id^="fnr"]'))s=e.id.replace("fnr","").toLowerCase();else if(e.matches("span.footnote-reference"))s=e.getAttribute("data-footnote-id")||"";else if(e.matches("span.footnote-link"))s=e.getAttribute("data-footnote-id")||"",l=e.getAttribute("data-footnote-content")||"";else if(e.matches("a.citation"))s=(null===(i=e.textContent)||void 0===i?void 0:i.trim())||"",l=e.getAttribute("href")||"";else if(e.matches('a[id^="fnref"]'))s=e.id.replace("fnref","").toLowerCase();else{const t=e.getAttribute("href");if(t){const e=t.replace(/^[#]/,"");s=e.toLowerCase()}}if(s){const r=Object.entries(t).find((([e,t])=>t.originalId===s.toLowerCase()));if(r){const[t,n]=r,a=n.refs.length>0?`fnref:${t}-${n.refs.length+1}`:`fnref:${t}`;n.refs.push(a);const i=this.findOuterFootnoteContainer(e);"sup"===i.tagName.toLowerCase()?(o.has(i)||o.set(i,[]),o.get(i).push(this.createFootnoteReference(t,a))):i.replaceWith(this.createFootnoteReference(t,a))}}})),o.forEach(((e,t)=>{if(e.length>0){const r=document.createDocumentFragment();e.forEach(((e,t)=>{const o=e.querySelector("a");if(o){const t=document.createElement("sup");t.id=e.id,t.appendChild(o.cloneNode(!0)),r.appendChild(t)}})),t.replaceWith(r)}}));const n=document.createElement("div");n.className="footnotes";const a=document.createElement("ol");Object.entries(t).forEach((([e,t])=>{const r=this.createFootnoteItem(parseInt(e),t.content,t.refs);a.appendChild(r)})),e.querySelectorAll(d).forEach((e=>e.remove())),a.children.length>0&&(n.appendChild(a),e.appendChild(n))}handleLazyImages(e){let t=0;e.querySelectorAll("img[data-src], img[data-srcset]").forEach((e=>{if(!(e instanceof HTMLImageElement))return;const r=e.getAttribute("data-src");r&&!e.src&&(e.src=r,t++);const o=e.getAttribute("data-srcset");o&&!e.srcset&&(e.srcset=o,t++),e.classList.remove("lazy","lazyload"),e.removeAttribute("data-ll-status"),e.removeAttribute("data-src"),e.removeAttribute("data-srcset")})),this._log("Processed lazy images:",t)}standardizeElements(e){let t=0;p.forEach((r=>{e.querySelectorAll(r.selector).forEach((e=>{if(r.transform){const o=r.transform(e);e.replaceWith(o),t++}}))})),e.querySelectorAll("lite-youtube").forEach((e=>{const r=e.getAttribute("videoid");if(!r)return;const o=document.createElement("iframe");o.width="560",o.height="315",o.src=`https://www.youtube.com/embed/${r}`,o.title=e.getAttribute("videotitle")||"YouTube video player",o.frameBorder="0",o.allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share",o.setAttribute("allowfullscreen",""),e.replaceWith(o),t++})),this._log("Converted embedded elements:",t)}findSmallImages(e){const t=new Set,r=/scale\(([\d.]+)\)/,o=performance.now();let n=0;const a=[...Array.from(e.getElementsByTagName("img")),...Array.from(e.getElementsByTagName("svg"))].filter((e=>!(e instanceof HTMLImageElement)||!(e.classList.contains("lazy")||e.classList.contains("lazyload")||e.hasAttribute("data-src")||e.hasAttribute("data-srcset"))));if(0===a.length)return t;const i=a.map((e=>({element:e,naturalWidth:e instanceof HTMLImageElement?e.naturalWidth:0,naturalHeight:e instanceof HTMLImageElement?e.naturalHeight:0,attrWidth:parseInt(e.getAttribute("width")||"0"),attrHeight:parseInt(e.getAttribute("height")||"0")})));for(let e=0;e<i.length;e+=50){const o=i.slice(e,e+50);try{const e=o.map((({element:e})=>window.getComputedStyle(e))),a=o.map((({element:e})=>e.getBoundingClientRect()));o.forEach(((o,i)=>{var s;try{const l=e[i],c=a[i],d=l.transform,m=d?parseFloat((null===(s=d.match(r))||void 0===s?void 0:s[1])||"1"):1,h=[o.naturalWidth,o.attrWidth,parseInt(l.width)||0,c.width*m].filter((e=>"number"==typeof e&&e>0)),u=[o.naturalHeight,o.attrHeight,parseInt(l.height)||0,c.height*m].filter((e=>"number"==typeof e&&e>0));if(h.length>0&&u.length>0){const e=Math.min(...h),r=Math.min(...u);if(e<33||r<33){const e=this.getElementIdentifier(o.element);e&&(t.add(e),n++)}}}catch(e){this.debug&&console.warn("Defuddle: Failed to process element dimensions:",e)}}))}catch(e){this.debug&&console.warn("Defuddle: Failed to process batch:",e)}}const s=performance.now();return this._log("Found small elements:",{count:n,totalElements:a.length,processingTime:`${(s-o).toFixed(2)}ms`}),t}removeSmallImages(e,t){let r=0;["img","svg"].forEach((o=>{const n=e.getElementsByTagName(o);Array.from(n).forEach((e=>{const o=this.getElementIdentifier(e);o&&t.has(o)&&(e.remove(),r++)}))})),this._log("Removed small elements:",r)}getElementIdentifier(e){if(e instanceof HTMLImageElement){const t=e.getAttribute("data-src");if(t)return`src:${t}`;const r=e.src||"",o=e.srcset||"",n=e.getAttribute("data-srcset");if(r)return`src:${r}`;if(o)return`srcset:${o}`;if(n)return`srcset:${n}`}const t=e.id||"",r=e.className||"",o=e instanceof SVGElement&&e.getAttribute("viewBox")||"";return t?`id:${t}`:o?`viewBox:${o}`:r?`class:${r}`:null}findMainContent(e){const t=[];return n.forEach(((r,o)=>{e.querySelectorAll(r).forEach((e=>{let r=10*(n.length-o);r+=this.scoreElement(e),t.push({element:e,score:r})}))})),0===t.length?this.findContentByScoring(e):(t.sort(((e,t)=>t.score-e.score)),this.debug&&this._log("Content candidates:",t.map((e=>({element:e.element.tagName,selector:this.getElementSelector(e.element),score:e.score})))),t[0].element)}findContentByScoring(e){const t=this.scoreElements(e);return t.length>0?t[0].element:null}getElementSelector(e){const t=[];let r=e;for(;r&&r!==document.documentElement;){let e=r.tagName.toLowerCase();r.id?e+="#"+r.id:r.className&&"string"==typeof r.className&&(e+="."+r.className.trim().split(/\s+/).join(".")),t.unshift(e),r=r.parentElement}return t.join(" > ")}scoreElements(e){const t=[];return a.forEach((r=>{Array.from(e.getElementsByTagName(r)).forEach((e=>{const r=this.scoreElement(e);r>0&&t.push({score:r,element:e})}))})),t.sort(((e,t)=>t.score-e.score))}scoreElement(e){let t=0;e.className&&"string"==typeof e.className&&e.className.toLowerCase(),e.id&&e.id.toLowerCase();const r=e.textContent||"",o=r.split(/\s+/).length;t+=Math.min(Math.floor(o/100),3);const n=e.getElementsByTagName("a"),a=Array.from(n).reduce(((e,t)=>{var r;return e+((null===(r=t.textContent)||void 0===r?void 0:r.length)||0)}),0);(r.length?a/r.length:0)>.5&&(t-=10),t+=e.getElementsByTagName("p").length;const i=e.getElementsByTagName("img").length;return t+=Math.min(3*i,9),t}}}},t={};function r(o){var n=t[o];if(void 0!==n)return n.exports;var a=t[o]={exports:{}};return e[o](a,a.exports,r),a.exports}var o={};return(()=>{var e=o;Object.defineProperty(e,"__esModule",{value:!0}),e.Defuddle=void 0;var t=r(628);Object.defineProperty(e,"Defuddle",{enumerable:!0,get:function(){return t.Defuddle}})})(),o})()));
|
|
1
|
+
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.Defuddle=t():e.Defuddle=t()}("undefined"!=typeof self?self:this,(()=>(()=>{"use strict";var e={608:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.MetadataExtractor=void 0,t.MetadataExtractor=class{static extract(e,t){var r,o;let n="",a="";try{a=(null===(r=e.location)||void 0===r?void 0:r.href)||"",a||(a=this.getMetaContent(e,"property","og:url")||this.getMetaContent(e,"property","twitter:url")||this.getSchemaProperty(t,"url")||this.getSchemaProperty(t,"mainEntityOfPage.url")||this.getSchemaProperty(t,"mainEntity.url")||this.getSchemaProperty(t,"WebSite.url")||(null===(o=e.querySelector('link[rel="canonical"]'))||void 0===o?void 0:o.getAttribute("href"))||""),a&&(n=new URL(a).hostname.replace(/^www\./,""))}catch(t){const r=e.querySelector("base[href]");if(r)try{a=r.getAttribute("href")||"",n=new URL(a).hostname.replace(/^www\./,"")}catch(e){console.warn("Failed to parse base URL:",e)}}return{title:this.getTitle(e,t),description:this.getDescription(e,t),domain:n,favicon:this.getFavicon(e,a),image:this.getImage(e,t),published:this.getPublished(e,t),author:this.getAuthor(e,t),site:this.getSite(e,t),schemaOrgData:t}}static getAuthor(e,t){return this.getMetaContent(e,"name","sailthru.author")||this.getSchemaProperty(t,"author.name")||this.getMetaContent(e,"property","author")||this.getMetaContent(e,"name","byl")||this.getMetaContent(e,"name","author")||this.getMetaContent(e,"name","authorList")||this.getMetaContent(e,"name","copyright")||this.getSchemaProperty(t,"copyrightHolder.name")||this.getMetaContent(e,"property","og:site_name")||this.getSchemaProperty(t,"publisher.name")||this.getSchemaProperty(t,"sourceOrganization.name")||this.getSchemaProperty(t,"isPartOf.name")||this.getMetaContent(e,"name","twitter:creator")||this.getMetaContent(e,"name","application-name")||""}static getSite(e,t){return this.getSchemaProperty(t,"publisher.name")||this.getMetaContent(e,"property","og:site_name")||this.getSchemaProperty(t,"sourceOrganization.name")||this.getMetaContent(e,"name","copyright")||this.getSchemaProperty(t,"copyrightHolder.name")||this.getSchemaProperty(t,"isPartOf.name")||this.getMetaContent(e,"name","application-name")||""}static getTitle(e,t){var r,o;return this.getMetaContent(e,"property","og:title")||this.getMetaContent(e,"name","twitter:title")||this.getSchemaProperty(t,"headline")||this.getMetaContent(e,"name","title")||this.getMetaContent(e,"name","sailthru.title")||(null===(o=null===(r=e.querySelector("title"))||void 0===r?void 0:r.textContent)||void 0===o?void 0:o.trim())||""}static getDescription(e,t){return this.getMetaContent(e,"name","description")||this.getMetaContent(e,"property","description")||this.getMetaContent(e,"property","og:description")||this.getSchemaProperty(t,"description")||this.getMetaContent(e,"name","twitter:description")||this.getMetaContent(e,"name","sailthru.description")||""}static getImage(e,t){return this.getMetaContent(e,"property","og:image")||this.getMetaContent(e,"name","twitter:image")||this.getSchemaProperty(t,"image.url")||this.getMetaContent(e,"name","sailthru.image.full")||""}static getFavicon(e,t){var r,o;const n=this.getMetaContent(e,"property","og:image:favicon");if(n)return n;const a=null===(r=e.querySelector("link[rel='icon']"))||void 0===r?void 0:r.getAttribute("href");if(a)return a;const i=null===(o=e.querySelector("link[rel='shortcut icon']"))||void 0===o?void 0:o.getAttribute("href");if(i)return i;if(t)try{return new URL("/favicon.ico",t).href}catch(e){console.warn("Failed to construct favicon URL:",e)}return""}static getPublished(e,t){return this.getSchemaProperty(t,"datePublished")||this.getMetaContent(e,"name","publishDate")||this.getMetaContent(e,"property","article:published_time")||this.getTimeElement(e)||this.getMetaContent(e,"name","sailthru.date")||""}static getMetaContent(e,t,r){var o,n;const a=`meta[${t}]`,i=Array.from(e.querySelectorAll(a)).find((e=>{var o;return(null===(o=e.getAttribute(t))||void 0===o?void 0:o.toLowerCase())===r.toLowerCase()})),s=i&&null!==(n=null===(o=i.getAttribute("content"))||void 0===o?void 0:o.trim())&&void 0!==n?n:"";return this.decodeHTMLEntities(s)}static getTimeElement(e){var t,r,o,n;const a=Array.from(e.querySelectorAll("time"))[0],i=a&&null!==(n=null!==(r=null===(t=a.getAttribute("datetime"))||void 0===t?void 0:t.trim())&&void 0!==r?r:null===(o=a.textContent)||void 0===o?void 0:o.trim())&&void 0!==n?n:"";return this.decodeHTMLEntities(i)}static decodeHTMLEntities(e){const t=document.createElement("textarea");return t.innerHTML=e,t.value}static getSchemaProperty(e,t,r=""){if(!e)return r;const o=(e,t,r,n=!0)=>{if("string"==typeof e)return 0===t.length?[e]:[];if(!e||"object"!=typeof e)return[];if(Array.isArray(e)){const a=t[0];if(/^\[\d+\]$/.test(a)){const i=parseInt(a.slice(1,-1));return e[i]?o(e[i],t.slice(1),r,n):[]}return 0===t.length&&e.every((e=>"string"==typeof e||"number"==typeof e))?e.map(String):e.flatMap((e=>o(e,t,r,n)))}const[a,...i]=t;if(!a)return"string"==typeof e?[e]:"object"==typeof e&&e.name?[e.name]:[];if(e.hasOwnProperty(a))return o(e[a],i,r?`${r}.${a}`:a,!0);if(!n){const n=[];for(const a in e)if("object"==typeof e[a]){const i=o(e[a],t,r?`${r}.${a}`:a,!1);n.push(...i)}if(n.length>0)return n}return[]};try{let n=o(e,t.split("."),"",!0);0===n.length&&(n=o(e,t.split("."),"",!1));const a=n.length>0?n.filter(Boolean).join(", "):r;return this.decodeHTMLEntities(a)}catch(e){return console.error(`Error in getSchemaProperty for ${t}:`,e),r}}static extractSchemaOrgData(e){const t=e.querySelectorAll('script[type="application/ld+json"]'),r=[];return t.forEach((e=>{let t=e.textContent||"";try{t=t.replace(/\/\*[\s\S]*?\*\/|^\s*\/\/.*$/gm,"").replace(/^\s*<!\[CDATA\[([\s\S]*?)\]\]>\s*$/,"$1").replace(/^\s*(\*\/|\/\*)\s*|\s*(\*\/|\/\*)\s*$/g,"").trim();const e=JSON.parse(t);e["@graph"]&&Array.isArray(e["@graph"])?r.push(...e["@graph"]):r.push(e)}catch(e){console.error("Error parsing schema.org data:",e),console.error("Problematic JSON content:",t)}})),r}}},628:(e,t,r)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.Defuddle=void 0;const o=r(608),n=["article",'[role="article"]','[itemprop="articleBody"]',".post-content",".article-content","#article-content",".content-article","main",'[role="main"]',"body"],a=["div","section","article","main"],i=["[hidden]",'[aria-hidden="true"]','[style*="visibility: hidden"]','[style*="visibility:hidden"]',".hidden",".invisible"].join(","),s=["noscript","script","style",'.ad:not([class*="gradient"])','[class^="ad-" i]','[class$="-ad" i]','[id^="ad-" i]','[id$="-ad" i]','[role="banner" i]',".promo",".Promo",'[id="comments" i]',"header","#header","nav",".navigation","#navigation",'[role="navigation" i]','[role="dialog" i]','[role*="complementary" i]','[class*="pagination" i]',".author",".Author",".contributor",".date",".meta",".toc",".Toc","#toc","#title","#Title",'[href*="/category"]','[href*="/categories"]','[href*="/tag/"]','[href*="/tags/"]','[href*="/topics"]','[href*="author"]','[href="#site-content"]','[src*="author"]',"footer","aside","button","canvas","dialog","fieldset","form","input","label","link","option","select","textarea","time","instaread-player",'iframe:not([src*="youtube"]):not([src*="youtu.be"]):not([src*="vimeo"]):not([src*="twitter"])','[class="logo" i]',"#logo","#Logo","#newsletter","#Newsletter",".noprint",'[data-link-name*="skip" i]','[data-print-layout="hide" i]','[data-block="donotprint" i]','[class*="clickable-icon" i]','li span[class*="ltx_tag" i][class*="ltx_tag_item" i]','a[href^="#"][class*="anchor" i]','a[href^="#"][class*="ref" i]','[data-container*="most-viewed" i]',".sidebar",".Sidebar","#sidebar","#Sidebar","#sitesub","table.infobox",".pencraft:not(.pc-display-contents)",'[data-optimizely="related-articles-section" i]'],l=["access-wall","activitypub","appendix","avatar","advert","-ad-","_ad_","allterms","around-the-web","article__copy","article_date","article-end ","article_header","article__header","article__info","article-info","article__meta","article-subject","article_subject","article-snippet","article-tags","article_tags","article-title","article_title","articletopics","article-topics","article-type","article--lede","associated-people","back-to-top","backlinks-section","banner","bio-block","blog-pager","bottom-of-article","brand-bar","breadcrumb","button-wrapper","btn-","-btn","byline","captcha","cat_header","catlinks","chapter-list","collections","comments","comment-count","comment-content","comment-form","comment-respond","comment-thread","complementary","consent","content-card","content-topics","contentpromo","core-collateral","_cta","-cta","cta-","cta_","current-issue","custom-list-number","dateline","dateheader","date-header","date_header-","disclaimer","disclosure","discussion","discuss_","disqus","donate","dropdown","eletters","emailsignup","engagement-widget","entry-author-info","entry-date","entry-meta","entry-title","entry-utility","eyebrow","expand-reduce","externallinkembedwrapper","facebook","favorite","feedback","feed-links","field-site-sections","fixed","follow","footer","footnote-back","footnoteback","for-you","frontmatter","further-reading","gist-meta","google","goog-","header-logo","header-pattern","hero-list","hide-for-print","hide-print","hidden-sidenote","interlude","interaction","jumplink","kicker","-labels","language-name","latest-content","-ledes-","-license","link-box","links-grid","links-title","listing-dynamic-terms","loading","loa-info","logo_container","ltx_role_refnum","ltx_tag_bibitem","ltx_error","marketing","media-inquiry","menu-","meta-","metadata","might-like","_modal","-modal","more-","morenews","morestories","mw-editsection","mw-cite-backlink","mw-indicators","mw-jump-link","nav-","nav_","navbar","navigation","next-","news-story-title","newsletter_","newsletter-signup","newslettersignup","newsletterwidget","newsletterwrapper","not-found","nomobile","noprint","originally-published","overlay","page-title","-partners","plea","popular","pop-up","popover","post-bottom","post__category","postcomment","postdate","post-date","post_date","post-feeds","postinfo","post-info","post_info","post-inline-date","post-links","post-meta","postmeta","postsnippet","post_snippet","post-snippet","posttitle","post-title","post_title","posttax","post-tax","post_tax","posttag","post_tag","post-tag","prevnext","previousnext","print-none","print-header","profile","pubdate","pub_date","pub-date","publication-date","publicationName","qr-code","qr_code","_rail","readmore","read-next","read_next","read_time","read-time","reading_time","reading-time","reading-list","recentpost","recent_post","recent-post","recommend","redirectedfrom","recirc","register","related","reversefootnote","screen-reader-text","share-box","share-icons","sharelinks","share-section","sidebartitle","sidebar_","similar-","similar_","similars-","sideitems","side-box","site-index","site-header","site-logo","site-name","skip-link","social","speechify-ignore","sponsor","_stats","sticky","storyreadtime","storypublishdate","subject-label","subscribe","_tags","tags__item","tag_list","taxonomy","table-of-contents","tabs-","terminaltout","time-rubric","timestamp","tip_off","tiptout","-toc","topic-list","toolbar","tooltip","top-wrapper","tree-item","trending","trust-feat","trust-badge","twitter","visually-hidden","welcomebox"],c=["sup.reference","cite.ltx_cite",'sup[id^="fnr"]','sup[id^="fnref:"]',"span.footnote-link","a.citation",'a[id^="ref-link"]','a[href^="#fn"]','a[href^="#cite"]','a[href^="#reference"]','a[href^="#footnote"]','a[href^="#r"]','a[href^="#b"]','a[href*="cite_note"]','a[href*="cite_ref"]',"a.footnote-anchor","span.footnote-hovercard-target a",'a[role="doc-biblioref"]','a[id^="fnref"]','a[id^="ref-link"]'].join(","),d=["div.footnote ol","div.footnotes ol",'div[role="doc-endnotes"]','div[role="doc-footnotes"]',"ol.footnotes-list","ol.footnotes","ol.references",'ol[class*="article-references"]',"section.footnotes ol",'section[role="doc-endnotes"]','section[role="doc-footnotes"]','section[role="doc-bibliography"]',"ul.footnotes-list","ul.ltx_biblist",'div.footnote[data-component-name="FootnoteToDOM"]'].join(","),m=new Set(["area","audio","base","br","circle","col","defs","ellipse","embed","figure","g","hr","iframe","img","input","line","link","mask","meta","object","param","path","pattern","picture","polygon","polyline","rect","source","stop","svg","td","th","track","use","video","wbr"]),h=new Set(["alt","allow","allowfullscreen","aria-label","class","colspan","controls","data-src","data-srcset","data-lang","dir","frameborder","headers","height","href","id","lang","role","rowspan","src","srcset","title","type","width"]),u=new Set(["markup","html","xml","svg","mathml","ssml","atom","rss","javascript","js","jsx","typescript","ts","tsx","webassembly","wasm","python","java","csharp","cs","dotnet","aspnet","cpp","c++","c","objc","ruby","rb","php","golang","rust","swift","kotlin","scala","dart","bash","shell","sh","powershell","batch","json","jsonp","yaml","yml","toml","dockerfile","gitignore","sql","mysql","postgresql","graphql","mongodb","sparql","markdown","md","latex","tex","asciidoc","adoc","jsdoc","haskell","hs","elm","elixir","erlang","ocaml","fsharp","scheme","lisp","elisp","clojure","matlab","fortran","cobol","pascal","perl","lua","julia","groovy","crystal","nim","zig","regex","gradle","cmake","makefile","nix","terraform","solidity","glsl","hlsl","nasm","masm","armasm","gdscript","unrealscript","abap","actionscript","ada","agda","antlr4","applescript","arduino","coffeescript","django","erlang","fortran","haxe","idris","kotlin","livescript","matlab","nginx","pascal","prolog","puppet","scala","scheme","tcl","verilog","vhdl"]),p=[{selector:"pre",element:"pre",transform:e=>{if(!(e instanceof HTMLElement))return e;const t=e=>{const t=e.getAttribute("data-lang");if(t)return t.toLowerCase();const r=[/^language-(\w+)$/,/^lang-(\w+)$/,/^(\w+)-code$/,/^code-(\w+)$/,/^syntax-(\w+)$/,/^code-snippet__(\w+)$/,/^highlight-(\w+)$/,/^(\w+)-snippet$/];if(e.className&&"string"==typeof e.className){for(const t of r){const r=e.className.toLowerCase().match(t);if(r)return r[1].toLowerCase()}if(u.has(e.className.toLowerCase()))return e.className.toLowerCase()}const o=Array.from(e.classList);for(const e of o)for(const t of r){const r=e.match(t);if(r)return r[1].toLowerCase()}for(const e of o)if(u.has(e.toLowerCase()))return e.toLowerCase();return""};let r="",o=e;for(;o&&!r;)r=t(o),!r&&o.querySelector("code")&&(r=t(o.querySelector("code"))),o=o.parentElement;const n=e=>{if(e.nodeType===Node.TEXT_NODE)return e.textContent||"";let t="";if(e instanceof HTMLElement){if("BR"===e.tagName)return"\n";e.childNodes.forEach((e=>{t+=n(e)})),"CODE"===e.tagName&&(t+="\n")}return t};let a=n(e);a=a.replace(/^\n+/,"").replace(/\n+$/,"").replace(/\n{3,}/g,"\n\n");const i=document.createElement("pre");Array.from(e.attributes).forEach((e=>{h.has(e.name)&&i.setAttribute(e.name,e.value)}));const s=document.createElement("code");return r&&(s.setAttribute("data-lang",r),s.setAttribute("class",`language-${r}`)),s.textContent=a,i.appendChild(s),i}},{selector:"h1, h2, h3, h4, h5, h6",element:"keep",transform:e=>{var t,r,o,n,a;if(1===e.children.length&&"A"===(null===(t=e.firstElementChild)||void 0===t?void 0:t.tagName)&&((null===(r=e.firstElementChild.getAttribute("href"))||void 0===r?void 0:r.includes("#"))||(null===(o=e.firstElementChild.getAttribute("href"))||void 0===o?void 0:o.startsWith("#")))){const t=document.createElement(e.tagName);return Array.from(e.attributes).forEach((e=>{h.has(e.name)&&t.setAttribute(e.name,e.value)})),t.textContent=(null===(n=e.textContent)||void 0===n?void 0:n.trim())||"",t}if(e.querySelectorAll("button").length>0){const t=document.createElement(e.tagName);return Array.from(e.attributes).forEach((e=>{h.has(e.name)&&t.setAttribute(e.name,e.value)})),t.textContent=(null===(a=e.textContent)||void 0===a?void 0:a.trim())||"",t}return e}},{selector:'div[data-testid^="paragraph"], div[role="paragraph"]',element:"p",transform:e=>{const t=document.createElement("p");return t.innerHTML=e.innerHTML,Array.from(e.attributes).forEach((e=>{h.has(e.name)&&t.setAttribute(e.name,e.value)})),t}},{selector:'div[role="list"]',element:"ul",transform:e=>{var t;const r=e.querySelector('div[role="listitem"] .label'),o=((null===(t=null==r?void 0:r.textContent)||void 0===t?void 0:t.trim())||"").match(/^\d+\)/),n=document.createElement(o?"ol":"ul");return e.querySelectorAll('div[role="listitem"]').forEach((e=>{const t=document.createElement("li"),r=e.querySelector(".content");r&&(r.querySelectorAll('div[role="paragraph"]').forEach((e=>{const t=document.createElement("p");t.innerHTML=e.innerHTML,e.replaceWith(t)})),r.querySelectorAll('div[role="list"]').forEach((e=>{var t;const r=e.querySelector('div[role="listitem"] .label'),o=((null===(t=null==r?void 0:r.textContent)||void 0===t?void 0:t.trim())||"").match(/^\d+\)/),n=document.createElement(o?"ol":"ul");e.querySelectorAll('div[role="listitem"]').forEach((e=>{const t=document.createElement("li"),r=e.querySelector(".content");r&&(r.querySelectorAll('div[role="paragraph"]').forEach((e=>{const t=document.createElement("p");t.innerHTML=e.innerHTML,e.replaceWith(t)})),t.innerHTML=r.innerHTML),n.appendChild(t)})),e.replaceWith(n)})),t.innerHTML=r.innerHTML),n.appendChild(t)})),n}},{selector:'div[role="listitem"]',element:"li",transform:e=>{const t=e.querySelector(".content");return t?(t.querySelectorAll('div[role="paragraph"]').forEach((e=>{const t=document.createElement("p");t.innerHTML=e.innerHTML,e.replaceWith(t)})),t):e}},{selector:'.wp-block-syntaxhighlighter-code, .syntaxhighlighter, .highlight, .highlight-source, .wp-block-code, pre[class*="language-"], pre[class*="brush:"]',element:"pre",transform:e=>{if(!(e instanceof HTMLElement))return e;const t=document.createElement("pre");let r="";const o=e.querySelector(".syntaxhighlighter");if(o){const e=Array.from(o.classList).find((e=>!["syntaxhighlighter","nogutter"].includes(e)));e&&u.has(e.toLowerCase())&&(r=e.toLowerCase())}if(!r){const t=Array.from(e.classList),o=[/(?:^|\s)(?:language|lang|brush|syntax)-(\w+)(?:\s|$)/i,/(?:^|\s)(\w+)(?:\s|$)/i];for(const e of t){for(const t of o){const o=e.match(t);if(o&&o[1]&&u.has(o[1].toLowerCase())){r=o[1].toLowerCase();break}}if(r)break}}let n="";const a=e.querySelector(".syntaxhighlighter table .code .container");if(a)n=Array.from(a.children).map((e=>{const t=Array.from(e.querySelectorAll("code")).map((e=>{let t=e.textContent||"";return e.classList.contains("spaces")&&(t=" ".repeat(t.length)),t})).join("");return t||e.textContent||""})).join("\n");else{const t=e.querySelectorAll(".code .line");n=t.length>0?Array.from(t).map((e=>{const t=Array.from(e.querySelectorAll("code")).map((e=>e.textContent||"")).join("");return t||e.textContent||""})).join("\n"):e.textContent||""}n=n.replace(/^\s+|\s+$/g,"").replace(/\t/g," ").replace(/\n{3,}/g,"\n\n").replace(/\u00a0/g," ");const i=document.createElement("code");return r&&(i.setAttribute("data-lang",r),i.setAttribute("class",`language-${r}`)),i.textContent=n,t.appendChild(i),t}}];t.Defuddle=class{constructor(e,t={}){this.doc=e,this.options=t,this.debug=t.debug||!1}parse(){const e=o.MetadataExtractor.extractSchemaOrgData(this.doc),t=o.MetadataExtractor.extract(this.doc,e);try{const e=this._evaluateMediaQueries(this.doc),r=this.findSmallImages(this.doc),o=this.doc.cloneNode(!0);this.applyMobileStyles(o,e);const n=this.findMainContent(o);return n?(this.removeSmallImages(o,r),this.removeHiddenElements(o),this.removeClutter(o),this.cleanContent(n,t),Object.assign({content:n?n.outerHTML:this.doc.body.innerHTML},t)):Object.assign({content:this.doc.body.innerHTML},t)}catch(e){return console.error("Defuddle","Error processing document:",e),Object.assign({content:this.doc.body.innerHTML},t)}}_log(...e){this.debug&&console.log("Defuddle:",...e)}_evaluateMediaQueries(e){const t=[],r=/max-width[^:]*:\s*(\d+)/;try{Array.from(e.styleSheets).filter((e=>{try{return e.cssRules,!0}catch(e){if(e instanceof DOMException&&"SecurityError"===e.name)return!1;throw e}})).flatMap((e=>{try{return Array.from(e.cssRules).filter((e=>e instanceof CSSMediaRule&&e.conditionText.includes("max-width")))}catch(e){return this.debug&&console.warn("Defuddle: Failed to process stylesheet:",e),[]}})).forEach((e=>{const o=e.conditionText.match(r);o&&600<=parseInt(o[1])&&Array.from(e.cssRules).filter((e=>e instanceof CSSStyleRule)).forEach((e=>{try{t.push({selector:e.selectorText,styles:e.style.cssText})}catch(e){this.debug&&console.warn("Defuddle: Failed to process CSS rule:",e)}}))}))}catch(e){console.error("Defuddle: Error evaluating media queries:",e)}return t}applyMobileStyles(e,t){t.forEach((({selector:t,styles:r})=>{try{e.querySelectorAll(t).forEach((e=>{e.setAttribute("style",(e.getAttribute("style")||"")+r)}))}catch(e){console.error("Defuddle","Error applying styles for selector:",t,e)}}))}removeHiddenElements(e){let t=0;const r=new Set,o=e.querySelectorAll(i);o.forEach((e=>r.add(e))),t+=o.length;const n=document.createTreeWalker(e.body,NodeFilter.SHOW_ELEMENT,{acceptNode:e=>r.has(e)?NodeFilter.FILTER_REJECT:NodeFilter.FILTER_ACCEPT}),a=[];let s;for(;s=n.nextNode();)a.push(s);for(let e=0;e<a.length;e+=100){const o=a.slice(e,e+100),n=o.map((e=>window.getComputedStyle(e)));o.forEach(((e,o)=>{const a=n[o];"none"!==a.display&&"hidden"!==a.visibility&&"0"!==a.opacity||(r.add(e),t++)}))}r.forEach((e=>e.remove())),this._log("Removed hidden elements:",t)}removeClutter(e){const t=performance.now();let r=0,o=0;const n=new Set;e.querySelectorAll(s.join(",")).forEach((e=>{(null==e?void 0:e.parentNode)&&(n.add(e),r++)}));const a=l.join("|"),i=new RegExp(a,"i");e.querySelectorAll("[class],[id],[data-testid],[data-qa],[data-cy]").forEach((e=>{if(n.has(e))return;const t=[e.className&&"string"==typeof e.className?e.className:"",e.id||"",e.getAttribute("data-testid")||"",e.getAttribute("data-qa")||"",e.getAttribute("data-cy")||""].join(" ").toLowerCase();t.trim()&&i.test(t)&&(n.add(e),o++)})),n.forEach((e=>e.remove()));const c=performance.now();this._log("Removed clutter elements:",{exactSelectors:r,partialSelectors:o,total:n.size,processingTime:`${(c-t).toFixed(2)}ms`})}cleanContent(e,t){this.removeHtmlComments(e),this.handleHeadings(e,t.title),this.standardizeFootnotes(e),this.handleLazyImages(e),this.standardizeElements(e),this.stripUnwantedAttributes(e),this.removeEmptyElements(e),this.removeTrailingHeadings(e)}removeTrailingHeadings(e){let t=0;const r=t=>{let o="",n=t.nextSibling;for(;n;)(n.nodeType===Node.TEXT_NODE||n.nodeType===Node.ELEMENT_NODE)&&(o+=n.textContent||""),n=n.nextSibling;if(o.trim())return!0;const a=t.parentElement;return!(!a||a===e)&&r(a)};Array.from(e.querySelectorAll("h1, h2, h3, h4, h5, h6")).reverse().forEach((e=>{r(e)||(e.remove(),t++)})),t>0&&this._log("Removed trailing headings:",t)}handleHeadings(e,t){var r;const o=e.getElementsByTagName("h1");Array.from(o).forEach((e=>{var t;const r=document.createElement("h2");r.innerHTML=e.innerHTML,Array.from(e.attributes).forEach((e=>{h.has(e.name)&&r.setAttribute(e.name,e.value)})),null===(t=e.parentNode)||void 0===t||t.replaceChild(r,e)}));const n=e.getElementsByTagName("h2");if(n.length>0){const e=n[0],o=(null===(r=e.textContent)||void 0===r?void 0:r.trim().toLowerCase())||"",a=t.toLowerCase().trim();a&&a===o&&e.remove()}}removeHtmlComments(e){const t=[],r=document.createTreeWalker(e,NodeFilter.SHOW_COMMENT,null);let o;for(;o=r.nextNode();)t.push(o);t.forEach((e=>{e.remove()})),this._log("Removed HTML comments:",t.length)}stripUnwantedAttributes(e){let t=0;const r=e=>{e instanceof SVGElement||Array.from(e.attributes).forEach((r=>{const o=r.name.toLowerCase();h.has(o)||o.startsWith("data-")||(e.removeAttribute(r.name),t++)}))};r(e),e.querySelectorAll("*").forEach(r),this._log("Stripped attributes:",t)}removeEmptyElements(e){let t=0,r=0,o=!0;for(;o;){r++,o=!1;const n=Array.from(e.getElementsByTagName("*")).filter((e=>{if(m.has(e.tagName.toLowerCase()))return!1;const t=e.textContent||"",r=0===t.trim().length,o=t.includes(" "),n=!e.hasChildNodes()||Array.from(e.childNodes).every((e=>{if(e.nodeType===Node.TEXT_NODE){const t=e.textContent||"";return 0===t.trim().length&&!t.includes(" ")}return!1}));return r&&!o&&n}));n.length>0&&(n.forEach((e=>{e.remove(),t++})),o=!0)}this._log("Removed empty elements:",{count:t,iterations:r})}createFootnoteItem(e,t,r){const o=document.createElement("li");if(o.className="footnote",o.id=`fn:${e}`,"string"==typeof t){const e=document.createElement("p");e.innerHTML=t,o.appendChild(e)}else{const e=Array.from(t.querySelectorAll("p"));if(0===e.length){const e=document.createElement("p");e.innerHTML=t.innerHTML,o.appendChild(e)}else e.forEach((e=>{const t=document.createElement("p");t.innerHTML=e.innerHTML,o.appendChild(t)}))}const n=o.querySelector("p:last-of-type")||o;return r.forEach(((e,t)=>{const o=document.createElement("a");o.href=`#${e}`,o.title="return to article",o.className="footnote-backref",o.innerHTML="↩",t<r.length-1&&(o.innerHTML+=" "),n.appendChild(o)})),o}collectFootnotes(e){const t={};let r=1;const o=new Set;return e.querySelectorAll(d).forEach((e=>{if(e.matches('div.footnote[data-component-name="FootnoteToDOM"]')){const n=e.querySelector("a.footnote-number"),a=e.querySelector(".footnote-content");if(n&&a){const e=n.id.replace("footnote-","").toLowerCase();e&&!o.has(e)&&(t[r]={content:a,originalId:e,refs:[]},o.add(e),r++)}}else e.querySelectorAll('li, div[role="listitem"]').forEach((e=>{var n,a,i,s;let l="",c=null;const d=e.querySelector(".citations");if(null===(n=null==d?void 0:d.id)||void 0===n?void 0:n.toLowerCase().startsWith("r")){l=d.id.toLowerCase();const e=d.querySelector(".citation-content");e&&(c=e)}else{if(e.id.toLowerCase().startsWith("bib.bib"))l=e.id.replace("bib.bib","").toLowerCase();else if(e.id.toLowerCase().startsWith("fn:"))l=e.id.replace("fn:","").toLowerCase();else if(e.id.toLowerCase().startsWith("fn"))l=e.id.replace("fn","").toLowerCase();else if(e.hasAttribute("data-counter"))l=(null===(i=null===(a=e.getAttribute("data-counter"))||void 0===a?void 0:a.replace(/\.$/,""))||void 0===i?void 0:i.toLowerCase())||"";else{const t=null===(s=e.id.split("/").pop())||void 0===s?void 0:s.match(/cite_note-(.+)/);l=t?t[1].toLowerCase():e.id.toLowerCase()}c=e}l&&!o.has(l)&&(t[r]={content:c||e,originalId:l,refs:[]},o.add(l),r++)}))})),t}findOuterFootnoteContainer(e){let t=e,r=e.parentElement;for(;r&&("span"===r.tagName.toLowerCase()||"sup"===r.tagName.toLowerCase());)t=r,r=r.parentElement;return t}createFootnoteReference(e,t){const r=document.createElement("sup");r.id=t;const o=document.createElement("a");return o.href=`#fn:${e}`,o.textContent=e,r.appendChild(o),r}standardizeFootnotes(e){const t=this.collectFootnotes(e),r=e.querySelectorAll(c),o=new Map;r.forEach((e=>{var r,n,a,i;if(!(e instanceof HTMLElement))return;let s="",l="";if(e.matches('a[id^="ref-link"]'))s=(null===(r=e.textContent)||void 0===r?void 0:r.trim())||"";else if(e.matches('a[role="doc-biblioref"]')){const t=e.getAttribute("data-xml-rid");if(t)s=t;else{const t=e.getAttribute("href");(null==t?void 0:t.startsWith("#core-R"))&&(s=t.replace("#core-",""))}}else if(e.matches("a.footnote-anchor, span.footnote-hovercard-target a")){const t=(null===(n=e.id)||void 0===n?void 0:n.replace("footnote-anchor-",""))||"";t&&(s=t.toLowerCase())}else if(e.matches("cite.ltx_cite")){const t=e.querySelector("a");if(t){const e=t.getAttribute("href");if(e){const t=null===(a=e.split("/").pop())||void 0===a?void 0:a.match(/bib\.bib(\d+)/);t&&(s=t[1].toLowerCase())}}}else if(e.matches("sup.reference")){const t=e.querySelectorAll("a");Array.from(t).forEach((e=>{var t;const r=e.getAttribute("href");if(r){const e=null===(t=r.split("/").pop())||void 0===t?void 0:t.match(/(?:cite_note|cite_ref)-(.+)/);e&&(s=e[1].toLowerCase())}}))}else if(e.matches('sup[id^="fnref:"]'))s=e.id.replace("fnref:","").toLowerCase();else if(e.matches('sup[id^="fnr"]'))s=e.id.replace("fnr","").toLowerCase();else if(e.matches("span.footnote-reference"))s=e.getAttribute("data-footnote-id")||"";else if(e.matches("span.footnote-link"))s=e.getAttribute("data-footnote-id")||"",l=e.getAttribute("data-footnote-content")||"";else if(e.matches("a.citation"))s=(null===(i=e.textContent)||void 0===i?void 0:i.trim())||"",l=e.getAttribute("href")||"";else if(e.matches('a[id^="fnref"]'))s=e.id.replace("fnref","").toLowerCase();else{const t=e.getAttribute("href");if(t){const e=t.replace(/^[#]/,"");s=e.toLowerCase()}}if(s){const r=Object.entries(t).find((([e,t])=>t.originalId===s.toLowerCase()));if(r){const[t,n]=r,a=n.refs.length>0?`fnref:${t}-${n.refs.length+1}`:`fnref:${t}`;n.refs.push(a);const i=this.findOuterFootnoteContainer(e);"sup"===i.tagName.toLowerCase()?(o.has(i)||o.set(i,[]),o.get(i).push(this.createFootnoteReference(t,a))):i.replaceWith(this.createFootnoteReference(t,a))}}})),o.forEach(((e,t)=>{if(e.length>0){const r=document.createDocumentFragment();e.forEach(((e,t)=>{const o=e.querySelector("a");if(o){const t=document.createElement("sup");t.id=e.id,t.appendChild(o.cloneNode(!0)),r.appendChild(t)}})),t.replaceWith(r)}}));const n=document.createElement("div");n.className="footnotes";const a=document.createElement("ol");Object.entries(t).forEach((([e,t])=>{const r=this.createFootnoteItem(parseInt(e),t.content,t.refs);a.appendChild(r)})),e.querySelectorAll(d).forEach((e=>e.remove())),a.children.length>0&&(n.appendChild(a),e.appendChild(n))}handleLazyImages(e){let t=0;e.querySelectorAll("img[data-src], img[data-srcset]").forEach((e=>{if(!(e instanceof HTMLImageElement))return;const r=e.getAttribute("data-src");r&&!e.src&&(e.src=r,t++);const o=e.getAttribute("data-srcset");o&&!e.srcset&&(e.srcset=o,t++),e.classList.remove("lazy","lazyload"),e.removeAttribute("data-ll-status"),e.removeAttribute("data-src"),e.removeAttribute("data-srcset")})),this._log("Processed lazy images:",t)}standardizeElements(e){let t=0;p.forEach((r=>{e.querySelectorAll(r.selector).forEach((e=>{if(r.transform){const o=r.transform(e);e.replaceWith(o),t++}}))})),e.querySelectorAll("lite-youtube").forEach((e=>{const r=e.getAttribute("videoid");if(!r)return;const o=document.createElement("iframe");o.width="560",o.height="315",o.src=`https://www.youtube.com/embed/${r}`,o.title=e.getAttribute("videotitle")||"YouTube video player",o.frameBorder="0",o.allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share",o.setAttribute("allowfullscreen",""),e.replaceWith(o),t++})),this._log("Converted embedded elements:",t)}findSmallImages(e){const t=new Set,r=/scale\(([\d.]+)\)/,o=performance.now();let n=0;const a=[...Array.from(e.getElementsByTagName("img")),...Array.from(e.getElementsByTagName("svg"))].filter((e=>!(e instanceof HTMLImageElement)||!(e.classList.contains("lazy")||e.classList.contains("lazyload")||e.hasAttribute("data-src")||e.hasAttribute("data-srcset"))));if(0===a.length)return t;const i=a.map((e=>({element:e,naturalWidth:e instanceof HTMLImageElement?e.naturalWidth:0,naturalHeight:e instanceof HTMLImageElement?e.naturalHeight:0,attrWidth:parseInt(e.getAttribute("width")||"0"),attrHeight:parseInt(e.getAttribute("height")||"0")})));for(let e=0;e<i.length;e+=50){const o=i.slice(e,e+50);try{const e=o.map((({element:e})=>window.getComputedStyle(e))),a=o.map((({element:e})=>e.getBoundingClientRect()));o.forEach(((o,i)=>{var s;try{const l=e[i],c=a[i],d=l.transform,m=d?parseFloat((null===(s=d.match(r))||void 0===s?void 0:s[1])||"1"):1,h=[o.naturalWidth,o.attrWidth,parseInt(l.width)||0,c.width*m].filter((e=>"number"==typeof e&&e>0)),u=[o.naturalHeight,o.attrHeight,parseInt(l.height)||0,c.height*m].filter((e=>"number"==typeof e&&e>0));if(h.length>0&&u.length>0){const e=Math.min(...h),r=Math.min(...u);if(e<33||r<33){const e=this.getElementIdentifier(o.element);e&&(t.add(e),n++)}}}catch(e){this.debug&&console.warn("Defuddle: Failed to process element dimensions:",e)}}))}catch(e){this.debug&&console.warn("Defuddle: Failed to process batch:",e)}}const s=performance.now();return this._log("Found small elements:",{count:n,totalElements:a.length,processingTime:`${(s-o).toFixed(2)}ms`}),t}removeSmallImages(e,t){let r=0;["img","svg"].forEach((o=>{const n=e.getElementsByTagName(o);Array.from(n).forEach((e=>{const o=this.getElementIdentifier(e);o&&t.has(o)&&(e.remove(),r++)}))})),this._log("Removed small elements:",r)}getElementIdentifier(e){if(e instanceof HTMLImageElement){const t=e.getAttribute("data-src");if(t)return`src:${t}`;const r=e.src||"",o=e.srcset||"",n=e.getAttribute("data-srcset");if(r)return`src:${r}`;if(o)return`srcset:${o}`;if(n)return`srcset:${n}`}const t=e.id||"",r=e.className||"",o=e instanceof SVGElement&&e.getAttribute("viewBox")||"";return t?`id:${t}`:o?`viewBox:${o}`:r?`class:${r}`:null}findMainContent(e){const t=[];return n.forEach(((r,o)=>{e.querySelectorAll(r).forEach((e=>{let r=10*(n.length-o);r+=this.scoreElement(e),t.push({element:e,score:r})}))})),0===t.length?this.findContentByScoring(e):(t.sort(((e,t)=>t.score-e.score)),this.debug&&this._log("Content candidates:",t.map((e=>({element:e.element.tagName,selector:this.getElementSelector(e.element),score:e.score})))),t[0].element)}findContentByScoring(e){const t=this.scoreElements(e);return t.length>0?t[0].element:null}getElementSelector(e){const t=[];let r=e;for(;r&&r!==document.documentElement;){let e=r.tagName.toLowerCase();r.id?e+="#"+r.id:r.className&&"string"==typeof r.className&&(e+="."+r.className.trim().split(/\s+/).join(".")),t.unshift(e),r=r.parentElement}return t.join(" > ")}scoreElements(e){const t=[];return a.forEach((r=>{Array.from(e.getElementsByTagName(r)).forEach((e=>{const r=this.scoreElement(e);r>0&&t.push({score:r,element:e})}))})),t.sort(((e,t)=>t.score-e.score))}scoreElement(e){let t=0;e.className&&"string"==typeof e.className&&e.className.toLowerCase(),e.id&&e.id.toLowerCase();const r=e.textContent||"",o=r.split(/\s+/).length;t+=Math.min(Math.floor(o/100),3);const n=e.getElementsByTagName("a"),a=Array.from(n).reduce(((e,t)=>{var r;return e+((null===(r=t.textContent)||void 0===r?void 0:r.length)||0)}),0);(r.length?a/r.length:0)>.5&&(t-=10),t+=e.getElementsByTagName("p").length;const i=e.getElementsByTagName("img").length;return t+=Math.min(3*i,9),t}}}},t={};function r(o){var n=t[o];if(void 0!==n)return n.exports;var a=t[o]={exports:{}};return e[o](a,a.exports,r),a.exports}var o={};return(()=>{var e=o;Object.defineProperty(e,"__esModule",{value:!0}),e.Defuddle=void 0;var t=r(628);Object.defineProperty(e,"Defuddle",{enumerable:!0,get:function(){return t.Defuddle}})})(),o})()));
|