commit 750f1a766d6d088f7c5aef5f4f0fa05170943d1d Author: √(noham)² <100566912+NohamR@users.noreply.github.com> Date: Sat Jan 17 13:12:26 2026 +0100 Add Safari internal JS services and documentation diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..8db0128 --- /dev/null +++ b/.gitignore @@ -0,0 +1,216 @@ +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[codz] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +share/python-wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.nox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +*.py.cover +.hypothesis/ +.pytest_cache/ +cover/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py +db.sqlite3 +db.sqlite3-journal + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +.pybuilder/ +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# IPython +profile_default/ +ipython_config.py + +# pyenv +# For a library or package, you might want to ignore these files since the code is +# intended to run in multiple environments; otherwise, check them in: +# .python-version + +# pipenv +# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. +# However, in case of collaboration, if having platform-specific dependencies or dependencies +# having no cross-platform support, pipenv may install dependencies that don't work, or not +# install all needed dependencies. +# Pipfile.lock + +# UV +# Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control. +# This is especially recommended for binary packages to ensure reproducibility, and is more +# commonly ignored for libraries. +# uv.lock + +# poetry +# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control. +# This is especially recommended for binary packages to ensure reproducibility, and is more +# commonly ignored for libraries. +# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control +# poetry.lock +# poetry.toml + +# pdm +# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control. +# pdm recommends including project-wide configuration in pdm.toml, but excluding .pdm-python. +# https://pdm-project.org/en/latest/usage/project/#working-with-version-control +# pdm.lock +# pdm.toml +.pdm-python +.pdm-build/ + +# pixi +# Similar to Pipfile.lock, it is generally recommended to include pixi.lock in version control. +# pixi.lock +# Pixi creates a virtual environment in the .pixi directory, just like venv module creates one +# in the .venv directory. It is recommended not to include this directory in version control. +.pixi + +# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm +__pypackages__/ + +# Celery stuff +celerybeat-schedule +celerybeat.pid + +# Redis +*.rdb +*.aof +*.pid + +# RabbitMQ +mnesia/ +rabbitmq/ +rabbitmq-data/ + +# ActiveMQ +activemq-data/ + +# SageMath parsed files +*.sage.py + +# Environments +.env +.envrc +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ +.dmypy.json +dmypy.json + +# Pyre type checker +.pyre/ + +# pytype static type analyzer +.pytype/ + +# Cython debug symbols +cython_debug/ + +# PyCharm +# JetBrains specific template is maintained in a separate JetBrains.gitignore that can +# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore +# and can be added to the global gitignore or merged into this file. For a more nuclear +# option (not recommended) you can uncomment the following to ignore the entire idea folder. +# .idea/ + +# Abstra +# Abstra is an AI-powered process automation framework. +# Ignore directories containing user credentials, local state, and settings. +# Learn more at https://abstra.io/docs +.abstra/ + +# Visual Studio Code +# Visual Studio Code specific template is maintained in a separate VisualStudioCode.gitignore +# that can be found at https://github.com/github/gitignore/blob/main/Global/VisualStudioCode.gitignore +# and can be added to the global gitignore or merged into this file. However, if you prefer, +# you could uncomment the following to ignore the entire vscode folder +# .vscode/ + +# Ruff stuff: +.ruff_cache/ + +# PyPI configuration file +.pypirc + +# Marimo +marimo/_static/ +marimo/_lsp/ +__marimo__/ + +# Streamlit +.streamlit/secrets.toml +.DS_Store \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..7f4bc95 --- /dev/null +++ b/README.md @@ -0,0 +1,175 @@ +# Safari Internal JavaScript Services + +- Safari Version:** 15.7 +- Extraction Method:** dyld_shared_cache +- Extraction Date:** 16/01/2026 + +## Disclaimer: +These files are provided for educational and research purposes only. They are extracted from Safari's internal implementation to help developers and researchers understand browser functionality. These files are property of Apple Inc. and should not be used in production environments or for any commercial purposes. + +**Note:** The summaries and descriptions of each file below were AI-generated and may contain inaccuracies or inconsistencies. + +--- + +## Password & Form Autofill System + +### **[AutomaticPasswords.js](js/forms/AutomaticPasswords.js)** +Manages Safari's automatic strong password generation: +- Removes auto-generated passwords from password fields +- Controls visibility of suggested strong passwords +- Handles focus/blur events when users interact with password fields +- Manages the "autofilled" state of password inputs + +### **[FormMetadata.js](js/forms/FormMetadata.js)** +The brain of Safari's form autofill system: +- **Form Detection & Classification**: Identifies login forms, signup forms, password change forms, and standard forms +- **Smart Field Recognition**: Uses pattern matching, element positioning, visual analysis, and machine learning-like scoring to identify: + - Username fields + - Password fields (current, new, confirm) + - Credit card fields (number, CVV, expiration, cardholder) + - Address fields (street, city, postal code) + - Phone numbers (split across multiple fields) + - Email addresses + - One-time codes (2FA) + +### **[FormMetadataClassification.js](js/forms/FormMetadataClassification.js)** +Intelligently classifies form fields to enable autofill: +- **Identifies field types**: credit cards, names, addresses, phone numbers, emails, birthdays, passwords, etc. +- **Handles multi-part fields**: splits fields like "First Name | Last Name" or phone numbers across multiple inputs +- **Continuation detection**: recognizes when a single piece of data (like credit card number) is split across multiple fields +- **Uses multiple signals**: autocomplete attributes, field names, placeholders, sizes, and positioning +- **Date field parsing**: understands various date formats and splits (day/month/year) +- **Smart matching**: uses pattern recognition to classify fields even without explicit HTML hints + +### **[NodePath.js](js/utilities/NodePath.js)** +Creates stable references to DOM elements: +- **Path-based element identification**: creates a "fingerprint" for DOM nodes that works even when the DOM changes +- **Fuzzy matching**: uses similarity scoring (Levenshtein distance) to relocate elements after page updates +- **Handles shadow DOM and iframes**: traverses across shadow boundaries and iframe documents +- **Range support**: can reference text selections, not just elements +- **Resilient resolution**: uses multiple strategies (CSS selectors, position, attributes) to find elements + +--- + +## Reader Mode System + +### **[Reader.js](js/reader/Reader.js)** +Powers Safari's Reader Mode core functionality: +- Manages visibility transitions for Reader view +- Handles iframe URL caching/restoration when entering/exiting Reader +- Checks JavaScript enablement settings +- Mac-specific UI adjustments + +### **[ReaderArticleFinder.js](js/reader/ReaderArticleFinder.js)** (~3500 lines) +Safari's article detection and cleaning algorithm (similar to Mozilla's Readability): + +**Article Detection Strategies:** +1. Schema.org metadata (`
`) +2. OpenGraph tags (``) +3. Visual examination (hit-testing specific screen coordinates) +4. Quirks list for known sites (NYTimes, Medium, etc.) + +**Scoring System:** +- Text density analysis +- Link density (fewer links = more likely article) +- Tag names (article, main, section boost score) +- Class names ("article", "content" boost; "comment", "sidebar" reduce) +- Position on page +- Font consistency + +**Smart Cleaning:** +- Removes ads, comments, navigation +- Keeps images, videos, tweets +- Converts lazy-loaded images +- Preserves tables and code blocks +- Handles multi-column layouts +- Detects CJK (Chinese, Japanese, Korean) text using Unicode ranges + +### **[ReaderSharedUI.js](js/reader/ReaderSharedUI.js)** +Powers the actual Reader Mode interface: + +**Layout Management:** +- Multi-column pagination for long articles +- Responsive design adapting to window size +- 12+ font families (System, Charter, Georgia, Iowan, Palatino, etc.) +- 4 themes: White, Sepia, Gray, Night +- 12 text size levels with custom line heights per font + +**Interactive Features:** +- Smooth scrolling with animations +- Content-aware navigation (stops at natural break points) +- Next page auto-loading for paginated articles +- Print/email formatting +- Reading position memory +- Table of Contents generation from headings +- AI-generated summary display with collapsible UI +- Sidebar for TOC/summary on wide screens + +### **[ReaderSharedUINormalWorld.js](js/reader/ReaderSharedUINormalWorld.js)** +Enhances Reader Mode with rich content: +- **Twitter/X integration**: replaces simple tweet embeds with rich Twitter widgets +- Loads Twitter's widget JavaScript on demand +- Handles transition from placeholder tweets to interactive embeds + +--- + +## Web Page Analysis & Data Extraction + +### **[SchemaDataExtractor.js](js/schema/SchemaDataExtractor.js)** +Extracts contact information from web pages: +- Parses **Microdata** markup (HTML attributes like `itemscope`, `itemprop`) +- Parses **JSON-LD** structured data (schema.org formatted JSON) +- Extracts addresses, phone numbers, business names +- Enables Safari's "Add to Contacts" feature + +### **[SchemaOrgMarkupChecker.js](js/schema/SchemaOrgMarkupChecker.js)** +Simple detection utility: +- Returns `true` if page contains schema.org structured data +- Checks both JSON-LD scripts and microdata attributes +- Used to determine if page has extractable structured information + +### **[MetadataExtractor.js](js/metadata/MetadataExtractor.js)** +Extracts website icons and branding: +- Favicon URLs +- Apple Touch icons (for iOS home screen) +- Template icons with colors +- Sorts icons by size/quality + +### **[WebContentLayoutAnalyzer.js](js/layout/WebContentLayoutAnalyzer.js)** +Analyzes page responsive design: +- Detects centered container elements +- Determines if containers have fixed width (non-responsive) +- Measures container movement during window resize +- Helps Safari optimize reader mode and display adjustments + +--- + +## Search & Discovery + +### **[OpenSearchURLFinder.js](js/search/OpenSearchURLFinder.js)** +Enables custom search engine discovery: +- Finds `` tags in page header +- Powers Safari's search engine discovery feature +- Allows users to add custom search engines from websites + +--- + +## Localization & Translation + +### **[Translation.js](js/translation/Translation.js)** +Manages language attributes during translation: +- Updates page's `lang` attribute when Safari translates content +- Ensures accessibility tools and screen readers recognize current language + +--- + +## Save & Archive + +### **[SavePageInliningOrDiscardingExternalResources.js](js/utilities/SavePageInliningOrDiscardingExternalResources.js)** +Creates self-contained web archives: +- Copies all HTML elements and their styles +- Inlines CSS from stylesheets into the document +- Converts external resource URLs to local filenames +- Removes scripts, objects, and dynamic content +- Recursively captures iframe content +- Powers Safari's "Save As Web Archive" feature \ No newline at end of file diff --git a/js/forms/AutomaticPasswords.js b/js/forms/AutomaticPasswords.js new file mode 100644 index 0000000..648760f --- /dev/null +++ b/js/forms/AutomaticPasswords.js @@ -0,0 +1,43 @@ +//# sourceURL=__InjectedScript_AutomaticPasswords.js +/* Copyright (c) 2025 Apple Inc. All rights reserved. */ +((FormMetadata.prototype._collectExtraControlMetadata = function (t, o) { + let e = t.getAttribute("passwordrules"); + o.ControlPasswordRules = e || void 0; +}), + (FormMetadata.prototype.removeAutomaticStrongPasswordFromPasswordElement = + function (t) { + let o = this.formControlWithUniqueID(t); + o && + this._isTextField(o) && + (this.clearField(t), + this._updateAnnotationsForField(o), + FormMetadataJSController.setInputElementAutofilled(o, !1)); + })); +let AutomaticPasswords = function () {}; +AutomaticPasswords.prototype = { + removeAutomaticPasswordElements: function (t, o, e) { + for (let o of t) + FormMetadataJS.removeAutomaticStrongPasswordFromPasswordElement(o); + if (!e) return; + let r = document.activeElement, + a = o ? FormMetadataJS.formControlWithUniqueID(o) : null; + (a && a.blur(), a && a === r && a.focus()); + }, + blurControlWithID: function (t) { + let o = t ? FormMetadataJS.formControlWithUniqueID(t) : null; + o && o.blur(); + }, + setStrongPasswordElementViewableIfAppropriate: function (t, o) { + for (let e of t) { + let t = FormMetadataJS.formControlWithUniqueID(e); + if (!t) return; + if ("text" === t.type) + return ( + FormMetadataJSController.setInputElementAutoFilledAndViewable(t, !1), + void FormMetadataJSController.setInputElementAutofilled(t, !1) + ); + FormMetadataJSController.setInputElementAutoFilledAndViewable(t, o); + } + }, +}; +var AutomaticPasswordsJS = new AutomaticPasswords(); diff --git a/js/forms/FormMetadata.js b/js/forms/FormMetadata.js new file mode 100644 index 0000000..9d0d1b9 --- /dev/null +++ b/js/forms/FormMetadata.js @@ -0,0 +1,4395 @@ +//# sourceURL=__InjectedScript_FormMetadata.js +/* Copyright (c) 2025 Apple Inc. All rights reserved. */ +function regularExpressionForDomainMatching(e) { + let t = cachedRegularExpressionsForDomainMatching[e]; + return ( + t || + ((t = new RegExp("(^|.)" + e.replaceAll(".", "\\.") + "$")), + (cachedRegularExpressionsForDomainMatching[e] = t), + t) + ); +} +function userIsOnDomain(e) { + return regularExpressionForDomainMatching(e).test(document.location.hostname); +} +function legacyPlaceholderInfoForInputElement(e) { + if ("text" !== e.type) return null; + if (doctypeLooksLikeHTML5) return null; + var t = e.value.trim(); + if (!t) return null; + for (var o = !1, r = !0, n = e.attributes, i = n.length, l = 0; l < i; ++l) { + var a = n[l]; + if (t === a.value.trim() && ((o = !0), "value" !== a.name.toLowerCase())) { + r = !1; + break; + } + } + return o ? { Text: t, AttributeMatchedWasValue: r } : null; +} +function placeholderInfoForElement(e) { + var t = e.getAttribute("placeholder"); + if (t) return { Text: t, AttributeMatchedWasValue: !1 }; + var o = e.getAttribute("data-placeholder"); + return o && o.length + ? { Text: o, AttributeMatchedWasValue: !1 } + : isInputElement(e) + ? legacyPlaceholderInfoForInputElement(e) + : null; +} +function sharedPrefixLength(e, t) { + for (var o = 0, r = 0, n = e.length; r < n && e[r] === t[r]; ++r) o++; + return o; +} +function rowContainingLabelAboveRow(e) { + for ( + var t = e.getBoundingClientRect(), o = e.previousElementSibling; + o instanceof HTMLTableRowElement; + o = o.previousElementSibling + ) { + if (o.querySelector("input, select, textarea")) return null; + var r = o.getBoundingClientRect(); + if (t.top - r.bottom > t.height / 2) return null; + if (o.innerText.match(/\S/)) return o; + } + return null; +} +function cellVisuallyAbove(e) { + let t = e.parentElementIncludingShadowDOMHost(); + if (!(t && t instanceof HTMLTableRowElement)) return null; + var o = rowContainingLabelAboveRow(t); + if (!o) return null; + for ( + var r = e.getBoundingClientRect(), + n = o.children, + i = n.length, + l = null, + a = 0, + s = 0; + s < i; + ++s + ) { + var u = n[s], + c = u.getBoundingClientRect(), + d = Math.min(c.right, r.right) - Math.max(c.left, r.left); + (!l || d > a) && ((a = d), (l = u)); + } + return l; +} +function couldBeFormSubmissionControl(e) { + if (e instanceof HTMLButtonElement) return !0; + if (e instanceof HTMLInputElement) { + var t = e.type; + return "submit" === t || "image" === t; + } + return !1; +} +function isInputElement(e) { + return e instanceof HTMLInputElement; +} +function isDateTimeInputElement(e) { + return !!isInputElement(e) && DateTimeInputTypes.includes(e.type); +} +function isRadioButtonElement(e) { + return !!isInputElement(e) && "radio" === e.type; +} +function anchorWithURLString(e) { + var t = document.createElement("a"); + return ((t.href = e), t); +} +function pathComponentsForLocation(e) { + var t = e.pathname.substring(1).split("/"); + return (t[t.length - 1] || t.pop(), t); +} +function lastPathComponentFromAnchor(e) { + var t = pathComponentsForLocation(e); + return t.length ? t[t.length - 1] : null; +} +function lastPathComponentForURLString(e) { + return lastPathComponentFromAnchor(anchorWithURLString(e)); +} +function urlEncode(e) { + return encodeURIComponent(e).replace(/%20/g, "+"); +} +function isCheckboxOrRadioButtonInDefaultState(e) { + return e.checked === e.defaultChecked; +} +function isSelectInDefaultState(e) { + for (var t = e.options, o = t.length, r = 0; r < o; ++r) { + var n = t[r]; + if (n.selected !== n.defaultSelected) { + if (n.defaultSelected) return !1; + if (e.multiple || r) return !1; + } + } + return !0; +} +function formActionAsAnchorElement(e, t) { + if (!(e instanceof HTMLFormElement)) return null; + let o = e.getAttribute("action"); + if (!o && t) return null; + var r = document.createElement("a"); + return ((r.href = o || ""), r); +} +function eventThatBubbles(e) { + return new CustomEvent(e, { bubbles: !0 }); +} +function formControlHasBeenClassifiedInAnInterestingWay(e) { + return ( + e.ControlIsActiveElement || + e.ControlIsSecureTextField || + e.ControlLooksLikePasswordCredentialField || + e.ControlLooksLikeCreditCardNumberField || + e.ControlLooksLikeCreditCardSecurityCodeField || + e.ControlLooksLikeCreditCardCardholderField || + e.ControlLooksLikeCreditCardTypeField || + e.AddressBookLabel || + e.ControlLooksLikeDayField || + e.ControlLooksLikeMonthField || + e.ControlLooksLikeYearField || + e.ControlLooksLikeOneTimeCodeField || + e.ControlLooksLikeCreditCardCompositeExpirationDateField || + e.ControlLooksLikeEIDField || + e.ControlLooksLikeIMEIField + ); +} +function isValidUsernameOrEmail(e) { + const t = /^[a-z_][a-z0-9_.]{2,30}$/i, + o = /^[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,4}$/i; + return ( + !(!e || e.length < 3 || "true" === e || "false" === e) && + (t.test(e) || o.test(e)) + ); +} +function selectorForElement(e) { + let t = e.localName, + o = e.getAttribute("id"); + o && (t += `#${o}`); + let r = e.classList, + n = r.length; + for (let e = 0; e < n; e++) t += "." + r[e]; + return t; +} +function hasOwnProperties(e) { + return Object.getOwnPropertyNames(e).length > 0; +} +function defaultOptionForSelectElement(e) { + for (var t = e.options, o = t.length, r = 0; r < o; ++r) { + var n = t[r]; + if (n.defaultSelected) return n; + } + return t[0]; +} +function selectElementOptionsSequenceAnalysis(e, t) { + for ( + var o = e.options, r = o.length, n = 0, i = -1, l = -1, a = 0, s = 0; + s < r; + ++s + ) { + var u = o[s], + c = parseInt(u[t]); + isFiniteNumber(c) + ? -1 === l + ? ((l = c), (a = 1)) + : c === l + 1 && ((l = c), a++) + : (a >= n && ((n = a), (i = l)), (l = -1), (a = 0)); + } + return ( + a >= n && ((n = a), (i = l)), + { lengthOfLongestSequence: n, lastNumberInSequence: i } + ); +} +function isElementPositionedToBeEffectivelyInvisible(e) { + var t = !1; + for (let o = e; o; o = o.parentElementIncludingShadowDOMHost()) + if ("fixed" === getComputedStyle(o).position) { + t = !0; + break; + } + var o, + r, + n, + i = e.getBoundingClientRect(); + if (t) ((o = i), (r = window.innerWidth), (n = window.innerHeight)); + else { + var l = window.scrollY, + a = window.scrollX; + ((o = { + top: i.top + l, + right: i.right + a, + bottom: i.bottom + l, + left: i.left + a, + width: i.width, + height: i.height, + }), + (r = document.documentElement.scrollWidth), + (n = Math.max( + document.documentElement.scrollHeight, + window.innerHeight, + ))); + } + return o.top >= n || o.right <= 0 || o.bottom <= 0 || o.left >= r; +} +function rectIsWithinDocumentViewport(e) { + return ( + e.right >= 0 && + e.bottom >= 0 && + e.left <= window.innerWidth && + e.top <= window.innerHeight + ); +} +function isCredentialElementUniqueID(e, t) { + return ( + t === e.UsernameElementUniqueID || + t === e.PasswordElementUniqueID || + t === e.ConfirmPasswordElementUniqueID || + t === e.OldPasswordElementUniqueID + ); +} +function autocompleteTokens(e) { + const t = ["autocomplete", "autocompletetype", "x-autocompletetype"]; + let o = []; + for (const r of t) + e.hasAttribute(r) && o.push(e.getAttribute(r).trim().toLowerCase()); + if (!o.length) return null; + let r = o + .join(" ") + .split(/\s+/) + .filter(function (e) { + return e.length && "off" !== e && "on" !== e; + }); + return r.length ? r : null; +} +function elementIDOrAutocompleteTokensHasToken(e, t, o) { + return !!e.id?.includes(o) || !!t?.includes(o); +} +function controlAppearsToBePartOfPhotoTaggingInterface(e) { + const t = /photo.*tag/i; + for ( + let o = e.parentElementIncludingShadowDOMHost(); + o; + o = o.parentElementIncludingShadowDOMHost() + ) + if (t.test(o.className)) return !0; + return !1; +} +function levenshteinDistance(e, t) { + for ( + var o = e.length, r = t.length, n = new Array(o + 1), i = 0; + i < o + 1; + ++i + ) + ((n[i] = new Array(r + 1)), (n[i][0] = i)); + for (var l = 0; l < r + 1; ++l) n[0][l] = l; + for (l = 1; l < r + 1; ++l) + for (i = 1; i < o + 1; ++i) + if (e[i - 1] === t[l - 1]) n[i][l] = n[i - 1][l - 1]; + else { + var a = n[i - 1][l] + 1, + s = n[i][l - 1] + 1, + u = n[i - 1][l - 1] + 1; + n[i][l] = Math.min(a, s, u); + } + return n[o][r]; +} +function stringSimilarity(e, t) { + var o = Math.max(e.length, t.length); + return o ? (o - levenshteinDistance(e, t)) / o : 0; +} +function stripCommonPrefix(e, t) { + const o = e.length, + r = t.length, + n = o < r ? o : r; + let i = 0; + for (; i < n && e[i] === t[i]; ) i++; + return [e.slice(i), t.slice(i)]; +} +function articleTitleAndSiteNameFromTitleString(e, t) { + const o = [" - ", " \u2013 ", " \u2014 ", ": ", " | ", " \xbb "], + r = o.length, + n = 0.6; + for ( + var i, + l, + a = e.replace(/^(www|m|secure)\./, ""), + s = a.replace(/\.(com|info|net|org|edu|gov)$/, "").toLowerCase(), + u = 0; + u < r; + ++u + ) { + var c = t.split(o[u]); + if (2 === c.length) { + var d = c[0].trim(), + h = c[1].trim(), + m = d.toLowerCase(), + F = h.toLowerCase(), + f = Math.max(stringSimilarity(m, a), stringSimilarity(m, s)), + g = Math.max(stringSimilarity(F, a), stringSimilarity(F, s)), + p = Math.max(f, g); + (!l || p > l) && + ((l = p), + (i = + f > g + ? { siteName: d, articleTitle: h } + : { siteName: h, articleTitle: d })); + } + } + return i && l >= n ? i : null; +} +function documentTitleWithoutHostNamePrefix() { + const e = document.title, + t = articleTitleAndSiteNameFromTitleString(window.location.host, e); + return t ? t.articleTitle : e; +} +function querySelectorAllIncludingWithinShadowRoots(e, t) { + let o = []; + for (let r of e.querySelectorAll("*")) + if (r.shadowRoot) { + let e = querySelectorAllIncludingWithinShadowRoots(r.shadowRoot, t); + e.length && (o = o.concat(e)); + } else r.matches(t) && o.push(r); + return o; +} +function queryAllBySelector(e, t) { + try { + return window.collectMatchingElementsInFlatTree + ? window.collectMatchingElementsInFlatTree(e, t) + : querySelectorAllIncludingWithinShadowRoots(e, t); + } catch (e) { + return []; + } +} +function getElementByID(e) { + let t = queryAllBySelector(document, `[id='${e}']`); + return t.length ? t[0] : null; +} +function siblingsIncludingSelfForElement(e) { + let t = e.parentElement; + if (t) return t.children; + let o = e; + for (; o.previousElementSibling; ) o = o.previousElementSibling; + let r = [], + n = o; + for (; n; ) (r.push(n), (n = n.nextElementSibling)); + return r; +} +function regularExpressionFromUntrustedPatternAttributeString(e) { + if ((e.startsWith("/") && e.endsWith("/") && (e = e.slice(1, -1)), !e.length)) + return null; + try { + return (new RegExp(e, "v"), new RegExp("^(?:" + e + ")$", "v")); + } catch (e) { + return null; + } +} +function regularExpressionsFromStrings(e) { + return e.map((e) => new RegExp(e)); +} +function stringsMatchAnyRegularExpressions(e, t) { + for (let o of t) for (let t of e) if (o.test(t.toLowerCase())) return !0; + return !1; +} +function pathFromAnchorWithoutLeadingSlash(e) { + let t = /\/(.*)/.exec(e.pathname); + return t && 2 === t.length ? t[1] : null; +} +function innermostActiveElement() { + let e = document.activeElement, + t = e; + for (; t; ) ((t = t?.shadowRoot?.activeElement), t && (e = t)); + return e; +} +function elementAppearsToContinueCaptchaWidget(e) { + return !!e.querySelector( + "iframe[title*=captcha i], input[type=hidden][name*=recaptcha]", + ); +} +function isFiniteNumber(e) { + return "number" == typeof e && isFinite(e); +} +const WBSAutoFillFormTypeUndetermined = 0, + WBSAutoFillFormTypeAutoFillableStandard = 1, + WBSAutoFillFormTypeNonAutoFillable = 2, + WBSAutoFillFormTypeAutoFillableLogin = 3, + WBSAutoFillFormTypeNewAccount = 4, + WBSAutoFillFormTypeChangePassword = 5, + WBSFormMetadataRequestNormal = 0, + WBSFormMetadataRequestPreFill = 1, + WBSFormMetadataRequestTesting = 2, + WBSFormMetadataRequestTextChange = 3, + WBSFormMetadataRequestCollectMetadataFromDebugMenu = 4, + ShouldStopAfterFirstMatch = { CollectAllMatches: 0, StopAfterFirstMatch: 1 }, + ShouldFocus = { No: 0, Yes: 1 }, + ShouldBlur = { No: 0, Yes: 1 }, + ShouldAbandonCharacterByCharacterEntryIfTooSlow = { No: 0, Yes: 1 }, + ShouldObscure = { No: 0, Yes: 1 }, + ShouldSetAutoFilled = { No: 0, Yes: 1 }, + ForceNonFormElementAsLogicalBackingElement = { No: !1, Yes: !0 }, + LogicalFormCreationIsProvisional = { No: !1, Yes: !0 }, + MatchCriteria = { Property: 0, Category: 1, Literal: 2 }, + PageScanCharactersSearchedThreshold = 500, + PageScanMaxCharactersSearched = 600, + MaximumNumberOfCharactersToCollectForLanguageIdentification = 300, + MinValueForMaxLengthAttributeToTreatAsPasswordField = 4, + UsernameCandidateScoreForPlainTextField = 1, + UsernameCandidateScoreForPlainTextFieldDirectlyBeforePasswordField = 2, + UsernameCandidateScoreForEmailLabeledFieldBelowPasswordField = 3, + UsernameCandidateScoreForUsernameLabeledFieldBelowPasswordField = 4, + UsernameCandidateScoreForEmailLabeledFieldAbovePasswordField = 5, + UsernameCandidateScoreForUsernameLabeledFieldAbovePasswordField = 6, + UsernameCandidateScoreBonusForVisibleElement = 0.5, + UsernameCandidateScorePenaltyForReadOnlyElement = 0.5, + UsernameCandidateScorePenaltyForMatchingNonUsernameFieldLabelPattern = 2, + UsernameCandidateScorePenaltyForMatchingSearchFieldLabelPattern = 1.5, + UsernameCandidateScorePenaltyForAnonymousElement = 1, + LowestScoreForUsernameFieldCandidate = + UsernameCandidateScoreForPlainTextField, + LowestScoreForLabeledUsernameFieldCandidate = + UsernameCandidateScoreForEmailLabeledFieldBelowPasswordField, + MaxLengthForFieldAboveWhichToTreatPotentialOneTimeCodeFieldAsRequiringHigherScrutiny = 10, + DateTimeInputTypes = ["date", "datetime-local", "month", "time", "week"], + DateTimeInputTypeFormats = { + date: "yyyy-MM-dd", + "datetime-local": "yyyy-MM-dd'T'hh:mm", + month: "yyyy-MM", + time: "hh:mm", + week: "yyyy-'W'ww", + }, + numberOfConsecutiveElementsWithoutSuccessfulPageScanAfterWhichPageScanIsAbandoned = 40; +var mapOfFormTypeToProducerOfAssociatedKeywords = (function () { + var e = {}; + return ( + (e[WBSAutoFillFormTypeNewAccount] = function () { + return FormMetadataJSController.mapOfKeywordsIndicatingNewAccountFormTypeToScoreForMatching; + }), + (e[WBSAutoFillFormTypeAutoFillableLogin] = function () { + return FormMetadataJSController.mapOfKeywordsIndicatingLoginFormTypeToScoreForMatching; + }), + (e[WBSAutoFillFormTypeChangePassword] = function () { + return FormMetadataJSController.mapOfKeywordsIndicatingChangePasswordFormTypeToScoreForMatching; + }), + e + ); + })(), + visibilityCacheGeneration = 0; +let doctypeLooksLikeHTML5 = + "html" === document.doctype?.name && + "" === document.doctype?.publicId && + "" === document.doctype?.systemId; +((console.autofillDebugLog = function () { + FormMetadataJSController.isDebugConsoleLoggingEnabled; +}), + (Node.prototype.traversePreviousElement = function () { + for (var e = this.previousElementSibling; e && e.lastElementChild; ) + e = e.lastElementChild; + return e || this.parentElement; + }), + (Node.prototype.traversePreviousNode = function (e) { + if (this) { + var t = this.previousSibling; + if (e(t)) return null; + for (; t && t.lastChild; ) if (e((t = t.lastChild))) return null; + return t || this.parentNode; + } + }), + (Node.prototype.traverseNextNode = function (e) { + if (this) { + var t = this.firstChild; + if (t) return t; + if (e && this === e) return null; + if ((t = this.nextSibling)) return t; + for ( + t = this; + t && !t.nextSibling && (!e || !t.parentNode || t.parentNode !== e); + ) + t = t.parentNode; + return t ? t.nextSibling : null; + } + }), + (Node.prototype.isVisible = function () { + let e = this; + if (e._isVisible === visibilityCacheGeneration) return !0; + if (e._isVisible === -visibilityCacheGeneration) return !1; + let t = + e.nodeType == Node.TEXT_NODE + ? e.parentElementIncludingShadowDOMHost() + : e, + o = getComputedStyle(t, null); + if ( + ((e._isVisible = -visibilityCacheGeneration), + "none" === o.display || "visible" !== o.visibility) + ) + return !1; + let r = 0 === parseFloat(o.opacity) ? 6 : 2; + return ( + !(t.offsetWidth < r) && + !(t.offsetHeight < r) && + ((e._isVisible = visibilityCacheGeneration), !0) + ); + }), + Object.defineProperty(Array.prototype, "joinFirstItems", { + value: function (e, t) { + t > this.length && (t = this.length); + for (var o = "", r = 0; r < t; ++r) (r > 0 && (o += e), (o += this[r])); + return o; + }, + }), + (DOMRect.prototype.isZeroRect = function () { + return !(this.top || this.right || this.bottom || this.left); + }), + (DOMRect.prototype.distanceToRect = function (e) { + function t(e) { + function t(e, t) { + return Math.pow(e.x - t.x, 2) + Math.pow(e.y - t.y, 2); + } + var o = e[0], + r = e[1]; + return (o[0].x >= r[0].x && o[0].x < r[1].x) || + (r[0].x >= o[0].x && r[0].x < o[1].x) + ? Math.abs(o[0].y - r[0].y) + : (o[0].y >= r[0].y && o[0].y < r[1].y) || + (r[0].y >= o[0].y && r[0].y < o[1].y) + ? Math.abs(o[0].x - r[0].x) + : Math.sqrt(Math.min(t(o[0], r[1]), t(o[1], r[0]))); + } + var o = [ + { x: this.left, y: this.top }, + { x: this.right, y: this.top }, + ], + r = [ + { x: this.right, y: this.top }, + { x: this.right, y: this.bottom }, + ], + n = [ + { x: this.left, y: this.bottom }, + { x: this.right, y: this.bottom }, + ], + i = [ + { x: this.left, y: this.top }, + { x: this.left, y: this.bottom }, + ], + l = [ + { x: e.left, y: e.top }, + { x: e.right, y: e.top }, + ], + a = [ + { x: e.right, y: e.top }, + { x: e.right, y: e.bottom }, + ], + s = [ + { x: e.left, y: e.bottom }, + { x: e.right, y: e.bottom }, + ], + u = [ + { x: e.left, y: e.top }, + { x: e.left, y: e.bottom }, + ], + c = [ + [i, u], + [i, a], + [o, l], + [o, s], + [r, u], + [r, a], + [n, l], + [n, s], + ].map(t); + return Math.min.apply(Math, c); + }), + (Node.prototype.parentElementIncludingShadowDOMHost = function () { + let e = this.parentElement; + if (e) return e; + let t = this.getRootNode(); + return t && t.host ? t.host : null; + }), + (Node.prototype.allAncestorsAndSelfIncludingShadowDOMHosts = function () { + let e = [], + t = this; + for (; t; ) (e.push(t), (t = t.parentElementIncludingShadowDOMHost())); + return e; + }), + (HTMLElement.prototype.closestCommonAncestor = function (e) { + let t = this.parentElement; + for (; t; ) { + if (t.contains(e)) return t; + t = t.parentElement; + } + let o = this.allAncestorsAndSelfIncludingShadowDOMHosts().reverse(), + r = e.allAncestorsAndSelfIncludingShadowDOMHosts().reverse(), + n = Math.min(o.length, r.length), + i = null; + for (let e = 0; e < n; ++e) { + if (!(o[e] === r[e])) break; + i = o[e]; + } + return i || null; + }), + (HTMLElement.prototype.isHiddenFromAccessibilityTree = function () { + const e = 2; + for ( + let o = 0, r = this; + o <= e && r; + ++o, r = r.parentElementIncludingShadowDOMHost() + ) { + var t = r.getAttribute("aria-hidden"); + if (t && "true" === t.toLowerCase()) return !0; + } + return !1; + }), + (HTMLFormElement.prototype.isVisible = function () { + if (Node.prototype.isVisible.call(this)) return !0; + for (var e = this.elements, t = e.length, o = 0; o < t; ++o) + if (e[o].isVisible()) return !0; + return !1; + })); +let cachedRegularExpressionsForDomainMatching = {}; +((LogicalForm = function (e, t, o) { + let r = e.length; + var n = e[0].form, + i = n; + let l = e[0], + a = e[r - 1]; + ((!t && i) || (i = 1 === r ? l : l.closestCommonAncestor(a)), + (n && n.contains(a)) || (n = i)); + let s = i.closest('*[role~="dialog"]'); + s && (i = s); + let u = l._provisionalLogicalFormUniqueIDForFirstControlInLogicalForm; + (u || + ((u = FormMetadataJSController.nextFormUniqueID), + (l._provisionalLogicalFormUniqueIDForFirstControlInLogicalForm = u)), + (this._formUniqueID = u), + (this._metadata = {}), + (this._weakControls = Array.prototype.map.call(e, (e) => new WeakRef(e))), + (this._weakFormElement = new WeakRef(n)), + (this._weakBackingElement = new WeakRef(i)), + o || this.markElementsAsPartOfLogicalForm()); +}), + (LogicalForm.prototype = { + get elements() { + return this._weakControls.flatMap((e) => e.deref()); + }, + get formElement() { + return this._weakFormElement.deref(); + }, + get backingElement() { + return this._weakBackingElement.deref(); + }, + get formUniqueID() { + return this._formUniqueID; + }, + get metadata() { + return this._metadata; + }, + set metadata(e) { + this._metadata = e; + }, + containsControl: function (e) { + return e.hasOwnProperty("_logicalFormUniqueID") + ? e._logicalFormUniqueID === this.formUniqueID + : e.form === this.formElement; + }, + radioButtonsWithName: function (e) { + let t = queryAllBySelector(document.documentElement, `*[name="${e}"]`); + return Array.prototype.filter.call( + t, + function (e) { + return ( + (e.form === this.formElement || this.formElement?.contains(e)) && + isRadioButtonElement(e) + ); + }, + this, + ); + }, + annotate: function (e) { + let t = this.formElement; + if (t) { + var o = t._annotations; + if (o) { + for (var r in e) { + var n = e[r]; + n ? (o[r] = n) : delete o[r]; + } + hasOwnProperties(o) || delete t._annotations; + } else t._annotations = e; + } + }, + markElementsAsPartOfLogicalForm: function () { + let e = this._weakControls.length; + for (let t = 0; t < e; t++) { + let o = this._weakControls[t].deref(); + o && + ((o._logicalFormUniqueID = this.formUniqueID), + t + 1 < e && + (o._weakNextControlInLogicalForm = this._weakControls[t + 1]), + t > 0 && + (o._weakPreviousControlInLogicalForm = this._weakControls[t - 1])); + } + }, + get annotations() { + return this.formElement?._annotations; + }, + get isAnnotated() { + return !!this.annotations; + }, + }), + (LogicalFormCache = function () { + ((this._logicalFormsByUniqueID = new Map()), (this._allLogicalForms = [])); + }), + (LogicalFormCache.prototype = { + get size() { + return this._logicalFormsByUniqueID.size; + }, + removeUnparentedLogicalFormsFromCache: function () { + let e = new Set(); + for (let t of this._allLogicalForms) + t.formElement?.isConnected || e.add(t); + for (let t of e) this._logicalFormsByUniqueID.delete(t.formUniqueID); + this._allLogicalForms = Array.from(this._logicalFormsByUniqueID.values()); + }, + logicalFormForControl: function (e) { + for (let t of this._allLogicalForms) if (t.containsControl(e)) return t; + return null; + }, + allForms: function () { + return this._allLogicalForms.slice(); + }, + cachedForms: function () { + return Array.from(this._logicalFormsByUniqueID.values()); + }, + addOrUpdate: function (e) { + (this._logicalFormsByUniqueID.set(e.formUniqueID, e), + this._allLogicalForms.push(e)); + }, + clearCacheAndAdd: function (e) { + (this._logicalFormsByUniqueID.clear(), (this._allLogicalForms = [])); + for (let t of e) this.addOrUpdate(t); + }, + logicalFormWithUniqueID: function (e) { + return this._logicalFormsByUniqueID.get(e); + }, + }), + (FormMetadata = function () { + ((this._logicalFormsCache = new LogicalFormCache()), + (this._elementsWithGeneratedPasswords = []), + (this._generatedPasswords = []), + (this._labels = queryAllBySelector(document, "label")), + (this._controlUniqueIDToWeakControlMap = new Map()), + (this._mapOfFormTypeToExtraScoreProducer = (function () { + let e = {}; + return ( + (e[WBSAutoFillFormTypeNewAccount] = function () { + return 0; + }), + (e[WBSAutoFillFormTypeAutoFillableLogin] = function (e) { + const t = 2, + o = function (e) { + return ( + "checkbox" === e.type && + FormMetadataJS._labelsForElement(e).some( + (e) => + /(remember|keep) me/i.test(e.innerText.trim()) && + e.isVisible(), + ) + ); + }; + return 1 === e.elements.filter((e) => o(e)).length ? t : 0; + }), + (e[WBSAutoFillFormTypeChangePassword] = function () { + return 0; + }), + e + ); + })()), + (this._requiredFormatForDateTimeInput = DateTimeInputTypes.reduce( + function (e, t) { + let o = document.createElement("input"); + o.type = t; + let r = "a"; + return ( + (o.value = r), + (e[t] = "" === o.value ? DateTimeInputTypeFormats[t] : ""), + e + ); + }, + {}, + ))); + }), + (FormMetadata.prototype = { + _getTagName: function (e) { + var t = e.tagName; + return "string" == typeof t || "string" == typeof (t = e.nodeName) + ? t + : void 0; + }, + _getNameOrId: function (e) { + return e.name && e.name.length ? e.name : e.id; + }, + controlUniqueID: function (e) { + if (e._controlUniqueID) return e._controlUniqueID; + var t = "ControlID-" + FormMetadataJSController.nextControlUniqueID; + e._controlUniqueID = t; + this._controlUniqueIDToWeakControlMap.get(t); + return ( + this._controlUniqueIDToWeakControlMap.set(t, new WeakRef(e)), + e._controlUniqueID + ); + }, + _searchForLabelsAboveCell: function (e, t) { + var o = window.getComputedStyle(t, null); + if (!o || "table-cell" !== o.getPropertyValue("display")) return null; + var r = cellVisuallyAbove(t); + if (!r) return null; + for (var n = 0, i = r.firstChild; i; i = i.traverseNextNode(r)) + if (i.nodeType == Node.TEXT_NODE && i.isVisible()) { + var l = i.nodeValue, + a = e.searchReverse(l); + if (a) + return { + Distance: n, + Match: a[0], + Property: a[1], + Category: a[2], + ParentProperty: a[3], + }; + n += l.length; + } + return null; + }, + _collectStringFromNodeForPageScan: function (e, t, o) { + var r = e.nodeValue, + n = r.length; + return ( + o + n > PageScanMaxCharactersSearched && + ((r = r.substr(-(PageScanCharactersSearchedThreshold - o))), + (n = PageScanCharactersSearchedThreshold - o)), + (r = r.trim()).length && t.push(r), + o + ); + }, + _dataForComputingMatchFromPageScanBeforeElement: function (e, t) { + function o(e) { + return e && e.nodeType == Node.ELEMENT_NODE && e.matches("nav"); + } + var r, + n = [], + i = 0; + let l = this._logicalFormsCache.logicalFormForControl(e); + if (!l) return [[], null]; + var a = l.formElement, + s = a && a.isVisible(); + t || (t = a); + for ( + var u = e.traversePreviousNode(o); + u && i < PageScanCharactersSearchedThreshold; + u = u.traversePreviousNode(o) + ) { + var c = u.localName; + if (u === t) break; + if (this._isRenderedFormControl(u)) { + if (u.isVisible() || !s) break; + } else { + if (this._isLabelElement(u) && u.isVisible()) break; + if ("td" !== c || r) { + if ("tr" === c && r) break; + if ("ul" === c || "ol" === c || "dl" === c) break; + if ("li" === c) { + if (!u.parentNode.contains(e)) break; + } else + u.nodeType == Node.TEXT_NODE && + u.isVisible() && + (i += this._collectStringFromNodeForPageScan(u, n, i)); + } else r = u; + } + } + return [n, r]; + }, + _matchFromPageScanBeforeElement: function (e, t, o) { + var r = this._pageScanContext + ? this._pageScanContext.backwardScanCache + : null, + n = this._pageScanDataForElementWithCacheAndDataProducer( + t, + r, + this._dataForComputingMatchFromPageScanBeforeElement.bind(this), + o, + ), + i = n[0], + l = this._matchFromPatternMatcherAndStringsFromPageScan(e, i); + if (l) return l; + var a = n[1]; + if (a) { + var s = this._searchForLabelsAboveCell(e, a); + if (s) return ((s.IsInCellAbove = !0), s); + } + return null; + }, + _isElementFollowedByForgotUserNameOrEmailAffordance: function (e, t) { + (this._forgotUserNameRegularExpressions || + (this._forgotUserNameRegularExpressions = regularExpressionsFromStrings( + FormMetadataJSController.regularExpressionsForForgotUserNameAffordance, + )), + this._forgotEmailRegularExpressions || + (this._forgotEmailRegularExpressions = regularExpressionsFromStrings( + FormMetadataJSController.regularExpressionsForForgotEmailAffordance, + ))); + let o = this._stringsToEvaluateToDetermineIfElementIsFollowedByAffordance( + e, + t, + ); + return ( + !!stringsMatchAnyRegularExpressions( + o, + this._forgotUserNameRegularExpressions, + ) || + !!stringsMatchAnyRegularExpressions( + o, + this._forgotEmailRegularExpressions, + ) + ); + }, + _isElementFollowedByForgotPasswordAffordance: function (e, t) { + return ( + this._forgotPasswordRegularExpressions || + (this._forgotPasswordRegularExpressions = + regularExpressionsFromStrings( + FormMetadataJSController.regularExpressionsForForgotPasswordAffordance, + )), + stringsMatchAnyRegularExpressions( + this._stringsToEvaluateToDetermineIfElementIsFollowedByAffordance( + e, + t, + ), + this._forgotPasswordRegularExpressions, + ) + ); + }, + _numberOfForgotUserNameEmailOrPasswordAffordancesFollowingElement: + function (e, t) { + (this._forgotEmailRegularExpressions || + (this._forgotEmailRegularExpressions = regularExpressionsFromStrings( + FormMetadataJSController.regularExpressionsForForgotEmailAffordance, + )), + this._forgotPasswordRegularExpressions || + (this._forgotPasswordRegularExpressions = + regularExpressionsFromStrings( + FormMetadataJSController.regularExpressionsForForgotPasswordAffordance, + )), + this._forgotUserNameRegularExpressions || + (this._forgotUserNameRegularExpressions = + regularExpressionsFromStrings( + FormMetadataJSController.regularExpressionsForForgotUserNameAffordance, + ))); + let o = + this._stringsToEvaluateToDetermineIfElementIsFollowedByAffordance( + e, + t, + ), + r = 0; + return ( + stringsMatchAnyRegularExpressions( + o, + this._forgotUserNameRegularExpressions, + ) && r++, + stringsMatchAnyRegularExpressions( + o, + this._forgotEmailRegularExpressions, + ) && r++, + stringsMatchAnyRegularExpressions( + o, + this._forgotPasswordRegularExpressions, + ) && r++, + r + ); + }, + _stringsToEvaluateToDetermineIfElementIsFollowedByAffordance: function ( + e, + t, + ) { + let o = this._dataForComputingMatchFromPageScanAfterElement(e, "A"); + if (!o.length) { + const t = e.traverseNextNode(); + if (t) { + let e = t; + t instanceof Node && (e = t.parentElementIncludingShadowDOMHost()); + const r = e.querySelector("a"); + if (r) { + o.push(r.innerText); + const e = pathFromAnchorWithoutLeadingSlash(r); + e && o.push(e); + } + } + } + if (!o.length) { + for (let r of queryAllBySelector(t, "a")) { + if (e.compareDocumentPosition(r) & Node.DOCUMENT_POSITION_FOLLOWING) { + o.push(r.innerText); + const e = pathFromAnchorWithoutLeadingSlash(r); + e && o.push(e); + } + } + for (let r of queryAllBySelector(t, "button")) { + e.compareDocumentPosition(r) & Node.DOCUMENT_POSITION_FOLLOWING && + o.push(r.innerText); + } + } + const r = e._weakNextControlInLogicalForm?.deref(); + return (r && "button" === r.type && o.push(r.innerText), o); + }, + _dataForComputingMatchFromPageScanAfterElement: function (e, t, o) { + var r = [], + n = 0, + i = this._logicalFormsCache.logicalFormForControl(e); + if (!i) return []; + var l = i.formElement, + a = l && l.isVisible(); + let s = void 0 !== t; + o || (o = l); + for ( + var u = e.traverseNextNode(); + u && n < PageScanCharactersSearchedThreshold; + u = u.traverseNextNode() + ) { + var c = u.localName; + if (u === o) { + var d = this._pageScanContext; + d && !n && (d.forwardScanIsFutile = !0); + break; + } + if (this._isRenderedFormControl(u)) { + if (u.isVisible() || !a) break; + } else { + if (this._isLabelElement(u) && u.isVisible()) break; + if ("tr" === c) break; + if ("ul" === c || "ol" === c || "dl" === c) break; + if (u.nodeType == Node.TEXT_NODE && u.isVisible()) { + if (void 0 !== t && (!u.parentNode || u.parentNode.tagName !== t)) + continue; + if (((n += this._collectStringFromNodeForPageScan(u, r, n)), s)) + break; + } + } + } + return r; + }, + _matchFromPageScanAfterElement: function (e, t, o) { + var r = this._pageScanContext + ? this._pageScanContext.forwardScanCache + : null, + n = this._pageScanDataForElementWithCacheAndDataProducer( + t, + r, + this._dataForComputingMatchFromPageScanAfterElement.bind(this), + o, + ); + return this._matchFromPatternMatcherAndStringsFromPageScan(e, n); + }, + _pageScanDataForElementWithCacheAndDataProducer: function (e, t, o, r) { + if (!t) return o(e, r); + if ((n = t.get(e))) return n; + var n = o(e, r); + return (t.set(e, n), n); + }, + _matchFromPatternMatcherAndStringsFromPageScan: function (e, t) { + for (var o = t.length, r = 0, n = 0; n < o; ++n) { + var i = t[n]; + r += i.length; + var l = e.searchReverse(i); + if (l) + return { + Distance: r, + Match: l[0], + Property: l[1], + Category: l[2], + ParentProperty: l[3], + }; + } + return null; + }, + _matchPatternAgainstString: function (e, t) { + if (!t) return null; + var o = t.replace(/[\d_.-]/g, " "); + return ( + (o = o.replace(/[a-z][A-Z]/g, function (e) { + return e[0] + " " + e[1]; + })), + e.longestMatch(o) + ); + }, + _controlsAreAllButtons: function (e) { + for (var t = e.length, o = 0; o < t; ++o) { + if (!(e[o] instanceof HTMLButtonElement)) return !1; + } + return !0; + }, + _createLogicalFormsForControls: function (e, t, o) { + if (this._controlsAreAllButtons(e)) return []; + let r, + n, + i = e.map(function (e) { + return e.getBoundingClientRect(); + }), + l = e.length, + a = 0; + i[0].isZeroRect() ? ((r = 0), (n = null)) : ((r = 1), (n = i[0])); + for (let h = 1; h < l; ++h) { + let m = i[h]; + if (!m.isZeroRect()) { + if (n) { + let F = n.distanceToRect(m); + F && (++r, (a += F)); + } + n = m; + } + } + if (1 === r) { + function s(e) { + return e.closest("header, footer, aside"); + } + let f = [], + g = 0; + for (; g < l; ) { + let p = [e[g]], + C = s(e[g]); + for (let A = g + 1; A < l; ++A) { + let _ = e[A]; + if (C !== s(e[A])) break; + p.push(_); + } + (f.push(new LogicalForm(p, t, o)), (g += p.length)); + } + return f; + } + let u = r ? a / r : 0, + c = [], + d = 0; + for (; d < l; ) { + let b = [e[d]], + y = !1, + S = i[d].isZeroRect() ? null : i[d]; + for (let T = d + 1; T < l; ++T) { + let E = e[T], + I = i[T]; + if (!I.isZeroRect()) { + if (y) { + if (S && S.distanceToRect(I) > u) break; + } else y = couldBeFormSubmissionControl(E); + S = I; + } + b.push(E); + } + (c.push(new LogicalForm(b, t, o)), (d += b.length)); + } + return c; + }, + _formLooksLikeAspnetForm: function (e) { + const t = 3; + var o = 0; + ("aspnetForm" === e.getAttribute("id") && ++o, + "aspnetForm" === e.getAttribute("name") && ++o); + for ( + var r = queryAllBySelector(e, "input"), n = 0, i = r.length; + n < i; + ++n + ) { + var l = r[n], + a = l.getAttribute("id"), + s = l.getAttribute("name"); + (/ctl\d\d_/.test(a) && ++o, + /ctl\d\d\$/.test(s) && ++o, + "hidden" === l.getAttribute("type") && + (("__VIEWSTATE" === s && "__VIEWSTATE" === a) || + ("__EVENTTARGET" === s && "__EVENTTARGET" === a) || + ("__EVENTARGUMENT" === s && "__EVENTARGUMENT" === a) || + ("__LASTFOCUS" === s && "__LASTFOCUS" === a)) && + ++o); + } + for ( + var u = queryAllBySelector(document, "script"), c = u.length, d = 0; + d < c; + ++d + ) { + var h = anchorWithURLString(u[d].src); + if (h.host === window.location.host) { + var m = lastPathComponentFromAnchor(h); + ("WebResource.axd" !== m && "ScriptResource.axd" !== m) || ++o; + } + } + return o >= t; + }, + _anchorLooksLikeSubmitButton: function (e) { + return /submit|button/i.test(e.getAttribute("id")); + }, + _visibleInputAndSelectElementsInForm: function (e) { + let t = queryAllBySelector(e, "input:not([type='hidden']), select"), + o = []; + for (var r = 0, n = t.length; r < n; ++r) { + let e = t[r]; + e.isVisible() && o.push(e); + } + return o; + }, + _elementsActingAsButtonsInForm: function (e) { + let t = Array.prototype.slice.call( + queryAllBySelector(e, "input[type='submit'], input[type='image']"), + ), + o = queryAllBySelector(e, "a"); + for (var r = 0, n = o.length; r < n; ++r) { + let e = o[r]; + this._anchorLooksLikeSubmitButton(e) && e.isVisible() && t.push(e); + } + return t; + }, + _logicalFormsForAspnetForm: function (e) { + function t(e) { + var o = e.length; + if (o <= 1) + a.push( + new LogicalForm(e, ForceNonFormElementAsLogicalBackingElement.Yes), + ); + else { + var r = o - 1, + n = e[r]; + if (e[0].closestCommonAncestor(n) instanceof HTMLTableRowElement) { + for (var i = 0; i < r; ++i) { + if ( + !(e[i].closestCommonAncestor(n) instanceof HTMLTableRowElement) + ) + return (t(e.slice(0, i)), void t(e.slice(i))); + } + a.push( + new LogicalForm( + e, + ForceNonFormElementAsLogicalBackingElement.Yes, + ), + ); + } else + a.push( + new LogicalForm( + e, + ForceNonFormElementAsLogicalBackingElement.Yes, + ), + ); + } + } + for ( + var o = this._visibleInputAndSelectElementsInForm(e), + r = o.length, + n = this._elementsActingAsButtonsInForm(e), + i = n.length, + l = 0; + l < i; + ++l + ) { + (s = n[l]).getAttribute("id") && + (s._aspNetIDComponents = s.getAttribute("id").split("_")); + } + n.sort(function (e, t) { + var o = e._aspNetIDComponents || []; + return (t._aspNetIDComponents || []).length - o.length; + }); + var a = []; + for (l = 0; l < i; ++l) { + var s, + u = (s = n[l])._aspNetIDComponents; + if (u) { + var c = u.length; + if (!(c < 2)) { + for ( + var d = u.joinFirstItems("_", c - 1) + "_", h = [], m = r - 1; + m >= 0; + --m + ) { + var F = o[m], + f = F.getAttribute("id"); + f && f.startsWith(d) && (h.push(F), o.splice(m, 1)); + } + if ((h.length && t(h.reverse()), !(r = o.length))) break; + } + } + } + return (r && t(o), a); + }, + _logicalFormsInPage: function (e, t) { + let o = []; + const r = document.querySelector("form form"); + let n = {}, + i = r ? document.forms : queryAllBySelector(document, "form"); + const l = 400, + a = (e) => (e.length <= l ? e : Array.from(e).slice(0, l)), + s = (e, t, o) => { + let r = queryAllBySelector(e, t); + return r.length <= l ? r : a(queryAllBySelector(e, o)); + }; + let u = 0, + c = i.length, + d = new Set(); + for (var h = 0; h < c; ++h) { + let l = i[h], + c = r + ? a(l.elements) + : s( + l, + "input, select, textarea, button, fieldset", + "input, select, textarea, button[type='submit'], fieldset", + ); + for (let e of c) d.add(e); + if (c.length) { + if ((u++, e && u >= e)) return o; + if (t) { + let e = [l.method, l.name, l.action, l.className].join("|"), + o = n[e] || 0; + if (o > t) continue; + n[e] = o + 1; + } + this._formLooksLikeAspnetForm(l) + ? (o = o.concat(this._logicalFormsForAspnetForm(l))) + : o.push(new LogicalForm(c)); + } + } + let m = [], + F = s( + document, + "input, select, textarea, button", + "input, select, textarea, button[type='submit']", + ), + f = F.length; + for (let e = 0; e < f; ++e) { + let t = F[e]; + if (d.has(t)) { + if (!m.length) continue; + ((o = o.concat(this._createLogicalFormsForControls(m))), (m = [])); + } else + (this._isRenderedFormControl(t) || autocompleteTokens(t)) && + m.push(t); + } + m.length && (o = o.concat(this._createLogicalFormsForControls(m))); + let g = o.length; + for (h = 0; h < g - 1; ++h) { + let e = o[h], + t = e.backingElement, + r = t.getBoundingClientRect(), + n = o[h + 1], + i = n.backingElement, + l = i.getBoundingClientRect(); + const a = 40; + if ( + t.nextElementSibling === i && + t.action === i.action && + r.height && + l.height && + r.x === l.x && + r.width === l.width && + r.bottom + a >= l.top + ) { + let t = + 1 === + e.elements.filter(function (e) { + return e.isVisible(); + }).length, + r = e.elements.includes(function (e) { + return e.matches("input[type=submit], button") && e.isVisible(); + }); + if (t && !r) { + let t = e.elements.concat(n.elements), + r = this._createLogicalFormsForControls( + t, + ForceNonFormElementAsLogicalBackingElement.Yes, + LogicalFormCreationIsProvisional.Yes, + ); + if (1 === r.length) { + let e = r[0]; + (e.markElementsAsPartOfLogicalForm(), o.splice(h, 2, e), g--); + } + } + } + } + return o; + }, + _matchPatternAgainstElement: function (e, t, o) { + function r(e, t) { + if (!e) return null; + var r = o[t], + n = sharedPrefixLength(r, e[t]); + return n ? r.substr(n) : null; + } + function n(e, t) { + if (!t) return null; + const o = t.text; + if (/^-.+-$/.test(o)) return o; + if (!t.value.length && o.length) { + const r = e.options, + n = r.length; + let i = !0; + for (let e = 0; e < n; ++e) { + const o = r[e]; + if (o !== t && !o.value.length) { + i = !1; + break; + } + } + if (i) return o; + } + return null; + } + this._logicalFormsCache.logicalFormForControl(o); + var i = o._weakPreviousControlInLogicalForm?.deref(), + l = o._weakNextControlInLogicalForm?.deref(); + const a = ["name", "id"], + s = a.length; + for (var u = new Array(s), c = new Array(s), d = 0; d < s; ++d) { + var h = a[d]; + ((u[d] = r(i, h)), (c[d] = r(l, h))); + } + const m = t.length; + for (var F = 0; F < m; ++F) { + var f, + g = t[F]; + for ( + d = 0; + d < s && + !(f = this._matchPatternAgainstString(g, u[d])) && + !(f = this._matchPatternAgainstString(g, c[d])) && + !(f = this._matchPatternAgainstString(g, o[a[d]])); + ++d + ); + const r = "select" === this._getTagName(o).toLowerCase(); + if (!f && r) { + const e = r ? defaultOptionForSelectElement(o) : null, + t = r ? o.options[0] : null; + let i = n(o, e); + (i || e === t || (i = n(o, t)), + (f = this._matchPatternAgainstString(g, i))); + } + f && + e.push({ + FoundByPageScan: !1, + Match: f[0].toLowerCase(), + Property: f[1], + Category: f[2], + ParentProperty: f[3], + Priority: F, + }); + } + }, + _labelsForElement: function (e) { + if (e._cachedLabels) return e._cachedLabels; + e._cachedLabels = []; + let t = e.getAttribute("aria-labelledby"); + if (t && t.length) { + let r = t.split(" "); + for (var o = 0; o < r.length; o++) { + let t = getElementByID(r[o]); + t && e._cachedLabels.push(t); + } + } + if (e._cachedLabels.length) return e._cachedLabels; + let r = function (e) { + return e.replace(/[^a-zA-Z0-9]+/g, ""); + }; + for (let t of [e.getAttribute("id"), e.getAttribute("name")]) { + if (!t || !t.length) continue; + let o = [], + n = e.form; + for (let i of this._labels) { + if (n === i.closest("form")) { + let n = i.getAttribute("for"); + if (n === t) e._cachedLabels.push(i); + else if (n) { + let e = r(n); + e.length > 0 && e === r(t) && o.push(i); + } + } + } + if ( + (0 === e._cachedLabels.length && + 1 === o.length && + (e._cachedLabels = o), + e._cachedLabels.length) + ) + return e._cachedLabels; + } + let n = this._logicalFormsCache.logicalFormForControl(e)?.formElement; + for ( + let t = e.parentElementIncludingShadowDOMHost(); + t && t !== n; + t = t.parentElementIncludingShadowDOMHost() + ) + if (this._isLabelElement(t)) { + e._cachedLabels.push(t); + break; + } + return e._cachedLabels; + }, + _matchesForElement: function (e, t, o = !1) { + function r(e, o) { + for (var r = 0; r < l; ++r) { + var n = t[r].searchReverse(e); + if ( + n && + (i.push({ + FoundByPageScan: !1, + Match: n[0].toLowerCase(), + Property: n[1], + Category: n[2], + ParentProperty: n[3], + Priority: r, + }), + o === ShouldStopAfterFirstMatch.StopAfterFirstMatch) + ) + return; + } + } + function n(e, t) { + return e && + e.Match.length && + (!t || + (!e.IsInCellAbove && t.IsInCellAbove) || + (e.IsInCellAbove == t.IsInCellAbove && e.Distance < t.Distance)) + ? { + FoundByPageScan: !0, + Match: A.Match.toLowerCase(), + Property: A.Property, + Category: A.Category, + ParentProperty: A.ParentProperty, + Priority: y, + } + : t; + } + var i = [], + l = t.length; + this._matchPatternAgainstElement(i, t, e); + for ( + var a = !1, s = this._labelsForElement(e), u = 0; + u < s.length; + ++u + ) { + var c = s[u].innerText; + c && ((a = !0), r(c, ShouldStopAfterFirstMatch.StopAfterFirstMatch)); + } + let d = placeholderInfoForElement(e); + d && + !d.AttributeMatchedWasValue && + r(d.Text, ShouldStopAfterFirstMatch.StopAfterFirstMatch); + var h = e.getAttribute("title"); + h && r(h, ShouldStopAfterFirstMatch.StopAfterFirstMatch); + var m = + this._labelForElementIfElementAndLabelAreOnlyElementsOfTheirKindAmongSiblingElements( + e, + ); + m?.innerText.length && + ((a = !0), r(m.innerText, ShouldStopAfterFirstMatch.CollectAllMatches)); + let F = this._ariaLabelForElementOrParentOfElement(e); + F && r(F, ShouldStopAfterFirstMatch.StopAfterFirstMatch); + var f = e.getAttribute("formcontrolname"); + f && f.length && r(f, ShouldStopAfterFirstMatch.StopAfterFirstMatch); + var g = this._pageScanContext, + p = !0, + C = !1; + if ( + (g && + (g.shouldUsePageScan && (p = g.shouldUsePageScan()), + g.reportPageScanUsedSuccessfully && (C = !0)), + !p) + ) + return i; + if (a) return (C && g.reportPageScanUsedSuccessfully(!1), i); + if (!0 === o) return i; + for (var A, _ = null, b = null, y = 0; y < l; ++y) + ((_ = n((A = this._matchFromPageScanBeforeElement(t[y], e)), _)), + (g && g.forwardScanIsFutile) || + (b = n((A = this._matchFromPageScanAfterElement(t[y], e)), b))); + var S = !1; + if ((_ && (i.push(_), (S = !0)), b)) + for (var T = 0, E = i.length; T < E; ++T) { + var I = i[T]; + if (b.Priority === I.Priority) { + (i.push(b), (S = !0)); + break; + } + } + return ( + C && g.reportPageScanUsedSuccessfully(S), + i.length && + d && + d.AttributeMatchedWasValue && + r(d.Text, ShouldStopAfterFirstMatch.StopAfterFirstMatch), + i + ); + }, + _bestMatchFromMatches: function (e) { + function t(e, t) { + for (var o = e.length, r = {}, n = 0; n < o; ++n) { + var i, + l = e[n]; + switch (t) { + case MatchCriteria.Property: + i = l.Property || l.Match; + break; + case MatchCriteria.Category: + i = l.Category || l.Match; + break; + case MatchCriteria.Literal: + i = l.Match; + } + r[i] + ? (r[i].Frequency += 1) + : (r[i] = { Frequency: 1, FirstMatchObject: l }); + } + var a = []; + for (var s in r) a.push(r[s]); + var u = a.sort(function (e, t) { + return t.Frequency - e.Frequency; + }), + c = u.length; + if (c <= 1) return null; + if (t === MatchCriteria.Property) + for (n = 0; n < c; ++n) { + if (u[n].FirstMatchObject.ParentProperty in r) + return u[n].FirstMatchObject; + } + return u[0].Frequency > u[1].Frequency ? u[0].FirstMatchObject : void 0; + } + var o = e.length; + if (0 === o) return null; + if (1 === o) return e[0]; + var r = t(e, MatchCriteria.Property); + return ( + r || + ((r = t(e, MatchCriteria.Category)) + ? r + : e.sort(function (e, t) { + return e.Priority - t.Priority; + })[0]) + ); + }, + _bestMatchForElement: function (e, t, o = !1) { + if (!e) return null; + var r = this._matchesForElement(e, t, o); + return this._bestMatchFromMatches(r, e, t); + }, + _labelForElementIfElementAndLabelAreOnlyElementsOfTheirKindAmongSiblingElements: + function (e) { + for ( + var t = null, + o = e.tagName, + r = siblingsIncludingSelfForElement(e), + n = r.length, + i = 0; + i < n; + ++i + ) { + var l = r[i]; + if (e !== l) { + if (o === l.tagName) return null; + if (this._isLabelElement(l)) { + if (t) return null; + t = l; + } + } + } + return t; + }, + _ariaLabelForElementOrParentOfElement: function (e) { + var t = e; + let o = 3; + for (var r = 0; r < o && t; ++r) { + let e = t.getAttribute("aria-label"); + if (e && !t.isHiddenFromAccessibilityTree()) return e; + t = t.parentElementIncludingShadowDOMHost(); + } + return null; + }, + _cachedOneTimeCodePatternMatcher: function () { + return this._cachedPatternMatchers( + "oneTimeCodeFieldLabelPatternMatchers", + )[0]; + }, + _cachedPatternMatchers: function (e) { + let t = "_" + e, + o = this[t]; + return (o || ((this[t] = FormMetadataJSController[e]), (o = this[t])), o); + }, + _cachedElementPatternMatch: function (e, t, o) { + var r = t + "_wasVisible", + n = e[r]; + if (!0 === n) return e[t]; + var i = e.isVisible(); + if (n === i) return e[t]; + e[r] = i; + let l = this._cachedPatternMatchers(o); + return ((e[t] = this._bestMatchForElement(e, l)), e[t]); + }, + _isLabeledUsernameField: function (e) { + return ( + !!this._isAutoFillableTextField(e) && + null !== + this._cachedElementPatternMatch( + e, + "_usernameFieldPatternMatch", + "usernameFieldLabelPatternMatchers", + ) + ); + }, + _isLabeledLoginField: function (e) { + return ( + !!this._isAutoFillableTextField(e) && + null !== + this._cachedElementPatternMatch( + e, + "_loginFieldPatternMatch", + "loginFormTypePatternMatchers", + ) + ); + }, + _isLabeledSignUpField: function (e) { + return ( + !!this._isAutoFillableTextField(e) && + null !== + this._cachedElementPatternMatch( + e, + "_signUpFieldPatternMatch", + "newAccountFormTypePatternMatchers", + ) + ); + }, + _isLabeledEmailField: function (e) { + return ( + !!this._isAutoFillableTextField(e) && + ("email" === e.type || + null !== + this._cachedElementPatternMatch( + e, + "_emailFieldPatternMatch", + "emailFieldLabelPatternMatchers", + )) + ); + }, + _addressBookLabelForElement: function (e) { + if ( + !this._isAutoFillableTextField(e) && + !this._isAutoFillableSelectElement(e) && + !this._isAutoFillableTextAreaElement(e) + ) + return null; + var t = this._cachedElementPatternMatch( + e, + "_addressBookPatternMatch", + "addressBookFieldLabelPatternMatchers", + ); + return t ? t.Match : null; + }, + _elementDisallowsAutocomplete: function (e) { + var t = e.getAttribute("autocomplete"); + return t && "off" === t.toLowerCase(); + }, + _isTextArea: function (e) { + return e instanceof HTMLTextAreaElement; + }, + _isSelectElement: function (e) { + return e instanceof HTMLSelectElement; + }, + _isLabelElement: function (e) { + return e instanceof HTMLLabelElement; + }, + _isRenderedFormControl: function (e) { + var t = e.localName; + if (!t) return !1; + return ( + t in + { + button: !0, + isindex: !0, + fieldset: !0, + legend: !0, + meter: !0, + optgroup: !0, + option: !0, + progress: !0, + select: !0, + textarea: !0, + } || + (e instanceof HTMLInputElement && + (!!this._isElementAHiddenUsername(e) || + !e.type || + "hidden" !== e.type)) + ); + }, + _isEditablePlainTextField: function (e) { + return ( + !!isInputElement(e) && + !e.disabled && + !e.readOnly && + (!e.type || "text" === e.type) + ); + }, + _isTextField: function (e) { + if (this._isTextArea(e)) return !0; + if (!isInputElement(e)) return !1; + const t = { + date: !0, + "datetime-local": !0, + email: !0, + isindex: !0, + month: !0, + number: !0, + password: !0, + search: !0, + tel: !0, + telephone: !0, + text: !0, + time: !0, + url: !0, + week: !0, + }; + var o = e.type; + return !o || o in t; + }, + _isAutofocusedTextField: function (e) { + return !!this._isTextField(e) && !0 === e.autofocus; + }, + _isAutoFilledTextField: function (e) { + return !!this._isTextField(e) && e.matches(":-webkit-autofill"); + }, + _isSecureTextField: function (e) { + if (!isInputElement(e)) return !1; + if (e._wasPreviouslySecureTextField) return !0; + try { + if (e.matches(":-webkit-autofill-strong-password")) + return ((e._wasPreviouslySecureTextField = !0), !0); + } catch (e) {} + const t = getComputedStyle(e, null).getPropertyValue( + "-webkit-text-security", + ), + o = e.type; + if ("none" !== t || "password" === o) + return ((e._wasPreviouslySecureTextField = !0), !0); + if (o && "text" !== o) return !1; + const r = e._weakNextControlInLogicalForm?.deref(); + return ( + !(!r || !this._looksLikeShowHidePasswordButton(r)) && + !!this._matchesPasswordFieldLabelPattern(e) && + !this._isLabeledUsernameField(e) && + ((e._wasPreviouslySecureTextField = !0), !0) + ); + }, + _isVerticalWritingMode: function (e) { + const t = getComputedStyle(e).writingMode; + return !("horizontal-tb" === t || "horizontal-bt" === t); + }, + _looksLikePasswordCredentialField: function (e) { + if (!this._isSecureTextField(e)) return !1; + var t = e.getAttribute("maxlength"); + return ( + !( + t && parseInt(t) < MinValueForMaxLengthAttributeToTreatAsPasswordField + ) && + null === + this._cachedElementPatternMatch( + e, + "_nonAccountPasswordSecureTextEntryFieldPatternMatch", + "nonAccountPasswordSecureTextEntryFieldLabelPatternMatchers", + ) + ); + }, + _looksLikeShowHidePasswordButton: function (e) { + return ( + !(!this._isCustomFormButton(e) && !this._isCheckboxInputElement(e)) && + !!this._cachedElementPatternMatch( + e, + "_showHideButtonPatternMatch", + "showHideButtonLabelPatternMatchers", + ) + ); + }, + _isAutoFillable: function (e) { + return !e.disabled && !e.readOnly; + }, + _isAutoFillableSelectElement: function (e) { + return this._isAutoFillable(e) && this._isSelectElement(e); + }, + _isAutoFillableTextAreaElement: function (e) { + return this._isAutoFillable(e) && this._isTextArea(e); + }, + _isAutoFillableTextField: function (e) { + return this._isAutoFillable(e) && this._isTextField(e); + }, + _looksLikeCreditCardNumberField: function (e, t) { + if (!this._isAutoFillableTextField(e)) return !1; + if ( + this._cachedElementPatternMatch( + e, + "_nonCreditCardNumberPatternMatch", + "nonCreditCardCardNumberFieldLabelPatternMatchers", + ) + ) + return !1; + if ( + this._matchesCreditCardCompositeExpirationDateFieldLabelPatternMatchers( + e, + ) + ) + return !1; + if (elementIDOrAutocompleteTokensHasToken(e, t, "cc-number")) return !0; + const o = e.placeholder; + let r = new RegExp("[0-9]{4}[ -][0-9]{4}[ -][0-9]{4}[ -][0-9]{4}"); + if (o && r.test(o)) return !0; + let n = e.getAttribute("data-val-regex-pattern"); + if (n) { + let e = regularExpressionFromUntrustedPatternAttributeString(n); + if (e && !e.test("12345")) return !1; + } + return ( + null !== + this._cachedElementPatternMatch( + e, + "_creditCardNumberPatternMatch", + "creditCardNumberFieldLabelPatternMatchers", + ) + ); + }, + _looksLikeCreditCardSecurityCodeField: function (e, t) { + if (!this._isAutoFillableTextField(e)) return !1; + if (elementIDOrAutocompleteTokensHasToken(e, t, "cc-csc")) return !0; + let o = e.getAttribute("pattern"); + if (o) { + let e = regularExpressionFromUntrustedPatternAttributeString(o); + if (e && !e.test("123") && !e.test("1234")) return !1; + } + return ( + null !== + this._cachedElementPatternMatch( + e, + "_creditCardSecurityCodePatternMatch", + "creditCardSecurityCodeFieldLabelPatternMatchers", + ) + ); + }, + _looksLikeCreditCardCardholderField: function (e, t) { + return ( + !!this._isEditablePlainTextField(e) && + (!!elementIDOrAutocompleteTokensHasToken(e, t, "cc-name") || + null !== + this._cachedElementPatternMatch( + e, + "_creditCardCardholderPatternMatch", + "creditCardCardholderFieldLabelPatternMatchers", + )) + ); + }, + _looksLikeCreditCardCompositeExpirationDateField: function (e, t) { + return ( + !(!this._isAutoFillableTextField(e) || this._isSecureTextField(e)) && + (!!elementIDOrAutocompleteTokensHasToken(e, t, "cc-exp") || + this._matchesCreditCardCompositeExpirationDateFieldLabelPatternMatchers( + e, + )) + ); + }, + _matchesCreditCardCompositeExpirationDateFieldLabelPatternMatchers: + function (e) { + return ( + null !== + this._cachedElementPatternMatch( + e, + "_creditCardCompositeExpirationDateFieldPatternMatch", + "creditCardCompositeExpirationDateFieldLabelPatternMatchers", + ) + ); + }, + _looksLikeCreditCardTypeField: function (e, t) { + return ( + !(!this._isSelectElement(e) && !isRadioButtonElement(e)) && + (!!elementIDOrAutocompleteTokensHasToken(e, t, "cc-type") || + null !== + this._cachedElementPatternMatch( + e, + "_creditCardTypePatternMatch", + "creditCardTypeFieldLabelPatternMatchers", + )) + ); + }, + _looksLikeEIDField: function (e, t) { + return !!elementIDOrAutocompleteTokensHasToken(e, t, "device-eid"); + }, + _looksLikeIMEIField: function (e, t) { + return !!elementIDOrAutocompleteTokensHasToken(e, t, "device-imei"); + }, + _looksLikeDayField: function (e) { + return ( + !( + !this._isAutoFillableTextField(e) && + !this._isAutoFillableSelectElement(e) + ) && + null !== + this._cachedElementPatternMatch( + e, + "_dayFieldPatternMatch", + "dayFieldLabelPatternMatchers", + ) + ); + }, + _looksLikeMonthField: function (e, t) { + if ( + !this._isAutoFillableTextField(e) && + !this._isAutoFillableSelectElement(e) + ) + return !1; + if (elementIDOrAutocompleteTokensHasToken(e, t, "cc-exp-month")) + return !0; + if ( + null !== + this._cachedElementPatternMatch( + e, + "_monthFieldPatternMatch", + "monthFieldLabelPatternMatchers", + ) + ) + return !0; + if ("select" !== this._getTagName(e).toLowerCase()) return !1; + var o = e.options.length; + if (12 === o || 13 === o) + for ( + var r = [ + selectElementOptionsSequenceAnalysis(e, "text"), + selectElementOptionsSequenceAnalysis(e, "value"), + ], + n = r.length, + i = 0; + i < n; + i++ + ) { + var l = r[i], + a = l.lengthOfLongestSequence, + s = l.lastNumberInSequence; + if (a >= 11 && 12 === s) return !0; + } + return !1; + }, + _looksLikeYearField: function (e, t) { + if ( + !this._isAutoFillableTextField(e) && + !this._isAutoFillableSelectElement(e) + ) + return !1; + if (elementIDOrAutocompleteTokensHasToken(e, t, "cc-exp-year")) return !0; + if ( + null !== + this._cachedElementPatternMatch( + e, + "_yearFieldPatternMatch", + "yearFieldLabelPatternMatchers", + ) + ) + return !0; + if ("select" !== this._getTagName(e).toLowerCase()) return !1; + var o = selectElementOptionsSequenceAnalysis(e, "text"), + r = o.lengthOfLongestSequence, + n = o.lastNumberInSequence; + const i = 3; + return r >= e.options.length - i && 1e3 < n && n < 3e3; + }, + _looksLikeOneTimeCodeField: function (e, t, o, r, n, i) { + if ( + !this._isAutoFillableTextField(e) && + !this._isAutoFillableSelectElement(e) + ) + return !1; + if (elementIDOrAutocompleteTokensHasToken(e, t, "one-time-code")) + return !0; + const l = e.type; + if ("password" === l) { + if (/^(.+\.)?chase\.com\.?$/.test(document.location.hostname)) + return !1; + if (this._matchesPasswordFieldLabelPattern(e)) return !1; + } + if ( + /^(.+\.)?amazon\.(com|ae|com\.au|com\.br|ca|fr|de|in|it|com\.mx|nl|es|com\.tr|co\.uk|sa|sg|se|pl)\.?$/.test( + document.location.hostname, + ) + ) { + const t = /claim|promo/i; + if (t.test(e.id) || t.test(e.name)) return !1; + } + if ( + null !== + this._cachedElementPatternMatch( + e, + "_oneTimeCodePatternMatch", + "oneTimeCodeFieldLabelPatternMatchers", + ) + ) + return !0; + const a = e.getAttribute("maxlength"), + s = a ? parseInt(a) : void 0; + if ( + isFiniteNumber(s) && + s > + MaxLengthForFieldAboveWhichToTreatPotentialOneTimeCodeFieldAsRequiringHigherScrutiny + ) { + if (!n) return !1; + if ( + i.ControlLooksLikeIgnoredDataTypeField || + i.ControlLooksLikeCreditCardCardholderField || + i.ControlLooksLikeCreditCardNumberField || + i.ControlLooksLikeCreditCardSecurityCodeField || + i.ControlLooksLikeCreditCardTypeField || + i.AddressBookLabel + ) + return !1; + } + let u = e.pattern; + if (u) { + let e = regularExpressionFromUntrustedPatternAttributeString(u); + if ( + e && + (e.test("1234") || e.test("123456") || e.test("12345678")) && + !e.test("a") && + !e.test("A") + ) + return !0; + } + const c = "number" === l || "tel" === l; + if (1 === s) { + if (c || o || r) return !0; + const t = this._cachedOneTimeCodePatternMatcher(), + n = e.closest("fieldset"), + i = n?.querySelector("legend"); + if (i) { + if ( + e === (n ? Array.from(queryAllBySelector(n, "input")) : [])[0] && + this._matchPatternAgainstString(t, i.innerText) + ) + return !0; + } + for (let t of [n, e.parentElement, e.closest('*[role~="dialog"]')]) { + if (!t) continue; + const o = Array.from(queryAllBySelector(t, "input")), + r = o.length; + if (6 === r || 8 === r) { + if (e === o[0] && o.every((e) => 1 === parseInt(e.maxLength))) + return !0; + } + } + } + const d = + null !== + this._cachedElementPatternMatch( + e, + "_weakOneTimeCodePatternMatch", + "weakOneTimeCodeFieldLabelPatternMatchers", + ); + if (c && d) return !0; + const h = e.placeholder; + if (h && d && /^[#]+$/.test(h.replace(/ /g, ""))) return !0; + const m = (function () { + if (isFiniteNumber(s)) return s; + const e = h?.length; + return e && e < 10 && h === h[0].repeat(e) ? e : void 0; + })(); + if ((4 === m || 6 === m) && d) return !0; + if (7 === s && h && /\d{3} \d{3}/.test(h)) return !0; + if (this._isAutofocusedTextField(e)) { + if (d) return !0; + if ("0" === e.min && "9" === e.max) return !0; + } + if (n) { + let t = 0; + (d && t++, o && t++, r && t++, (4 !== m && 6 !== m) || t++); + const n = this._cachedOneTimeCodePatternMatcher(), + i = this._logicalFormsCache.logicalFormForControl(e); + if (i) { + const e = i.backingElement; + if (e) { + let o = !1; + for (let r of Array.from( + querySelectorAllIncludingWithinShadowRoots(e, "h1, h2, h3"), + )) { + let e = r.innerText.trim(); + if (e.length) { + this._matchPatternAgainstString(n, e) && ((o = !0), t++); + break; + } + } + if (!o) { + const o = e.closest("section")?.querySelector("h1, h2, h3"); + o && this._matchPatternAgainstString(n, o.innerText) && t++; + } + this._matchPatternAgainstString(n, e.getAttribute("id")) && t++; + } + } + const l = e.dataset.valRequired; + if ( + ("string" == typeof l && this._matchPatternAgainstString(n, l) && t++, + t >= 2) + ) + return !0; + const a = function (e) { + if (this._matchPatternAgainstString(n, e)) return !0; + const t = e.replaceAll("-", " "); + return e !== t && this._matchPatternAgainstString(n, t); + }.bind(this), + s = window.location.protocol, + u = "http:" === s || "https:" === s, + c = lastPathComponentFromAnchor(window.location); + if (u && c && a(c)) return !0; + { + const e = document.querySelector("link[rel=canonical]"), + t = e ? lastPathComponentForURLString(e.href) : null; + if (t && a(t)) return !0; + } + if (this._matchFromPageScanBeforeElement(n, e, document.body)) + return !0; + } + return !1; + }, + _looksLikeIgnoredDataTypeField: function (e, t) { + return ( + !!this._isAutoFillableTextField(e) && + !t?.length && + null !== + this._cachedElementPatternMatch( + e, + "_ignoredDataTypePatternMatch", + "ignoredDataTypeFieldLabelPatternMatchers", + ) + ); + }, + _collectTextSample: function (e) { + if (!e) return ""; + var t, + o = "", + r = e; + do { + ((t = (o = r.innerText.replace(/\s+/g, " ").trim()).length), + (r = r.parentElementIncludingShadowDOMHost())); + } while ( + t < MaximumNumberOfCharactersToCollectForLanguageIdentification && + r + ); + return ( + t > MaximumNumberOfCharactersToCollectForLanguageIdentification && + (o = o.substr( + 0, + MaximumNumberOfCharactersToCollectForLanguageIdentification, + )), + o + ); + }, + _explicitMaxLength: function (e) { + var t = e.getAttribute("maxlength"); + return t ? parseInt(t) : void 0; + }, + _explicitMinLength: function (e) { + let t = e.getAttribute("minlength"); + return t ? parseInt(t) : void 0; + }, + _observedMaxLength: function (e) { + const t = 20; + if ("password" !== e.type) return null; + const o = e.getAttribute("ng-pattern"); + if (!o) return null; + if (!o.startsWith("/") || !o.endsWith("/")) return null; + let r = regularExpressionFromUntrustedPatternAttributeString(o); + if (!r) return null; + let n, + i = "a1Abbb", + l = !1; + for (; i.length <= t; ) { + let e = r.test(i); + if (l && !e) return n; + (e && ((l = !0), (n = i.length)), (i += "b")); + } + return null; + }, + _collectControlMetadata: function (e, t, o, r, n, i, l) { + var a = { + ControlTagName: this._getTagName(e), + ControlFieldName: this._getNameOrId(e), + ControlUniqueID: this.controlUniqueID(e), + }; + (e === innermostActiveElement() && (a.ControlIsActiveElement = !0), + this._isAutoFilledTextField(e) && (a.ControlIsAutoFilledTextField = !0), + e.disabled && (a.ControlIsDisabled = !0), + e.readOnly && (a.ControlIsReadOnly = !0), + this._isTextField(e) && (a.ControlIsTextField = !0), + this._isSecureTextField(e) && (a.ControlIsSecureTextField = !0), + this._isLabeledUsernameField(e) && + (a.ControlIsLabeledUsernameField = !0), + this._elementDisallowsAutocomplete(e) && (a.DisallowsAutocomplete = !0), + this._isAutofocusedTextField(e) && + (a.ControlIsAutofocusedTextField = !0)); + const s = e.className; + s && s.length && (a.ControlFieldClass = s); + const u = e.id; + u && u.length && (a.ControlFieldID = u); + const c = e.value; + c && (a.ControlValue = c); + const d = this._associatedUsernameForControl(e); + d && (a.ControlAssociatedUsername = d); + const h = e.maxLength; + if (-1 !== h) a.ControlMaxLength = h; + else { + const t = this._observedMaxLength(e); + t && (a.ControlMaxLength = t); + } + const m = this._explicitMinLength(e); + m && m > 0 && (a.ControlMinLength = m); + const F = e.size; + (F > 0 && (a.ControlSize = F), + e.isVisible() && (a.IsVisible = !0), + isDateTimeInputElement(e) && + (a.ControlRequiredFormatForDateTimeInput = + this._requiredFormatForDateTimeInput[e.type])); + var f = autocompleteTokens(e); + (f && + ((a.AutocompleteTokens = f), + -1 !== f.indexOf("username") + ? (a.ControlClaimsToBeUsernameViaAutocompleteAttribute = !0) + : -1 !== f.indexOf("current-password") + ? (a.ControlClaimsToBeCurrentPasswordViaAutocompleteAttribute = !0) + : -1 !== f.indexOf("new-password") && + (a.ControlClaimsToBeNewPasswordViaAutocompleteAttribute = !0)), + this._looksLikePasswordCredentialField(e) && + ((a.ControlLooksLikePasswordCredentialField = !0), + "function" == typeof this._collectExtraControlMetadata && + this._collectExtraControlMetadata(e, a), + a.IsVisible && + !o && + (a.IsVisible = !isElementPositionedToBeEffectivelyInvisible(e)))); + let g = t === WBSFormMetadataRequestPreFill, + p = a.ControlIsActiveElement || !g; + if (p) { + const t = this._collectSelectElementInfo(e); + (t && (a.SelectElementInfo = t), + this._isVerticalWritingMode(e) && + (a.ControlIsVerticalWritingMode = !0)); + var C = placeholderInfoForElement(e); + C && !C.AttributeMatchedWasValue && (a.ControlPlaceholder = C.Text); + } + if ( + (this._looksLikeIgnoredDataTypeField(e, f) + ? (a.ControlLooksLikeIgnoredDataTypeField = !0) + : this._looksLikeCreditCardCardholderField(e, f) + ? (a.ControlLooksLikeCreditCardCardholderField = !0) + : this._looksLikeCreditCardNumberField(e, f) + ? (a.ControlLooksLikeCreditCardNumberField = !0) + : this._looksLikeCreditCardSecurityCodeField(e, f) + ? (a.ControlLooksLikeCreditCardSecurityCodeField = !0) + : this._looksLikeCreditCardTypeField(e, f) && + (a.ControlLooksLikeCreditCardTypeField = !0), + p && + (this._looksLikeMonthField(e, f) + ? (a.ControlLooksLikeMonthField = !0) + : this._looksLikeYearField(e, f) + ? (a.ControlLooksLikeYearField = !0) + : this._looksLikeDayField(e) + ? (a.ControlLooksLikeDayField = !0) + : !a.ControlLooksLikeCreditCardSecurityCodeField && + this._looksLikeCreditCardCompositeExpirationDateField(e, f) && + (a.ControlLooksLikeCreditCardCompositeExpirationDateField = + !0)), + g || + (this._looksLikeEIDField(e, f) + ? (a.ControlLooksLikeEIDField = !0) + : this._looksLikeIMEIField(e, f) && + (a.ControlLooksLikeIMEIField = !0)), + g || + a.ControlLooksLikeIgnoredDataTypeField || + a.ControlIsSecureTextField || + a.ControlLooksLikeCreditCardNumberField || + a.ControlLooksLikeCreditCardSecurityCodeField || + a.ControlLooksLikeCreditCardTypeField || + a.ControlLooksLikeCreditCardCompositeExpirationDateField || + a.ControlLooksLikeEIDField || + a.ControlLooksLikeIMEIField || + (a.AddressBookLabel = this._addressBookLabelForElement(e)), + a.ControlIsActiveElement || t === WBSFormMetadataRequestTesting || l) + ) { + let t = i && a.IsVisible; + this._looksLikeOneTimeCodeField(e, f, r, n, t, a) && + (a.ControlLooksLikeOneTimeCodeField = !0); + } + return ( + t === WBSFormMetadataRequestTesting && + globalThis.WAS && + (a.ControlNodePath = WAS.NodePath.fromNode(e)?.objectRepresentation), + a + ); + }, + _usesGeneratedPassword: function (e) { + for ( + var t = !1, o = this._elementsWithGeneratedPasswords.length, r = 0; + r < o; + ++r + ) { + var n = this._elementsWithGeneratedPasswords[r]; + if (e.containsControl(n)) { + if (n.value !== this._generatedPasswords[r]) return !1; + t = !0; + } + } + return t; + }, + _associatedUsernameForControl: function (e) { + return this._isAutoFillableTextField(e) + ? e.getAttribute("data-username") + : null; + }, + _collectSelectElementInfo: function (e) { + if (!this._isAutoFillableSelectElement(e)) return null; + if (!e.options.length) return null; + for (var t = [], o = e.options, r = o.length, n = 0; n < r; ++n) { + var i = o[n]; + i.disabled || + ((i.label || i.text) && t.push([n, i.label ? i.label : i.text])); + } + return t.length ? t : null; + }, + _stringsToInspectForDeterminingFormType: function (e) { + let t = [], + o = e.formElement, + r = o.getAttribute("id"), + n = o.getAttribute("name"); + (r && t.push(r), n && t.push(n)); + let i = queryAllBySelector(o, "legend"); + 1 === i.length && t.push(i[0].innerText); + let l = 0; + for (let e of this._logicalFormsCache.cachedForms()) + e.formElement.isVisible() && l++; + const a = 0.8; + if ( + 1 === l && + o.isVisible() && + !o.ownerDocument.defaultView.frameElement && + o.getBoundingClientRect().top < + a * document.documentElement.clientHeight + ) { + let e = documentTitleWithoutHostNamePrefix(); + e && t.push(e); + const o = lastPathComponentFromAnchor(window.location); + o && o.length && t.push(o); + } + let s = []; + if (o.isVisible()) { + const e = function (e, t) { + return ( + (t.left <= e.left && + e.right <= t.right && + e.distanceToRect(t) < 100) || + (e.left - t.left == t.right - e.right && e.distanceToRect(t) < 200) + ); + }; + let r = o.getBoundingClientRect(), + n = !1; + for ( + let i = 0, l = o; + i <= 2 && l; + ++i, l = l.parentElementIncludingShadowDOMHost() + ) { + let o = Array.prototype.slice.call( + queryAllBySelector( + l, + "h1, h2, h3, [class*='header' i], [class*='heading' i]", + ), + ), + i = [[], [], [], []]; + for (headerElement of o) { + let e = headerElement.tagName; + "H1" === e + ? i[0].push(headerElement) + : "H2" === e + ? i[1].push(headerElement) + : "H3" === e + ? i[2].push(headerElement) + : i[3].push(headerElement); + } + let a = !0; + for (headerElementsOfType of i) { + let o = headerElementsOfType.length; + if (0 === o) { + a = !1; + continue; + } + if (o > 1) break; + let i = headerElementsOfType[0]; + if (!i.isVisible()) break; + e(i.getBoundingClientRect(), r) && (t.push(i.innerText), (n = !0)); + break; + } + if (a) break; + } + const i = 100; + for ( + let l = o.traversePreviousElement(), a = 0; + l && a < i; + l = l.traversePreviousElement(), a++ + ) + if (l.matches("h1, h2, h3")) { + e(l.getBoundingClientRect(), r) && (t.push(l.innerText), (n = !0)); + break; + } + if (!n) { + let o = queryAllBySelector(document.documentElement, "h1"); + if (1 === o.length) { + let n = o[0]; + e(n.getBoundingClientRect(), r) && t.push(n.innerText); + } + } + for ( + let e = 0, t = o; + e <= 2 && t; + ++e, t = t.parentElementIncludingShadowDOMHost() + ) { + let e = Array.prototype.slice + .call(queryAllBySelector(t, "button, input[type=submit]")) + .filter(function (e) { + if (!e.isVisible()) return !1; + let t = e.getBoundingClientRect(); + return ( + t.top > r.bottom && + !o.contains(e) && + r.left <= t.left && + t.right <= r.right && + t.distanceToRect(r) < 100 + ); + }); + if (e.length) { + s = e; + break; + } + } + } + let u = !1, + c = [], + d = e.elements.concat(s); + for (const e of d) { + const o = e.type; + ("password" === o && (u = !0), + ("submit" !== o && "button" !== o) || + (u && + (e.isVisible() + ? this._addInterestingStringsForButton(e, t) + : c.push(e)))); + } + if (0 === t.length) + for (control of c) this._addInterestingStringsForButton(control, t); + return t; + }, + _addInterestingStringsForButton: function (e, t) { + const o = e.getAttribute("id"); + o && t.push(o); + const r = e.getAttribute("value"); + r && t.push(r); + const n = e.innerText; + n && n.length > 0 && t.push(n); + }, + _autoFillFormTypeOfTypesUsingKeywordMatching: function (e, t, o, r) { + for (var n = t.length, i = [], l = 0; l < n; ++l) { + var a = (0, mapOfFormTypeToProducerOfAssociatedKeywords[t[l]])(); + i.push(a); + } + var s = this._stringsToInspectForDeterminingFormType(e), + u = this._regularExpressionsIndicatingNonAutoFillableFormType; + u || + ((u = regularExpressionsFromStrings( + FormMetadataJSController.regularExpressionsIndicatingNonAutoFillableFormType, + )), + (this._regularExpressionsIndicatingNonAutoFillableFormType = u)); + var c = u.length, + d = []; + for (l = 0; l < n; ++l) d.push(0); + if (r) + for (const [e, o] of Object.entries(r)) d[t.indexOf(parseInt(e))] += o; + for (var h = s.length, m = 0; m < h; ++m) { + for (var F = s[m].toLowerCase(), f = 0; f < c; ++f) + if (u[f].test(F)) return WBSAutoFillFormTypeNonAutoFillable; + for (l = 0; l < n; ++l) { + a = i[l]; + for (var g in a) -1 !== F.indexOf(g) && (d[l] += a[g]); + } + } + for (let o = 0; o < n; ++o) { + const r = this._mapOfFormTypeToExtraScoreProducer[t[o]]; + d[o] += r(e); + } + for (l = 0; l < n; ++l) 0 !== d[l] && 0; + var p = formActionAsAnchorElement(e.formElement, !0); + if (p) { + var C = p.pathname.toLowerCase() + p.search.toLowerCase(); + for (l = 0; l < n; ++l) { + a = i[l]; + for (var g in a) -1 !== C.indexOf(g) && (d[l] += a[g]); + } + } + var A = [], + _ = 0; + for (l = 0; l < n; ++l) { + var b = d[l]; + b > 0 && (b >= _ ? ((_ = b), A.unshift(l)) : A.push(l)); + } + if (1 === A.length) return t[A[0]]; + if (A.length > 1) { + var y = A[0]; + if (d[y] > d[A[1]]) return t[y]; + } + return o; + }, + _matchesNonUsernameFieldLabelPattern: function (e) { + if ( + (this._nonUsernameFieldPatternMatchers || + (this._nonUsernameFieldPatternMatchers = + FormMetadataJSController.nonUsernameFieldLabelPatternMatchers), + this._bestMatchForElement(e, this._nonUsernameFieldPatternMatchers)) + ) + return !0; + const t = e.value; + if (!e.id && !e.name && t && e.disabled) + for (const e of this._nonUsernameFieldPatternMatchers) + if (this._matchPatternAgainstString(e, t)) return !0; + return !1; + }, + _matchSearchFieldLabelPattern: function (e) { + if ( + (this._searchFieldLabelPatternMatchers || + (this._searchFieldLabelPatternMatchers = + FormMetadataJSController.searchFieldLabelPatternMatchers), + this._bestMatchForElement(e, this._searchFieldLabelPatternMatchers, !0)) + ) + return !0; + const t = e.value; + if (!e.id && !e.name && t && e.disabled) + for (const e of this._searchFieldLabelPatternMatchers) + if (this._matchPatternAgainstString(e, t)) return !0; + return !1; + }, + _matchesNonEmailFieldLabelPattern: function (e) { + return ( + this._nonEmailFieldPatternMatchers || + (this._nonEmailFieldPatternMatchers = + FormMetadataJSController.nonEmailFieldLabelPatternMatchers), + !!this._bestMatchForElement(e, this._nonEmailFieldPatternMatchers) + ); + }, + _scoreForUsernameFieldCandidateFromLabelingAndPositionOfField: function ( + e, + t, + o, + ) { + return this._isLabeledUsernameField(e) + ? t + ? UsernameCandidateScoreForUsernameLabeledFieldBelowPasswordField + : UsernameCandidateScoreForUsernameLabeledFieldAbovePasswordField + : this._isLabeledEmailField(e) && + !this._matchesNonEmailFieldLabelPattern(e) + ? t + ? UsernameCandidateScoreForEmailLabeledFieldBelowPasswordField + : UsernameCandidateScoreForEmailLabeledFieldAbovePasswordField + : o + ? UsernameCandidateScoreForPlainTextFieldDirectlyBeforePasswordField + : UsernameCandidateScoreForPlainTextField; + }, + _scoreForUsernameFieldCandidate: function (e, t, o) { + var r = + this._scoreForUsernameFieldCandidateFromLabelingAndPositionOfField( + e, + t, + o, + ); + return ( + e.isVisible() && (r += UsernameCandidateScoreBonusForVisibleElement), + this._matchesNonUsernameFieldLabelPattern(e) && + (r -= + UsernameCandidateScorePenaltyForMatchingNonUsernameFieldLabelPattern), + this._matchSearchFieldLabelPattern(e) && + (r -= + UsernameCandidateScorePenaltyForMatchingSearchFieldLabelPattern), + e.readOnly && (r -= UsernameCandidateScorePenaltyForReadOnlyElement), + e.id || + e.name || + (r -= UsernameCandidateScorePenaltyForAnonymousElement), + r + ); + }, + _matchesPasswordFieldLabelPattern: function (e) { + return ( + this._passwordFieldPatternMatchers || + (this._passwordFieldPatternMatchers = + FormMetadataJSController.passwordFieldLabelPatternMatchers), + !!this._bestMatchForElement(e, this._passwordFieldPatternMatchers) + ); + }, + _matchesConfirmPasswordFieldLabelPattern: function (e, t = !1) { + return ( + this._confirmPasswordFieldPatternMatchers || + (this._confirmPasswordFieldPatternMatchers = + FormMetadataJSController.confirmPasswordFieldLabelPatternMatchers), + !!this._bestMatchForElement( + e, + this._confirmPasswordFieldPatternMatchers, + t, + ) + ); + }, + _matchesConfirmEmailFieldLabelPattern: function (e) { + return ( + !!this._isLabeledEmailField(e) && + (this._confirmEmailFieldPatternMatchers || + (this._confirmEmailFieldPatternMatchers = + FormMetadataJSController.confirmEmailFieldLabelPatternMatchers), + !!this._bestMatchForElement(e, this._confirmEmailFieldPatternMatchers)) + ); + }, + _collectRadioButtonInfo: function (e, t) { + function o(e, t) { + var o = e.trim(); + o && t.push(o); + } + function r(e, t) { + (o(e.alt, t), + o(e.title, t), + o(lastPathComponentForURLString(e.src), t)); + } + function n(e) { + let t = []; + o(e.innerText, t); + let n = queryAllBySelector(e, "img"), + i = n.length; + for (let e = 0; e < i; ++e) r(n[e], t); + return t.length ? t : null; + } + for ( + var i = e.radioButtonsWithName(t), l = i.length, a = !1, s = {}, u = 0; + u < l; + ++u + ) { + s[(f = i[u]).value] = [f.value]; + for ( + var c = this._labelsForElement(f), d = c.length, h = 0; + h < d; + ++h + ) { + a = !0; + var m = n(c[h]); + m && (s[f.value] = s[f.value].concat(m)); + } + } + if (a) return s; + const F = 64; + for (u = 0; u < l; ++u) { + for ( + var f, g = "", p = (f = i[u]).traverseNextNode(); + p && !this._isRenderedFormControl(p); + p = p.traverseNextNode() + ) { + var C = p.localName; + if ( + "td" === C || + "tr" === C || + "ul" === C || + "ol" === C || + "dl" === C + ) + break; + if (p instanceof HTMLImageElement) r(p, s[f.value]); + else if (p.nodeType === Node.TEXT_NODE) { + var A = p.nodeValue.trim(); + if ((A && (g += A.substr(0, F - g.length)), g.length >= F)) break; + } + } + g && s[f.value].push(g); + } + return s; + }, + _bestUsernameFieldCandidate: function (e, t, o) { + var r = t.FormControls, + n = r.filter(function (e) { + return e.ControlClaimsToBeUsernameViaAutocompleteAttribute; + }); + if (1 === n.length) return n[0]; + for ( + var i = 0, l = [], a = !1, s = r.indexOf(o), u = r.length, c = 0; + c < u; + ++c + ) { + var d = r[c]; + if (d === o) { + a = !0; + continue; + } + if (!d.ControlIsTextField || d.ControlIsSecureTextField) continue; + if (t.IsVisible && !r[c].IsVisible && !d.ControlValue) continue; + const n = 100; + let F = e[c]; + if (!(F.value.length > n)) { + var h = c + 1 < u && c + 1 === s, + m = this._scoreForUsernameFieldCandidate(F, a, h); + m > i ? ((l = [c]), (i = m)) : m === i && l.push(c); + } + } + var F = l.length; + if (i < LowestScoreForLabeledUsernameFieldCandidate && F > 1) return null; + if (i < LowestScoreForUsernameFieldCandidate) return null; + switch (F) { + case 0: + return null; + case 1: + return r[l[0]]; + default: + var f = e[s].getBoundingClientRect(), + g = {}; + return ( + l.forEach(function (t) { + g[t] = f.distanceToRect(e[t].getBoundingClientRect()); + }), + r[ + l.sort(function (e, t) { + return g[e] - g[t]; + })[0] + ] + ); + } + }, + _autoFillFormTypeFromCandidateFormTypes: function (e, t, o) { + switch (t.length) { + case 1: + return t[0]; + case 2: + return this._autoFillFormTypeOfTypesUsingKeywordMatching( + e, + [t[0], t[1]], + o, + ); + default: + return WBSAutoFillFormTypeAutoFillableStandard; + } + }, + _shouldTrustElementThatClaimsToBeCurrentPasswordViaAutocompleteAttribute: + function (e) { + return !e.dataset.valRegexPattern; + }, + _identifyFormTypeAndPasswordFieldIndicesFromAutocompleteAttributes: + function (e, t) { + const o = [null, null]; + if (/^(.+\.)?roll20\.net\.?$/.test(document.location.hostname)) + return o; + var r = t.length; + if (r > 3) return o; + for (var n = [], i = [], l = 0; l < r; ++l) { + var a = t[l]; + a.ControlClaimsToBeCurrentPasswordViaAutocompleteAttribute && + this._shouldTrustElementThatClaimsToBeCurrentPasswordViaAutocompleteAttribute( + e[l], + ) + ? n.push(l) + : a.ControlClaimsToBeNewPasswordViaAutocompleteAttribute && + i.push(l); + } + var s = n.length, + u = i.length; + if (s + u !== r) return o; + switch (r) { + case 0: + return o; + case 1: + if (s) return [null, null, WBSAutoFillFormTypeAutoFillableLogin]; + if (u) return [null, null, WBSAutoFillFormTypeNewAccount]; + case 2: + if (1 === s && 1 === u) + return [ + [WBSAutoFillFormTypeChangePassword], + { OldPasswordFieldIndex: n[0], PasswordFieldIndex: i[0] }, + ]; + if (0 === s && 2 === u) + return [ + [ + WBSAutoFillFormTypeNewAccount, + WBSAutoFillFormTypeChangePassword, + ], + { PasswordFieldIndex: i[0], ConfirmationFieldIndex: i[1] }, + ]; + break; + case 3: + if (1 === s && 2 === u) + return [ + [WBSAutoFillFormTypeChangePassword], + { + OldPasswordFieldIndex: n[0], + PasswordFieldIndex: i[0], + ConfirmationFieldIndex: i[1], + }, + ]; + } + return o; + }, + _identifyPasswordFieldIndices: function (e, t) { + var o = e.length; + if (0 === o) return {}; + if (1 === o) return { PasswordFieldIndex: 0 }; + if ( + (this._oldPasswordPatternMatchers || + (this._oldPasswordPatternMatchers = + FormMetadataJSController.oldPasswordFieldLabelPatternMatchers), + 2 === o) + ) { + return this._bestMatchForElement(t[0], this._oldPasswordPatternMatchers) + ? { OldPasswordFieldIndex: 0, PasswordFieldIndex: 1 } + : this._bestMatchForElement(t[1], this._oldPasswordPatternMatchers) + ? { OldPasswordFieldIndex: 1, PasswordFieldIndex: 0 } + : { PasswordFieldIndex: 0, ConfirmationFieldIndex: 1 }; + } + return this._bestMatchForElement( + t[o - 1], + this._oldPasswordPatternMatchers, + ) + ? { + PasswordFieldIndex: o - 3, + ConfirmationFieldIndex: o - 2, + OldPasswordFieldIndex: o - 1, + } + : { + PasswordFieldIndex: o - 2, + ConfirmationFieldIndex: o - 1, + OldPasswordFieldIndex: o - 3, + }; + }, + _removePlaceholderTextForFormMetadata: function (e, t) { + for (var o = e.length, r = 0; r < o; ++r) { + var n = t.FormControls[r]; + if ( + n.ControlValue && + n.ControlIsTextField && + !n.ControlIsSecureTextField && + !n.ControlIsReadOnly + ) { + var i = legacyPlaceholderInfoForInputElement(e[r]); + i && + ((i.AttributeMatchedWasValue && + n.ControlUniqueID === t.UsernameElementUniqueID) || + (n.ControlValue = "")); + } + } + }, + _isPasswordConfirmPair: function (e, t) { + var o = this._matchesPasswordFieldLabelPattern(e), + r = this._matchesConfirmPasswordFieldLabelPattern(t); + return o && r; + }, + _trailingArgumentsForCollectControlMetadataFunction: function (e, t, o) { + let r = isElementPositionedToBeEffectivelyInvisible(e.backingElement), + n = !1, + i = !1; + if (innermostActiveElement() || t === WBSFormMetadataRequestTesting) { + let e = this._cachedOneTimeCodePatternMatcher(); + if ( + ((n = !!this._matchPatternAgainstString( + e, + documentTitleWithoutHostNamePrefix(), + )), + o) + ) { + let t = location.pathname.split("/"), + r = stripCommonPrefix(o.pathname.split("/"), t)[0].join("/"); + r.length && (i = !!this._matchPatternAgainstString(e, r)); + } + } + let l = !1; + for (let t of e.elements) + if (this._isTextField(t) && t.isVisible()) { + if (l) { + l = !1; + break; + } + l = !0; + } + return [r, i, n, l]; + }, + _collectFormMetadata: function (e, t) { + var o, + r, + n = + ((r = 0), + { + backwardScanCache: new WeakMap(), + forwardScanCache: new WeakMap(), + shouldUsePageScan: function () { + return ( + r < + numberOfConsecutiveElementsWithoutSuccessfulPageScanAfterWhichPageScanIsAbandoned + ); + }, + willStartCollectingMetadataForControl: function () { + o = null; + }, + reportPageScanUsedSuccessfully: function (e) { + o = !(!e && !o); + }, + didFinishCollectingMetadataForControl: function () { + !0 === o ? (r = 0) : !1 === o && r++; + }, + }); + this._pageScanContext = n; + var i = e.formElement, + l = { + FormID: e.formUniqueID, + ContainsActiveElement: !1, + FormControls: [], + AutoFillFormType: WBSAutoFillFormTypeAutoFillableStandard, + UsernameElementUniqueID: void 0, + OldPasswordElementUniqueID: void 0, + PasswordElementUniqueID: void 0, + ConfirmPasswordElementUniqueID: void 0, + UsesGeneratedPassword: this._usesGeneratedPassword(e), + FirstCreditCardCardholderFieldOrCreditCardNumberFieldUniqueID: void 0, + IsVisible: i.isVisible(), + TextSample: void 0, + RequestType: t, + }; + (this._elementDisallowsAutocomplete(i) && (l.DisallowsAutocomplete = !0), + i instanceof HTMLFormElement && + (l.FormIsSearchForm = this._isSearchForm(i, !0)), + e.isAnnotated && (l.Annotations = e.annotations)); + var a = i.getAttribute("rel"); + a && "async" === a.toLowerCase() && (l.FormUsesRelAsync = !0); + let s = formActionAsAnchorElement(i); + if ( + (s && s.href && (l.FormAction = s.href), + t == WBSFormMetadataRequestCollectMetadataFromDebugMenu || + t == WBSFormMetadataRequestTesting) + ) { + let e = selectorForElement(i); + e && e.length && (l.LogicalFormElementSelector = e); + } + var u = e.elements, + c = !u.some(this._isSecureTextField.bind(this)); + let [d, h, m, F] = + this._trailingArgumentsForCollectControlMetadataFunction(e, t, s); + var f = 0, + g = !1, + p = [], + C = [], + A = [], + _ = [], + b = void 0, + y = void 0, + S = void 0, + T = void 0, + E = !1, + I = !1, + v = {}, + P = []; + let w = !1; + for (var L = u.length, M = 0; M < L; ++M) { + var x = u[M]; + if (c && !x.isVisible() && !x._relatesToCredentials) continue; + var k = isRadioButtonElement(x), + B = x.name; + if (k && v[B]) continue; + n.willStartCollectingMetadataForControl(); + const o = !w; + var U = this._collectControlMetadata(x, t, d, h, m, F, o); + if ( + (n.didFinishCollectingMetadataForControl(), + (w = !0), + M + 1 < L && + (U.ControlNextFieldUniqueID = this.controlUniqueID(u[M + 1])), + l.FormControls.push(U), + P.push(x), + U.IsVisible || !l.IsVisible || x._relatesToCredentials) + ) + if ( + (U.ControlIsActiveElement && (l.ContainsActiveElement = !0), B && k) + ) + ((v[B] = 1), + (U.ControlValue = ""), + (U.RadioButtonInfo = this._collectRadioButtonInfo(e, B))); + else if (U.ControlIsTextField || U.SelectElementInfo) + if ( + (!I && U.ControlLooksLikeCreditCardSecurityCodeField && (I = !0), + E || + (!U.ControlLooksLikeCreditCardCardholderField && + !U.ControlLooksLikeCreditCardNumberField)) + ) { + if ( + !( + U.ControlLooksLikeDayField || + U.ControlLooksLikeMonthField || + U.ControlLooksLikeYearField || + U.ControlLooksLikeCreditCardCompositeExpirationDateField + ) + ) { + if (U.ControlLooksLikePasswordCredentialField) { + if ( + U.ControlLooksLikeCreditCardSecurityCodeField || + U.ControlLooksLikeCreditCardNumberField || + U.ControlLooksLikeIgnoredDataTypeField + ) + continue; + x.isHiddenFromAccessibilityTree() + ? (A.push(x), _.push(U)) + : (p.push(x), C.push(U)); + } + if (this._isLabeledEmailField(x)) { + if (++f > 2) { + g = !1; + continue; + } + if ( + !( + M + 1 < L && + this._matchesConfirmEmailFieldLabelPattern(u[M + 1]) + ) + ) + continue; + g = !0; + } + } + } else + ((E = !0), + (l.FirstCreditCardCardholderFieldOrCreditCardNumberFieldUniqueID = + U.ControlUniqueID)); + } + !p.length && A.length && ((p = A), (C = _)); + var D, + W, + N = + this._identifyFormTypeAndPasswordFieldIndicesFromAutocompleteAttributes( + p, + C, + ), + O = N[0], + q = N[1], + R = N[2], + V = q || this._identifyPasswordFieldIndices(C, p); + if ( + (void 0 !== V.PasswordFieldIndex && + ((b = C[V.PasswordFieldIndex]), + (l.PasswordElementUniqueID = b.ControlUniqueID), + (y = this._explicitMaxLength(p[V.PasswordFieldIndex]))), + void 0 !== V.ConfirmationFieldIndex && + ((S = C[V.ConfirmationFieldIndex]), + (l.ConfirmPasswordElementUniqueID = S.ControlUniqueID), + (T = this._explicitMaxLength(p[V.ConfirmationFieldIndex]))), + void 0 !== V.OldPasswordFieldIndex) + ) { + var H = C[V.OldPasswordFieldIndex]; + l.OldPasswordElementUniqueID = H.ControlUniqueID; + } + if ( + (b && (D = this._bestUsernameFieldCandidate(P, l, b)), + D + ? (l.UsernameElementUniqueID = D.ControlUniqueID) + : (W = this._findHiddenUsernameElement(e, l, P)), + O) + ) + l.AutoFillFormType = this._autoFillFormTypeFromCandidateFormTypes( + e, + O, + O[0], + ); + else if (1 === p.length && g) + l.AutoFillFormType = this._autoFillFormTypeOfTypesUsingKeywordMatching( + e, + [WBSAutoFillFormTypeNewAccount, WBSAutoFillFormTypeChangePassword], + WBSAutoFillFormTypeNewAccount, + ); + else if (l.UsernameElementUniqueID) + switch (p.length) { + case 0: + break; + case 1: + if ( + I && + l.UsernameElementUniqueID === + l.FirstCreditCardCardholderFieldOrCreditCardNumberFieldUniqueID && + C[0].ControlLooksLikeCreditCardNumberField + ) + break; + if (this._matchesConfirmPasswordFieldLabelPattern(p[0])) { + let t = {}; + (this._isElementFollowedByForgotPasswordAffordance(x, i) && + (t[WBSAutoFillFormTypeAutoFillableLogin] = 2), + (l.AutoFillFormType = + this._autoFillFormTypeOfTypesUsingKeywordMatching( + e, + [ + WBSAutoFillFormTypeNewAccount, + WBSAutoFillFormTypeChangePassword, + ], + R || WBSAutoFillFormTypeAutoFillableLogin, + t, + ))); + } else { + let t = p[0], + o = {}, + r = + 2 * + this._numberOfForgotUserNameEmailOrPasswordAffordancesFollowingElement( + t, + e.backingElement, + ); + (r && (o[WBSAutoFillFormTypeAutoFillableLogin] = r), + (l.AutoFillFormType = + this._autoFillFormTypeOfTypesUsingKeywordMatching( + e, + [ + WBSAutoFillFormTypeNewAccount, + WBSAutoFillFormTypeAutoFillableLogin, + ], + R || WBSAutoFillFormTypeAutoFillableLogin, + o, + ))); + } + break; + case 2: + y === T + ? (l.AutoFillFormType = + this._autoFillFormTypeOfTypesUsingKeywordMatching( + e, + [ + WBSAutoFillFormTypeNewAccount, + WBSAutoFillFormTypeChangePassword, + ], + WBSAutoFillFormTypeNewAccount, + )) + : T + ? this._isPasswordConfirmPair(p[0], p[1]) + ? (l.AutoFillFormType = + this._autoFillFormTypeOfTypesUsingKeywordMatching( + e, + [ + WBSAutoFillFormTypeNewAccount, + WBSAutoFillFormTypeChangePassword, + ], + WBSAutoFillFormTypeNonAutoFillable, + )) + : (l.AutoFillFormType = WBSAutoFillFormTypeNonAutoFillable) + : (l.AutoFillFormType = + this._autoFillFormTypeOfTypesUsingKeywordMatching( + e, + [ + WBSAutoFillFormTypeNewAccount, + WBSAutoFillFormTypeChangePassword, + ], + WBSAutoFillFormTypeNonAutoFillable, + )); + break; + case 3: + y === T || + !T || + this._isPasswordConfirmPair( + p[V.PasswordFieldIndex], + p[V.ConfirmationFieldIndex], + ) + ? (l.AutoFillFormType = WBSAutoFillFormTypeChangePassword) + : (l.AutoFillFormType = WBSAutoFillFormTypeNonAutoFillable); + break; + default: + l.AutoFillFormType = WBSAutoFillFormTypeNonAutoFillable; + } + else if (2 === p.length || 3 === p.length) + if (y !== T && T) + 2 === p.length + ? this._isPasswordConfirmPair(p[0], p[1]) + ? (l.AutoFillFormType = + this._autoFillFormTypeOfTypesUsingKeywordMatching( + e, + [ + WBSAutoFillFormTypeNewAccount, + WBSAutoFillFormTypeChangePassword, + ], + WBSAutoFillFormTypeNonAutoFillable, + )) + : (l.AutoFillFormType = WBSAutoFillFormTypeNonAutoFillable) + : this._isPasswordConfirmPair( + p[V.PasswordFieldIndex], + p[V.ConfirmationFieldIndex], + ) + ? (l.AutoFillFormType = WBSAutoFillFormTypeChangePassword) + : (l.AutoFillFormType = WBSAutoFillFormTypeNonAutoFillable); + else { + let t = {}; + (this._isPasswordConfirmPair( + p[V.PasswordFieldIndex], + p[V.ConfirmationFieldIndex], + ) && (t[WBSAutoFillFormTypeChangePassword] = 2), + (l.AutoFillFormType = + this._autoFillFormTypeOfTypesUsingKeywordMatching( + e, + [ + WBSAutoFillFormTypeNewAccount, + WBSAutoFillFormTypeChangePassword, + ], + WBSAutoFillFormTypeChangePassword, + t, + ))); + } + else if (1 === p.length) { + var Y = p[0]; + if (this._matchesConfirmPasswordFieldLabelPattern(Y, !0)) { + let t = {}; + (this._isElementFollowedByForgotPasswordAffordance(x, i) && + (t[WBSAutoFillFormTypeAutoFillableLogin] = 2), + (l.AutoFillFormType = + this._autoFillFormTypeOfTypesUsingKeywordMatching( + e, + [ + WBSAutoFillFormTypeAutoFillableLogin, + WBSAutoFillFormTypeChangePassword, + ], + WBSAutoFillFormTypeChangePassword, + t, + ))); + } else if (this._matchesPasswordFieldLabelPattern(Y)) + if (this._isElementFollowedByForgotPasswordAffordance(Y, i)) + l.AutoFillFormType = WBSAutoFillFormTypeAutoFillableLogin; + else { + var J = [ + WBSAutoFillFormTypeNewAccount, + WBSAutoFillFormTypeAutoFillableLogin, + WBSAutoFillFormTypeChangePassword, + ]; + ((l.AutoFillFormType = + this._autoFillFormTypeOfTypesUsingKeywordMatching( + e, + J, + WBSAutoFillFormTypeNonAutoFillable, + )), + l.AutoFillFormType === WBSAutoFillFormTypeNonAutoFillable && + W && + (l.AutoFillFormType = WBSAutoFillFormTypeNewAccount)); + } + else l.AutoFillFormType = WBSAutoFillFormTypeNonAutoFillable; + } else + 0 !== p.length && + (l.AutoFillFormType = WBSAutoFillFormTypeNonAutoFillable); + if (l.AutoFillFormType === WBSAutoFillFormTypeAutoFillableStandard) { + var G = null, + K = null, + z = null, + $ = 0, + j = P.length; + for (M = 0; M < j; ++M) { + x = P[M]; + var Z = l.FormControls[M], + X = Z.IsVisible; + if ((X && Z.ControlIsTextField && $++, $ > 1)) break; + if (x.closest("footer")) continue; + let t = {}; + this._isElementFollowedByForgotUserNameOrEmailAffordance(x, i) && + (t[WBSAutoFillFormTypeAutoFillableLogin] = 2); + var Q = this._isLabeledEmailField(x); + if ( + X && + (Z.ControlClaimsToBeUsernameViaAutocompleteAttribute || + Z.ControlIsLabeledUsernameField || + Q || + this._isLabeledLoginField(x)) && + !this._matchesNonUsernameFieldLabelPattern(x) && + !this._matchSearchFieldLabelPattern(x) && + !x.readOnly && + "INPUT" === x.tagName && + !this._isLabeledSignUpField(x) + ) { + let t = {}; + (this._isElementFollowedByForgotUserNameOrEmailAffordance(x, i) && + (t[WBSAutoFillFormTypeAutoFillableLogin] = 2), + this._autoFillFormTypeOfTypesUsingKeywordMatching( + e, + [ + WBSAutoFillFormTypeNewAccount, + WBSAutoFillFormTypeAutoFillableLogin, + ], + Q + ? WBSAutoFillFormTypeNewAccount + : WBSAutoFillFormTypeAutoFillableLogin, + t, + ) === WBSAutoFillFormTypeAutoFillableLogin && + ((G = x), (K = Z), (z = WBSAutoFillFormTypeAutoFillableLogin))); + } + const o = Z.AutocompleteTokens; + if (o) { + const r = o.includes("username"), + n = o.includes("webauthn"); + if (r && n) { + ((G = x), (K = Z), (z = WBSAutoFillFormTypeAutoFillableLogin)); + continue; + } + r && + Q && + ((G = x), + (K = Z), + (z = this._autoFillFormTypeOfTypesUsingKeywordMatching( + e, + [ + WBSAutoFillFormTypeNewAccount, + WBSAutoFillFormTypeAutoFillableLogin, + ], + WBSAutoFillFormTypeAutoFillableLogin, + t, + ))); + } + } + 1 === $ && + K && + z && + !controlAppearsToBePartOfPhotoTaggingInterface(G) && + ((l.AutoFillFormType = z), + (l.UsernameElementUniqueID = K.ControlUniqueID)); + } + (l.AutoFillFormType === WBSAutoFillFormTypeNewAccount && + l.FirstCreditCardCardholderFieldOrCreditCardNumberFieldUniqueID === + l.UsernameElementUniqueID && + (l.UsernameElementUniqueID = void 0), + !l.UsernameElementUniqueID && + W && + this._extractMetadataForHiddenUsernameElement(W, l, P), + l.AutoFillFormType != WBSAutoFillFormTypeAutoFillableLogin && + l.AutoFillFormType != WBSAutoFillFormTypeNewAccount && + l.AutoFillFormType != WBSAutoFillFormTypeChangePassword && + ((l.UsernameElementUniqueID = void 0), + (l.OldPasswordElementUniqueID = void 0), + (l.PasswordElementUniqueID = void 0), + (l.ConfirmPasswordElementUniqueID = void 0)), + l.IsVisible || + l.AutoFillFormType == WBSAutoFillFormTypeAutoFillableLogin || + l.AutoFillFormType == WBSAutoFillFormTypeNewAccount || + l.AutoFillFormType == WBSAutoFillFormTypeChangePassword || + (l.AutoFillFormType = WBSAutoFillFormTypeNonAutoFillable), + t !== WBSFormMetadataRequestPreFill && + (l.TextSample = this._collectTextSample(e.formElement)), + (l.FormIsEligibleForAutomaticLogin = + this._formIsEligibleForAutomaticLogin(l, e.backingElement))); + for (let e of l.FormControls) + if ( + e.ControlLooksLikeOneTimeCodeField && + this._oneTimeCodeIsEligibleForAutomaticLogin(e, l) + ) { + e.OneTimeCodeIsEligibleForAutomaticLogin = !0; + break; + } + if (l.IsVisible) + for (M = (j = P.length) - 1; M >= 0; --M) + this._shouldIncludeControlMetadata(l, P[M], l.FormControls[M]) || + (t !== WBSFormMetadataRequestCollectMetadataFromDebugMenu + ? (l.FormControls.splice(M, 1), P.splice(M, 1)) + : (l.FormControls[M].WOULD_NORMALLY_NOT_BE_SENT_TO_UI_PROCESS = + !0)); + return ( + this._removePlaceholderTextForFormMetadata(P, l), + delete this._pageScanContext, + t !== WBSFormMetadataRequestPreFill && + globalThis.FormMetadataClassificationJS && + globalThis.FormMetadataClassificationJS.classify(l), + l + ); + }, + _formIsEligibleForAutomaticLogin: function (e, t) { + if (e.AutoFillFormType !== WBSAutoFillFormTypeAutoFillableLogin) + return !1; + let o = !1; + for (const t of e.FormControls) { + const r = t.ControlUniqueID; + if (r === e.UsernameElementUniqueID || r === e.PasswordElementUniqueID) + continue; + if (t.ControlIsDisabled) continue; + if (t.ControlIsReadOnly) continue; + if (!t.IsVisible) continue; + const n = this.formControlWithUniqueID(r); + if (!n) continue; + if (this._isTextArea(n)) return !1; + if (this._isSelectElement(n)) return !1; + if (this._isSubmitButton(n)) continue; + if (this._looksLikeShowHidePasswordButton(n)) continue; + if (!isInputElement(n)) continue; + const i = n.type; + if ( + "button" !== i && + "reset" !== i && + "submit" !== i && + "image" !== i + ) { + if (!this._isCheckboxInputElement(n)) return !1; + if (o) return !1; + o = !0; + } + } + return !t || !elementAppearsToContinueCaptchaWidget(t); + }, + _oneTimeCodeIsEligibleForAutomaticLogin: function (e, t) { + for (const e of t.FormControls) { + if (e.ControlLooksLikeOneTimeCodeField) continue; + if (e.ControlIsDisabled) continue; + if (e.ControlIsReadOnly) continue; + if (!e.IsVisible) continue; + const t = this.formControlWithUniqueID(e.ControlUniqueID); + if (!t) continue; + if (this._isTextArea(t)) return !1; + if (this._isSelectElement(t)) return !1; + if (this._isSubmitButton(t)) continue; + if (this._looksLikeShowHidePasswordButton(t)) continue; + if (!isInputElement(t)) continue; + const o = t.type; + if ("button" !== o && "reset" !== o && "submit" !== o && "image" !== o) + return !1; + } + return !0; + }, + _shouldIncludeControlMetadata: function (e, t, o) { + if (t._relatesToCredentials) return !0; + if (o.IsVisible) { + if (formControlHasBeenClassifiedInAnInterestingWay(o)) return !0; + if (o.ControlValue) return !0; + } + return !( + !e.UsernameElementUniqueID || + o.ControlUniqueID !== e.UsernameElementUniqueID + ); + }, + _isElementAHiddenUsername: function (e) { + const t = /user|email/i; + return ( + "hidden" === e.type && + !(!t.test(e.getAttribute("id")) && !t.test(e.getAttribute("name"))) && + !!isValidUsernameOrEmail(e.value) + ); + }, + _findHiddenUsernameElement: function (e) { + var t = e.formElement; + if (!(t instanceof HTMLElement)) return; + let o = queryAllBySelector(t, "input"), + r = o.length; + for (let e = 0; e < r; ++e) { + let t = o[e]; + if (this._isElementAHiddenUsername(t)) return t; + } + return null; + }, + _extractMetadataForHiddenUsernameElement: function (e, t, o) { + var r = { + ControlTagName: this._getTagName(e), + ControlFieldName: this._getNameOrId(e), + ControlUniqueID: this.controlUniqueID(e), + ControlIsReadOnly: !0, + ControlValue: e.value, + }; + ((t.UsernameElementUniqueID = r.ControlUniqueID), + t.FormControls.push(r), + o.push(e)); + }, + _cachedMetadataForLogicalForm: function (e) { + var t = e.metadata, + o = t?.FormControls, + r = o?.length ?? 0; + if (!r) return null; + const n = innermostActiveElement(); + for (var i = 0; i < r; ++i) { + var l = o[i], + a = this.formControlWithUniqueID(l.ControlUniqueID); + a && + ((l.ControlIsActiveElement = a === n), + (l.ControlValue = a.value), + (l.ControlIsAutoFilledTextField = this._isAutoFilledTextField(a))); + } + return ( + (t.UsesGeneratedPassword = this._usesGeneratedPassword(e)), + (t.Annotations = e.annotations), + t + ); + }, + _markFormIsBestForPageLevelAutoFill: function () { + function e(e) { + switch (e) { + case WBSAutoFillFormTypeAutoFillableLogin: + return 30; + case WBSAutoFillFormTypeNewAccount: + case WBSAutoFillFormTypeChangePassword: + return 20; + case WBSAutoFillFormTypeAutoFillableStandard: + return 10; + case WBSAutoFillFormTypeUndetermined: + case WBSAutoFillFormTypeNonAutoFillable: + return 0; + } + return -100; + } + function t(e) { + return e ? 50 : 0; + } + let o = this._logicalFormWithHighestScoreIfGreaterThanZero(function (o) { + var r = o.PasswordElementUniqueID ? 0 : -1; + return e(o.AutoFillFormType) + t(o.IsVisible) + r; + }); + null !== o && (o.metadata.FormIsBestForPageLevelAutoFill = !0); + }, + _markFormIsBestForStreamlinedLogin: function () { + let e = this._logicalFormWithHighestScoreIfGreaterThanZero( + function (e, t) { + if (!e.IsVisible) return 0; + let o = t.getBoundingClientRect(); + if (!rectIsWithinDocumentViewport(o)) return 0; + if (o.bottom + window.scrollY < 80) { + let e = !( + location.hash || + (location.pathname && "/" !== location.pathname) || + location.search + ), + t = o.width / o.height; + if (!e && t > 4) return 0; + } + if (t.closest("footer")) return 0; + let r = e.AutoFillFormType === WBSAutoFillFormTypeAutoFillableLogin, + n = 0, + i = e.FormControls, + l = i.length; + for (var a = 0; a < l; ++a) { + let t = i[a], + o = FormMetadataJS.formControlWithUniqueID(t.ControlUniqueID); + if (!o) continue; + const l = parseInt(o.tabIndex, 10); + if (!(isFiniteNumber(l) && l < 0)) { + if (r) { + t.ControlIsAutofocusedTextField && (n += 1); + let o = t.ControlUniqueID; + if ( + o === e.UsernameElementUniqueID || + o === e.PasswordElementUniqueID + ) { + n += 10; + continue; + } + } + t.OneTimeCodeIsEligibleForAutomaticLogin && (n += 5); + } + } + return n; + }, + ); + null !== e && (e.metadata.FormIsBestForStreamlinedLogin = !0); + }, + _logicalFormWithHighestScoreIfGreaterThanZero: function (e) { + let t = null, + o = null; + for (let n of this._logicalFormsCache.allForms()) { + var r = e(n.metadata, n.backingElement); + (null === t || r > t) && ((o = n), (t = r)); + } + return t > 0 ? o : null; + }, + isAnyFormAnnotated: function () { + return this._logicalFormsCache.allForms().some((e) => e.isAnnotated); + }, + annotateFormWithID: function (e, t) { + let o = this._logicalFormsCache.logicalFormWithUniqueID(e); + o && o.annotate(t); + }, + _collectMetadata: function (e) { + const t = 100, + o = 10; + var r = this._logicalFormsInPage(t, o); + this._logicalFormsCache.clearCacheAndAdd(r); + for (var n = r.length, i = 0; i < n; ++i) + (e === WBSFormMetadataRequestTesting && + "function" == typeof willCollectFormMetadata && + willCollectFormMetadata(), + (r[i].metadata = this._collectFormMetadata(r[i], e))); + (this._markFormIsBestForPageLevelAutoFill(), + e !== WBSFormMetadataRequestNormal && + this._markFormIsBestForStreamlinedLogin()); + }, + _collectAndCacheFormMetadata: function (e, t) { + let o = this._collectFormMetadata(e, t), + r = this._logicalFormsCache.logicalFormWithUniqueID(e.formUniqueID); + return ( + r + ? (r.metadata = o) + : ((e.metadata = o), this._logicalFormsCache.addOrUpdate(e)), + o + ); + }, + _metadataForFormWithID: function (e) { + return this._logicalFormsCache.logicalFormWithUniqueID(e)?.metadata; + }, + _recollectMetadataForFormWithID: function (e) { + const t = this._logicalFormsCache.logicalFormWithUniqueID(e); + return t + ? this._collectAndCacheFormMetadata(t, WBSFormMetadataRequestNormal) + : null; + }, + _fillControlWithGeneratedPassword: function (e, t) { + var o = this._elementsWithGeneratedPasswords.indexOf(e); + (-1 === o && + (this._elementsWithGeneratedPasswords.push(e), + (o = this._elementsWithGeneratedPasswords.length - 1)), + (this._generatedPasswords[o] = t), + this._autoFillControlWithValueWithSingleValueUpdate( + e, + t, + ShouldFocus.Yes, + ShouldBlur.Yes, + ShouldSetAutoFilled.Yes, + )); + }, + fillFormWithPassword: function (e, t, o) { + var r = this._metadataForFormWithID(e); + if (null === r) return null; + const n = r.PasswordElementUniqueID, + i = n ? this.formControlWithUniqueID(n) : void 0, + l = o ? this.formControlWithUniqueID(o) : void 0; + var a = i || l; + const s = n || o; + if (!a) return null; + this._fillControlWithGeneratedPassword(a, t); + let u = r.ConfirmPasswordElementUniqueID; + u || + (r.AutoFillFormType !== WBSAutoFillFormTypeChangePassword && + r.AutoFillFormType !== WBSAutoFillFormTypeNewAccount) || + (u = (r = this._recollectMetadataForFormWithID(e) || r) + .ConfirmPasswordElementUniqueID); + let c = u ? this.formControlWithUniqueID(u) : null; + return c ? (this._fillControlWithGeneratedPassword(c, t), [s, u]) : [s]; + }, + fillFieldWithGeneratedPassword: function (e, t) { + var o = this.formControlWithUniqueID(e); + o && this._isTextField(o) && this._fillControlWithGeneratedPassword(o, t); + }, + clearField: function (e) { + var t = this.formControlWithUniqueID(e); + this._clearFormField(t); + }, + _clearFormField: function (e, t) { + if (e) + if (this._isSelectElement(e)) e.selectedIndex = 0; + else if (isDateTimeInputElement(e)) e.value = ""; + else if (isRadioButtonElement(e)) { + let t = this._logicalFormsCache + .logicalFormForControl(e) + .radioButtonsWithName(e.name), + o = t.length; + for (let e = 0; e < o; ++e) t[e].checked = !1; + } else if (this._isTextField(e) && e.value.length) { + var o = e.matches(":focus"); + (o || e.dispatchEvent(new Event("focus")), + e.dispatchEvent(eventThatBubbles("keydown")), + (e.value = ""), + e.dispatchEvent(eventThatBubbles("input")), + e.dispatchEvent(eventThatBubbles("keyup")), + e.dispatchEvent(eventThatBubbles("change")), + o || t === ShouldBlur.No || e.dispatchEvent(new Event("blur"))); + } + }, + focusFormForStreamlinedLogin: function (e) { + const t = function (e) { + for (const t of e.FormControls) { + const o = t.ControlUniqueID; + if ( + o === e.UsernameElementUniqueID || + o === e.PasswordElementUniqueID || + t.ControlLooksLikeOneTimeCodeField + ) { + let e = this.formControlWithUniqueID(o); + if (e.isVisible() && !e.disabled) return e; + } + } + return null; + }.bind(this); + var o = this._metadataForFormWithID(e); + null !== o && this._focusControlForStreamlinedLogin(t(o)); + }, + focusControlForStreamlinedLogin: function (e) { + this._focusControlForStreamlinedLogin(this.formControlWithUniqueID(e)); + }, + _focusControlForStreamlinedLogin: function (e) { + e && rectIsWithinDocumentViewport(e.getBoundingClientRect()) && e.focus(); + }, + formsAndMetadata: function (e) { + (visibilityCacheGeneration++, this._collectMetadata(e)); + let t = [], + o = []; + for (let e of this._logicalFormsCache.allForms()) + (t.push(e.formElement), o.push(e.metadata)); + return [t, o]; + }, + formControlWithUniqueID: function (e) { + let t = this._controlUniqueIDToWeakControlMap.get(e)?.deref(); + return t; + }, + formElementWithFormID: function (e) { + return this._logicalFormsCache.logicalFormWithUniqueID(e)?.formElement; + }, + selectIfTextField: function (e) { + this._isTextField(e) && e.select(); + }, + _getOrCreateCachedMetadataForLogicalForm: function (e, t) { + var o = this._cachedMetadataForLogicalForm(e); + return !o || + (null != t && + o.RequestType === WBSFormMetadataRequestPreFill && + t !== WBSFormMetadataRequestPreFill) + ? this._collectAndCacheFormMetadata(e, t) + : o; + }, + _getOrCreateLogicalFormForTextFieldOrSelectElement: function (e) { + let t = this._logicalFormsCache.logicalFormForControl(e); + if (t) + for ( + var o = t.metadata, + r = o?.FormControls, + n = r?.length ?? 0, + i = e._controlUniqueID, + l = 0; + l < n; + ++l + ) + if (r[l].ControlUniqueID === i) return t; + var a = this._logicalFormsInPage(), + s = a.length; + for (l = 0; l < s; ++l) { + var u = a[l]; + if (u.containsControl(e)) + return ( + this._logicalFormsCache.addOrUpdate(u), + (u.metadata = this._collectFormMetadata( + u, + WBSFormMetadataRequestNormal, + )), + u + ); + } + return null; + }, + _cachedMetadataForFormWithTextFieldOrSelectElement: function (e, t) { + if (!this._isTextField(e) && !this._isSelectElement(e)) return null; + var o = this._getOrCreateLogicalFormForTextFieldOrSelectElement(e); + return o ? this._getOrCreateCachedMetadataForLogicalForm(o, t) : null; + }, + _isAnyPasswordElementUniqueID: function (e, t) { + return ( + e.PasswordElementUniqueID === t || + e.ConfirmPasswordElementUniqueID === t || + e.OldPasswordElementUniqueID === t + ); + }, + _isCurrentPasswordElementUniqueID: function (e, t) { + switch (e.AutoFillFormType) { + case WBSAutoFillFormTypeNewAccount: + case WBSAutoFillFormTypeChangePassword: + return e.OldPasswordElementUniqueID === t; + default: + return e.PasswordElementUniqueID === t; + } + }, + _isNewPasswordElementUniqueID: function (e, t) { + switch (e.AutoFillFormType) { + case WBSAutoFillFormTypeNewAccount: + case WBSAutoFillFormTypeChangePassword: + return ( + e.PasswordElementUniqueID === t || + e.ConfirmPasswordElementUniqueID === t + ); + default: + return !1; + } + }, + _updateAnnotationsForField: function (e) { + var t = this._getOrCreateLogicalFormForTextFieldOrSelectElement(e); + if (t) { + var o = this._getOrCreateCachedMetadataForLogicalForm(t); + if (o) { + var r = e._controlUniqueID; + (this._isCurrentPasswordElementUniqueID(o, r) + ? t.annotate({ CurrentPassword: e.value }) + : this._isNewPasswordElementUniqueID(o, r) + ? t.annotate({ NewPassword: e.value }) + : o.UsernameElementUniqueID === r && + t.annotate({ Username: e.value }), + isCredentialElementUniqueID(o, r) && + (e._relatesToCredentials = "" !== e.value)); + } + } + }, + textFieldOrSelectElementMetadata: function (e, t, o) { + (visibilityCacheGeneration++, + this._logicalFormsCache.removeUnparentedLogicalFormsFromCache()); + var r = [null, null], + n = this._cachedMetadataForFormWithTextFieldOrSelectElement(e, t); + if (!n) return r; + this._pageScanContext = { + backwardScanCache: new WeakMap(), + forwardScanCache: new WeakMap(), + }; + let i = this._logicalFormsCache.logicalFormWithUniqueID(n.FormID), + l = formActionAsAnchorElement(i.formElement), + [a, s, u, c] = this._trailingArgumentsForCollectControlMetadataFunction( + i, + t, + l, + ); + const d = !0; + var h = this._collectControlMetadata( + e, + WBSFormMetadataRequestNormal, + a, + s, + u, + c, + d, + ); + if ( + (delete this._pageScanContext, + h.ControlLooksLikeOneTimeCodeField && + this._oneTimeCodeIsEligibleForAutomaticLogin(h, n) && + (h.OneTimeCodeIsEligibleForAutomaticLogin = !0), + (h.SelectionStart = e.selectionStart), + (h.SelectionLength = e.selectionEnd - e.selectionStart), + t === WBSFormMetadataRequestTextChange && + (!n.UsernameElementUniqueID && + this._isAnyPasswordElementUniqueID(n, h.ControlUniqueID) && + i.isAnnotated && + i.annotate({ Username: null }), + this._updateAnnotationsForField(e)), + n.RequestType !== WBSFormMetadataRequestPreFill) + ) + for (let e of n.FormControls) + if (h.ControlUniqueID === e.ControlUniqueID) { + ((h.ControlClassification = e.ControlClassification), + (h.ControlClassificationHints = e.ControlClassificationHints), + (h.ControlOrderedParts = e.ControlOrderedParts), + (h.ControlContinuationID = e.ControlContinuationID), + (h.ControlContinuationIndex = e.ControlContinuationIndex)); + break; + } + if (o) { + for (const e of n.FormControls) + e.ControlUniqueID == h.ControlUniqueID && (e.ControlValue = null); + this._cachedFormMetadata = JSON.stringify(n); + } + return ((r[0] = h), (r[1] = n), r); + }, + clearTextFieldOrSelectElementMetadataCache: function () { + this._cachedFormMetadata = null; + }, + disableSpellCheckInFieldIfNeeded: function (e) { + if (e) { + var t = this.formControlWithUniqueID(e); + t && + this._isAutoFillableTextField(t) && + FormMetadataJSController.setInputElementSpellCheckEnabled(t, !1); + } + }, + selectionRangeInField: function (e) { + var t = this.formControlWithUniqueID(e); + return t && this._isTextField(t) + ? [t.selectionStart, t.selectionEnd - t.selectionStart] + : null; + }, + setFormFieldSelection: function (e, t, o) { + var r = this.formControlWithUniqueID(e); + r && + this._isTextField(r) && + ((r.selectionStart = t), (r.selectionEnd = t + o)); + }, + replaceFormFieldRangeAndSelectTail: function (e, t, o, r, n) { + var i = this.formControlWithUniqueID(e); + if (i && this._isTextField(i)) { + var l = i.value, + a = l.substr(0, t) + r + l.substr(t + o); + ((i.value = a), + (i.selectionStart = n), + (i.selectionEnd = a.length), + i.dispatchEvent(eventThatBubbles("input")), + i.dispatchEvent(eventThatBubbles("change"))); + } + }, + _collectVisibleNonEmptyTextFieldsAndTextAreasInForm: function (e, t, o) { + visibilityCacheGeneration++; + for (var r = e.elements, n = r.length, i = 0; i < n; ++i) { + var l = r[i]; + l.isVisible() && + null != l.value && + l.value.length && + (this._isTextField(l) ? t.push(l) : this._isTextArea(l) && o.push(l)); + } + }, + visibleNonEmptyFormTextControls: function () { + var e = [], + t = []; + let o = queryAllBySelector(document, "form"); + for (let r = 0; r < o.length; ++r) + this._collectVisibleNonEmptyTextFieldsAndTextAreasInForm(o[r], e, t); + return [e, t]; + }, + visibleNonEmptyFormTextControlsInForm: function (e) { + var t = [], + o = []; + return ( + this._collectVisibleNonEmptyTextFieldsAndTextAreasInForm(e, t, o), + [t, o] + ); + }, + _autoFillRadioButton: function (e, t, o) { + var r = this._logicalFormsCache.logicalFormForControl(e), + n = r?.radioButtonsWithName(e.name) ?? []; + for (let e of n) + if (e.value === t) + return ( + e.dispatchEvent(eventThatBubbles("click")), + (e.checked = !0), + void FormMetadataJSController.setInputElementAutofilled(e, o) + ); + }, + _autoFillControlWithValueWithSingleValueUpdate: function ( + e, + t, + o, + r, + n, + i, + l, + ) { + (o === ShouldFocus.Yes && e.dispatchEvent(new Event("focus")), + e.dispatchEvent(eventThatBubbles("keydown")), + (e.value = t), + this._updateAnnotationsForField(e), + l || e.dispatchEvent(eventThatBubbles("input")), + e.dispatchEvent(eventThatBubbles("keyup")), + l || e.dispatchEvent(eventThatBubbles("change")), + r === ShouldBlur.Yes && e.dispatchEvent(new Event("blur")), + i === ShouldObscure.Yes + ? FormMetadataJSController.setInputElementAutofilledAndObscured( + e, + t.length && n === ShouldSetAutoFilled.Yes, + ) + : FormMetadataJSController.setInputElementAutofilled( + e, + t.length && n === ShouldSetAutoFilled.Yes, + )); + }, + _autoFillControlWithValueCharacterByCharacter: function ( + e, + t, + o, + r, + n, + i, + l, + ) { + let a = t.split(""), + s = a.length, + u = Date.now(), + c = !e; + const d = 100, + h = userIsOnDomain("account.ui.com") && l ? 40 : 0, + m = () => { + (this._autoFillControlWithValueWithSingleValueUpdate( + e, + t, + ShouldFocus.Yes, + ShouldBlur.Yes, + o, + r, + ), + i?.()); + }; + let F = (f) => { + try { + if (f >= s) return void i?.(); + c && (e = innermostActiveElement()); + let g = e.value, + p = a[f], + C = g.slice(-1); + if (C === p && f && !t.slice(f - 1).startsWith(C + p)) + return void setTimeout(F, 0, f + 1); + let A = 0 === f ? ShouldFocus.Yes : ShouldFocus.No, + _ = f === s - 1, + b = _ ? ShouldBlur.Yes : ShouldBlur.No, + y = _ ? o : ShouldSetAutoFilled.No, + S = _ ? r : ShouldObscure.No, + T = g + p, + E = !_; + if ( + (l && (E = !1), + this._autoFillControlWithValueWithSingleValueUpdate( + e, + T, + A, + b, + y, + S, + E, + ), + !c && + !this._controlContainsAllCharactersFromFilling( + e.value, + t.substring(0, f + 1), + )) + ) + return void m(); + const I = Date.now() - u; + if ( + ((u = Date.now()), + I > d && n === ShouldAbandonCharacterByCharacterEntryIfTooSlow.Yes) + ) + return void m(); + setTimeout(F, h, f + 1); + } catch (e) {} + }; + F(0); + }, + _controlContainsAllCharactersFromFilling: function (e, t) { + if (e.length < t.length) return !1; + var o = t; + for (let r = 0; r < t.length; r++) { + -1 !== e.indexOf(t[r]) && + ((e = e.replace(t[r], "")), (o = o.replace(t[r], ""))); + } + return !o.length; + }, + _autoFillControlWithValueRecursively: function (e, t, o, r, n, i) { + if (isRadioButtonElement(e)) + return ( + this._autoFillRadioButton(e, t, o === ShouldSetAutoFilled.Yes), + void (i && i()) + ); + if (this._isSelectElement(e)) + return ( + this._autoFillSelectWithOptionIndex( + e, + t, + o === ShouldSetAutoFilled.Yes, + ), + void (i && i()) + ); + let l = this._logicalFormsCache.logicalFormForControl(e); + FormMetadataJS._cachedMetadataForLogicalForm(l); + if (n || !this._isTextField(e)) + return ( + this._autoFillControlWithValueWithSingleValueUpdate( + e, + t, + ShouldFocus.Yes, + ShouldBlur.Yes, + o, + r, + ), + void (i && i()) + ); + this._clearFormField(e, ShouldBlur.No); + let a = () => { + (this._controlContainsAllCharactersFromFilling(e.value, t) || + this._autoFillControlWithValueWithSingleValueUpdate( + e, + t, + ShouldFocus.Yes, + ShouldBlur.Yes, + o, + r, + ), + i && i()); + }; + this._autoFillControlWithValueCharacterByCharacter( + e, + t, + o, + r, + ShouldAbandonCharacterByCharacterEntryIfTooSlow.Yes, + a, + ); + }, + _autoFillSelectWithOptionIndex: function (e, t, o) { + (e.dispatchEvent(eventThatBubbles("mousedown")), + e.dispatchEvent(new Event("focus")), + e.selectedIndex !== t && + ((e.selectedIndex = t), + e.dispatchEvent(eventThatBubbles("input")), + e.dispatchEvent(eventThatBubbles("change"))), + e.dispatchEvent(eventThatBubbles("mouseup")), + e.dispatchEvent(eventThatBubbles("click")), + e.dispatchEvent(new Event("blur")), + FormMetadataJSController.setInputElementAutofilled(e, o)); + }, + autoFillOneTimeCodeFieldsWithValue: function (e, t) { + let o = innermostActiveElement(); + if (!this._isAutoFillableTextField(o)) return; + this._clearFormField(o); + let r = () => { + FormMetadataJSController.finishedAutoFillingOneTimeCode(e, t); + }, + n = !0; + this._autoFillControlWithValueCharacterByCharacter( + null, + e, + ShouldSetAutoFilled.Yes, + ShouldObscure.No, + ShouldAbandonCharacterByCharacterEntryIfTooSlow.No, + r, + n, + ); + }, + _shouldSelectElementAfterFillingForm: function (e) { + if (!/(^|\.)etrade\.com/.test(document.location.hostname)) return !0; + var t = this._cachedMetadataForLogicalForm(e); + return !t || t.AutoFillFormType !== WBSAutoFillFormTypeAutoFillableLogin; + }, + autoFillControlsByID: function (e, t, o, r, n, i, l) { + let a = arguments[arguments.length - 1], + s = o ? ShouldSetAutoFilled.Yes : ShouldSetAutoFilled.No, + u = r; + if (u) { + let e = u.getAttribute("onfocus"); + e && e.length && /this\.value/.test(e) && (u = null); + } else u = innermostActiveElement(); + var c = null; + for (let t in e) { + c = this._logicalFormsCache.logicalFormForControl( + this.formControlWithUniqueID(t), + ); + break; + } + var d = function () { + (n + ? innermostActiveElement().blur() + : u && + this._shouldSelectElementAfterFillingForm(c) && + this.selectIfTextField(u), + c?.backingElement && + elementAppearsToContinueCaptchaWidget(c.backingElement) && + (a = !1), + FormMetadataJSController.finishedAutoFillingControlsInForm( + this._getOrCreateCachedMetadataForLogicalForm(c), + a, + )); + }.bind(this); + if (t) { + var h = []; + for (var m in e) + e.hasOwnProperty(m) && + h.push([this.formControlWithUniqueID(m), e[m]]); + this._synchronouslyAutoFillControls(h, s, l, d); + } else this._asynchronouslyAutoFillControls(e, c, s, i, l, d); + }, + _synchronouslyAutoFillControls: function (e, t, o, r) { + for (var n = e.length, i = 0; i < n; ++i) { + var l = e[i][0], + a = e[i][1]; + this._autoFillControlWithValueRecursively(l, a, t, ShouldObscure.NO, o); + } + r(); + }, + _asynchronouslyAutoFillControls: function (e, t, o, r, n, i) { + var l = t.elements, + a = l.length, + s = function (t) { + if (t >= a) return void i(); + var u = l[t], + c = e[u._controlUniqueID]; + let d = () => { + s(t + 1); + }; + if (void 0 !== c) { + let e = r.some((e) => u._controlUniqueID.includes(e)) + ? ShouldObscure.Yes + : ShouldObscure.No; + this._autoFillControlWithValueRecursively(u, c, o, e, n, d); + } else d(); + }.bind(this); + s(0); + }, + _isInputAllowedInSearchForm: function (e, t) { + var o = this._getTagName(e).toLowerCase(); + if ("button" === o || "fieldset" === o) return !0; + if ("select" === o) return !t || isSelectInDefaultState(e); + if ( + "input" !== o && + !this._textAreaElementLookLikeItIsPartOfASearchForm(e) + ) + return !1; + var r = e.type; + return "radio" === r || "checkbox" === r + ? !t || isCheckboxOrRadioButtonInDefaultState(e) + : "hidden" === r || + "reset" === r || + "submit" === r || + "button" === r || + "image" === r || + (this._isTextField(e) && !this._isSecureTextField(e)); + }, + _isSearchForm: function (e, t) { + if ("get" !== e.method) return !1; + for (var o = e.elements, r = o.length, n = 0; n < r; ++n) + if (!this._isInputAllowedInSearchForm(o[n], t)) return !1; + return !0; + }, + _textAreaElementLookLikeItIsPartOfASearchForm: function (e) { + return ( + !!this._isTextArea(e) && + ("search" === e.getAttribute("type") || + "search" === e.inputMode || + "search" === e.getAttribute("enterkeyhint")) + ); + }, + _shouldInputBeIncludedInSearchURLQuery: function (e) { + if (e.disabled) return !1; + if (!e.name.length) return !1; + if (!e.value.length) return !1; + if (this._isSelectElement(e)) return !0; + var t = this._getTagName(e).toLowerCase(), + o = e.type; + return "button" === t + ? "submit" === o + : "input" === t && + ("submit" === o || + ("checkbox" === o || "radio" === o + ? e.checked + : "hidden" === o || this._isTextField(e))); + }, + _isSubmitButton: function (e) { + return ( + (e instanceof HTMLButtonElement || e instanceof HTMLInputElement) && + e.type && + "submit" === e.type + ); + }, + _isCustomFormButton: function (e) { + return ( + "button" === e.type && + (e instanceof HTMLButtonElement || e instanceof HTMLInputElement) + ); + }, + _isCheckboxInputElement: function (e) { + return "checkbox" === e.type && e instanceof HTMLInputElement; + }, + _setQueryString: function (e, t) { + var o = document.createElement("a"); + return ((o.href = e), (o.search = t), o.href); + }, + searchTextFieldFormSubmissionURLString: function (e, t) { + if ( + (visibilityCacheGeneration++, + !this._isTextField(e) || this._isSecureTextField(e) || !e.isVisible()) + ) + return null; + var o = e.form; + if (!o) return null; + var r = o.getAttribute("action"); + if (!r || !r.length) return null; + if (!/^https?:/i.test(o.action)) return null; + if (!this._isSearchForm(o, t)) return null; + for ( + var n = null, i = "", l = o.elements, a = l.length, s = 0; + s < a; + ++s + ) { + var u = l[s]; + if ( + (u === e || this._shouldInputBeIncludedInSearchURLQuery(u)) && + (!this._isSubmitButton(u) || (n || (n = u), u === n)) + ) { + i.length && (i += "&"); + var c = u === e ? "{searchTerms}" : urlEncode(u.value); + i += urlEncode(u.name) + "=" + c; + } + } + return this._setQueryString(o.action, i); + }, + })); +var FormMetadataJS = new FormMetadata(); diff --git a/js/forms/FormMetadataClassification.js b/js/forms/FormMetadataClassification.js new file mode 100644 index 0000000..43fa776 --- /dev/null +++ b/js/forms/FormMetadataClassification.js @@ -0,0 +1,638 @@ +//# sourceURL=__InjectedScript_FormMetadataClassification.js +/* Copyright (c) 2025 Apple Inc. All rights reserved. */ +"use strict"; +const WBSABAddressProperty = "Address", + WBSABPhoneProperty = "Phone", + _WBSABAddressZIPKey = "ZIP", + WBSFormControlMetadataDefaultMaxLength = 524288, + WBSIgnoredClassificationToken = "-sf-ignored", + WBSDateDayOrderedPartToken = "-sf-day", + WBSDateMonthOrderedPartToken = "-sf-month", + WBSDateYearOrderedPartToken = "-sf-year", + WBSGivenNameOrderedPartToken = "given-name", + WBSAdditionalNameOrderedPartToken = "additional-name", + WBSFamilyNameOrderedPartToken = "family-name", + WBSLocaleForCreditCardExpirationDate = "en_US", + WBSCreditCardTypeClassificationToken = "cc-type", + WBSCreditCardHolderNameClassificationToken = "cc-name", + WBSCreditCardNumberClassificationToken = "cc-number", + WBSCreditCardExpirationClassificationToken = "cc-exp", + WBSCreditCardSecurityCodeClassificationToken = "cc-csc", + WBSCreditCardHolderNameClassificationDefaultOrderedParts = [ + WBSGivenNameOrderedPartToken, + WBSAdditionalNameOrderedPartToken, + WBSFamilyNameOrderedPartToken, + ], + WBSCreditCardExpirationClassificationDefaultOrderedParts = [ + WBSDateMonthOrderedPartToken, + WBSDateYearOrderedPartToken, + ], + WBSCredentialUsernameClassificationToken = "username", + WBSCredentialCurrentPasswordClassificationToken = "current-password", + WBSCredentialNewPasswordClassificationToken = "new-password", + WBSContactNameClassificationToken = "name", + WBSContactNameClassificationDefaultOrderedParts = [ + WBSGivenNameOrderedPartToken, + WBSAdditionalNameOrderedPartToken, + WBSFamilyNameOrderedPartToken, + ], + WBSNameOrderedPartTokensSet = new Set( + WBSContactNameClassificationDefaultOrderedParts, + ), + WBSContactInstantMessageClassificationToken = "-sf-instant-message", + WBSContactPostalCodeClassificationToken = "postal-code", + WBSContactStreetAddressClassificationToken = "street-address", + WBSContactStreetAddressLine1OrderedPartToken = "address-line1", + WBSContactStreetAddressLine2OrderedPartToken = "address-line2", + WBSContactStreetAddressLine3OrderedPartToken = "address-line3", + WBSContactTelephoneClassificationToken = "tel", + WBSTelephoneCountryCodeOrderedPartToken = "tel-country-code", + WBSTelephoneAreaCodeOrderedPartToken = "tel-area-code", + WBSTelephoneLocalPrefixOrderedPartToken = "tel-local-prefix", + WBSTelephoneLocalSuffixOrderedPartToken = "tel-local-suffix", + WBSTelephoneExtensionOrderedPartToken = "tel-extension", + WBSTelephoneDefaultOrderedParts = [ + WBSTelephoneCountryCodeOrderedPartToken, + WBSTelephoneAreaCodeOrderedPartToken, + WBSTelephoneLocalPrefixOrderedPartToken, + WBSTelephoneLocalSuffixOrderedPartToken, + WBSTelephoneExtensionOrderedPartToken, + ], + WBSContactBirthdayClassificationToken = "bday", + WBSContactEmailClassificationToken = "email", + WBSDeviceEIDClassificationToken = "device-eid", + WBSDeviceIMEIClassificationToken = "device-imei", + AllowedControlTagsForStandaloneCreditCardCompositeExpirationControl = new Set( + ["input", "select", "textarea"], + ); +class FormMetadataClassification { + #e(e) { + return null != e && "object" == typeof e; + } + #t(e) { + return this.#e(e) && "string" == typeof e.ControlTagName; + } + #o(e) { + return this.#e(e) && "string" == typeof e.property; + } + fieldLooksLikeDateField(e) { + return !!( + e.ControlLooksLikeDayField || + e.ControlLooksLikeMonthField || + e.ControlLooksLikeYearField + ); + } + #r(e) { + let t = e.ControlMaxLength; + return ( + (void 0 === t || t < 0 || t > WBSFormControlMetadataDefaultMaxLength) && + (t = WBSFormControlMetadataDefaultMaxLength), + t + ); + } + fieldLooksLikeItExpectsDataOfSize(e, t) { + return (e.ControlSize ?? 0) <= t || this.#r(e) <= t; + } + fieldCouldBeCreditCardNumberContinuation(e, t) { + const o = 4; + if (t.length >= o) return !1; + if (!t[0]?.ControlLooksLikeCreditCardNumberField) return !1; + const r = 2; + if (e.ControlMaxLength === r) return !1; + if (e.ControlLooksLikeCreditCardNumberField) return !0; + if (e.ControlLooksLikeCreditCardSecurityCodeField) return !1; + if (e.ControlLooksLikeCreditCardCompositeExpirationDateField) return !1; + const n = 6; + if (!this.fieldLooksLikeItExpectsDataOfSize(e, n)) return !1; + const i = t.at(-1); + return !(i && !this.fieldLooksLikeItExpectsDataOfSize(i, n)); + } + labelsCouldRepresentContinuation(e, t, o, r) { + return ( + !(!e || !o) && + (e === o || + (!!t && + (!r || + (t.property === r.property && + (!r.component || t.component === r.component))))) + ); + } + #n(e) { + const t = [ + WBSContactStreetAddressLine1OrderedPartToken, + WBSContactStreetAddressLine2OrderedPartToken, + WBSContactStreetAddressLine3OrderedPartToken, + ], + o = [ + WBSContactStreetAddressLine2OrderedPartToken, + WBSContactStreetAddressLine3OrderedPartToken, + ]; + if (e.AutocompleteTokens) + for (let o of e.AutocompleteTokens) + switch (o) { + case "street-address": + return t; + case "address-line1": + return [WBSContactStreetAddressLine1OrderedPartToken]; + case "address-line2": + case "address-level2": + return [WBSContactStreetAddressLine2OrderedPartToken]; + case "address-line3": + case "address-level1": + return [WBSContactStreetAddressLine3OrderedPartToken]; + } + let r = e.ControlFieldName, + n = r?.indexOf("1") ?? -1, + i = r?.indexOf("2") ?? -1; + return -1 === n + ? -1 === i + ? t + : o + : -1 === i || digit1location < digit2location + ? [WBSContactStreetAddressLine1OrderedPartToken] + : o; + } + fieldCouldBePhoneNumberContinuation(e, t) { + const o = 5; + if (t.length >= o) return !1; + if (t[0]?.AddressBookValueSpecifier?.property !== WBSABPhoneProperty) + return !1; + const r = 5; + return !!this.fieldLooksLikeItExpectsDataOfSize(e, r); + } + fieldCouldBePostCodeContinuation(e, t) { + const o = 3; + if (t.length >= o) return !1; + if (t[0]?.AddressBookValueSpecifier?.component != _WBSABAddressZIPKey) + return !1; + const r = 6; + return !!this.fieldLooksLikeItExpectsDataOfSize(e, r); + } + fieldLooksLikeSameDataType(e, t) { + const o = t.at(-1); + return ( + !!this.labelsCouldRepresentContinuation( + o?.AddressBookLabel, + o?.AddressBookValueSpecifier, + e?.AddressBookLabel, + e?.AddressBookValueSpecifier, + ) || + !!( + o && + this.fieldLooksLikeDateField(o) && + this.fieldLooksLikeDateField(e) + ) || + !!this.fieldCouldBePhoneNumberContinuation(e, t) || + !!this.fieldCouldBePostCodeContinuation(e, t) || + !!this.fieldCouldBeCreditCardNumberContinuation(e, t) + ); + } + #i(e) { + if ( + (globalThis.DOMRect || + (globalThis.DOMRect = class { + constructor(e, t, o, r) { + ((this.left = e), + (this.right = e + o), + (this.top = t), + (this.bottom = t + r), + (this.width = o), + (this.height = r)); + } + }), + e.ControlRectLeft || + e.ControlRectTop || + e.ControlRectWidth || + e.ControlRectHeight) + ) + return new DOMRect( + e.ControlRectLeft, + e.ControlRectTop, + e.ControlRectWidth, + e.ControlRectHeight, + ); + let t = globalThis.FormMetadataJS?.formControlWithUniqueID( + e.ControlUniqueID, + ); + return t ? t.getBoundingClientRect() : new DOMRect(0, 0, 0, 0); + } + fieldLooksLikeContinuation(e, t, o) { + if (!e.ControlIsTextField && "SELECT" !== e.ControlTagName.toUpperCase()) + return !1; + if (!this.fieldLooksLikeSameDataType(e, t)) return !1; + if (o) return !0; + const r = this.#i(t.at(-1)), + n = this.#i(e); + if (Math.abs(r.top - n.top) > 3) return !1; + let i, a; + return ( + r.left < n.left ? ((i = r), (a = n)) : ((i = n), (a = r)), + !(a.left - i.right > 60) + ); + } + continuingFieldsInFormControls(e, t, o, r) { + const n = [e[t]]; + for (let i = t + 1; i < e.length; ++i) { + const t = e[i]; + if (o && !t.ControlIsTextField) break; + if (!this.fieldLooksLikeContinuation(t, n, r)) break; + n.push(t); + } + return n; + } + classifyControlsRelatedToNameParts(e, t, o) { + const r = e[t]; + ((r.ControlClassification = o), + (r.ControlOrderedParts = [r.AddressBookValueSpecifier?.classification])); + const n = new Set([r.AddressBookValueSpecifier?.classification]), + i = [e[t]]; + for (let r = t + 1; r < e.length; ++r) { + const t = e[r]; + if (!t.ControlIsTextField) break; + const a = t.AddressBookValueSpecifier?.classification; + if (!a) break; + if (!WBSNameOrderedPartTokensSet.has(a) || n.has(a)) break; + ((t.ControlClassification = o), + (t.ControlOrderedParts = [a]), + n.add(a), + i.push(t)); + } + return i; + } + identifyDateFields(e) { + let t, + o, + r, + n = !1; + for (let i of e) + if (i.ControlLooksLikeDayField) { + if (t) return [!1]; + ((t = i), (n = !0)); + } else if (i.ControlLooksLikeMonthField) { + if (o) return [!1]; + ((o = i), (n = !0)); + } else if (i.ControlLooksLikeYearField) { + if (r) return [!1]; + ((r = i), (n = !0)); + } + return [n, r, o, t]; + } + canonicalizedDateTemplate(e) { + if (e && (e = e.replace(/\s/g, "")).length && !/[^dmyDMY\/.-]/g.test(e)) + return (e = (e = (e = e.replace(/D/g, "d")).replace(/m/g, "M")).replace( + /Y/g, + "y", + )); + } + classifyDateFields(e, t, o, r, n, i, a) { + if (e.length > 3) return !1; + if (1 === e.length) { + if (!e[0].ControlIsTextField) return !1; + let i = e[0].ControlRequiredFormatForDateTimeInput; + if (!i) { + const t = n ? new Date(1999, 11, 30) : new Date(1999, 11); + let o = this.#r(e[0]), + r = this.canonicalizedDateTemplate(e[0].ControlPlaceholder), + s = r?.length ? r : n ? "ddMMy" : "MMyy"; + i = FormMetadataJSController.dateFormatFromTemplate(s, a); + let l = FormMetadataJSController.stringFromDateFormat(i, t); + if ( + (l.length > o && + ((s = n ? "dMMyy" : "MMyy"), + (i = FormMetadataJSController.dateFormatFromTemplate(s, a)), + (l = FormMetadataJSController.stringFromDateFormat(i, t)), + l.length > o && + ((s = n ? "dMyy" : "Myy"), + (i = FormMetadataJSController.dateFormatFromTemplate(s, a)), + (l = FormMetadataJSController.stringFromDateFormat(i, t)))), + l.length > o) + ) + return !1; + } + const s = []; + for (const e of i) { + let t; + ("y" === e ? (t = o) : "M" === e ? (t = r) : "d" === e && (t = n), + t && !s.includes(t) && s.push(t)); + } + return ( + (e[0].ControlClassification = t), + (e[0].ControlOrderedParts = s), + (e[0].ControlRequiredFormatForDateTimeInput = i), + !0 + ); + } + let [s, l, d, C] = this.identifyDateFields(e); + if (!s) return !1; + if (C && !d) return !1; + let c = 0; + for (const a of e) + ((a.ControlClassification = t), + (a.ControlContinuationID = i), + (a.ControlContinuationIndex = c++), + a === C + ? (a.ControlOrderedParts = [n]) + : a === d + ? (a.ControlOrderedParts = [r]) + : a === l && (a.ControlOrderedParts = [o])); + return !0; + } + classify(e) { + const t = e.FormControls, + o = t.length, + r = e.AutoFillFormType === WBSAutoFillFormTypeNewAccount, + n = e.AutoFillFormType === WBSAutoFillFormTypeChangePassword, + i = e.UsernameElementUniqueID, + a = e.PasswordElementUniqueID, + s = e.OldPasswordElementUniqueID, + l = e.ConfirmPasswordElementUniqueID; + for (let e of t) + (e.AutocompleteTokens || e.AddressBookLabel) && + (e.AddressBookValueSpecifier = + FormMetadataJSController.specifierForAutocompleteTokensAndAddressBookLabel( + e.AutocompleteTokens, + e.AddressBookLabel, + )); + let d = !1, + C = !1, + c = !1, + f = !1, + S = !1, + k = 0; + for (let u = 0, T = 1; u < o; u += T, T = 1) { + const o = t[u]; + if (o.ControlLooksLikeIgnoredDataTypeField) { + o.ControlClassification = WBSIgnoredClassificationToken; + continue; + } + const B = o.ControlUniqueID; + if (B === a || B === l) { + o.ControlClassification = + r || n + ? WBSCredentialNewPasswordClassificationToken + : WBSCredentialCurrentPasswordClassificationToken; + continue; + } + if (B === s) { + o.ControlClassification = + WBSCredentialCurrentPasswordClassificationToken; + continue; + } + const h = o.AddressBookValueSpecifier?.classification; + if (h === WBSContactEmailClassificationToken) { + o.ControlClassification = WBSContactEmailClassificationToken; + continue; + } + if (B === i) { + o.ControlClassification = WBSCredentialUsernameClassificationToken; + continue; + } + if (!C && o.ControlLooksLikeCreditCardCardholderField) { + if (((C = !0), h && WBSNameOrderedPartTokensSet.has(h))) { + const e = this.classifyControlsRelatedToNameParts( + t, + u, + WBSCreditCardHolderNameClassificationToken, + ); + if (e.length > 1) { + let t = ++k, + o = 0; + for (let r of e) + ((r.ControlContinuationID = t), + (r.ControlContinuationIndex = o++)); + } + T = e.length; + continue; + } + ((o.ControlClassification = WBSCreditCardHolderNameClassificationToken), + (o.ControlOrderedParts = + WBSCreditCardHolderNameClassificationDefaultOrderedParts)); + continue; + } + if (!d && o.ControlLooksLikeCreditCardNumberField) { + d = !0; + const e = this.continuingFieldsInFormControls(t, u, !0, !1); + let o = 0, + r = e.length > 1 ? ++k : 0; + for (let t of e) + ((t.ControlClassification = WBSCreditCardNumberClassificationToken), + (t.ControlContinuationID = r), + (t.ControlContinuationIndex = o++)); + T = e.length; + continue; + } + const P = + this.fieldLooksLikeDateField(o) || + o.ControlLooksLikeCreditCardCompositeExpirationDateField; + if (!c && P) { + let e = f || C || d; + if ( + ((e ||= + !o.ControlLooksLikeOneTimeCodeField && + 1 === + t.filter((e) => + AllowedControlTagsForStandaloneCreditCardCompositeExpirationControl.has( + e.ControlTagName.toLowerCase(), + ), + ).length), + e) + ) { + c = !0; + const e = this.continuingFieldsInFormControls(t, u, !1, !0); + let o = e.length > 1 ? ++k : 0; + (this.classifyDateFields( + e, + WBSCreditCardExpirationClassificationToken, + WBSDateYearOrderedPartToken, + WBSDateMonthOrderedPartToken, + void 0, + o, + WBSLocaleForCreditCardExpirationDate, + ), + (T = e.length)); + continue; + } + } + if (S || !o.ControlLooksLikeCreditCardSecurityCodeField) + if (f || !o.ControlLooksLikeCreditCardTypeField) + if (h) { + const r = o.AddressBookValueSpecifier.classificationHint; + if (h === WBSContactNameClassificationToken) { + ((o.ControlClassification = h), + (o.ControlOrderedParts = + WBSContactNameClassificationDefaultOrderedParts)); + continue; + } + if (WBSNameOrderedPartTokensSet.has(h)) { + const e = this.classifyControlsRelatedToNameParts( + t, + u, + WBSContactNameClassificationToken, + ); + if (e.length > 1) { + let t = ++k, + o = 0; + for (let r of e) + ((r.ControlContinuationID = t), + (r.ControlContinuationIndex = o++)); + } + T = e.length; + continue; + } + if (h === WBSContactPostalCodeClassificationToken) { + const e = this.continuingFieldsInFormControls(t, u, !0, !1); + let o = e.length > 1 ? ++k : 0, + r = 0; + for (let t of e) + ((t.ControlClassification = + WBSContactPostalCodeClassificationToken), + (t.ControlContinuationID = o), + (t.ControlContinuationIndex = r++)); + T = e.length; + continue; + } + if (h === WBSContactStreetAddressClassificationToken) { + const e = this.continuingFieldsInFormControls(t, u, !0, !0); + let o = e.length > 1 ? ++k : 0, + r = 0; + for (let t of e) + ((t.ControlClassification = + WBSContactStreetAddressClassificationToken), + (t.ControlContinuationID = o), + (t.ControlContinuationIndex = r++)); + if (1 === e.length) { + let t = e[0]; + t.ControlOrderedParts = this.#n(t); + } else + 2 === e.length + ? ((e[0].ControlOrderedParts = [ + WBSContactStreetAddressLine1OrderedPartToken, + ]), + (e[1].ControlOrderedParts = [ + WBSContactStreetAddressLine2OrderedPartToken, + WBSContactStreetAddressLine3OrderedPartToken, + ])) + : e.length >= 3 && + ((e[0].ControlOrderedParts = [ + WBSContactStreetAddressLine1OrderedPartToken, + ]), + (e[1].ControlOrderedParts = [ + WBSContactStreetAddressLine2OrderedPartToken, + ]), + (e[2].ControlOrderedParts = [ + WBSContactStreetAddressLine3OrderedPartToken, + ])); + T = e.length; + continue; + } + if (h === WBSContactInstantMessageClassificationToken) { + const e = this.continuingFieldsInFormControls(t, u, !0, !0); + (1 === e.length && + ((e[0].ControlClassification = + WBSContactInstantMessageClassificationToken), + r && (e[0].ControlClassificationHints = [r])), + (T = e.length)); + continue; + } + if (h.startsWith(WBSContactTelephoneClassificationToken)) { + const e = this.continuingFieldsInFormControls(t, u, !0, !1); + if (1 == e.length) { + ((e[0].ControlClassification = + WBSContactTelephoneClassificationToken), + (e[0].ControlOrderedParts = WBSTelephoneDefaultOrderedParts), + r && (e[0].ControlClassificationHints = [r])); + continue; + } + let o = ++k, + n = 0; + for (let t of e) + ((t.ControlClassification = + WBSContactTelephoneClassificationToken), + (t.ControlContinuationID = o), + (t.ControlContinuationIndex = n++), + r && (t.ControlClassificationHints = [r])); + (2 === e.length + ? ((e[0].ControlOrderedParts = [ + WBSTelephoneAreaCodeOrderedPartToken, + ]), + (e[1].ControlOrderedParts = [ + WBSTelephoneLocalPrefixOrderedPartToken, + WBSTelephoneLocalSuffixOrderedPartToken, + ])) + : 3 === e.length + ? ((e[0].ControlOrderedParts = [ + WBSTelephoneAreaCodeOrderedPartToken, + ]), + (e[1].ControlOrderedParts = [ + WBSTelephoneLocalPrefixOrderedPartToken, + ]), + (e[2].ControlOrderedParts = [ + WBSTelephoneLocalSuffixOrderedPartToken, + ])) + : 4 === e.length + ? ((e[0].ControlOrderedParts = [ + WBSTelephoneCountryCodeOrderedPartToken, + ]), + (e[1].ControlOrderedParts = [ + WBSTelephoneAreaCodeOrderedPartToken, + ]), + (e[2].ControlOrderedParts = [ + WBSTelephoneLocalPrefixOrderedPartToken, + ]), + (e[3].ControlOrderedParts = [ + WBSTelephoneLocalSuffixOrderedPartToken, + ])) + : ((e[0].ControlOrderedParts = [ + WBSTelephoneCountryCodeOrderedPartToken, + ]), + (e[1].ControlOrderedParts = [ + WBSTelephoneAreaCodeOrderedPartToken, + ]), + (e[2].ControlOrderedParts = [ + WBSTelephoneLocalPrefixOrderedPartToken, + ]), + (e[3].ControlOrderedParts = [ + WBSTelephoneLocalSuffixOrderedPartToken, + ]), + (e[4].ControlOrderedParts = [ + WBSTelephoneExtensionOrderedPartToken, + ])), + (T = e.length)); + continue; + } + if (h === WBSContactBirthdayClassificationToken) { + const o = this.continuingFieldsInFormControls(t, u, !1, !1), + r = o.length > 1 ? ++k : void 0, + n = + e.RequestType === WBSFormMetadataRequestTesting + ? "en_US" + : void 0; + (this.classifyDateFields( + o, + WBSContactBirthdayClassificationToken, + WBSDateYearOrderedPartToken, + WBSDateMonthOrderedPartToken, + WBSDateDayOrderedPartToken, + r, + n, + ), + (T = o.length)); + continue; + } + o.ControlClassification = h; + } else + o.ControlLooksLikeEIDField + ? (o.ControlClassification = WBSDeviceEIDClassificationToken) + : o.ControlLooksLikeIMEIField && + (o.ControlClassification = WBSDeviceIMEIClassificationToken); + else + ((f = !0), + (o.ControlClassification = WBSCreditCardTypeClassificationToken)); + else + ((S = !0), + (o.ControlClassification = + WBSCreditCardSecurityCodeClassificationToken)); + } + } +} +globalThis.FormMetadataClassificationJS = new FormMetadataClassification(); diff --git a/js/layout/WebContentLayoutAnalyzer.js b/js/layout/WebContentLayoutAnalyzer.js new file mode 100644 index 0000000..f8ad96a --- /dev/null +++ b/js/layout/WebContentLayoutAnalyzer.js @@ -0,0 +1,71 @@ +//# sourceURL=__InjectedScript_WebContentLayoutAnalyzer.js +/* Copyright (c) 2025 Apple Inc. All rights reserved. */ +// Copyright (c) 2013 Apple Inc. All rights reserved. +function elementAppearsCentered(e, t) { + var n = window.innerWidth - t.right - t.left; + return Math.abs(n) <= 1; +} +function centeredElementIsNotAContainer(e, t) { + if (e === document.documentElement || e === document.body) return !0; + if (0 === t.left && t.width === window.innerWidth) return !0; + if (!t.height) return !0; + var n = e.innerText; + return !n || !n.trim(); +} +var WebContentLayoutAnalyzer = function () { + ((this.centeredContainerElement = null), + (this.rectOfCenteredContainerElementBeforeResize = null), + (this.rectOfCenteredContainerElementAfterResize = null)); +}; +WebContentLayoutAnalyzer.prototype = { + findCenteredContainerElement: function () { + for ( + var e = null, + t = null, + n = document.getElementsByTagName("*"), + r = n.length, + i = 0; + i < r; + ++i + ) { + var o = n[i], + l = o.getBoundingClientRect(); + elementAppearsCentered(o, l) && + (centeredElementIsNotAContainer(o, l) || + ((!t || l.width > t.width) && ((e = o), (t = l)))); + } + return e; + }, + collectInformationBeforeResize: function () { + ((this.centeredContainerElement = this.findCenteredContainerElement()), + this.centeredContainerElement && + (this.rectOfCenteredContainerElementBeforeResize = + this.centeredContainerElement.getBoundingClientRect())); + }, + collectInformationAfterResize: function () { + this.centeredContainerElement && + document.contains(this.centeredContainerElement) && + (this.rectOfCenteredContainerElementAfterResize = + this.centeredContainerElement.getBoundingClientRect()); + }, + layoutInformation: function () { + var e = !1, + t = null; + return ( + this.rectOfCenteredContainerElementBeforeResize && + this.rectOfCenteredContainerElementAfterResize && + ((e = + this.rectOfCenteredContainerElementBeforeResize.width === + this.rectOfCenteredContainerElementAfterResize.width), + (t = + this.rectOfCenteredContainerElementBeforeResize.left - + this.rectOfCenteredContainerElementAfterResize.left)), + { + FoundCenteredContainer: !!this.centeredContainerElement, + CenteredContainerIsFixedWidth: e, + DistanceContainerMoved: t, + } + ); + }, +}; +var WebContentLayoutAnalyzerJS = new WebContentLayoutAnalyzer(); diff --git a/js/metadata/MetadataExtractor.js b/js/metadata/MetadataExtractor.js new file mode 100644 index 0000000..41d1351 --- /dev/null +++ b/js/metadata/MetadataExtractor.js @@ -0,0 +1,104 @@ +//# sourceURL=__InjectedScript_MetadataExtractor.js +/* Copyright (c) 2025 Apple Inc. All rights reserved. */ +function getIconType(e) { + var o = e.getAttribute("rel"); + return "apple-touch-icon" === o + ? IconTypeAppleTouchIcon + : "apple-touch-icon-precomposed" === o + ? IconTypeAppleTouchIconPrecomposed + : IconTypeFavicon; +} +function compareIconsDescending(e, o) { + var c = getIconType(e), + t = getIconType(o); + if (c === IconTypeFavicon && t !== IconTypeFavicon) return 1; + if (t === IconTypeFavicon && c !== IconTypeFavicon) return -1; + var n = e.getAttribute("sizes"), + r = o.getAttribute("sizes"), + p = 0, + a = 0; + return ( + n + ? (p = parseInt(n)) + : n || + (c !== IconTypeAppleTouchIcon && + c !== IconTypeAppleTouchIconPrecomposed) || + (p = AppleTouchIconDefaultWidth), + r + ? (a = parseInt(r)) + : r || + (t !== IconTypeAppleTouchIcon && + t !== IconTypeAppleTouchIconPrecomposed) || + (a = AppleTouchIconDefaultWidth), + a > p + ? 1 + : a < p + ? -1 + : c !== IconTypeAppleTouchIconPrecomposed && + t === IconTypeAppleTouchIconPrecomposed + ? 1 + : t !== IconTypeAppleTouchIconPrecomposed && + c === IconTypeAppleTouchIconPrecomposed + ? -1 + : 0 + ); +} +function colorComponentsFromString(e) { + var o = document.createElement("canvas"); + ((o.width = 1), (o.height = 1)); + var c = o.getContext("2d"); + ((c.fillStyle = e), c.fillRect(0, 0, 1, 1)); + var t = c.getImageData(0, 0, 1, 1); + return [t.data[0], t.data[1], t.data[2]]; +} +var MetadataExtractor = function () {}; +const IconTypeFavicon = 0, + IconTypeAppleTouchIcon = 1, + IconTypeAppleTouchIconPrecomposed = 2, + AppleTouchIconDefaultWidth = 60; +MetadataExtractor.prototype = { + extractAndSortIconsWithSelector: function (e) { + var o = document.head.querySelectorAll(e); + return o.length + ? Array.prototype.slice.call(o).sort(compareIconsDescending) + : []; + }, + extractAppleTouchIconURLs: function () { + for ( + var e = this.extractAndSortIconsWithSelector( + "link[rel=apple-touch-icon], link[rel=apple-touch-icon-precomposed]", + ), + o = [], + c = 0; + c < e.length; + ++c + ) { + var t = e[c].href; + t && o.push(t); + } + return o; + }, + extractFaviconURLs: function () { + for ( + var e = this.extractAndSortIconsWithSelector( + "link[rel='shortcut icon'], link[rel=icon]", + ), + o = [], + c = e.length, + t = 0; + t < c; + ++t + ) + o.push(e[t].href); + return o; + }, + extractTemplateIconURLAndColor: function () { + var e = document.head.querySelector("link[rel=mask-icon]"); + if (!e) return null; + var o = e.getAttribute("color"); + return o && e.href + ? { url: e.href, color: colorComponentsFromString(o) } + : null; + }, +}; +var MetadataExtractorJS = new MetadataExtractor(); diff --git a/js/reader/Reader.js b/js/reader/Reader.js new file mode 100644 index 0000000..ddc74b6 --- /dev/null +++ b/js/reader/Reader.js @@ -0,0 +1,35 @@ +//# sourceURL=__InjectedScript_Reader.js +/* Copyright (c) 2025 Apple Inc. All rights reserved. */ +/* + * Copyright (c) 2010 Apple Inc. All rights reserved. + */ +function setScrollTop(e) { + document.documentElement.scrollTop = e; +} +function readerWillBecomeVisible() { + setReaderIsActive(!0); +} +function readerWillEnterBackground() { + setReaderIsActive(!1); +} +ReaderJS._clickingOutsideOfPaperRectangleDismissesReader = !0; +let cachedIframeURLMap = new Map(); +((ReaderJS._readerWillBecomeVisible = function () { + for (let e of document.querySelectorAll("iframe")) { + let r = cachedIframeURLMap.get(e); + r && ((e.src = r), cachedIframeURLMap.delete(e)); + } +}), + (ReaderJS._readerWillEnterBackground = function () { + for (let e of document.querySelectorAll("iframe")) { + e.src && (cachedIframeURLMap.set(e, e.src), e.removeAttribute("src")); + } + }), + (ReaderJS._isJavaScriptEnabled = function () { + return !!(ReaderJSController.initialConfiguration() || {})[ + ReaderConfigurationJavaScriptEnabledKey + ]; + }), + (ReaderAppearanceJS._tryApplyStaticConfiguration = function () { + return (document.body.classList.add("mac"), !1); + })); diff --git a/js/reader/ReaderArticleFinder.js b/js/reader/ReaderArticleFinder.js new file mode 100644 index 0000000..d32a870 --- /dev/null +++ b/js/reader/ReaderArticleFinder.js @@ -0,0 +1,5076 @@ +//# sourceURL=__InjectedScript_ReaderArticleFinder.js +/* Copyright (c) 2025 Apple Inc. All rights reserved. */ +/* + * Copyright (c) 2010 Apple Inc. All rights reserved. + * + * Portions Copyright (c) 2009 Arc90 Inc + * Readability. An Arc90 Lab Experiment. + * Website: http://lab.arc90.com/experiments/readability + * Source: http://code.google.com/p/arc90labs-readability + * Readability is licensed under the Apache License, Version 2.0. + */ +function hostnameMatchesHostKnownToContainEmbeddableMedia(e) { + return /^(.+\.)?(youtube(-nocookie)?\.com|vimeo\.com|dailymotion\.com|soundcloud\.com|mixcloud\.com|embedly\.com|embed\.ly)\.?$/.test( + e, + ); +} +function lazyLoadingImageURLForElement(e, t) { + function n(e) { + const t = /\.(jpe?g|png|gif|bmp)$/i; + if (t.test(e)) return !0; + let n = urlFromString(e); + return !!n && t.test(n.pathname); + } + function r(e) { + let t = attributesForElement(e); + for (let r of t) { + let t = r.name; + if (a.has(t.toLowerCase())) return e.getAttribute(t); + let i = n(r.value); + if (o.has(t.toLowerCase()) && i) return e.getAttribute(t); + if (s && /^data.*(src|source)$/i.test(t) && i) return e.getAttribute(t); + if ( + e instanceof HTMLImageElement && + /^data-/.test(t) && + i && + 1 === e.naturalWidth && + 1 === e.naturalHeight + ) + return e.getAttribute(t); + } + } + const i = + /(data:image\/)?gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==/, + a = new Set([ + "data-lazy-src", + "data-original", + "datasrc", + "data-src", + "original-src", + "rel:bf_image_src", + "deferred-src", + "data-mediaviewer-src", + "data-hi-res-src", + "data-native-src", + ]), + o = new Set(["original"]); + let l = e.getAttribute("src"), + s = /transparent|empty/i.test(l) || i.test(l); + const c = 2; + for (let t = e, n = 0; t && n < c; t = t.parentElement, ++n) { + let e = r(t); + if (e) return e; + } + let u = e.closest("*[itemscope]"); + if ( + u && + /^https?:\/\/schema\.org\/ImageObject\/?$/.test(u.getAttribute("itemtype")) + ) { + let e = u.getAttribute("itemid"); + if (n(e) && !u.querySelector("img")) return e; + } + if (LazyLoadRegex.test(t) && "function" == typeof URL) { + var m; + try { + m = new URL(e.src); + } catch (e) {} + if (m && m.search) { + var d, h; + const t = ["w", "width"]; + for (var g = t.length, f = 0; f < g; ++f) { + var p = t[f], + E = m.searchParams.get(p); + if (E && !isNaN(parseInt(E))) { + d = p; + break; + } + } + const n = ["h", "height"]; + var v = n.length; + for (f = 0; f < v; ++f) { + var N = n[f], + C = m.searchParams.get(N); + if (C && !isNaN(parseInt(C))) { + h = N; + break; + } + } + if (d && h) { + var A = e.getAttribute("width"), + S = e.getAttribute("height"); + if (!isNaN(parseInt(A)) && !isNaN(parseInt(S))) + return (m.searchParams.set(d, A), m.searchParams.set(h, S), m.href); + } + } + } + return null; +} +function sanitizeElementByRemovingAttributes(e) { + elementLooksLikeEmbeddedIframeTweetWithSrc(e) && + (e.setAttribute("height", e.style.height), + e.setAttribute("width", e.style.width)); + const t = /^on|^id$|^class$|^style$|^autofocus$/; + for (var n = attributesForElement(e), r = 0; r < n.length; ++r) { + var i = n[r].nodeName; + t.test(i) && (e.removeAttribute(i), r--); + } +} +function characterAppearsToBeCJK(e) { + if (!e || 0 === e.length) return !1; + var t = e.charCodeAt(0); + return ( + (t > 11904 && t < 12031) || + (t > 12352 && t < 12543) || + (t > 12736 && t < 19903) || + (t > 19968 && t < 40959) || + (t > 44032 && t < 55215) || + (t > 63744 && t < 64255) || + (t > 65072 && t < 65103) || + (t > 131072 && t < 173791) || + (t > 194560 && t < 195103) + ); +} +function domDistance(e, t, n) { + for (var r = [], i = e; i; ) (r.unshift(i), (i = i.parentNode)); + var a = []; + for (i = t; i; ) (a.unshift(i), (i = i.parentNode)); + for ( + var o = Math.min(r.length, a.length), + l = Math.abs(r.length - a.length), + s = o; + s >= 0 && r[s] !== a[s]; + --s + ) + if (((l += 2), n && l >= n)) return n; + return l; +} +function fontSizeFromComputedStyle(e, t) { + var n = parseInt(e.fontSize); + return (isNaN(n) && (n = t || BaseFontSize), n); +} +function contentTextStyleForNode(e, t) { + function n(e) { + if (isNodeWhitespace(e)) return null; + var t = getComputedStyle(e.parentNode); + return "none" !== t.float ? null : t; + } + for ( + var r = + "descendant::text()[not(parent::h1) and not(parent::h2) and not(parent::h3) and not(parent::h4) and not(parent::h5) and not(parent::h6)]", + i = e.evaluate(r, t, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null), + a = i.snapshotLength, + o = 0; + o < a; + ++o + ) { + for ( + var l = i.snapshotItem(o), s = !1, c = l.parentElement; + c !== t; + c = c.parentElement + ) + if (NegativeRegEx.test(c.className)) { + s = !0; + break; + } + if (!s) { + var u = n(l); + if (u) return u; + } + } + return null; +} +function isNodeWhitespace(e) { + return !(!e || e.nodeType !== Node.TEXT_NODE) && !/\S/.test(e.data); +} +function removeWhitespace(e) { + return e.replace(/\s+/g, ""); +} +function isElementNode(e) { + return !(!e || e.nodeType !== Node.ELEMENT_NODE); +} +function computedStyleIndicatesElementIsInvisibleDueToClipping(e) { + if ("absolute" !== e.position) return !1; + var t = e.clip.match( + /^rect\((\d+px|auto), (\d+px|auto), (\d+px|auto), (\d+px|auto)\)$/, + ); + if (!t || 5 !== t.length) return !1; + var n = t.map(function (e) { + return parseInt(e); + }), + r = n[1]; + isNaN(r) && (r = 0); + var i = n[2], + a = n[3], + o = n[4]; + return (isNaN(o) && (o = 0), r >= a || i >= o); +} +function isElementVisible(e) { + var t = getComputedStyle(e); + if ("visible" !== t.visibility || "none" === t.display) return !1; + if (cachedElementBoundingRect(e).height) return !0; + var n = document.createRange(); + return (n.selectNode(e), !!n.getBoundingClientRect().height); +} +function isElementPositionedOffScreen(e) { + var t = cachedElementBoundingRect(e); + return !(!t.height || !t.width) && (t.bottom <= 0 || t.right <= 0); +} +function elementDepth(e) { + for (var t = 0; e; e = e.parentElement) t++; + return t; +} +function depthOfElementWithinElement(e, t) { + for (var n = 0; e !== t; e = e.parentElement) { + if (!e) return NaN; + n++; + } + return n; +} +function nearestAncestorElementWithTagName(e, t, n) { + var r = {}; + if (n) for (var i = 0; i < n.length; ++i) r[n[i]] = !0; + if (r[normalizedElementTagName(e)]) return null; + for (; (e = e.parentElement); ) { + var a = normalizedElementTagName(e); + if (r[a]) break; + if (a === t) return e; + } + return null; +} +function elementDescendsFromElementMatchingSelector(e, t) { + do { + if (e.matches(t)) return !0; + } while ((e = e.parentElement)); + return !1; +} +function elementDescendsFromElementInSet(e, t) { + do { + if (t.has(e)) return !0; + } while ((e = e.parentElement)); + return !1; +} +function elementIsHidingContentDueToContentVisibilityAuto(e) { + return ( + !!window.ContentVisibilityAutoStateChangeEvent && + "auto" === getComputedStyle(e).contentVisibility && + !!e.children.length && + !e.children[0].checkVisibility({ contentVisibilityAuto: !0 }) + ); +} +function cachedElementBoundingRect(e) { + if (e._cachedElementBoundingRect) return e._cachedElementBoundingRect; + if ( + ReaderArticleFinderJS.shouldSuppressBoundingRectCalculationForSkippedElements() && + elementIsHidingContentDueToContentVisibilityAuto(e) + ) { + let n = e.previousElementSibling; + return n && !elementIsHidingContentDueToContentVisibilityAuto(n) + ? (((t = cachedElementBoundingRect(n)).top += t.height), + (t.bottom += t.height), + t) + : { top: 0, right: 0, bottom: 0, left: 0, width: 0, height: 0 }; + } + var t = e.getBoundingClientRect(); + return ( + ReaderArticleFinderJS._elementsWithCachedBoundingRects.push(e), + ReaderArticleFinderJS._cachedScrollX || ReaderArticleFinderJS._cachedScrollY + ? ((e._cachedElementBoundingRect = { + top: t.top + ReaderArticleFinderJS._cachedScrollY, + right: t.right + ReaderArticleFinderJS._cachedScrollX, + bottom: t.bottom + ReaderArticleFinderJS._cachedScrollY, + left: t.left + ReaderArticleFinderJS._cachedScrollX, + width: t.width, + height: t.height, + }), + e._cachedElementBoundingRect) + : ((e._cachedElementBoundingRect = t), e._cachedElementBoundingRect) + ); +} +function clearCachedElementBoundingRects() { + for ( + var e = ReaderArticleFinderJS._elementsWithCachedBoundingRects, + t = e.length, + n = 0; + n < t; + ++n + ) + e[n]._cachedElementBoundingRect = null; + ReaderArticleFinderJS._elementsWithCachedBoundingRects = []; +} +function trimmedInnerTextIgnoringTextTransform(e) { + var t = e.innerText; + if (!/\S/.test(t)) return e.textContent.trim(); + var n = getComputedStyle(e).textTransform; + return "uppercase" === n || "lowercase" === n + ? e.textContent.trim() + : t + ? t.trim() + : ""; +} +function levenshteinDistance(e, t) { + for ( + var n = e.length, r = t.length, i = new Array(n + 1), a = 0; + a < n + 1; + ++a + ) + ((i[a] = new Array(r + 1)), (i[a][0] = a)); + for (var o = 0; o < r + 1; ++o) i[0][o] = o; + for (o = 1; o < r + 1; ++o) + for (a = 1; a < n + 1; ++a) + if (e[a - 1] === t[o - 1]) i[a][o] = i[a - 1][o - 1]; + else { + var l = i[a - 1][o] + 1, + s = i[a][o - 1] + 1, + c = i[a - 1][o - 1] + 1; + i[a][o] = Math.min(l, s, c); + } + return i[n][r]; +} +function stringSimilarity(e, t) { + var n = Math.max(e.length, t.length); + return n ? (n - levenshteinDistance(e, t)) / n : 0; +} +function stringsAreNearlyIdentical(e, t) { + return ( + e === t || + stringSimilarity(e, t) > StringSimilarityToDeclareStringsNearlyIdentical + ); +} +function elementIsCommentBlock(e) { + if (/(^|\s)comment/.test(e.className)) return !0; + var t = e.getAttribute("id"); + return !(!t || (0 !== t.indexOf("comment") && 0 !== t.indexOf("Comment"))); +} +function elementLooksLikeEmbeddedTweet(e) { + var t = null; + if ("iframe" === normalizedElementTagName(e)) { + if (!e.contentDocument) + return elementLooksLikeEmbeddedIframeTweetWithSrc(e); + t = e.contentDocument.documentElement; + } else "twitter-widget" === normalizedElementTagName(e) && (t = e.shadowRoot); + if (!t) return !1; + if (e.closest(".twitter-video") && t.querySelector("[data-tweet-id]")) + return !0; + let n = 0, + r = t.querySelector("blockquote"); + r && TweetURLRegex.test(r.getAttribute("cite")) && ++n; + let i = t.querySelector("[data-iframe-title]"); + return ( + i && TweetIframeTitleRegex.test(i.getAttribute("data-iframe-title")) && ++n, + e.classList.contains("twitter-tweet") && ++n, + t.querySelector("[data-tweet-id]") && ++n, + n > 2 + ); +} +function elementLooksLikeEmbeddedIframeTweetWithSrc(e) { + return ( + EmbeddedTwitterIframeSrcRegEx.test(e.getAttribute("src")) && + "Twitter Tweet" === e.getAttribute("title") + ); +} +function elementLooksLikeACarousel(e) { + const t = /carousel-|carousel_|-carousel|_carousel|swiper-/; + return t.test(e.className) || t.test(e.getAttribute("data-analytics")); +} +function elementLooksLikePartOfACarousel(e) { + const t = 3; + for (var n = e, r = 0; r < t; ++r) { + if (!n) return !1; + if (elementLooksLikeACarousel(n)) return !0; + n = n.parentElement; + } + return !1; +} +function urlIsHTTPFamilyProtocol(e) { + let t = e.protocol; + return "http:" === t || "https:" === t; +} +function shouldPruneIframe(e) { + if (e.srcdoc) return !0; + let t = urlFromString(e.src); + if (t) { + if (!urlIsHTTPFamilyProtocol(t)) return !0; + if (hostnameMatchesHostKnownToContainEmbeddableMedia(t.hostname)) return !1; + } + return !elementLooksLikeEmbeddedTweet(e.originalElement); +} +function textContentAppearsToBeCJK(e, t) { + if (!e || !e.length) return !1; + let n = e.length; + t && !isNaN(t) && (n = Math.min(n, t)); + let r = 0; + for (let t = 0; t < n; t++) characterAppearsToBeCJK(e[t]) && r++; + return r >= n * MinimumRatioOfCharactersForLanguageMultiplier; +} +function languageScoreMultiplierForTextNodes(e) { + if (!e || !e.length) return 1; + for ( + var t = Math.min( + e.length, + DefaultNumberOfTextNodesToCheckForLanguageMultiplier, + ), + n = 0, + r = 0, + i = 0; + i < t; + i++ + ) { + for ( + var a = e[i].nodeValue.trim(), + o = Math.min( + a.length, + NumberOfCharactersPerTextNodeToEvaluateForLanguageMultiplier, + ), + l = 0; + l < o; + l++ + ) + characterAppearsToBeCJK(a[l]) && n++; + r += o; + } + return n >= r * MinimumRatioOfCharactersForLanguageMultiplier + ? ScoreMultiplierForChineseJapaneseKorean + : 1; +} +function scoreMultiplierForElementTagNameAndAttributes(e) { + for (var t = 1, n = e; n; n = n.parentElement) { + var r = n.getAttribute("id"); + r && + (ArticleRegEx.test(r) && (t += ArticleMatchBonus), + CommentRegEx.test(r) && (t -= CommentMatchPenalty), + CarouselRegEx.test(r) && (t -= CarouselMatchPenalty)); + var i = n.className; + (i && + (ArticleRegEx.test(i) && (t += ArticleMatchBonus), + CommentRegEx.test(i) && (t -= CommentMatchPenalty), + CarouselRegEx.test(i) && (t -= CarouselMatchPenalty)), + "article" === normalizedElementTagName(n) && (t += ArticleMatchBonus)); + } + return t < 0 ? 0 : t; +} +function elementAtPoint(e, t, n) { + if ( + "undefined" != typeof ReaderArticleFinderJSController && + ReaderArticleFinderJSController.nodeAtPoint + ) { + var r = ReaderArticleFinderJSController.nodeAtPoint(e, t); + return (r && r.nodeType !== Node.ELEMENT_NODE && (r = r.parentElement), r); + } + return n.elementFromPoint(e, t); +} +function userVisibleURLString(e) { + return "undefined" != typeof ReaderArticleFinderJSController && + ReaderArticleFinderJSController.userVisibleURLString + ? ReaderArticleFinderJSController.userVisibleURLString(e) + : e; +} +function urlFromString(e, t) { + try { + return null != t ? new URL(e, t) : new URL(e); + } catch (e) { + return null; + } +} +function urlStringShouldHaveItsAnchorMadeNonFunctional(e, t) { + if (!e) return !0; + var n = urlFromString(e); + if ((n || (n = urlFromString(e, t)), !n || !n.href || !n.href.length)) + return !0; + let r = n.href; + return ( + "javascript:" === r.trim().substring(0, 11).toLowerCase() || + "data:" === r.trim().substring(0, 5).toLowerCase() + ); +} +function anchorLinksToAttachment(e) { + return /\battachment\b/i.test(e.getAttribute("rel")); +} +function anchorLinksToTagOrCategoryPage(e) { + return /\bcategory|tag\b/i.test(e.getAttribute("rel")); +} +function anchorLooksLikeDownloadFlashLink(e) { + return /^https?:\/\/(www\.|get\.)(adobe|macromedia)\.com\/(((products|[a-zA-Z]{1,2}|)\/flashplayer|flashplayer|go\/getflash(player)?)|(shockwave\/download\/(index|download)\.cgi\?P1_Prod_Version=ShockwaveFlash)\/?$)/i.test( + e.href, + ); +} +function elementsHaveSameTagAndClassNames(e, t) { + return ( + normalizedElementTagName(e) === normalizedElementTagName(t) && + e.className === t.className + ); +} +function selectorForElement(e) { + let t = normalizedElementTagName(e); + for (var n = e.classList, r = n.length, i = 0; i < r; i++) t += "." + n[i]; + return t; +} +function elementFingerprintForDepth(e, t) { + function n(e, t) { + if (!e) return ""; + var o = []; + o.push(selectorForElement(e)); + var l = e.children, + s = l.length; + if (s && t > 0) { + o.push(r); + for (var c = 0; c < s; ++c) + (o.push(n(l[c], t - 1)), c !== s - 1 && o.push(a)); + o.push(i); + } + return o.join(""); + } + const r = " / ", + i = " \\", + a = " | "; + return n(e, t); +} +function childrenOfParentElement(e) { + var t = e.parentElement; + return t ? t.children : []; +} +function arrayOfKeysAndValuesOfObjectSortedByValueDescending(e) { + var t = []; + for (var n in e) e.hasOwnProperty(n) && t.push({ key: n, value: e[n] }); + return ( + t.sort(function (e, t) { + return t.value - e.value; + }), + t + ); +} +function walkElementSubtree(e, t, n) { + if (!(t < 0)) { + for (var r = e.children, i = r.length, a = t - 1, o = 0; o < i; ++o) + walkElementSubtree(r[o], a, n); + n(e, t); + } +} +function elementIndicatesItIsASchemaDotOrgArticleContainer(e) { + var t = e.getAttribute("itemtype"); + return /^https?:\/\/schema\.org\/((News)?Article|APIReference)$/.test(t); +} +function elementIndicatesItIsASchemaDotOrgImageObject(e) { + var t = e.getAttribute("itemtype"); + return ( + "https://schema.org/ImageObject" === t || + "http://schema.org/ImageObject" === t + ); +} +function elementWouldAppearBetterAsFigureOrAuxiliary(e, t) { + const n = /caption/i; + if (!e) return !1; + if (t.closest("figure, .auxiliary")) return !1; + if ( + elementIndicatesItIsASchemaDotOrgImageObject(e) && + !t.querySelector("figure, .auxiliary") + ) + return !0; + var r = t.ownerDocument.createTreeWalker( + t, + NodeFilter.SHOW_ELEMENT | NodeFilter.SHOW_TEXT, + { + acceptNode: function () { + return NodeFilter.FILTER_ACCEPT; + }, + }, + ); + r.currentNode = t; + for (var i = !1, a = !1; r.nextNode(); ) { + var o = r.currentNode; + if (o.nodeType === Node.TEXT_NODE) { + if (!i && /\S/.test(o.nodeValue)) return !1; + continue; + } + if (o.nodeType !== Node.ELEMENT_NODE) return !1; + let e = normalizedElementTagName(o); + if ("figure" === e || "table" === e) return !1; + if (o.classList.contains("auxiliary")) return !1; + if ("img" === e) { + if (i) return !1; + i = !0; + } + var l = o.originalElement; + a || + (l && !hasClassMatchingRegexp(o.originalElement, n)) || + !/\S/.test(o.innerText) || + (a = !0); + } + return i && a; +} +function cleanStyleAndClassList(e) { + (e.classList.length || e.removeAttribute("class"), + e.getAttribute("style") || e.removeAttribute("style")); +} +function getVisibleNonWhitespaceTextNodes(e, t, n, r, i) { + function a(e) { + var t = e.children[0]; + if (t) + for (var n = t.children, r = n.length, i = 0; i < r; ++i) + if ("none" !== getComputedStyle(n[i]).float) return !1; + return !0; + } + function o(e, r) { + if (e.nodeType === Node.TEXT_NODE) + return void (/\S/.test(e.nodeValue) && s.push(e)); + if (e.nodeType !== Node.ELEMENT_NODE) return; + if (!isElementVisible(e)) return; + if (n && ++l > n) return; + if (i && i.has(e)) return; + let u = normalizedElementTagName(e); + if ("iframe" !== u && "form" !== u) { + if (c.has(u)) r--; + else if (("ul" !== u && "ol" !== u) || !a(e)) { + var m = e.parentElement; + if (m) + "section" !== normalizedElementTagName(m) || + e.previousElementSibling || + e.nextElementSibling || + r--; + } else r--; + var d = r + 1; + if (d < t) + for (var h = e.childNodes, g = h.length, f = 0; f < g; ++f) o(h[f], d); + } + } + var l = 0, + s = []; + let c = new Set(["p", "strong", "b", "em", "i", "span", "section"]); + return (r && (c.add("center"), c.add("font")), o(e, 0), s); +} +function mapOfVisibleTextNodeComputedStyleReductionToNumberOfMatchingCharacters( + e, + t, +) { + for ( + var n = {}, + r = getVisibleNonWhitespaceTextNodes(e, 100), + i = r.length, + a = 0; + a < i; + ++a + ) { + var o = r[a], + l = o.length, + s = o.parentElement, + c = t(getComputedStyle(s)); + n[c] ? (n[c] += l) : (n[c] = l); + } + return n; +} +function keyOfMaximumValueInDictionary(e) { + var t, n; + for (var r in e) { + var i = e[r]; + (!n || i > n) && ((t = r), (n = i)); + } + return t; +} +function elementIsProtected(e) { + return e.classList.contains("protected") || e.querySelector(".protected"); +} +function dominantFontFamilyAndSizeForElement(e) { + return keyOfMaximumValueInDictionary( + mapOfVisibleTextNodeComputedStyleReductionToNumberOfMatchingCharacters( + e, + function (e) { + return e.fontFamily + "|" + e.fontSize; + }, + ), + ); +} +function dominantFontSizeInPointsFromFontFamilyAndSizeString(e) { + return e ? parseInt(e.split("|")[1]) : null; +} +function canvasElementHasNoUserVisibleContent(e) { + if (!e.width || !e.height) return !0; + for ( + var t = e.getContext("2d").getImageData(0, 0, e.width, e.height).data, + n = 0, + r = t.length; + n < r; + n += 4 + ) { + if (t[n + 3]) return !1; + } + return !0; +} +function findArticleNodeSelectorsInQuirksListForHostname(e, t) { + const n = [ + [AppleDotComAndSubdomainsRegex, "*[itemprop='articleBody']"], + [/^(.+\.)?buzzfeed\.com\.?$/, "article #buzz_sub_buzz"], + [/^(.+\.)?mashable\.com\.?$/, ".parsec-body .parsec-container"], + [/^(.+\.)?cnet\.com\.?$/, "#rbContent.container"], + [/^(.+\.)?engadget\.com\.?$/, "main article #page_body"], + [/^(.*\.)?m\.wikipedia\.org\.?$/, "#content #bodyContent"], + [/^(.*\.)?theintercept\.com\.?$/, ".PostContent"], + [/^(.*\.)?tools\.ietf\.org\.?$/, "div.content"], + [/^(.+\.)?meteoinfo\.ru\.?$/, "#jm-content-bottom"], + [/^(.*\.)?tmd\.go\.th\.?$/, "#sidebar"], + ]; + for (var r = n.length, i = 0; i < r; ++i) { + var a = n[i]; + if (a[0].test(e.toLowerCase())) if (t(a[1])) return; + } +} +function functionToPreventPruningDueToInvisibilityInQuirksListForHostname(e) { + const t = [ + [ + /^mobile\.nytimes\.com\.?$/, + function (e, t) { + var n = e; + if (!t) return !1; + for (; n && n !== t; ) { + if (n.classList.contains("hidden")) return !0; + n = n.parentElement; + } + return !1; + }, + ], + ]; + for (var n = t.length, r = 0; r < n; ++r) { + var i = t[r]; + if (i[0].test(e.toLowerCase())) return i[1]; + } + return null; +} +function elementIsAHeader(e) { + return !!{ h1: 1, h2: 1, h3: 1, h4: 1, h5: 1, h6: 1 }[ + normalizedElementTagName(e) + ]; +} +function leafElementForElementAndDirection(e, t) { + var n = e.ownerDocument, + r = n.createTreeWalker(n.body, NodeFilter.SHOW_ELEMENT, { + acceptNode: function (e) { + return 0 === e.children.length + ? NodeFilter.FILTER_ACCEPT + : NodeFilter.FILTER_SKIP; + }, + }); + return ((r.currentNode = e), r[t]()); +} +function previousLeafElementForElement(e) { + return leafElementForElementAndDirection(e, "previousNode"); +} +function nextLeafElementForElement(e) { + return leafElementForElementAndDirection(e, "nextNode"); +} +function nextNonFloatingVisibleElementSibling(e) { + for (var t = e; (t = t.nextElementSibling); ) + if (isElementVisible(t) && "none" === getComputedStyle(t).float) return t; + return null; +} +function elementWithLargestAreaFromElements(e) { + var t, + n = e.length; + if (!n) return null; + for (var r = 0, i = 0; i < n; ++i) { + var a = e[i], + o = cachedElementBoundingRect(a), + l = o.width * o.height; + l > r && ((t = a), (r = l)); + } + return t; +} +function unwrappedArticleContentElement(e) { + for (var t = e; ; ) { + for (var n = t.childNodes, r = n.length, i = null, a = 0; a < r; ++a) { + var o = n[a], + l = o.nodeType; + if ( + l === Node.ELEMENT_NODE || + (l === Node.TEXT_NODE && !isNodeWhitespace(o)) + ) { + if (i) return t; + var s = normalizedElementTagName(o); + if ("div" !== s && "article" !== s && "section" !== s) return t; + i = o; + } + } + if (!i) break; + t = i; + } + return t; +} +function elementsMatchingClassesInClassList(e, t) { + return elementsOfSameClassIgnoringClassNamesMatchingRegexp(e, t); +} +function elementsMatchingClassesInClassListIgnoringCommonLayoutClassNames( + e, + t, +) { + return elementsOfSameClassIgnoringClassNamesMatchingRegexp(e, t, /clearfix/i); +} +function elementsMatchingClassesInClassListIgnoringClassesWithNumericSuffix( + e, + t, +) { + return elementsOfSameClassIgnoringClassNamesMatchingRegexp(e, t, /\d+$/); +} +function elementsOfSameClassIgnoringClassNamesMatchingRegexp(e, t, n) { + for (var r = "", i = e.length, a = 0; a < i; ++a) { + var o = e[a]; + (n && n.test(o)) || (r += "." + o); + } + try { + return t.querySelectorAll(r); + } catch (e) { + return []; + } +} +function imageIsContainedByContainerWithImageAsBackgroundImage(e) { + var t = e.parentElement; + if (!t || !t.style || !t.style.backgroundImage) return !1; + var n = /url\((.*)\)/.exec(t.style.backgroundImage); + return !(!n || 2 !== n.length) && n[1] === e.src; +} +function pseudoElementContent(e, t) { + var n = getComputedStyle(e, t).content, + r = /^\"(.*)\"$/.exec(n); + return r && 2 == r.length ? r[1] : null; +} +function hasClassMatchingRegexp(e, t) { + for (var n = e.classList, r = n.length, i = 0; i < r; ++i) + if (t.test(n[i])) return !0; + return !1; +} +function elementLooksLikeDropCap(e) { + return hasClassMatchingRegexp(e, DropCapRegex) && 1 === e.innerText.length; +} +function changeElementType(e, t) { + for ( + var n = e.ownerDocument.createElement(t), + r = attributesForElement(e), + i = r.length, + a = 0; + a < i; + ++a + ) { + var o = r.item(a); + n.setAttribute(o.nodeName, o.nodeValue); + } + for (; e.firstChild; ) n.appendChild(e.firstChild); + return (e.replaceWith(n), n); +} +function pathComponentsForAnchor(e) { + var t = e.pathname.substring(1).split("/"); + return (t[t.length - 1] || t.pop(), t); +} +function lastPathComponentFromAnchor(e) { + var t = pathComponentsForAnchor(e); + return t.length ? t[t.length - 1] : null; +} +function clamp(e, t, n) { + return Math.min(Math.max(e, t), n); +} +function normalizedElementTagName(e) { + return e.localName; +} +function childrenWithParallelStructure(e) { + var t = e.children; + if (!t) return []; + var n = t.length; + if (!n) return []; + for (var r = {}, i = 0; i < n; ++i) { + var a = t[i]; + if ( + !SetOfCandidateTagNamesToIgnore.has(normalizedElementTagName(a)) && + a.className + ) + for (var o = a.classList, l = o.length, s = 0; s < l; ++s) { + (m = r[(u = o[s])]) ? m.push(a) : (r[u] = [a]); + } + } + var c = Math.floor(n / 2); + for (var u in r) { + var m; + if ((m = r[u]).length > c) return m; + } + return []; +} +function elementAppearsToBeCollapsed(e) { + return ( + !( + !ReaderArticleFinderJS.isMediaWikiPage() || !/collaps/.test(e.className) + ) || + ("false" === e.getAttribute("aria-expanded") && !isElementVisible(e)) + ); +} +const ReaderMinimumScore = 1600, + ReaderMinimumAdvantage = 15, + ArticleMinimumScoreDensity = 4.25, + CandidateMinimumWidthPortionForIndicatorElements = 0.5, + CandidateMinumumListItemLineCount = 4, + SetOfCandidateTagNamesToIgnore = new Set([ + "a", + "embed", + "form", + "html", + "iframe", + "object", + "ol", + "option", + "script", + "style", + "svg", + "ul", + ]), + PrependedArticleCandidateMinimumHeight = 50, + AppendedArticleCandidateMinimumHeight = 200, + AppendedArticleCandidateMaximumVerticalDistanceFromArticle = 150, + StylisticClassNames = { justfy: 1, justify: 1, left: 1, right: 1, small: 1 }, + CommentRegEx = /[Cc]omment|meta|footer|footnote|talkback/, + CommentMatchPenalty = 0.75, + ArticleRegEx = + /(?:(?:^|\s)(?:(post|hentry|entry)[-_]{0,2}(?:content|text|body)?|article[-_]{0,2}(?:content|text|body|page|copy)?)(?:\s|$))/i, + ArticleMatchBonus = 0.5, + CarouselRegEx = /carousel/i, + CarouselMatchPenalty = 0.75, + SectionRegex = /section|content.*component/i, + DropCapRegex = /first.*letter|drop.*cap/i, + ProgressiveLoadingRegex = /progressive/i, + DensityExcludedElementSelector = "#disqus_thread, #comments, .userComments", + PositiveRegEx = + /article|body|content|entry|hentry|page|pagination|post|related-asset|text/i, + NegativeRegEx = + /advertisement|breadcrumb|combx|comment|contact|disqus|footer|link|meta|mod-conversations|promo|related|scroll|share|shoutbox|sidebar|social|sponsor|spotim|subscribe|talkback|tags|toolbox|widget|[-_]ad$|zoom-(in|out)/i, + VeryPositiveClassNameRegEx = /instapaper_body/, + VeryNegativeClassNameRegEx = /instapaper_ignore/, + SharingRegex = + /email|print|rss|digg|slashdot|delicious|reddit|share|twitter|facebook|pinterest|whatsapp/i, + VeryLiberalCommentRegex = /comment/i, + AdvertisementHostRegex = /^adserver\.|doubleclick.net$/i, + SidebarRegex = /sidebar/i, + MinimumAverageDistanceBetweenHRElements = 400, + MinimumAverageDistanceBetweenHeaderElements = 400, + PortionOfCandidateHeightToIgnoreForHeaderCheck = 0.1, + DefaultNumberOfTextNodesToCheckForLanguageMultiplier = 3, + NumberOfCharactersPerTextNodeToEvaluateForLanguageMultiplier = 12, + MinimumRatioOfCharactersForLanguageMultiplier = 0.5, + ScoreMultiplierForChineseJapaneseKorean = 3, + MinimumContentMediaHeight = 150, + MinimumContentMediaWidthToArticleWidthRatio = 0.25, + MaximumContentMediaAreaToArticleAreaRatio = 0.2, + LinkContinueMatchRegEx = /continue/gi, + LinkNextMatchRegEx = /next/gi, + LinkPageMatchRegEx = /page/gi, + LinkListItemBonus = 5, + LinkPageMatchBonus = 10, + LinkNextMatchBonus = 15, + LinkContinueMatchBonus = 15, + LinkNextOrdinalValueBase = 3, + LinkMismatchValueBase = 2, + LinkMatchWeight = 200, + LinkMaxVerticalDistanceFromArticle = 200, + LinkVerticalDistanceFromArticleWeight = 150, + LinkCandidateXPathQuery = + "descendant-or-self::*[(not(@id) or (@id!='disqus_thread' and @id!='comments')) and (not(@class) or @class!='userComments')]/a", + LinkDateRegex = + /\D(?:\d\d(?:\d\d)?[\-\/](?:10|11|12|0?[1-9])[\-\/](?:30|31|[12][0-9]|0?[1-9])|\d\d(?:\d\d)?\/(?:10|11|12|0[1-9])|(?:10|11|12|0?[1-9])\-(?:30|31|[12][0-9]|0?[1-9])\-\d\d(?:\d\d)?|(?:30|31|[12][0-9]|0?[1-9])\-(?:10|11|12|0?[1-9])\-\d\d(?:\d\d)?)\D/, + LinkURLSearchParameterKeyMatchRegex = /(page|^p$|^pg$)/i, + LinkURLPageSlashNumberMatchRegex = /\/.*page.*\/\d+/i, + LinkURLSlashDigitEndMatchRegex = /\/\d+\/?$/, + LinkURLArchiveSlashDigitEndMatchRegex = /archives?\/\d+\/?$/, + LinkURLBadSearchParameterKeyMatchRegex = + /author|comment|feed|id|nonce|related/i, + LinkURLSemanticMatchBonus = 100, + LinkMinimumURLSimilarityRatio = 0.75, + SubheadRegex = /sub(head|title)|description|dec?k|abstract/i, + HeaderMinimumDistanceFromArticleTop = 200, + HeaderLevenshteinDistanceToLengthRatio = 0.75, + MinimumRatioOfListItemsBeingRelatedToSharingToPruneEntireList = 0.5, + FloatMinimumHeight = 130, + ImageSizeTiny = 32, + ToleranceForLeadingMediaWidthToArticleWidthForFullWidthPresentation = 80, + MaximumFloatWidth = 325, + AnchorImageMinimumWidth = 100, + AnchorImageMinimumHeight = 100, + MinimumHeightForImagesAboveTheArticleTitle = 50, + MainImageMinimumWidthAndHeight = 83, + BaseFontSize = 16, + BaseLineHeightRatio = 1.125, + MaximumExactIntegralValue = 9007199254740992, + TitleCandidateDepthScoreMultiplier = 0.1, + TextNodeLengthPower = 1.25, + LazyLoadRegex = /lazy/i, + HeaderElementsSelector = "h1, h2, h3, h4, h5, h6", + PageType = { + homepage: "homepage", + searchResults: "search-results", + article: "article", + }, + StringSimilarityToDeclareStringsNearlyIdentical = 0.97, + FindArticleMode = { Element: !1, ExistenceOfElement: !0 }, + AppleDotComAndSubdomainsRegex = /.*\.apple\.com\.?$/, + SchemaDotOrgArticleContainerSelector = + "*[itemtype='https://schema.org/Article'], *[itemtype='https://schema.org/NewsArticle'], *[itemtype='https://schema.org/APIReference'], *[itemtype='http://schema.org/Article'], *[itemtype='http://schema.org/NewsArticle'], *[itemtype='http://schema.org/APIReference']", + CleaningType = { MainArticleContent: 0, MetadataContent: 1, LeadingMedia: 2 }, + MaximumWidthOrHeightOfImageInMetadataSection = 20; +var attributesForElement = (function () { + var e = Element.prototype.__lookupGetter__("attributes"); + return function (t) { + return e.call(t); + }; +})(); +const TweetURLRegex = + /^https?:\/\/(.+\.)?twitter\.com\/.*\/status\/(.*\/)*[0-9]+\/?$/i, + TweetIframeTitleRegex = /tweet/i, + EmbeddedTwitterIframeSrcRegEx = + /^https?:\/\/platform\.twitter\.com\/embed\/Tweet\.html/i; +((CandidateElement = function (e, t) { + ((this.element = e), + (this.contentDocument = t), + (this.textNodes = this.usableTextNodesInElement(this.element)), + (this.rawScore = this.calculateRawScore()), + (this.tagNameAndAttributesScoreMultiplier = + this.calculateElementTagNameAndAttributesScoreMultiplier()), + (this.languageScoreMultiplier = 0), + (this.depthInDocument = 0)); +}), + (CandidateElement.extraArticleCandidateIfElementIsViable = function ( + e, + t, + n, + r, + ) { + const i = "a, b, strong, i, em, u, span"; + var a = cachedElementBoundingRect(e), + o = cachedElementBoundingRect(t.element); + if ( + ((r && a.height < PrependedArticleCandidateMinimumHeight) || + (!r && a.height < AppendedArticleCandidateMinimumHeight)) && + e.childElementCount && + e.querySelectorAll("*").length !== e.querySelectorAll(i).length + ) + return null; + if (r) { + if (a.bottom > o.top) return null; + } else if (a.top < o.bottom) return null; + if ( + !r && + a.top - o.bottom > + AppendedArticleCandidateMaximumVerticalDistanceFromArticle + ) + return null; + if (a.left > o.right || a.right < o.left) return null; + if (elementLooksLikePartOfACarousel(e)) return null; + var l = new CandidateElement(e, n); + return ((l.isPrepended = r), l); + }), + (CandidateElement.candidateIfElementIsViable = function (e, t, n) { + var r = cachedElementBoundingRect(e), + i = ReaderArticleFinderJS.candidateElementFilter; + return r.width < i.minimumWidth || + r.height < i.minimumHeight || + r.width * r.height < i.minimumArea || + (!n && r.top > i.maximumTop) || + CandidateElement.candidateElementAdjustedHeight(e) < i.minimumHeight + ? null + : new CandidateElement(e, t); + }), + (CandidateElement.candidateElementAdjustedHeight = function (e) { + for ( + var t = cachedElementBoundingRect(e), + n = t.height, + r = e.getElementsByTagName("form"), + i = r.length, + a = 0; + a < i; + ++a + ) { + var o = cachedElementBoundingRect(r[a]); + o.width > t.width * CandidateMinimumWidthPortionForIndicatorElements && + (n -= o.height); + } + var l = e.querySelectorAll("ol, ul"), + s = l.length, + c = null; + for (a = 0; a < s; ++a) { + var u = l[a]; + if ( + !( + c && + c.compareDocumentPosition(u) & Node.DOCUMENT_POSITION_CONTAINED_BY + ) + ) { + var m = u.getElementsByTagName("li"), + d = m.length, + h = cachedElementBoundingRect(u); + if (d) { + var g = h.height / d, + f = getComputedStyle(m[0]), + p = parseInt(f.lineHeight); + if (isNaN(p)) p = fontSizeFromComputedStyle(f) * BaseLineHeightRatio; + h.width > + t.width * CandidateMinimumWidthPortionForIndicatorElements && + g / p < CandidateMinumumListItemLineCount && + ((n -= h.height), (c = u)); + } else n -= h.height; + } + } + return n; + }), + (CandidateElement.prototype = { + calculateRawScore: function () { + for (var e = 0, t = this.textNodes, n = t.length, r = 0; r < n; ++r) + e += this.rawScoreForTextNode(t[r]); + return e; + }, + calculateElementTagNameAndAttributesScoreMultiplier: function () { + return scoreMultiplierForElementTagNameAndAttributes(this.element); + }, + calculateLanguageScoreMultiplier: function () { + 0 === this.languageScoreMultiplier && + (this.languageScoreMultiplier = languageScoreMultiplierForTextNodes( + this.textNodes, + )); + }, + depth: function () { + return ( + this.depthInDocument || + (this.depthInDocument = elementDepth(this.element)), + this.depthInDocument + ); + }, + finalScore: function () { + return ( + this.calculateLanguageScoreMultiplier(), + this.basicScore() * this.languageScoreMultiplier + ); + }, + basicScore: function () { + return this.rawScore * this.tagNameAndAttributesScoreMultiplier; + }, + scoreDensity: function () { + var e = 0, + t = this.element.querySelector(DensityExcludedElementSelector); + t && (e = t.clientWidth * t.clientHeight); + for ( + var n = this.element.children || [], r = n.length, i = 0; + i < r; + ++i + ) { + var a = n[i]; + elementIsCommentBlock(a) && (e += a.clientWidth * a.clientHeight); + } + var o = + cachedElementBoundingRect(this.element).width * + cachedElementBoundingRect(this.element).height, + l = o * MaximumContentMediaAreaToArticleAreaRatio, + s = + cachedElementBoundingRect(this.element).width * + MinimumContentMediaWidthToArticleWidthRatio, + c = this.element.querySelectorAll("img, video"), + u = c.length; + for (i = 0; i < u; ++i) { + var m = cachedElementBoundingRect(c[i]); + if (m.width >= s && m.height > MinimumContentMediaHeight) { + var d = m.width * m.height; + d < l && (e += d); + } + } + var h = this.basicScore(), + g = o - e, + f = this.textNodes.length, + p = 0, + E = 0; + for (i = 0; i < f; ++i) { + var v = this.textNodes[i].parentNode; + v && ((E += fontSizeFromComputedStyle(getComputedStyle(v))), p++); + } + var N = BaseFontSize; + return ( + p && (N = E /= p), + this.calculateLanguageScoreMultiplier(), + (h / g) * 1e3 * (N / BaseFontSize) * this.languageScoreMultiplier + ); + }, + usableTextNodesInElement: function (e) { + var t = []; + if (!e) return t; + const n = new Set([ + "a", + "dd", + "dt", + "noscript", + "ol", + "option", + "pre", + "script", + "style", + "td", + "ul", + "iframe", + ]); + var r = this.contentDocument, + i = function (e) { + const i = + "text()|*/text()|*/a/text()|*/li/text()|*/li/p/text()|*/span/text()|*/em/text()|*/i/text()|*/strong/text()|*/b/text()|*/font/text()|blockquote/*/text()|div[count(./p)=count(./*)]/p/text()|div[count(*)=1]/div/p/text()|div[count(*)=1]/div/p/*/text()|div/div/text()"; + for ( + var a = r.evaluate( + i, + e, + null, + XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, + null, + ), + o = a.snapshotLength, + l = 0; + l < o; + ++l + ) { + var s = a.snapshotItem(l); + n.has(normalizedElementTagName(s.parentNode)) || + s._countedTextNode || + isNodeWhitespace(s) || + ((s._countedTextNode = !0), t.push(s)); + } + }; + i(e); + for ( + var a = childrenWithParallelStructure(e), o = a.length, l = 0; + l < o; + ++l + ) { + i(a[l]); + } + var s = t.length; + for (l = 0; l < s; ++l) delete t[l]._countedTextNode; + return t; + }, + addTextNodesFromCandidateElement: function (e) { + for (var t = this.textNodes.length, n = 0; n < t; ++n) + this.textNodes[n].alreadyCounted = !0; + var r = e.textNodes, + i = r.length; + for (n = 0; n < i; ++n) r[n].alreadyCounted || this.textNodes.push(r[n]); + for (t = this.textNodes.length, n = 0; n < t; ++n) + this.textNodes[n].alreadyCounted = null; + this.rawScore = this.calculateRawScore(); + }, + rawScoreForTextNode: function (e) { + const t = 20; + if (!e) return 0; + var n = e.length; + if (n < t) return 0; + var r = e.parentNode; + if (!isElementVisible(r)) return 0; + for (var i = 1; r && r !== this.element; ) + ((i -= 0.1), (r = r.parentNode)); + return Math.pow(n * i, TextNodeLengthPower); + }, + shouldDisqualifyDueToScoreDensity: function () { + return this.scoreDensity() < ArticleMinimumScoreDensity; + }, + shouldDisqualifyDueToHorizontalRuleDensity: function () { + for ( + var e = this.element.getElementsByTagName("hr"), + t = e.length, + n = 0, + r = cachedElementBoundingRect(this.element), + i = 0.7 * r.width, + a = 0; + a < t; + ++a + ) + e[a].clientWidth > i && n++; + if (n && r.height / n < MinimumAverageDistanceBetweenHRElements) + return !0; + return !1; + }, + shouldDisqualifyDueToHeaderDensity: function () { + var e = "(h1|h2|h3|h4|h5|h6|*/h1|*/h2|*/h3|*/h4|*/h5|*/h6)[a[@href]]", + t = this.contentDocument.evaluate( + e, + this.element, + null, + XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, + null, + ), + n = t.snapshotLength; + if (n > 2) { + for ( + var r = 0, + i = cachedElementBoundingRect(this.element), + a = i.height * PortionOfCandidateHeightToIgnoreForHeaderCheck, + o = 0; + o < n; + ++o + ) { + var l = t.snapshotItem(o); + if ( + "#" !== + l.querySelector("a[href]").getAttribute("href").substring(0, 1) + ) { + var s = cachedElementBoundingRect(l); + s.top - i.top > a && i.bottom - s.bottom > a && r++; + } + } + if (i.height / r < MinimumAverageDistanceBetweenHeaderElements) + return !0; + } + return !1; + }, + shouldDisqualifyDueToSimilarElements: function (e) { + function t(e, t) { + if (!e || !t) return !1; + var n = 1; + return e.className + ? e.className === t.className + : elementFingerprintForDepth(e, n) === + elementFingerprintForDepth(t, n); + } + var n = function (e) { + const t = /related-posts/i; + for ( + var n = e.parentElement; + n && n !== this.contentDocument.body; + n = n.parentElement + ) + if (t.test(n.className)) return !0; + return !1; + }.bind(this), + r = this.element; + if ("article" === normalizedElementTagName(r.parentElement)) return !1; + let i = normalizedElementTagName(r); + if ("li" === i || "dd" === i) + for (var a = r.parentNode, o = a.children.length, l = 0; l < o; ++l) { + if ( + normalizedElementTagName((f = a.children[l])) === i && + f.className === r.className && + f !== r + ) + return !0; + } + var s = r.classList; + if ( + (s.length || + ((r = r.parentElement) && + ((s = r.classList).length || + ((r = r.parentElement) && (s = r.classList)))), + s.length) + ) { + e || (e = []); + var c = e.length; + for (l = 0; l < c; ++l) e[l].element.candidateElement = e[l]; + var u = + elementsMatchingClassesInClassListIgnoringCommonLayoutClassNames( + s, + this.contentDocument, + ), + m = !1, + d = elementDepth(r), + h = n(r), + g = u.length; + for (l = 0; l < g; ++l) { + var f; + if ( + (f = u[l]) !== r && + f.parentElement !== r && + r.parentElement !== f && + isElementVisible(f) + ) { + var p = f.candidateElement; + if ( + (p || (p = new CandidateElement(f, this.contentDocument))) && + p.basicScore() * ReaderMinimumAdvantage > this.basicScore() + ) { + if (f.closest("section") && r.closest("section")) return !1; + if ( + SectionRegex.test(f.className) && + SectionRegex.test(r.className) + ) + return !1; + if (n(f) && !h) return !1; + if ( + !m && + cachedElementBoundingRect(f).bottom < + cachedElementBoundingRect(this.element).top + ) { + m = !0; + continue; + } + if ( + t(r.previousElementSibling, f.previousElementSibling) || + t(r.nextElementSibling, f.nextElementSibling) + ) { + var E = r.querySelector(HeaderElementsSelector), + v = f.querySelector(HeaderElementsSelector); + if (E && v && elementsHaveSameTagAndClassNames(E, v)) return !0; + if ( + ((E = r.previousElementSibling), + (v = f.previousElementSibling), + E && + v && + elementIsAHeader(E) && + elementIsAHeader(v) && + elementsHaveSameTagAndClassNames(E, v)) + ) + return !0; + } + if (elementDepth(f) === d) + for ( + ; + f.parentElement && + r.parentElement && + f.parentElement !== r.parentElement; + ) + ((f = f.parentElement), (r = r.parentElement)); + for (; r.childElementCount <= 1; ) { + if (!r.childElementCount || !f.childElementCount) return !1; + if (f.childElementCount > 1) return !1; + if ( + normalizedElementTagName(r.firstElementChild) !== + normalizedElementTagName(f.firstElementChild) + ) + return !1; + ((r = r.firstElementChild), (f = f.firstElementChild)); + } + if (f.childElementCount <= 1) return !1; + v = f.firstElementChild; + var N = f.lastElementChild, + C = ((E = r.firstElementChild), r.lastElementChild); + if (normalizedElementTagName(v) !== normalizedElementTagName(E)) + return !1; + if (normalizedElementTagName(N) !== normalizedElementTagName(C)) + return !1; + var A = v.className, + S = N.className, + b = E.className, + y = N.className, + T = y === b ? 2 : 1; + if (A.length || b.length) { + if (!A.length || !b.length) return !1; + if ( + A === b && + elementsMatchingClassesInClassList(E.classList, r).length <= T + ) + return !0; + } + if (S.length || y.length) { + if (!S.length || !y.length) return !1; + if ( + S === y && + elementsMatchingClassesInClassList(N.classList, r).length <= T + ) + return !0; + } + var x = E.clientHeight, + R = C.clientHeight; + return ( + !(!x || !v.clientHeight) && + !(!R || !N.clientHeight) && + (x === v.clientHeight || R === N.clientHeight) + ); + } + } + } + for (l = 0; l < c; ++l) e[l].element.candidateElement = null; + } + return !1; + }, + shouldDisqualifyForDeepLinking: function () { + const e = 5; + for ( + var t = this.element, + n = this.contentDocument.location, + r = pathComponentsForAnchor(n).length, + i = [], + a = t.getElementsByTagName("a"), + o = a.length, + l = 0; + l < o; + l++ + ) { + var s = a[l]; + if ( + n.host === s.host && + !( + pathComponentsForAnchor(s).length <= r || + 0 !== (s.host + s.pathname).indexOf(n.host + n.pathname) || + anchorLinksToAttachment(s) || + (i.push(s), i.length < e) + ) + ) { + var c = t.offsetTop + t.offsetHeight / e; + return i[0].offsetTop < c; + } + } + return !1; + }, + }), + (String.prototype.lastInteger = function () { + const e = /[0-9]+/g; + var t = this.match(e); + return t ? parseInt(t[t.length - 1]) : NaN; + })); +((ReaderArticleFinder = function (e) { + ((this.contentDocument = e), + (this.didSearchForArticleNode = !1), + (this.didChangeContentDocumentToFrameOnPage = !1), + (this.article = null), + (this.didSearchForExtraArticleNode = !1), + (this.extraArticle = null), + (this._leadingMediaElement = null), + (this._isMediaWikiPage = void 0), + (this._cachedScrollY = 0), + (this._cachedScrollX = 0), + (this._elementsWithCachedBoundingRects = []), + (this._cachedContentTextStyle = null), + (this.pageNumber = 1), + (this.prefixWithDateForNextPageURL = null), + (this.previouslyDiscoveredPageURLStrings = []), + (this.candidateElementFilter = { + minimumWidth: 280, + minimumHeight: 295, + minimumArea: 17e4, + maxTop: 1300, + })); + let t = 0; + ((this._nextUniqueID = function () { + return t++ + ""; + }), + (this._mapOfUniqueIDToOriginalElement = new Map()), + (this._weakMapOfOriginalElementToUniqueID = new WeakMap())); +}), + (ReaderArticleFinder.prototype = { + setCandidateElementFilter: function (e) { + let [t, n] = this._validityAndValidCandidateElementFilterFromFilter(e); + t && (this.candidateElementFilter = n); + }, + _validityAndValidCandidateElementFilterFromFilter: function (e) { + let t = {}, + n = !1; + for (let i of [ + "minimumWidth", + "minimumHeight", + "minimumArea", + "maxTop", + ]) { + let r = (e || {})[i]; + if (void 0 === r || "number" != typeof r || r < 0) { + ((t = {}), (n = !1)); + break; + } + ((t[i] = r), (n = !0)); + } + return [n, t]; + }, + pointsForDominantIframeHitTest: function () { + const e = 60; + return [ + [e, e], + [window.innerWidth - e, e], + [e, window.innerHeight - e], + [window.innerWidth - e, window.innerHeight - e], + ]; + }, + dominantContentIframe: function () { + let e, + t = this.pointsForDominantIframeHitTest(), + n = t.length; + for (let i = 0; i < n; i++) { + if ( + ((cornerElement = document.elementFromPoint(t[i][0], t[i][1])), + !cornerElement || "IFRAME" !== cornerElement.tagName) + ) + return null; + if (e) { + if (e !== cornerElement) return null; + } else e = cornerElement; + } + return e; + }, + checkForIframeCoveringMostOfWebpage: function () { + let e = this.dominantContentIframe(); + e && + !this.didChangeContentDocumentToFrameOnPage && + ((this.contentDocument = e.contentDocument), + this.resetArticleInformation(), + (this.didChangeContentDocumentToFrameOnPage = !0)); + }, + isReaderModeAvailable: function () { + return ( + this.setSuppressBoundingRectCalculationForSkippedElements(!0), + this.checkForIframeCoveringMostOfWebpage(), + !!this.findArticleBySearchingQuirksList() || + (this.cacheWindowScrollPosition(), + !!this.findArticleFromMetadata(FindArticleMode.ExistenceOfElement) || + ((this.article = this.findArticleByVisualExamination()), + this.article && this.articleIsLTR(), + !!this.article)) + ); + }, + resetArticleInformation: function () { + ((this.didSearchForArticleNode = !1), + (this.didSearchForExtraArticleNode = !1), + delete this.article, + delete this.extraArticle, + delete this._articleTitleInformation, + delete this._articleTitleElement, + delete this._leadingMediaElement, + delete this._cachedContentTextStyle, + delete this._adoptableArticle, + delete this._articleIsLTR, + delete this._nextPageURL, + delete this._cachedScrollY, + delete this._cachedScrollX, + clearCachedElementBoundingRects()); + }, + reset: function () { + (this.resetArticleInformation(), this.prepareToTransitionToReader()); + }, + prepareToTransitionToReader: function () { + (this.adoptableArticle(!0), this.nextPageURL(), this.articleIsLTR()); + }, + nextPageURL: function () { + if (!this._nextPageURL) { + var e = this.nextPageURLString(); + ("undefined" != typeof ReaderArticleFinderJSController && + e && + (e = ReaderArticleFinderJSController.substituteURLForNextPageURL(e)), + (this._nextPageURL = e)); + } + return this._nextPageURL; + }, + containerElementsForMultiPageContent: function () { + const e = /(.*page[^0-9]*|.*article.*item[^0-9]*)(\d{1,2})(.*)/i, + t = 3; + for ( + var n, i = [], r = this.articleNode(), a = 0; + !(n = e.exec(r.getAttribute("id"))); + ) + if (!(r = r.parentElement) || a++ === t) return []; + for ( + var l = childrenOfParentElement(r), o = l.length, s = 0; + s < o; + ++s + ) { + var c = l[s]; + if (c !== r) { + var m = e.exec(c.getAttribute("id")); + m && + m[1] === n[1] && + m[3] === n[3] && + ((isElementVisible(c) && !isElementPositionedOffScreen(c)) || + i.push(c)); + } + } + return i; + }, + adoptableMultiPageContentElements: function () { + return this.containerElementsForMultiPageContent().map(function (e) { + return this.cleanArticleNode( + e, + e.cloneNode(!0), + CleaningType.MainArticleContent, + !1, + ); + }, this); + }, + classNameIsSignificantInRouteComputation: function (e) { + return !!e && !(e.toLowerCase() in StylisticClassNames); + }, + shouldIgnoreInRouteComputation: function (e) { + let t = normalizedElementTagName(e); + return ( + "script" === t || + "link" === t || + "style" === t || + ("tr" === t && !e.offsetHeight) + ); + }, + routeToArticleNode: function () { + for (var e = [], t = this.articleNode(); t; ) { + var n = {}; + n.tagName = normalizedElementTagName(t); + var i = t.getAttribute("id"); + (i && (n.id = i), + this.classNameIsSignificantInRouteComputation(t.className) && + (n.className = t.className), + (n.index = 1)); + for (var r = t.previousElementSibling; r; r = r.previousElementSibling) + this.shouldIgnoreInRouteComputation(r) || n.index++; + (e.unshift(n), (t = t.parentElement)); + } + return e; + }, + adjustArticleNodeUpwardIfNecessary: function () { + if (!this.article) return; + var e = this.article.element; + if (!e.parentElement) return; + for (var t = e; t; t = t.parentElement) + if (VeryPositiveClassNameRegEx.test(t.className)) + return void (this.article.element = t); + if ( + "header" === normalizedElementTagName(e) && + "article" === normalizedElementTagName(e.parentElement) + ) + return void (this.article.element = e.parentElement); + var n = e.previousElementSibling; + if ( + n && + "figure" === normalizedElementTagName(n) && + "article" === normalizedElementTagName(e.parentElement) + ) + return void (this.article.element = e.parentElement); + var i = + "section" === normalizedElementTagName(e) + ? e + : nearestAncestorElementWithTagName(e, "section", ["article"]); + if (i) { + var r = i.parentElement, + a = (function () { + for (var e = r.children, t = e.length, n = 0; n < t; ++n) { + var a = e[n], + l = normalizedElementTagName(a); + if (a !== i && ("section" === l || "header" === l)) return !0; + } + return !1; + })(); + if ( + a && + (/\barticleBody\b/.test(r.getAttribute("itemprop")) || + "main" === normalizedElementTagName(r) || + "main" === r.getAttribute("role") || + "article" === normalizedElementTagName(r) || + r === this.contentDocument.body || + r.classList.contains("entry-content")) + ) + return void (this.article.element = r); + } + const l = /intro/i, + o = /body|content/i; + if ( + ((e = this.article.element), + (l.test(e.className) && + e.nextElementSibling && + o.test(e.nextElementSibling.className)) || + (o.test(e.className) && + e.previousElementSibling && + l.test(e.previousElementSibling.className))) + ) + return void (this.article.element = e.parentElement); + if ("article" !== normalizedElementTagName(e)) { + var s = e.parentElement.closest("*[itemprop='articleBody']"); + if (s && s.parentElement.closest(SchemaDotOrgArticleContainerSelector)) + return void (this.article.element = s); + } + var c = e.closest("article"); + if (c) { + e = unwrappedArticleContentElement(e); + var m, + d = elementDepth(e); + ("p" !== normalizedElementTagName(e) || + e.className || + ((e = e.parentElement), d--), + e.classList.length + ? 1 === + (m = + elementsMatchingClassesInClassListIgnoringCommonLayoutClassNames( + e.classList, + this.contentDocument, + )).length && + (m = + elementsMatchingClassesInClassListIgnoringClassesWithNumericSuffix( + e.classList, + this.contentDocument, + )) + : (m = e.parentElement.children)); + for (var h = m.length, u = 0; u < h; ++u) { + var g = m[u]; + if ( + e !== g && + d === elementDepth(g) && + isElementVisible(g) && + !g.querySelector("article") && + Object.keys(e.dataset).join() === Object.keys(g.dataset).join() && + dominantFontFamilyAndSizeForElement(e) === + dominantFontFamilyAndSizeForElement(g) + ) + return void (this.article.element = c); + } + } + let f = this.findExtraArticle(), + p = f ? f.element : null; + if ( + p && + p.parentElement && + e.parentElement === p.parentElement && + ArticleRegEx.test(e.parentElement.className) + ) { + if ( + dominantFontFamilyAndSizeForElement(e) === + dominantFontFamilyAndSizeForElement(p) + ) + return void (this.article.element = e.parentElement); + } + let E = e.parentElement; + if ( + elementIsCommentBlock(e) && + !elementIsCommentBlock(E) && + ArticleRegEx.test(E.className) + ) { + let e = CandidateElement.candidateIfElementIsViable( + E, + this.contentDocument, + !0, + ); + if (e && e.finalScore() >= ReaderMinimumScore) + return void (this.article.element = E); + } + if (!(e = this.article.element).getAttribute("id") && e.className) { + var v = normalizedElementTagName(e), + T = e.className, + y = e.parentElement; + if (y) + for (var S = y.children, A = ((u = 0), S.length); u < A; ++u) { + var N = S[u]; + if ( + N !== e && + normalizedElementTagName(N) === v && + N.className === T + ) { + var b = CandidateElement.candidateIfElementIsViable( + N, + this.contentDocument, + !0, + ); + if (b && !(b.finalScore() < ReaderMinimumScore)) + return void (this.article.element = y); + } + } + } + }, + findArticleBySearchingQuirksList: function () { + var e, + t = this.contentDocument; + return ( + findArticleNodeSelectorsInQuirksListForHostname( + t.location.hostname, + function (n) { + var i = t.querySelectorAll(n); + if (1 === i.length) + return ((e = new CandidateElement(i[0], t)), !0); + }, + ), + e + ); + }, + articleNode: function (e) { + return ( + this.checkForIframeCoveringMostOfWebpage(), + this.didSearchForArticleNode || + ((this.article = this.findArticleBySearchingQuirksList()), + this.article || + (this.article = this.findArticleBySearchingAllElements()), + this.article || + (this.article = this.findArticleByVisualExamination()), + this.article || (this.article = this.findArticleFromMetadata()), + !this.article && + e && + (this.article = this.findArticleBySearchingAllElements(!0)), + (this.didSearchForArticleNode = !0), + this.adjustArticleNodeUpwardIfNecessary(), + this.article && + (this.article.element = unwrappedArticleContentElement( + this.article.element, + )), + this.article && this.articleIsLTR()), + this.article ? this.article.element : null + ); + }, + extraArticleNode: function () { + return ( + this.didSearchForArticleNode || this.articleNode(), + this.didSearchForExtraArticleNode || + ((this.extraArticle = this.findExtraArticle()), + (this.didSearchForExtraArticleNode = !0)), + this.extraArticle ? this.extraArticle.element : null + ); + }, + cacheWindowScrollPosition: function () { + ((this._cachedScrollY = window.scrollY), + (this._cachedScrollX = window.scrollX)); + }, + contentTextStyle: function () { + return ( + this._cachedContentTextStyle || + ((this._cachedContentTextStyle = contentTextStyleForNode( + this.contentDocument, + this.articleNode(), + )), + this._cachedContentTextStyle || + (this._cachedContentTextStyle = getComputedStyle( + this.articleNode(), + ))), + this._cachedContentTextStyle + ); + }, + commaCountIsLessThan: function (e, t) { + for ( + var n = 0, i = e.textContent, r = -1; + n < t && (r = i.indexOf(",", r + 1)) >= 0; + ) + n++; + return n < t; + }, + calculateLinkDensityForPruningElement: function (e, t) { + var n = removeWhitespace(e.textContent).length; + if (!n) return 0; + for ( + var i = this.article.element, + r = (function () { + for (var t = e.originalElement; t && t !== i; t = t.parentElement) + if ("none" !== getComputedStyle(t).float) return t; + return null; + })(), + a = e.getElementsByTagName("a"), + l = 0, + o = a.length, + s = 0; + s < o; + ++s + ) { + var c = a[s]; + (!r && + c.href && + t && + t === dominantFontFamilyAndSizeForElement(c.originalElement)) || + (l += removeWhitespace(c.textContent).length); + } + return l / n; + }, + shouldPruneElement: function (e, t, n) { + const i = 0.33, + r = 0.5, + a = 0.2, + l = 25, + o = 4e4; + let s = normalizedElementTagName(e); + if (!e.parentElement) return !1; + if (t.classList.contains("footnotes")) return !1; + if (e.querySelector(".tweet-wrapper")) return !1; + if ( + "figure" === normalizedElementTagName(e.parentElement) && + e.querySelector("img") + ) + return !1; + if ("iframe" === s) return shouldPruneIframe(e); + if ("canvas" !== s) { + for (var c = !1, m = e.childNodes.length, d = 0; d < m; ++d) { + var h = e.childNodes[d], + u = h.nodeType; + if ( + u === Node.ELEMENT_NODE || + (u === Node.TEXT_NODE && !isNodeWhitespace(h)) + ) { + c = !0; + break; + } + } + if (!c) { + if ("p" === s) { + var g = e.previousSibling, + f = e.nextSibling; + if ( + g && + g.nodeType === Node.TEXT_NODE && + !isNodeWhitespace(g) && + f && + f.nodeType === Node.TEXT_NODE && + !isNodeWhitespace(f) + ) + return !1; + } + return !0; + } + if ("p" === s) return !1; + } + if ("canvas" === s) + return ( + (window.innerWidth === t.width && window.innerHeight === t.height) || + !( + !ProgressiveLoadingRegex.test(t.className) || + "img" !== normalizedElementTagName(t.nextElementSibling) + ) || + !!canvasElementHasNoUserVisibleContent(t) || + "cufon" === normalizedElementTagName(e.parentNode) + ); + if (e.closest("figure") && e.querySelector("picture")) return !1; + var p = 0; + if (t) { + if (VeryNegativeClassNameRegEx.test(t.className)) return !0; + var E = t.className, + v = t.getAttribute("id"); + (PositiveRegEx.test(E) && p++, + PositiveRegEx.test(v) && p++, + NegativeRegEx.test(E) && p--, + NegativeRegEx.test(v) && p--); + } + let T = this.isMediaWikiPage(); + if (p < 0 && !T) return !0; + if (elementIsProtected(e)) return !1; + if ("ul" === s || "ol" === s) { + if (t.querySelector("iframe") && t.querySelector("script")) return !0; + var y = t.children, + S = y.length; + if (!S && !/\S/.test(e.innerText)) return !0; + var A = 0, + N = 0; + for (d = 0; d < S; ++d) { + var b = y[d]; + if (SharingRegex.test(b.className)) A++; + else { + var x = b.children; + 1 === x.length && SharingRegex.test(x[0].className) && A++; + } + NegativeRegEx.test(y[d].className) && N++; + } + return ( + A / S >= + MinimumRatioOfListItemsBeingRelatedToSharingToPruneEntireList || + N / S >= MinimumRatioOfListItemsBeingRelatedToSharingToPruneEntireList + ); + } + if (1 === e.childElementCount) { + var C = e.firstElementChild; + if ("a" === normalizedElementTagName(C)) return !1; + if ( + "span" === normalizedElementTagName(C) && + "converted-anchor" === C.className && + nearestAncestorElementWithTagName(C, "table") + ) + return !1; + } + var D = e.getElementsByTagName("img"), + I = D.length; + if (I) { + var M = 0; + for (d = 0; d < I; ++d) { + var L = D[d].originalElement; + if (isElementVisible(L)) { + var R = cachedElementBoundingRect(L); + M += (R.width / I) * (R.height / I); + } + } + if (M > o) return !1; + } + if (!this.commaCountIsLessThan(e, 10)) return !1; + var w = e.getElementsByTagName("p").length, + F = e.getElementsByTagName("br").length, + _ = w + Math.floor(F / 2); + if (I > _ && "table" !== s) return !0; + if ( + !e.closest("table") && + !e._originalElementDepthInCollapsedArea && + !T + ) { + if ( + e.getElementsByTagName("li").length > _ && + dominantFontFamilyAndSizeForElement(t.querySelector("li")) !== n + ) + return !0; + if (e.textContent.length < l && 1 !== I) return !0; + let i = this.calculateLinkDensityForPruningElement(e, n); + if (p >= 1 && i > r) return !0; + if (p < 1 && i > a) return !0; + } + if (e.getElementsByTagName("input").length / _ > i) return !0; + if ("table" === s) { + if ( + removeWhitespace(e.innerText).length <= + 0.5 * removeWhitespace(t.innerText).length + ) + return !0; + if (T && t.classList.contains("toc")) return !0; + } + return !1; + }, + wordCountIsLessThan: function (e, t) { + for ( + var n = 0, i = e.textContent, r = -1; + (r = i.indexOf(" ", r + 1)) >= 0 && n < t; + ) + n++; + return n < t; + }, + leadingMediaIsAppropriateWidth: function (e) { + return ( + !(!this.article || !e) && + e.getBoundingClientRect().width >= + this.article.element.getBoundingClientRect().width - + ToleranceForLeadingMediaWidthToArticleWidthForFullWidthPresentation + ); + }, + newDivFromNode: function (e) { + var t = this.contentDocument.createElement("div"); + return (e && (t.innerHTML = e.innerHTML), t); + }, + headerElement: function () { + if (!this.article) return null; + var e = this.article.element.previousElementSibling; + if (e && "header" === normalizedElementTagName(e)) return e; + var t = this._articleTitleElement; + if (!t) return null; + var n = t.parentElement; + if ( + n && + "header" === normalizedElementTagName(n) && + !this.article.element.contains(n) + ) + for ( + var i = n.querySelectorAll("img"), r = i.length, a = 0; + a < r; + ++a + ) { + var l = i[a], + o = cachedElementBoundingRect(l); + if ( + o.width >= MainImageMinimumWidthAndHeight && + o.height >= MainImageMinimumWidthAndHeight + ) + return n; + } + return null; + }, + adoptableLeadingMedia: function () { + if ( + !this.article || + !this._leadingMediaElement || + !this.leadingMediaIsAppropriateWidth(this._leadingMediaElement) + ) + return null; + var e = this._leadingMediaElement.closest("figure"); + if (e) + return this.cleanArticleNode( + e, + e.cloneNode(!0), + CleaningType.LeadingMedia, + !0, + ); + if ("img" !== normalizedElementTagName(this._leadingMediaElement)) + return this.cleanArticleNode( + this._leadingMediaElement, + this._leadingMediaElement.cloneNode(!0), + CleaningType.LeadingMedia, + !0, + ); + const t = 5, + n = /credit/, + i = /caption/, + r = /src|alt/; + var a = this._leadingMediaElement.parentNode, + l = null, + o = null, + s = a.children.length; + if ("div" === normalizedElementTagName(a) && s > 1 && s < t) + for ( + var c = a.cloneNode(!0).querySelectorAll("p, div"), + m = c.length, + d = 0; + d < m; + ++d + ) { + var h = c[d]; + n.test(h.className) + ? (l = h.cloneNode(!0)) + : i.test(h.className) && (o = h.cloneNode(!0)); + } + var u = this._leadingMediaElement.cloneNode(!1), + g = lazyLoadingImageURLForElement(u, u.className); + (g && u.setAttribute("src", g), + (!g && u.hasAttribute("src")) || + !u.hasAttribute("data-srcset") || + u.setAttribute("srcset", u.getAttribute("data-srcset"))); + var f = attributesForElement(u); + for (d = 0; d < f.length; ++d) { + var p = f[d].nodeName; + r.test(p) || (u.removeAttribute(p), d--); + } + var E = this.contentDocument.createElement("div"); + if (((E.className = "leading-image"), E.appendChild(u), l)) { + var v = this.newDivFromNode(l); + ((v.className = "credit"), E.appendChild(v)); + } + if (o) { + var T = this.newDivFromNode(o); + ((T.className = "caption"), E.appendChild(T)); + } + return E; + }, + articleBoundingRect: function () { + return ( + this._articleBoundingRect || + (this._articleBoundingRect = cachedElementBoundingRect( + this.article.element, + )), + this._articleBoundingRect + ); + }, + adoptableArticle: function (e) { + if (this._adoptableArticle) return this._adoptableArticle.cloneNode(!0); + (this.setSuppressBoundingRectCalculationForSkippedElements(!1), + clearCachedElementBoundingRects(), + this.cacheWindowScrollPosition()); + var t = this.articleNode(e); + if ( + ((this._adoptableArticle = t ? t.cloneNode(!0) : null), + !this._adoptableArticle) + ) + return this._adoptableArticle; + if ( + ((this._adoptableArticle = this.cleanArticleNode( + t, + this._adoptableArticle, + CleaningType.MainArticleContent, + !1, + )), + "p" === normalizedElementTagName(this._adoptableArticle)) + ) { + var n = document.createElement("div"); + (n.appendChild(this._adoptableArticle), (this._adoptableArticle = n)); + } + var i = this.extraArticleNode(); + if (i) { + var r = this.cleanArticleNode( + i, + i.cloneNode(!0), + CleaningType.MainArticleContent, + !0, + ); + r + ? this.extraArticle.isPrepended + ? this._adoptableArticle.insertBefore( + r, + this._adoptableArticle.firstChild, + ) + : this._adoptableArticle.appendChild(r) + : (i = null); + var a = cachedElementBoundingRect(this.article.element), + l = cachedElementBoundingRect(this.extraArticle.element), + o = { + top: Math.min(a.top, l.top), + right: Math.max(a.right, l.right), + bottom: Math.max(a.bottom, l.bottom), + left: Math.min(a.left, l.left), + }; + ((o.width = o.right - o.left), + (o.height = o.bottom - o.top), + (this._articleBoundingRect = o)); + } + this._articleTextContent = this._adoptableArticle.innerText; + var s = this.headerElement(); + if ( + this._leadingMediaElement && + (!s || !s.contains(this._leadingMediaElement)) + ) { + var c = this.adoptableLeadingMedia(); + c && + this._adoptableArticle.insertBefore( + c, + this._adoptableArticle.firstChild, + ); + } + var m = !!s; + if (m && i && (i === s && (m = !1), m)) { + var d = i.compareDocumentPosition(s); + (d & Node.DOCUMENT_POSITION_CONTAINS || + d & Node.DOCUMENT_POSITION_CONTAINED_BY) && + (m = !1); + } + if (m) { + var h = this.cleanArticleNode( + s, + s.cloneNode(!0), + CleaningType.MainArticleContent, + !0, + ); + h && + this._adoptableArticle.insertBefore( + h, + this._adoptableArticle.firstChild, + ); + } + return this._adoptableArticle; + }, + dominantContentSelectorAndDepth: function (e) { + var t, + n = {}, + i = {}; + walkElementSubtree(e, 2, function (e, t) { + if (isElementVisible(e)) { + var r = selectorForElement(e) + " | " + t; + i[r] ? (i[r] += 1) : ((i[r] = 1), (n[r] = e)); + } + }); + var r = arrayOfKeysAndValuesOfObjectSortedByValueDescending(i); + switch (r.length) { + case 0: + break; + case 1: + t = r[0].key; + break; + default: + var a = r[0]; + a.value > r[1].value && (t = a.key); + } + if (!t) return null; + var l = n[t]; + return { + selector: selectorForElement(l), + depth: depthOfElementWithinElement(l, e), + }; + }, + functionToPreventPruningElementDueToInvisibility: function () { + return ( + functionToPreventPruningDueToInvisibilityInQuirksListForHostname( + this.contentDocument.location.hostname, + ) || + function () { + return !1; + } + ); + }, + cleanArticleNode: function (e, t, n, i) { + function r(e) { + ((v += e), + T && (T += e), + y && (y += e), + S && (S += e), + A && (A += e), + N && (N += e)); + } + function a() { + (1 === T && (T = 0), + 1 === y && (y = 0), + 1 === S && (S = 0), + 1 === A && (A = 0), + 1 === N && (N = 0)); + } + function l() { + const t = 0.8; + var n = cachedElementBoundingRect(e); + if (0 === n.width || 0 === n.height) return !0; + var i, + r = childrenWithParallelStructure(e), + a = r.length; + if (a) { + i = []; + for (var l = 0; l < a; ++l) { + var o = r[l]; + if ("none" === getComputedStyle(o).float) + for (var s = o.children, c = s.length, m = 0; m < c; ++m) + i.push(s[m]); + else i.push(o); + } + } else i = e.children; + var d = i.length, + h = 0; + for (l = 0; l < d; ++l) { + var u = i[l]; + "none" !== getComputedStyle(u).float && (h += u.innerText.length); + } + return h / e.innerText.length > t; + } + function o(t) { + const n = 50; + if (cachedElementBoundingRect(t).height > n) return !1; + return ( + !!new Set(["ul", "li", "nav"]).has(normalizedElementTagName(t)) || + (t.parentElement === e && !t.nextElementSibling) + ); + } + function s(e, t) { + const n = 0.9; + return !( + cachedElementBoundingRect(e).height > + n * cachedElementBoundingRect(t).height + ); + } + function c(e, t) { + const n = 1.1, + i = 1.4; + t && + H && + (e.matches(HeaderElementsSelector) || + ((t > i * H || (V.test(b.className) && t > n * H)) && + !e.closest(".pullquote") && + (e.classList.add("pullquote"), + e.classList.contains("float") || + ((e.style.width = null), cleanStyleAndClassList(e))))); + } + function m(e, t) { + for (var n = e[t]; n; n = n[t]) + if (!isNodeWhitespace(n) && n.nodeType !== Node.COMMENT_NODE) + return !1; + return !0; + } + const d = new Set([ + "form", + "script", + "style", + "link", + "button", + "object", + "embed", + "applet", + ]), + h = new Set([ + "div", + "table", + "ul", + "canvas", + "p", + "iframe", + "aside", + "section", + "footer", + "nav", + "ol", + "menu", + "svg", + ]), + u = new Set(["i", "em"]), + g = new Set(["b", "strong", "h1", "h2", "h3", "h4", "h5", "h6"]), + f = new Set(["i-amphtml-sizer"]), + p = /lightbox/i; + var E = [], + v = 0, + T = 0, + y = 0, + S = 0, + A = 0, + N = 0, + b = e, + x = b.ownerDocument.defaultView, + C = t, + D = this.articleTitle(), + I = this._articleTitleElement, + M = (this.articleSubhead(), this._articleSubheadElement), + L = + I && + cachedElementBoundingRect(I).top > + cachedElementBoundingRect(e).bottom, + R = isElementVisible(e), + w = new Set([I, M]), + F = new Set(); + if (n === CleaningType.MainArticleContent) { + this.updateArticleBylineAndDateElementsIfNecessary(); + var _ = this.articleBylineElement(); + _ && F.add(_); + var O = this.articleDateElement(); + O && F.add(O); + } + var B = this.dominantContentSelectorAndDepth(e), + P = l(), + k = new Set(); + this.previouslyDiscoveredPageURLStrings.forEach(function (e) { + k.add(e); + }); + var q = this.nextPageURL(); + q && k.add(q); + var z = null; + this._articleTitleElement && + (z = cachedElementBoundingRect(this._articleTitleElement)); + var W = this.functionToPreventPruningElementDueToInvisibility(), + U = dominantFontFamilyAndSizeForElement(e), + H = dominantFontSizeInPointsFromFontFamilyAndSizeString(U); + const V = /pull(ed)?quote/i; + for (var j = [], G = [], X = [], Y = [], K = []; b; ) { + try { + var Q, + J = null, + $ = normalizedElementTagName(C), + Z = !1, + ee = elementLooksLikeDropCap(b); + if ( + ((C.originalElement = b), + !N && elementAppearsToBeCollapsed(b) && (N = 1), + (d.has($) || (this.isAMPPage() && f.has($))) && (J = C), + !J && b !== e && w.has(b) + ? (J = C) + : !J && b !== e && F.has(b) + ? ((C.parentElementBeforePruning = C.parentElement), + (J = C), + j.push(C)) + : elementIsAHeader(C) && + previousLeafElementForElement(b) === I && + C.classList.add("protected"), + "twitter-widget" === $ && C.classList.add("protected"), + !J && ("h1" === $ || "h2" === $)) + ) + if ( + b.offsetTop - e.offsetTop < + HeaderMinimumDistanceFromArticleTop + ) { + var te = trimmedInnerTextIgnoringTextTransform(b), + ne = te.length * HeaderLevenshteinDistanceToLengthRatio; + levenshteinDistance(D, te) <= ne && (J = C); + } + if ( + (J || + (this.isMediaWikiPage() && + /editsection|icon-edit|edit-page|mw-empty-elt/.test( + b.className, + ) && + (J = C)), + "video" === $) + ) + if (C.getAttribute("src")) { + C.classList.add("protected"); + var ie = cachedElementBoundingRect(b); + (C.setAttribute("width", ie.width), + C.setAttribute("height", ie.height), + C.removeAttribute("style")); + b.hasAttribute("autoplay") && + b.hasAttribute("muted") && + b.hasAttribute("loop") + ? C.setAttribute("data-reader-silent-looped-animation", "") + : (C.setAttribute("controls", !0), + C.removeAttribute("autoplay"), + C.removeAttribute("preload")); + } else J = C; + J || (Q = getComputedStyle(b)); + let t = (function () { + if ("div" !== $ && "span" !== $) return !1; + if (LazyLoadRegex.test(b.className)) return !0; + for (let e of attributesForElement(b)) + if ( + /^data-/.test(e.name) && + LazyLoadRegex.test(e.value) && + cachedElementBoundingRect(b).height + ) + return !0; + return !1; + })(); + if ( + !J && + t && + (!b.innerText || + (b.previousElementSibling && + "noscript" === + normalizedElementTagName(b.previousElementSibling))) + ) + if ((Ie = lazyLoadingImageURLForElement(C, b.className))) { + var re = this.contentDocument.createElement("img"); + (re.setAttribute("src", Ie), + C.parentNode.replaceChild(re, C), + ((C = re).originalElement = b), + ($ = normalizedElementTagName(C)), + (J = C), + C.classList.add("protected")); + } + if (!J && "img" !== $ && /img/.test($)) { + lazyLoadingImageURLForElement(C, b.className) && + (((C = changeElementType(C, "img")).originalElement = b), + ($ = "img")); + } + if (!J && "div" === $ && C.parentNode) { + var ae = b.querySelectorAll( + "a, blockquote, dl, div, img, ol, p, pre, table, ul", + ), + le = T || "none" !== Q.float, + oe = null; + if ( + (le || ae.length + ? elementIndicatesItIsASchemaDotOrgImageObject(b) && + !C.querySelector("figure, .auxiliary") + ? (oe = "figure") + : ee && (oe = "span") + : (oe = "p"), + oe) + ) { + for ( + var se = C.parentNode, + ce = this.contentDocument.createElement(oe); + C.firstChild; + ) { + var me = C.firstChild; + ce.appendChild(me); + } + (se.replaceChild(ce, C), + ((C = ce).originalElement = b), + ($ = normalizedElementTagName(C))); + } + } + if ( + (b.dataset && + b.dataset.mathml && + b.querySelector("math") && + X.push(C), + !J && + C.parentNode && + h.has($) && + ((C._originalElementDepthInCollapsedArea = N), E.push(C)), + J || + (isElementPositionedOffScreen(b) + ? (J = C) + : b === e || + T || + "none" === Q.float || + P || + !( + cachedElementBoundingRect(b).height >= FloatMinimumHeight || + b.childElementCount > 1 + ) || + (T = 1)), + !J) + ) { + if ( + (sanitizeElementByRemovingAttributes(C), + n === CleaningType.MetadataContent) + ) + if ("|" === C.innerText) + ((C.innerText = ""), C.classList.add("delimiter")); + else if ("time" === normalizedElementTagName(C)) { + var de = C.previousElementSibling; + if ( + de && + "span" === normalizedElementTagName(de) && + !de.classList.contains("delimiter") + ) { + var he = this.contentDocument.createElement("span"); + (he.classList.add("delimiter"), C.before(he)); + } + } else "figure" === $ && (J = C); + if ( + ("both" === Q.clear && C.classList.add("clear"), + "ul" === $ || "ol" === $ || "menu" === $) + ) { + if (z && !N && cachedElementBoundingRect(b).top < z.top) J = C; + else if ( + "none" === Q["list-style-type"] && + "none" === Q["background-image"] + ) { + for ( + var ue = b.children, ge = ue.length, fe = !0, pe = 0; + pe < ge; + ++pe + ) { + var Ee = ue[pe], + ve = getComputedStyle(Ee); + if ( + "none" !== ve["list-style-type"] || + 0 !== parseInt(ve["-webkit-padding-start"]) + ) { + fe = !1; + break; + } + var Te = getComputedStyle(Ee, ":before").content; + if (/\u2022|\u25e6|\u2023|\u2219|counter/.test(Te)) { + fe = !1; + break; + } + } + fe && C.classList.add("list-style-type-none"); + } + if (b.querySelector("code")) { + const e = /monospace|menlo|courier/i; + var ye = dominantFontFamilyAndSizeForElement(b); + e.test(ye) && + (C.classList.add("code-block"), C.classList.add("protected")); + } + } + if ( + (S || + "normal" === Q.fontStyle || + (u.has($) || (C.style && (C.style.fontStyle = Q.fontStyle)), + (S = 1)), + !A && "normal" !== Q.fontWeight) + ) { + if (!g.has($)) { + var Se = parseInt(Q.fontWeight), + Ae = null; + (isNaN(Se) + ? (Ae = Q.fontWeight) + : Se <= 400 || (Se >= 500 && (Ae = "bold")), + Ae && C.style && (C.style.fontWeight = Ae)); + } + A = 1; + } + if ((T && "section" !== $ && s(b, e)) || "aside" === $) { + ye = dominantFontFamilyAndSizeForElement(b); + var Ne = dominantFontSizeInPointsFromFontFamilyAndSizeString(ye), + be = ye && ye === U; + if ( + (1 !== T || + ee || + (cachedElementBoundingRect(b).width <= MaximumFloatWidth + ? C.setAttribute("class", "auxiliary float " + Q.float) + : be || C.classList.add("auxiliary")), + C.closest(".auxiliary") && b.style) + ) { + var xe = b.style.getPropertyValue("width"); + if ("table" === Q.display && /%/.test(xe) && parseInt(xe) < 2) + C.style.width = Q.width; + else if (xe) C.style.width = xe; + else { + var Ce = x.getMatchedCSSRules(b, "", !0); + if (Ce) + for (pe = Ce.length - 1; pe >= 0; --pe) { + xe = Ce[pe].style.getPropertyValue("width"); + var De = parseInt(xe); + if (xe && (isNaN(De) || De > 0)) { + C.style.width = xe; + break; + } + } + } + 1 !== T || + xe || + (C.style.width = cachedElementBoundingRect(b).width + "px"); + } + ee || c(C, Ne); + } + if ("table" === $) y || (y = 1); + else if ("img" === $) { + var Ie; + if ((Ie = lazyLoadingImageURLForElement(C, b.className))) { + C.setAttribute("src", Ie); + var Me = !!C.closest("figure"); + if (!Me) { + var Le = attributesForElement(b), + Re = Le.length; + for (pe = 0; pe < Re; ++pe) + if (p.test(Le[pe].nodeName)) { + Me = !0; + break; + } + } + (Me && C.classList.add("protected"), (Z = !0)); + } + ((!Ie && C.hasAttribute("src")) || + !b.hasAttribute("data-srcset") || + C.setAttribute("srcset", b.getAttribute("data-srcset")), + C.removeAttribute("border"), + C.removeAttribute("hspace"), + C.removeAttribute("vspace")); + var we = C.getAttribute("align"); + if ( + (C.removeAttribute("align"), + ("left" !== we && "right" !== we) || + (C.classList.add("float"), C.classList.add(we)), + !T && !Z) + ) { + var Fe, + _e = (Fe = cachedElementBoundingRect(b)).width, + Oe = Fe.height; + hasClassMatchingRegexp(b, ProgressiveLoadingRegex) && + b.nextElementSibling && + "img" === normalizedElementTagName(b.nextElementSibling) + ? (J = C) + : imageIsContainedByContainerWithImageAsBackgroundImage(b) + ? C.classList.add("protected") + : (1 === _e && 1 === Oe) || + (z && + Oe < MinimumHeightForImagesAboveTheArticleTitle && + Fe.bottom < z.top) + ? (J = C) + : _e < ImageSizeTiny && + Oe < ImageSizeTiny && + C.setAttribute("class", "reader-image-tiny"); + } + if (n === CleaningType.MetadataContent) + ((Fe = cachedElementBoundingRect(b)).width > + MaximumWidthOrHeightOfImageInMetadataSection || + Fe.height > MaximumWidthOrHeightOfImageInMetadataSection) && + (J = C); + if (b.classList.contains("emoji")) { + let e = urlFromString(C.src); + if ( + e && + "s.w.org" === e.hostname && + e.pathname.startsWith("/images/core/emoji/") + ) { + let e = this.replaceImageWithAltText(C); + e && + (((C = e).originalElement = b), + ($ = normalizedElementTagName(C)), + (J = C), + C.classList.add("protected")); + } + } + } else if ("font" === $) + (C.removeAttribute("size"), + C.removeAttribute("face"), + C.removeAttribute("color")); + else if ("a" === $ && C.parentNode) { + let e, t; + C instanceof HTMLAnchorElement + ? ((e = C.getAttribute("href")), (t = HTMLAnchorElement)) + : C instanceof SVGAElement && + ((e = C.getAttribute("xlink:href")), (t = SVGAElement)); + let i = C.originalElement.ownerDocument.location, + r = urlStringShouldHaveItsAnchorMadeNonFunctional(e, i); + if ( + t === HTMLAnchorElement && + "author" === b.getAttribute("itemprop") + ) + C.classList.add("protected"); + else if (e && e.length && ("#" === e[0] || r)) { + const e = new Set(["li", "sup"]); + if ( + !y && + !C.childElementCount && + 1 === C.parentElement.childElementCount && + !e.has(normalizedElementTagName(C.parentElement)) + ) + this.contentDocument.evaluate( + "text()", + C.parentElement, + null, + XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, + null, + ).snapshotLength || (J = C); + if (!J) { + ce = this.contentDocument.createElement("span"); + if ( + 1 === C.childElementCount && + "img" === normalizedElementTagName(C.firstElementChild) + ) { + var Be = C.firstElementChild; + Be.width > AnchorImageMinimumWidth && + Be.height > AnchorImageMinimumHeight && + ce.setAttribute("class", "converted-image-anchor"); + } + for ( + ce.className || + ce.setAttribute("class", "converted-anchor"); + C.firstChild; + ) + ce.appendChild(C.firstChild); + (C.parentNode.replaceChild(ce, C), + ((C = ce).originalElement = b)); + } + } else if (AdvertisementHostRegex.test(C.host) && !C.innerText) + J = C; + else if ( + n !== CleaningType.MetadataContent && + I && + !L && + I.compareDocumentPosition(b) & + document.DOCUMENT_POSITION_PRECEDING && + cachedElementBoundingRect(b).top < + cachedElementBoundingRect(I).top + ) + G.push(C); + else { + var Pe = b.children; + 1 === Pe.length && + "img" === normalizedElementTagName(Pe[0]) && + !b.innerText && + anchorLooksLikeDownloadFlashLink(b) && + (J = C); + } + r && (C.removeAttribute("xlink:href"), C.removeAttribute("href")); + } else if ( + "aside" === $ || + "blockquote" === $ || + "q" === $ || + ("div" === $ && V.test(b.className)) + ) { + ((ye = dominantFontFamilyAndSizeForElement(b)), + (Ne = dominantFontSizeInPointsFromFontFamilyAndSizeString(ye))); + ee || c(C, Ne); + } else if ("cite" === $) { + var ke = pseudoElementContent(b, ":after") ?? "", + qe = document.createElement("span"); + ((qe.innerText = ke), C.after(qe)); + } else + "pre" === $ + ? (C.style.whiteSpace = Q.whiteSpace) + : "source" === $ && b.hasAttribute("data-srcset") + ? (C.setAttribute("srcset", b.getAttribute("data-srcset")), + C.classList.add("protected")) + : C instanceof SVGAnimateElement && + "xlink:href" === C.attributes.attributeName.value && + (J = C); + } + if (Q && R && !Z) { + var ze = + "none" === Q.display || + "visible" !== Q.visibility || + computedStyleIndicatesElementIsInvisibleDueToClipping(Q); + if ( + (ze || + "img" === $ || + (ze = + "0" === Q.opacity && + "absolute" === Q.position && + !C.closest("figure")), + ze && !N) + ) + (!!B && v === B.depth && selectorForElement(b) === B.selector) || + W(b, e) || + (J = C); + } + if ( + (!J && elementIsCommentBlock(b) && (J = C), + !J && + z && + cachedElementBoundingRect(b).top < z.top && + VeryLiberalCommentRegex.test(b.className) && + C.parentElement && + (J = C), + !J && "a" === $ && k.has(b.href)) + ) { + for ( + var We, Ue, He = b, Ve = C; + (He = He.parentElement) && (Ve = Ve.parentElement); + ) { + const t = 10; + if ( + cachedElementBoundingRect(He).top - + cachedElementBoundingRect(b).top > + t + ) + break; + if (He === e) break; + o(He) && ((We = He), (Ue = Ve)); + } + (We && + ((J = Ue), + (b = We), + ((C = Ue).originalElement = b), + ($ = normalizedElementTagName(C))), + (He = null), + (Ve = null), + (We = null), + (Ue = null)); + } + } catch (e) { + J = C; + } + if ( + (!J || J.parentElement || i || (J = null), + "div" === $ ? Y.push(C) : "aside" === $ && K.push(C), + !J) + ) { + let e = this._weakMapOfOriginalElementToUniqueID.get( + C.originalElement, + ); + (e || (e = this._nextUniqueID()), + this._mapOfUniqueIDToOriginalElement.set(e, C.originalElement), + C.setAttribute(this.elementReaderUniqueIDAttributeKey(), e), + this._weakMapOfOriginalElementToUniqueID.set(C.originalElement, e)); + } + var je = J ? null : b.firstElementChild; + if (je) ((b = je), (C = C.firstElementChild), r(1)); + else { + for (var Ge; b !== e && !(Ge = b.nextElementSibling); ) + ((b = b.parentElement), (C = C.parentElement), r(-1)); + if (b === e) { + if (J && !elementIsProtected(J)) + if (J.parentElement) J.remove(); + else if (i) return null; + break; + } + ((b = Ge), (C = C.nextElementSibling), a()); + } + if (J && !elementIsProtected(J)) + if (J.parentElement) J.remove(); + else if (i) return null; + } + for (let e of t.querySelectorAll("iframe")) { + if (elementLooksLikeEmbeddedTweet(e.originalElement)) + (Xe = this.adoptableSimpleTweetFromTwitterElement(e)) && + e.parentElement.replaceChild(Xe, e); + (e.classList.add("protected"), + e.setAttribute("sandbox", "allow-scripts allow-same-origin")); + } + for (let e of t.querySelectorAll("twitter-widget")) { + var Xe; + if (elementLooksLikeEmbeddedTweet(e.originalElement)) + (Xe = this.adoptableSimpleTweetFromTwitterElement(e)) && + e.parentElement.replaceChild(Xe, e); + e.classList.add("protected"); + } + const Ye = t.querySelectorAll("blockquote"), + Ke = Ye.length; + for (pe = 0; pe < Ke; ++pe) { + const e = Ye[pe], + t = e.originalElement; + t && this.convertBlockquoteTweetToSimpleTweetIfAppropriate(e, t); + } + for (pe = E.length - 1; pe >= 0; --pe) { + ((vt = E[pe]).parentNode && + this.shouldPruneElement(vt, vt.originalElement, U) && + vt.remove(), + delete vt._originalElementDepthInCollapsedArea); + } + var Qe = G.length; + for (pe = 0; pe < Qe; ++pe) G[pe].remove(); + var Je = t.querySelectorAll(".float"); + for (pe = 0; pe < Je.length; ++pe) { + var $e = !1, + Ze = Je[pe]; + if (!$e) { + var et = Ze.querySelectorAll("a, span.converted-image-anchor"), + tt = Ze.querySelectorAll("span.converted-anchor"); + $e = Ze.parentNode && tt.length > et.length; + } + if (!$e) { + var nt = Ze.querySelectorAll("embed, object").length, + it = Ze.originalElement.querySelectorAll("embed, object").length; + !nt && it && ($e = !0); + } + if (!$e) { + for ( + var rt = Ze.originalElement.getElementsByTagName("img"), + at = rt.length, + lt = 0, + ot = 0; + ot < at && (R && isElementVisible(rt[ot]) && lt++, !(lt > 1)); + ++ot + ); + if (1 === lt) Ze.getElementsByTagName("img").length || ($e = !0); + } + if (!$e) { + const e = "img, video, embed, iframe, object, svg"; + /\S/.test(Ze.innerText) || + Ze.matches(e) || + Ze.querySelector(e) || + ($e = !0); + } + $e && !elementIsProtected(Ze) && Ze.remove(); + } + var st = t.querySelectorAll("br"); + for (pe = st.length - 1; pe >= 0; --pe) { + var ct = st[pe]; + ct.originalElement && + "block" === + getComputedStyle(ct.originalElement.parentElement).display && + (m(ct, "nextSibling") || m(ct, "previousSibling")) && + ct.remove(); + } + if ( + i && + !removeWhitespace(t.innerText).length && + (n !== CleaningType.LeadingMedia || + !t.querySelector("video, iframe, img")) + ) + return null; + var mt = {}, + dt = (et = t.querySelectorAll("a")).length; + for (pe = 0; pe < dt; ++pe) { + (mt[(ht = (ft = et[pe]).style.fontWeight)] || (mt[ht] = []), + mt[ht].push(ft)); + } + for (var ht in mt) { + var ut = mt[ht], + gt = ut.length; + if (gt > 0.7 * dt) + for (pe = 0; pe < gt; ++pe) { + var ft; + (((ft = ut[pe]).style.fontWeight = null), + ft.getAttribute("style") || ft.removeAttribute("style")); + } + } + var pt = t.querySelectorAll(".protected"), + Et = pt.length; + for (pe = 0; pe < Et; ++pe) { + var vt; + ((vt = pt[pe]).classList.remove("protected"), + vt.classList.length || vt.removeAttribute("class")); + } + var Tt = t.querySelectorAll("p.auxiliary"), + yt = Tt.length; + for (pe = 0; pe < yt; ++pe) { + for ( + var St = Tt[pe], At = [St], Nt = St.nextElementSibling; + Nt && + "p" === normalizedElementTagName(Nt) && + Nt.classList.contains("auxiliary"); + ) + (At.push(Nt), (Nt = Nt.nextElementSibling)); + var bt = At.length; + if (bt > 1) { + for (ot = 0; ot < bt; ++ot) { + var xt = At[ot]; + (xt.classList.remove("auxiliary"), + xt.style && (xt.style.width = null), + cleanStyleAndClassList(xt)); + } + pe += bt - 1; + } + } + for (pe = Y.length - 1; pe >= 0; --pe) { + var Ct = Y[pe]; + Ct !== t && + elementWouldAppearBetterAsFigureOrAuxiliary(Ct.originalElement, Ct) && + changeElementType(Ct, "figure"); + } + for (pe = K.length - 1; pe >= 0; --pe) { + var Dt = K[pe]; + Dt !== t && + elementWouldAppearBetterAsFigureOrAuxiliary(Dt.originalElement, Dt) && + Dt.classList.add("auxiliary"); + } + var It = j.length; + for (pe = 0; pe < It; ++pe) { + var Mt = j[pe], + Lt = Mt.parentElementBeforePruning, + Rt = null, + wt = null; + if (Lt) + ((Rt = depthOfElementWithinElement(Lt, t)), + (wt = selectorForElement(Lt))); + var Ft = Lt ? Lt.closest("ul") : null; + if (Ft) Ft.remove(); + else { + const e = 40; + Lt && + cachedElementBoundingRect(Lt.originalElement).height < e && + (!B || B.selector !== wt || B.depth !== Rt) + ? Lt.remove() + : Mt.remove(); + } + } + var _t = X.length; + for (pe = 0; pe < _t; ++pe) { + var Ot = X[pe], + Bt = this.contentDocument.createElement("div"); + ((Bt.innerHTML = Ot.dataset ? Ot.dataset.mathml : ""), + Ot.parentNode.replaceChild(Bt, Ot)); + } + return t; + }, + convertBlockquoteTweetToSimpleTweetIfAppropriate: function (e, t) { + const n = t.classList; + if (!n.contains("twitter-tweet") && !n.contains("twitter-video")) return; + const i = t.getElementsByTagName("a"), + r = i.length; + if (r < 1) return; + const a = i[r - 1]; + if ("twitter.com" !== a.host) return; + const l = lastPathComponentFromAnchor(a); + if (isNaN(parseInt(l))) return; + const o = this.contentDocument.createElement("div"); + (o.setAttribute("data-reader-tweet-id", l), + o.classList.add("tweet-wrapper"), + e.parentElement.replaceChild(o, e), + e.classList.add("simple-tweet"), + o.appendChild(e)); + }, + adoptableSimpleTweetFromTwitterElement: function (e) { + var t = function (e) { + var t = this.contentDocument.createElement("div"), + n = this.contentDocument.createTextNode(e); + return (t.appendChild(n), t.innerHTML); + }.bind(this); + let n = null, + i = e.originalElement; + if ( + ("iframe" === normalizedElementTagName(e) + ? (n = i.contentDocument ? i.contentDocument.documentElement : null) + : "twitter-widget" === normalizedElementTagName(e) && + (n = i.shadowRoot), + !n) + ) + return null; + var r = + n.querySelector("[data-tweet-id].expanded") || + n.querySelector("[data-tweet-id]"); + if (!r) return null; + var a = this.contentDocument.createElement("div"); + a.classList.add("tweet-wrapper"); + var l = this.contentDocument.createElement("blockquote"); + (l.classList.add("simple-tweet"), a.appendChild(l)); + var o = r.getAttribute("data-tweet-id"); + a.setAttribute("data-reader-tweet-id", o); + var s = r.querySelector(".dateline"), + c = r.querySelector('[data-scribe="element:screen_name"]'), + m = r.querySelector('[data-scribe="element:name"]'), + d = r.querySelector(".e-entry-title"); + if (!(s && c && m && d)) return a; + var h = "— " + t(m.innerText) + " (" + t(c.innerText) + ")", + u = this.contentDocument.createElement("p"); + ((u.innerHTML = d.innerHTML), + l.appendChild(u), + l.insertAdjacentHTML("beforeend", h)); + var g = this.contentDocument.createElement("span"); + ((g.innerHTML = s.innerHTML), l.appendChild(g)); + for (let e of l.querySelectorAll("img.twitter-emoji")) + this.replaceImageWithAltText(e); + for ( + var f = l.getElementsByTagName("*"), p = f.length, E = 0; + E < p; + ++E + ) { + e = f[E]; + "script" === normalizedElementTagName(e) + ? e.remove() + : sanitizeElementByRemovingAttributes(e); + } + return a; + }, + replaceImageWithAltText: function (e) { + var t = e.getAttribute("alt"); + if (!t || t.length < 1) return null; + let n = this.contentDocument.createElement("span"); + return ((n.innerText = t), e.parentNode.replaceChild(n, e), n); + }, + leadingVideoNode: function () { + var e = this.leadingContentNodeWithSelector("video, iframe"); + return e && + e.parentElement && + !e.previousElementSibling && + !e.nextElementSibling + ? e.parentElement + : null; + }, + leadingImageNode: function () { + return this.leadingContentNodeWithSelector("figure img, img"); + }, + ancestorsOfElement: function (e) { + let t = [], + n = e.parentNode; + for (; n; ) (t.push(n), (n = n.parentNode)); + return t; + }, + leadingContentNodeWithSelector: function (e) { + const t = 250, + n = 0.5, + i = 0.9, + r = 3; + if (!this.article || !this.article.element) return null; + let a = 0; + if (this._articleTitleElement) { + let e, + t = this.ancestorsOfElement(this.article.element); + for (let n of t) + if (n.contains(this._articleTitleElement)) { + e = n; + break; + } + a = t.length - this.ancestorsOfElement(e).length + 2; + } + let l = Math.max(r, a); + for (var o = this.article.element, s = 0; s < l && o.parentNode; ++s) { + var c = (o = o.parentNode).querySelectorAll(e); + for (var m of c) + if (m && isElementVisible(m)) { + var d = cachedElementBoundingRect(m); + if (!(d.width >= window.innerWidth * i) && d.height < t) continue; + if (d.width < this._articleWidth * n) continue; + var h = this.article.element.compareDocumentPosition(m); + if ( + !(h & Node.DOCUMENT_POSITION_PRECEDING) || + h & Node.DOCUMENT_POSITION_CONTAINED_BY + ) + continue; + var u = this.extraArticle ? this.extraArticle.element : null; + if ( + u && + this.article.element.compareDocumentPosition(u) & + Node.DOCUMENT_POSITION_FOLLOWING && + (h = u.compareDocumentPosition(m)) && + (!(h & Node.DOCUMENT_POSITION_PRECEDING) || + h & Node.DOCUMENT_POSITION_CONTAINED_BY) + ) + continue; + return m; + } + } + return null; + }, + pageImageURLFromMetadata: function (e) { + var t = e["property:og:image"]; + if ( + (t || (t = e["property:twitter:image"]), + t || (t = e["property:twitter:image:src"]), + t) + ) { + let e = urlFromString(t); + if (e) { + let n = e.href; + n && urlIsHTTPFamilyProtocol(e) && (t = n); + } + } + return t; + }, + mainImageNode: function () { + var e = this.leadingImageNode(); + if (e) return e; + if (this.article && this.article.element) + for ( + var t = this.article.element.querySelectorAll("img"), + n = t.length, + i = 0; + i < n; + ++i + ) { + var r = t[i], + a = r._cachedElementBoundingRect; + if ( + (a || (a = r.getBoundingClientRect()), + a.width >= MainImageMinimumWidthAndHeight && + a.height >= MainImageMinimumWidthAndHeight) + ) + return r; + } + return null; + }, + schemaDotOrgMetadataObjectForArticle: function () { + if (this._schemaDotOrgMetadataObjectForArticle) + return this._schemaDotOrgMetadataObjectForArticle; + const e = new Set([ + "Article", + "NewsArticle", + "Report", + "ScholarlyArticle", + "SocialMediaPosting", + "BlogPosting", + "LiveBlogPosting", + "DiscussionForumPosting", + "TechArticle", + "APIReference", + ]); + var t = this.contentDocument.querySelectorAll( + "script[type='application/ld+json']", + ), + n = t.length; + try { + for (var i = 0; i < n; ++i) { + var r = t[i], + a = JSON.parse(r.textContent), + l = a["@context"]; + if ("https://schema.org" === l || "http://schema.org" === l) { + var o = a["@type"]; + if (e.has(o)) + return ((this._schemaDotOrgMetadataObjectForArticle = a), a); + } + } + return null; + } catch (e) { + return null; + } + }, + articleTitle: function () { + var e = this.articleTitleInformation(); + return e ? e.titleText : ""; + }, + articleTitleInformation: function () { + function e(e, t) { + var n = e ? t.indexOf(e) : -1; + return -1 !== n && (0 === n || n + e.length === t.length); + } + function t(e, t) { + return ( + e.host === t.host && e.pathname === t.pathname && e.hash === t.hash + ); + } + function n(e) { + let t = + nearestAncestorElementWithTagName(e, "a") || e.querySelector("a"); + return t + ? urlStringShouldHaveItsAnchorMadeNonFunctional( + t.href, + t.ownerDocument.location, + ) + ? null + : t + : null; + } + if (!this.articleNode()) return; + if (this._articleTitleInformation) return this._articleTitleInformation; + const i = + /((article|post).*title|headline|instapaper_title|inside-head)/i, + r = 600, + a = 20, + l = 8, + o = 1.1, + s = 1.25, + c = /header|title|headline|instapaper_title/i, + m = 1.5, + d = 1.8, + h = 1.5, + u = 0.6, + g = 3, + f = 1.5, + p = 0.8, + E = 0.8, + v = 9, + T = 1.5, + y = /byline|author/i; + var S = function (e, t) { + var n = this.contentFromUniqueMetadataSelector(e, t); + if (n) { + var i = this.articleTitleAndSiteNameFromTitleString(n); + i && (n = i.articleTitle); + } + return n; + }.bind(this), + A = function () { + for (var e = this.articleNode(); e; e = e.parentElement) + if (elementIndicatesItIsASchemaDotOrgArticleContainer(e)) return e; + return null; + }.bind(this)(), + N = A + ? this.contentFromUniqueMetadataSelector(A, "meta[itemprop=headline]") + : "", + b = A + ? this.contentFromUniqueMetadataSelector( + A, + "meta[itemprop=alternativeHeadline]", + ) + : "", + x = this.contentDocument, + C = x.location, + D = x.title, + I = S(x, "meta[property='og:title']"), + M = this.contentFromUniqueMetadataSelector( + x, + "meta[property='og:site_name']", + ), + L = S(x, "meta[name='twitter:title']"), + R = S(x, "meta[name='sailthru.headline']"), + w = this.schemaDotOrgMetadataObjectForArticle(), + F = w ? w.headline : null, + _ = this.articleNode(), + O = cachedElementBoundingRect(_); + this.extraArticleNode() && + this.extraArticle.isPrepended && + (O = cachedElementBoundingRect(this.extraArticleNode())); + var B = O.left + O.width / 2, + P = O.top, + k = P; + ((this._articleWidth = O.width), + (this._leadingMediaElement = this.leadingImageNode()), + this._leadingMediaElement || + (this._leadingMediaElement = this.leadingVideoNode()), + this._leadingMediaElement) && + (k = + (cachedElementBoundingRect(this._leadingMediaElement).top + P) / 2); + var q = "h1, h2, h3, h4, h5, a:not(svg a), p, div, span", + z = normalizedElementTagName(this.article.element); + ("dl" !== z && "dd" !== z) || (q += ", dt"); + for ( + var W = [], U = x.querySelectorAll(q), H = U.length, V = 0; + V < H; + ++V + ) { + var j = U[V], + G = normalizedElementTagName(j); + if ("a" === G) + j.innerText === I && + t(j, C) && + (j.previousElementSibling || j.nextElementSibling + ? W.push(j) + : W.push(j.parentElement)); + else if ("div" === G || "span" === G || "p" === G) { + if (hasClassMatchingRegexp(j, i) || i.test(j.getAttribute("id"))) { + var X = j.parentElement; + elementIsAHeader(X) || W.push(j); + } + } else W.push(j); + } + W = Array.prototype.slice.call(W, 0); + const Y = 2; + var K = this.article.element; + for (V = 0; V < Y; ++V) K.parentElement && (K = K.parentElement); + for ( + var Q, J = K.querySelectorAll("a:not(svg a)"), $ = ((V = 0), J.length); + V < $; + ++V + ) { + var Z = J[V]; + if (Z.offsetTop > _.offsetTop + a) break; + if (t(Z, C) && "#" !== Z.getAttribute("href")) { + W.push(Z); + break; + } + } + var ee = W.map(trimmedInnerTextIgnoringTextTransform), + te = W.length, + ne = 0, + ie = [], + re = [], + ae = [], + le = [], + oe = [], + se = [], + ce = []; + const me = {}, + de = (e) => { + const t = me[e]; + if (t) return t; + const n = stringSimilarity(D, e); + return ((me[e] = n), n); + }; + for (V = 0; V < te; ++V) { + var he = W[V], + ue = ee[V]; + const e = {}, + t = (t) => { + const n = e[t]; + if (n) return n; + const i = stringSimilarity(ue, t); + return ((e[t] = i), i); + }; + let n = de(ue); + if (I) { + const e = t(I); + ((n += e), + e > StringSimilarityToDeclareStringsNearlyIdentical && re.push(he)); + } + if (L) { + const e = t(L); + ((n += e), + e > StringSimilarityToDeclareStringsNearlyIdentical && ae.push(he)); + } + if (N) { + const e = t(N); + ((n += e), + e > StringSimilarityToDeclareStringsNearlyIdentical && le.push(he)); + } + if (b) { + const e = t(b); + ((n += e), + e > StringSimilarityToDeclareStringsNearlyIdentical && oe.push(he)); + } + if (R) { + const e = t(R); + ((n += e), + e > StringSimilarityToDeclareStringsNearlyIdentical && se.push(he)); + } + if (F) { + const e = t(F); + ((n += e), + e > StringSimilarityToDeclareStringsNearlyIdentical && ce.push(he)); + } + n === ne ? ie.push(he) : n > ne && ((ne = n), (ie = [he])); + } + let ge = []; + for (let e of W) { + let t = e.nextElementSibling; + t && SubheadRegex.test(t.className) && ge.push(e); + } + if ( + (1 === re.length + ? ((Q = re[0]).headerText = trimmedInnerTextIgnoringTextTransform(Q)) + : 1 === ae.length + ? ((Q = ae[0]).headerText = + trimmedInnerTextIgnoringTextTransform(Q)) + : 1 === le.length + ? ((Q = le[0]).headerText = + trimmedInnerTextIgnoringTextTransform(Q)) + : 1 === se.length + ? ((Q = se[0]).headerText = + trimmedInnerTextIgnoringTextTransform(Q)) + : 1 === ce.length && + ((Q = ce[0]).headerText = + trimmedInnerTextIgnoringTextTransform(Q)), + !Q) + ) + for (V = 0; V < te; ++V) { + he = W[V]; + if (!isElementVisible(he)) continue; + var fe = cachedElementBoundingRect(he), + pe = fe.left + fe.width / 2, + Ee = pe - B, + ve = fe.top + fe.height / 2 - k, + Te = -1 !== re.indexOf(he), + ye = -1 !== ae.indexOf(he), + Se = he.classList.contains("instapaper_title"), + Ae = /\bheadline\b/.test(he.getAttribute("itemprop")), + Ne = -1 !== le.indexOf(he), + be = -1 !== oe.indexOf(he), + xe = -1 !== se.indexOf(he), + Ce = -1 !== ce.indexOf(he); + let t = ge.includes(he) && ve < 0; + var De = Te || ye || Se || Ae || Ne || be || xe || Ce || t, + Ie = Math.sqrt(Ee * Ee + ve * ve), + Me = De ? r : Math.max(r - Ie, 0), + Le = ((ue = ee[V]), he.getAttribute("property")); + if (Le) { + var Re = /dc.title/i.exec(Le); + if (Re && Re[0]) + if ( + 1 === + this.contentDocument.querySelectorAll( + '*[property~="' + Re[0] + '"]', + ).length + ) { + (Q = he).headerText = ue; + break; + } + } + if (!y.test(he.className)) { + if (!De) { + if (Ie > r) continue; + if (pe < O.left || pe > O.right) continue; + } + if (D && stringsAreNearlyIdentical(ue, D)) Me *= g; + else if (e(ue, D)) Me *= f; + else if (ue.length < l) continue; + if (ue !== M || !I) { + var we = !1; + if ((We = n(he))) { + if ("author" === We.getAttribute("rel")) continue; + var Fe = We.host === C.host, + _e = We.pathname === C.pathname; + if (Fe && _e) Me *= h; + else { + if (Fe && nearestAncestorElementWithTagName(he, "li")) + continue; + ((Me *= u), (we = !0)); + } + } + var Oe = fontSizeFromComputedStyle(getComputedStyle(he)); + (we || (Me *= Oe / BaseFontSize), + (Me *= + 1 + TitleCandidateDepthScoreMultiplier * elementDepth(he))); + var Be = parseInt(this.contentTextStyle().fontSize); + (parseInt(Oe) > Be * o && (Me *= s), + (c.test(he.className) || c.test(he.getAttribute("id"))) && + (Me *= m)); + var Pe = he.parentElement; + (Pe && + (c.test(Pe.className) || c.test(Pe.getAttribute("id"))) && + (Me *= m), + -1 !== ie.indexOf(he) && (Me *= d)); + _ = this.article.element; + for (var ke = he; ke && ke !== _; ke = ke.parentElement) + if (SidebarRegex.test(ke.className)) { + Me *= p; + break; + } + (he.closest("li") && (Me *= E), + (!Q || Me > Q.headerScore) && + (((Q = he).headerScore = Me), (Q.headerText = ue))); + } + } + } + var qe; + if ( + (Q && + domDistance(Q, _, v + 1) > v && + parseInt(getComputedStyle(Q).fontSize) < T * Be && + (Q = null), + Q) + ) { + this._articleTitleElement = Q; + var ze = Q.headerText.trim(); + qe = I && e(I, ze) ? I : D && e(D, ze) ? D : ze; + } + (this._leadingMediaElement || + (this._leadingMediaElement = this.leadingImageNode()), + this._leadingMediaElement || + (this._leadingMediaElement = this.leadingVideoNode()), + qe || (qe = I && e(I, D) ? I : D)); + var We, + Ue = null, + He = !1, + Ve = !1; + Q && + (We = n(Q)) && + ((Ue = We.href), + (He = "_blank" === We.getAttribute("target")), + (Ve = We.host !== C.host || We.pathname !== C.pathname)); + let je = { + titleText: qe, + linkURL: Ue, + linkIsTargetBlank: He, + linkIsForExternalPage: Ve, + }; + if (this._articleTitleElement) { + const e = this.titleUniqueID(); + (this._mapOfUniqueIDToOriginalElement.set(e, Q), + this._weakMapOfOriginalElementToUniqueID.set(Q, e)); + } + return ((this._articleTitleInformation = je), je); + }, + contentFromUniqueMetadataSelector: function (e, t) { + var n = e.querySelectorAll(t); + if (1 !== n.length) return null; + var i = n[0]; + return i + ? this.elementAttributesContainImproperQuote(i) + ? null + : i.content + : null; + }, + elementAttributesContainImproperQuote: function (e) { + for (var t = attributesForElement(e), n = t.length, i = 0; i < n; ++i) + if (/['"]/.test(t[i].name)) return !0; + return !1; + }, + articleSubhead: function () { + function e(e) { + return elementIsAHeader(e) + ? parseInt(/h(\d)?/.exec(normalizedElementTagName(e))[1]) + : NaN; + } + function t(e) { + if (!e) return null; + var t = e.content; + return t ? t.trim() : null; + } + const n = /author|kicker/i; + if (this._articleSubhead) return this._articleSubhead; + var i = this.articleNode(); + if (!i) return; + var r = this._articleTitleElement; + if (!r) return; + var a = this.contentDocument, + l = a.location, + o = e(r), + s = cachedElementBoundingRect(r), + c = new Set(), + m = t(a.querySelector("meta[property='og:description']")); + m && c.add(m); + var d = t(a.querySelector("meta[name=description]")); + d && c.add(d); + var h, + u = this.schemaDotOrgMetadataObjectForArticle(); + if (u) { + var g = u.description; + g && "string" == typeof g && c.add(g.trim()); + } + var f = this.contentFromUniqueMetadataSelector( + a, + "head meta.swiftype[name=dek]", + ); + f && (h = f); + let p = [], + E = nextNonFloatingVisibleElementSibling(r); + E && p.push(E); + let v = nextLeafElementForElement(r); + if ( + (v && + r && + r.contains(v) && + v.innerText && + v.innerText.trim() === r.innerText.trim() && + (v = nextLeafElementForElement(v)), + v && p.push(v), + c.size) + ) + for ( + var T = a.querySelectorAll( + HeaderElementsSelector + ", *[itemprop=description]", + ), + y = T.length, + S = 0; + S < y; + ++S + ) { + var A = T[S]; + c.has(A.innerText.trim()) && p.push(A); + } + var N = p.length; + for (S = 0; S < N; ++S) { + var b = p[S]; + if (!b) continue; + if (b === i) continue; + var x = b.className; + if (n.test(x)) continue; + var C = b.closest("a"); + if (C) { + var D = C.host === l.host, + I = C.pathname === l.pathname; + if (!D || !I) continue; + } + var M, + L = !1; + if (elementIsAHeader(b)) + if (isNaN(o)) L = !0; + else e(b) - 1 === o && (L = !0); + if ((!L && SubheadRegex.test(x) && (L = !0), !L)) { + const e = b.getAttribute("itemprop"); + /\bdescription\b/.test(e) && !/\barticleBody\b/.test(e) && (L = !0); + } + if ( + (!L && c.has(b.innerText) && (L = !0), + !L && h && h === b.innerText && (L = !0), + L || "summary" !== b.getAttribute("itemprop") || (L = !0), + !L) + ) + continue; + if ("meta" === normalizedElementTagName(b)) { + var R = b.getAttribute("content"); + M = R ? R.trim() : ""; + var w = b.nextElementSibling; + if (!w || trimmedInnerTextIgnoringTextTransform(w) !== M) continue; + b = w; + } else { + if (cachedElementBoundingRect(b).top < (s.bottom + s.top) / 2) + continue; + M = trimmedInnerTextIgnoringTextTransform(b).trim(); + } + if (!M.length) continue; + this._articleSubheadElement = b; + const t = this.subheadUniqueID(); + (this._mapOfUniqueIDToOriginalElement.set(t, b), + this._weakMapOfOriginalElementToUniqueID.set(b, t), + (this._articleSubhead = M)); + break; + } + return this._articleSubhead; + }, + adoptableMetadataBlock: function () { + function e(e) { + function t(e, i) { + if (e.nodeType !== Node.TEXT_NODE) { + if (e.nodeType === Node.ELEMENT_NODE) { + var r = e.childNodes, + a = r.length; + 0 !== a && + (1 !== a + ? (i !== n.Right && t(r[0], n.Left), + i !== n.Left && t(r[a - 1], n.Right)) + : t(r[0], i)); + } + } else + i === n.Left + ? (e.textContent = e.textContent.trimLeft()) + : i === n.Right + ? (e.textContent = e.textContent.trimRight()) + : (e.textContent = e.textContent.trim()); + } + const n = { Left: 1, Right: 2, Both: 3 }; + t(e); + } + this.updateArticleBylineAndDateElementsIfNecessary(); + var t = this.articleBylineElement(), + n = this.articleDateElement(); + if (!t && !n) return null; + if (t && n) { + var i = t.compareDocumentPosition(n); + (i & Node.DOCUMENT_POSITION_CONTAINS && (t = null), + i & Node.DOCUMENT_POSITION_CONTAINED_BY && (n = null), + t === n && (n = null)); + } + var r, + a = this.contentDocument.createElement("div"), + l = !1, + o = !1; + t && + (e( + (r = this.cleanArticleNode( + t, + t.cloneNode(!0), + CleaningType.MetadataContent, + !1, + )), + ), + r.innerText.trim() && ((l = !0), r.classList.add("byline"))); + if (n) { + var s = this.cleanArticleNode( + n, + n.cloneNode(!0), + CleaningType.MetadataContent, + !1, + ); + (e(s), s.innerText.trim() && ((o = !0), s.classList.add("date"))); + } + if ((l && a.appendChild(r), l && o)) { + var c = document.createElement("span"); + (c.classList.add("delimiter"), a.appendChild(c)); + } + return (o && a.appendChild(s), a); + }, + articleBylineElement: function () { + return this._articleBylineElement; + }, + findArticleBylineElement: function () { + var e = this.findArticleBylineElementWithoutRejection(); + return e && + ("footer" === normalizedElementTagName(e) || e.closest("figure")) + ? null + : e; + }, + findArticleBylineElementWithoutRejection: function () { + function e(e) { + if (!e.length) return null; + e = e.filter(isElementVisible); + for ( + var t = new Set(), n = new Set(), r = e.length, o = 0; + o < r - 1; + ++o + ) { + var s = e[o], + c = e[o + 1]; + if (isElementVisible(s) && isElementVisible(c)) { + var m = s.parentElement; + m === c.parentElement && + (m.contains(i) || (n.add(s.parentElement), t.add(s), t.add(c))); + } + } + var d = new Set(e); + (n.forEach(function (e) { + d.add(e); + }), + t.forEach(function (e) { + d.delete(e); + }), + (e = []), + d.forEach(function (t) { + e.push(t); + })); + var h, + u = null; + r = e.length; + for (o = 0; o < r; ++o) { + s = e[o]; + if (isElementVisible(s)) { + var g = cachedElementBoundingRect(s), + f = g.left + g.width / 2, + p = g.top + g.height / 2, + E = a - f, + v = l - p, + T = Math.sqrt(E * E + v * v); + (!u || T < h) && ((u = s), (h = T)); + } + } + return u; + } + const t = "[itemprop~=author], a[rel='author']:not(svg a)", + n = + "#byline, .byline, .article-byline, .byline__author, .entry-meta, .author-name, .byline-dateline, .article-author, [itemprop~=author], a[rel='author']:not(svg a)"; + var i = this._articleSubheadElement || this._articleTitleElement; + if (i) + var r, + a = (r = i ? cachedElementBoundingRect(i) : null).left + r.width / 2, + l = r.top + r.height / 2; + var o = this.contentFromUniqueMetadataSelector( + this.contentDocument, + "head meta[name=author]", + ); + if ( + (o || + (o = this.contentFromUniqueMetadataSelector( + this.contentDocument, + "head meta[property=author]", + )), + !o) + ) { + var s = this.schemaDotOrgMetadataObjectForArticle(); + if (s) { + var c = s.author; + c && "object" == typeof c && (o = c.name); + } + } + var m = this.article.element, + d = m.querySelectorAll(n); + if (1 === d.length) return d[0]; + var h = i ? i.nextElementSibling : null; + if (h) { + if ((h.matches(n) || h.innerText === o || (h = h.querySelector(n)), h)) + if (h.querySelector("li")) { + var u = h.querySelector(n); + u && (h = u); + } + if (h) return h; + } + for ( + var g = this.contentDocument.getElementsByTagName("a"), + f = 0, + p = g.length; + f < p; + ++f + ) { + var E = g[f]; + if (trimmedInnerTextIgnoringTextTransform(E) === o) return E; + } + var v = m.closest("article"); + if (i && v) { + if ((y = e(Array.from(v.querySelectorAll(t))))) return y; + if ((y = e(Array.from(v.querySelectorAll(n))))) return y; + } + var T = m.previousElementSibling; + if (T) { + var y; + if ((y = e(Array.from(T.querySelectorAll(t))))) return y; + if ((y = e(Array.from(T.querySelectorAll(n))))) return y; + } + return null; + }, + articleDateElement: function () { + return this._articleDateElement; + }, + findArticleDateElement: function () { + function e(e) { + for (var t = e; t && t !== l; t = t.parentElement) + if (elementIsCommentBlock(t) || elementLooksLikeACarousel(t)) + return !0; + return !1; + } + function t(t) { + for (var n, i = null, r = t.length, a = 0; a < r; ++a) { + var l = t[a]; + if (isElementVisible(l) && !e(l)) { + var o = cachedElementBoundingRect(l), + s = o.left + o.width / 2, + d = o.top + o.height / 2, + h = c - s, + u = m - d, + g = Math.sqrt(h * h + u * u); + (!i || g < n) && ((i = l), (n = g)); + } + } + return i; + } + const n = /date/i, + i = "time, .dateline, .entry-date"; + var r, + a = this._articleSubheadElement || this._articleTitleElement, + l = this.article.element, + o = a ? a.nextElementSibling : null; + if ( + (o && 1 === (r = o.querySelectorAll(i)).length && (o = r[0]), + !o || + o.matches(i) || + hasClassMatchingRegexp(o, n) || + o.querySelector(i) || + (o = null), + o && o.contains(l) && (o = null), + o) + ) + return o; + if (a) + var s, + c = (s = a ? cachedElementBoundingRect(a) : null).left + s.width / 2, + m = s.top + s.height / 2; + if ((r = l.querySelectorAll(i)).length) return t(r); + if ((l = l.closest("article")) && (r = l.querySelectorAll(i)).length) + return t(r); + return null; + }, + articleDateElementWithBylineElementHint: function (e) { + function t(e) { + return ( + /date/.test(e.className) || + /\bdatePublished\b/.test(e.getAttribute("itemprop")) + ); + } + var n = e.nextElementSibling; + if (n && t(n)) return n; + var i = nextLeafElementForElement(e); + return i && t(i) ? i : null; + }, + updateArticleBylineAndDateElementsIfNecessary: function () { + this.article && + (this._didArticleBylineAndDateElementDetection || + (this.updateArticleBylineAndDateElements(), + (this._didArticleBylineAndDateElementDetection = !0))); + }, + updateArticleBylineAndDateElements: function () { + var e = this.findArticleBylineElement(), + t = this.findArticleDateElement(); + (!t && e && (t = this.articleDateElementWithBylineElementHint(e)), + (this._articleDateElement = t), + (this._articleBylineElement = e)); + }, + articleIsLTR: function () { + if (!this._articleIsLTR) { + var e = getComputedStyle(this.article.element); + this._articleIsLTR = !e || "ltr" === e.direction; + } + return this._articleIsLTR; + }, + findSuggestedCandidate: function () { + var e, + t, + n = this.suggestedRouteToArticle; + if (!n || !n.length) return null; + for ( + t = n.length - 1; + t >= 0 && + (!n[t].id || !(e = this.contentDocument.getElementById(n[t].id))); + --t + ); + for (t++, e || (e = this.contentDocument); t < n.length; ) { + for ( + var i = n[t], + r = + e.nodeType === Node.DOCUMENT_NODE + ? e.documentElement + : e.firstElementChild, + a = 1; + r && a < i.index; + r = r.nextElementSibling + ) + this.shouldIgnoreInRouteComputation(r) || a++; + if (!r) return null; + if (normalizedElementTagName(r) !== normalizedElementTagName(i)) + return null; + if (i.className && r.className !== i.className) return null; + ((e = r), t++); + } + return isElementVisible(e) + ? new CandidateElement(e, this.contentDocument) + : null; + }, + findArticleBySearchingAllElements: function (e) { + var t = this.findSuggestedCandidate(), + n = this.findCandidateElements(); + if (!n || !n.length) return t; + if (t && t.basicScore() >= ReaderMinimumScore) return t; + for ( + var i = this.highestScoringCandidateFromCandidates(n), r = i.element; + r !== this.contentDocument; + r = r.parentNode + ) + if ("blockquote" === normalizedElementTagName(r)) { + for (var a = r.parentNode, l = n.length, o = 0; o < l; ++o) { + var s = n[o]; + if (s.element === a) { + i = s; + break; + } + } + break; + } + if (t && i.finalScore() < ReaderMinimumScore) return t; + if (!e) { + if (i.shouldDisqualifyDueToScoreDensity()) return null; + if (i.shouldDisqualifyDueToHorizontalRuleDensity()) return null; + if (i.shouldDisqualifyDueToHeaderDensity()) return null; + if (i.shouldDisqualifyDueToSimilarElements(n)) return null; + } + return i; + }, + findExtraArticle: function () { + if (!this.article) return null; + for ( + var e = 0, t = this.article.element; + e < 3 && t; + ++e, t = t.parentNode + ) { + var n = this.findExtraArticleCandidateElements(t); + if (n && n.length) + for ( + var i, + r = this.sortCandidateElementsInDescendingScoreOrder(n), + a = 0; + a < r.length && (i = r[a]) && i.basicScore(); + a++ + ) + if ( + !i.shouldDisqualifyDueToScoreDensity() && + !i.shouldDisqualifyDueToHorizontalRuleDensity() && + !( + i.shouldDisqualifyDueToHeaderDensity() || + (cachedElementBoundingRect(i.element).height < + PrependedArticleCandidateMinimumHeight && + cachedElementBoundingRect(this.article.element).width !== + cachedElementBoundingRect(i.element).width) + ) + ) { + var l = contentTextStyleForNode(this.contentDocument, i.element); + if ( + l && + l.fontFamily === this.contentTextStyle().fontFamily && + l.fontSize === this.contentTextStyle().fontSize && + i + ) + return i; + } + } + return null; + }, + highestScoringCandidateFromCandidates: function (e) { + for (var t = 0, n = null, i = e.length, r = 0; r < i; ++r) { + var a = e[r], + l = a.basicScore(); + l >= t && ((t = l), (n = a)); + } + return n; + }, + sortCandidateElementsInDescendingScoreOrder: function (e) { + function t(e, t) { + return e.basicScore() !== t.basicScore() + ? t.basicScore() - e.basicScore() + : t.depth() - e.depth(); + } + return e.sort(t); + }, + findCandidateElements: function () { + const e = 1e3; + for ( + var t = Date.now() + e, + n = this.contentDocument.getElementsByTagName("*"), + i = n.length, + r = [], + a = 0; + a < i; + ++a + ) { + var l = n[a]; + if (!SetOfCandidateTagNamesToIgnore.has(normalizedElementTagName(l))) { + var o = CandidateElement.candidateIfElementIsViable( + l, + this.contentDocument, + ); + if ((o && r.push(o), Date.now() > t)) { + r = []; + break; + } + } + } + var s = r.length; + for (a = 0; a < s; ++a) r[a].element.candidateElement = r[a]; + for (a = 0; a < s; ++a) { + var c = r[a]; + if ("blockquote" === normalizedElementTagName(c.element)) { + var m = c.element.parentElement.candidateElement; + m && m.addTextNodesFromCandidateElement(c); + } + } + for (a = 0; a < s; ++a) r[a].element.candidateElement = null; + return r; + }, + findExtraArticleCandidateElements: function (e) { + if (!this.article) return []; + e || (e = this.article.element); + for ( + var t = "preceding-sibling::*/descendant-or-self::*", + n = this.contentDocument.evaluate( + t, + e, + null, + XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, + null, + ), + i = n.snapshotLength, + r = [], + a = 0; + a < i; + ++a + ) { + var l = n.snapshotItem(a); + if (!SetOfCandidateTagNamesToIgnore.has(normalizedElementTagName(l))) + (o = CandidateElement.extraArticleCandidateIfElementIsViable( + l, + this.article, + this.contentDocument, + !0, + )) && r.push(o); + } + ((t = "following-sibling::*/descendant-or-self::*"), + (i = (n = this.contentDocument.evaluate( + t, + e, + null, + XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, + null, + )).snapshotLength)); + for (a = 0; a < i; ++a) { + var o; + l = n.snapshotItem(a); + if (!SetOfCandidateTagNamesToIgnore.has(normalizedElementTagName(l))) + (o = CandidateElement.extraArticleCandidateIfElementIsViable( + l, + this.article, + this.contentDocument, + !1, + )) && r.push(o); + } + return r; + }, + isGeneratedBy: function (e) { + var t = this.contentDocument.head + ? this.contentDocument.head.querySelector("meta[name=generator]") + : null; + if (!t) return !1; + var n = t.content; + return !!n && e.test(n); + }, + isMediaWikiPage: function () { + return ( + void 0 === this._isMediaWikiPage && + (this._isMediaWikiPage = this.isGeneratedBy(/^MediaWiki /)), + this._isMediaWikiPage + ); + }, + isWordPressSite: function () { + return this.isGeneratedBy(/^WordPress/); + }, + isAMPPage: function () { + return this.contentDocument.documentElement.hasAttribute("amp-version"); + }, + nextPageURLString: function () { + if (!this.article) return null; + if (this.isMediaWikiPage()) return null; + var e, + t = 0, + n = this.article.element; + n.parentNode && + "inline" === getComputedStyle(n).display && + (n = n.parentNode); + for ( + var i = n, + r = + cachedElementBoundingRect(n).bottom + + LinkMaxVerticalDistanceFromArticle; + isElementNode(i) && cachedElementBoundingRect(i).bottom <= r; + ) + i = i.parentNode; + i === n || (i !== this.contentDocument && !isElementNode(i)) || (n = i); + var a = this.contentDocument.evaluate( + LinkCandidateXPathQuery, + n, + null, + XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, + null, + ), + l = a.snapshotLength; + if (this.pageNumber <= 2 && !this.prefixWithDateForNextPageURL) { + var o = this.contentDocument.location.pathname, + s = o.match(LinkDateRegex); + s && + ((s = s[0]), + (this.prefixWithDateForNextPageURL = o.substring( + 0, + o.indexOf(s) + s.length, + ))); + } + for (var c = 0; c < l; ++c) { + var m = a.snapshotItem(c), + d = this.scoreNextPageLinkCandidate(m); + d > t && ((e = m), (t = d)); + } + return e ? e.href : null; + }, + scoreNextPageLinkCandidate: function (e) { + function t(e, t, n, i) { + t.substring(0, e.length) === e && + ((t = t.substring(e.length)), (e = "")); + var r = t.lastInteger(); + if (isNaN(r)) return !1; + var a = e ? e.lastInteger() : NaN; + return ( + (isNaN(a) || a >= MaximumExactIntegralValue) && (a = i), + r === a ? n.lastInteger() === a + 1 : r === a + 1 + ); + } + function n(e) { + for ( + var t = {}, n = e.substring(1).split("&"), i = n.length, r = 0; + r < i; + ++r + ) { + var a = n[r], + l = a.indexOf("="); + -1 === l + ? (t[a] = null) + : (t[a.substring(0, l)] = a.substring(l + 1)); + } + return t; + } + var i = this.contentDocument.location; + if (e.host !== i.host) return 0; + if (e.pathname === i.pathname && e.search === i.search) return 0; + if (-1 !== e.toString().indexOf("#")) return 0; + if (anchorLinksToAttachment(e) || anchorLinksToTagOrCategoryPage(e)) + return 0; + if (!isElementVisible(e)) return 0; + var r = cachedElementBoundingRect(e), + a = this.articleBoundingRect(), + l = Math.max( + 0, + Math.max(a.top - (r.top + r.height), r.top - (a.top + a.height)), + ); + if (r.top < a.top) return 0; + if (l > LinkMaxVerticalDistanceFromArticle) return 0; + if ( + Math.max( + 0, + Math.max(a.left - (r.left + r.width), r.left - (a.left + a.width)), + ) > 0 + ) + return 0; + var o = i.pathname, + s = e.pathname; + if (this.prefixWithDateForNextPageURL) { + if (-1 === e.pathname.indexOf(this.prefixWithDateForNextPageURL)) + return 0; + ((o = o.substring(this.prefixWithDateForNextPageURL.length)), + (s = s.substring(this.prefixWithDateForNextPageURL.length))); + } + var c = s.substring(1).split("/"); + c[c.length - 1] || c.pop(); + var m = c.length, + d = o.substring(1).split("/"), + h = !1; + d[d.length - 1] || ((h = !0), d.pop()); + var u = d.length; + if (m < u) return 0; + for (var g = 0, f = 0, p = e.textContent, E = 0; E < m; ++E) { + var v = c[E], + T = E < u ? d[E] : ""; + if (T !== v) { + if (E < u - 2) return 0; + if (v.length >= T.length) { + for (var y = 0; v[v.length - 1 - y] === T[T.length - 1 - y]; ) y++; + y && + ((v = v.substring(0, v.length - y)), + (T = T.substring(0, T.length - y))); + var S = v.indexOf(T); + -1 !== S && (v = v.substring(S)); + } + t(T, v, p, this.pageNumber) + ? (f = Math.pow(LinkNextOrdinalValueBase, E - m + 1)) + : g++; + } + if (g > 1) return 0; + } + var A = !1; + if (e.search) + for (var N in ((linkParameters = n(e.search)), + (referenceParameters = n(i.search)), + linkParameters)) { + var b = linkParameters[N], + x = N in referenceParameters ? referenceParameters[N] : null; + if (x !== b) + if ( + (null === x && (x = ""), + null === b && (b = ""), + b.length < x.length) + ) + g++; + else if (t(x, b, p, this.pageNumber)) { + if (LinkURLSearchParameterKeyMatchRegex.test(N)) { + if (o.toLowerCase() !== s.toLowerCase()) return 0; + if (this.isWordPressSite() && h) return 0; + A = !0; + } + if (LinkURLBadSearchParameterKeyMatchRegex.test(N)) { + g++; + continue; + } + f = Math.max(f, 1 / LinkNextOrdinalValueBase); + } else g++; + } + if (!f) return 0; + if ( + ((LinkURLPageSlashNumberMatchRegex.test(e.href) || + LinkURLSlashDigitEndMatchRegex.test(e.href)) && + (A = !0), + !A && m === u && stringSimilarity(o, s) < LinkMinimumURLSimilarityRatio) + ) + return 0; + if (LinkURLArchiveSlashDigitEndMatchRegex.test(e)) return 0; + var C = + LinkMatchWeight * (Math.pow(LinkMismatchValueBase, -g) + f) + + (LinkVerticalDistanceFromArticleWeight * l) / + LinkMaxVerticalDistanceFromArticle; + (A && (C += LinkURLSemanticMatchBonus), + "li" === normalizedElementTagName(e.parentNode) && + (C += LinkListItemBonus)); + p = e.innerText; + return ( + LinkNextMatchRegEx.test(p) && (C += LinkNextMatchBonus), + LinkPageMatchRegEx.test(p) && (C += LinkPageMatchBonus), + LinkContinueMatchRegEx.test(p) && (C += LinkContinueMatchBonus), + C + ); + }, + elementContainsEnoughTextOfSameStyle: function (e, t, n) { + const i = 110; + var r = "body" === normalizedElementTagName(e), + a = getVisibleNonWhitespaceTextNodes(e, r ? 2 : 3, i, r, t); + const l = 0.2, + o = + n / + clamp(scoreMultiplierForElementTagNameAndAttributes(e), l, 1 / 0) / + languageScoreMultiplierForTextNodes(a); + for (var s = {}, c = a.length, m = 0; m < c; ++m) { + var d = a[m], + h = d.length, + u = d.parentElement, + g = window.getComputedStyle(u), + f = g.fontFamily + "|" + g.fontSize, + p = Math.pow(h, TextNodeLengthPower); + if (s[f]) { + if ((s[f] += p) > o) break; + } else s[f] = p; + } + for (var f in s) if (s[f] > o) return !0; + return !1; + }, + openGraphMetadataClaimsPageTypeIsArticle: function () { + if (!this._openGraphMetadataClaimsPageTypeIsArticle) { + var e = this.contentDocument.querySelector( + "head meta[property='og:type']", + ); + this._openGraphMetadataClaimsPageTypeIsArticle = + e && "article" === e.content; + } + return this._openGraphMetadataClaimsPageTypeIsArticle; + }, + prismGenreClaimsPageIsHomepage: function () { + return ( + "homePage" === + this.contentFromUniqueMetadataSelector( + this.contentDocument, + "head meta[name='prism.genre']", + ) + ); + }, + pointsToUseForHitTesting: function () { + const e = window.innerWidth, + t = e / 4, + n = e / 2, + i = 128, + r = 320; + var a = [ + [n, 800], + [n, 600], + [t, 800], + [n, 400], + [n - i, 1100], + [r, 700], + [3 * t, 800], + [e - r, 700], + ]; + return ( + this.openGraphMetadataClaimsPageTypeIsArticle() && + a.push([n - i, 1400]), + a + ); + }, + findArticleByVisualExamination: function () { + for ( + var e = new Set(), + t = this.pointsToUseForHitTesting(), + n = t.length, + i = AppleDotComAndSubdomainsRegex.test( + this.contentDocument.location.hostname.toLowerCase(), + ) + ? 7200 + : 1800, + r = this.candidateElementFilter, + a = 0; + a < n; + a++ + ) + for ( + var l = t[a][0], + o = t[a][1], + s = elementAtPoint(l, o, this.contentDocument); + s && !e.has(s); + s = s.parentElement + ) { + if (VeryPositiveClassNameRegEx.test(s.className)) + return new CandidateElement(s, this.contentDocument); + if ( + !SetOfCandidateTagNamesToIgnore.has(normalizedElementTagName(s)) + ) { + var c = s.offsetWidth, + m = s.offsetHeight; + if (!c && !m) { + var d = cachedElementBoundingRect(s); + ((c = d.width), (m = d.height)); + } + if ( + !( + c < r.minimumWidth || + m < r.minimumHeight || + c * m < r.minimumArea + ) + ) { + var h = this.elementContainsEnoughTextOfSameStyle(s, e, i); + if ( + (e.add(s), + h && + !( + CandidateElement.candidateElementAdjustedHeight(s) < + r.minimumHeight + )) + ) { + var u = new CandidateElement(s, this.contentDocument); + if (!u.shouldDisqualifyDueToSimilarElements()) { + if (u.shouldDisqualifyDueToHorizontalRuleDensity()) + return null; + if (u.shouldDisqualifyDueToHeaderDensity()) return null; + if (!u.shouldDisqualifyForDeepLinking()) return u; + } + } + } + } + } + return null; + }, + findTextSamplesByVisualExamination: function () { + function e(e) { + if (!e || !e.innerText) return null; + let n = t(e.innerText.trim()); + return (n && a.add(e), n); + } + function t(e) { + const t = 10; + let i = textContentAppearsToBeCJK(e, d) ? d : m, + r = e.length; + if (r < i) return null; + if (r > f * c) return null; + let a = n(e); + return (a.match(/\n/g) || []).length > t ? null : a; + } + function n(e) { + return e.substring(0, h); + } + function i(t, n) { + let i = [], + r = s.querySelectorAll(t); + for (let t of r) { + if (i.length >= n) break; + if (elementDescendsFromElementInSet(t, l)) continue; + let r = e(t); + r && i.push([t, r]); + } + return i; + } + function r(e) { + const n = document.querySelectorAll("div"), + i = new Set(); + for (let r of n) { + if (r.firstElementChild) continue; + let n = t(r.textContent); + if (n && (i.add(n), i.size >= e)) break; + } + return i; + } + this.setSuppressBoundingRectCalculationForSkippedElements(!0); + var a = new Set(), + l = new Set(), + o = new Set(), + s = this.contentDocument, + c = s.body.innerText.length; + const m = 20, + d = 10, + h = 200, + u = 5, + g = 5, + f = 0.8; + let p = s.title, + E = t(p); + E && (o.add(E), l.add(p)); + let v = this.pointsToUseForHitTesting(), + T = v.length; + for (var y = 0; y < T; y++) { + let t = v[y][0], + n = v[y][1], + i = 0; + for ( + let r = elementAtPoint(t, n, this.contentDocument); + r && !a.has(r) && !(i > u); + r = r.parentElement, i++ + ) { + let t = e(r); + if (t) { + if (elementDescendsFromElementMatchingSelector(r, "code, form")) + break; + (o.add(t), l.add(r)); + break; + } + } + } + let S = { p: 3, h1: 2, h2: 2, h3: 1 }; + for (let [e, t] of Object.entries(S)) { + let n = i(e, t); + for (let [e, t] of n) e && t && (o.add(t), l.add(e)); + } + if (o.size < g) { + let e = ["article", "header", "a", "footer", "body"]; + for (let t of e) { + let e = i(t, 1) || [], + [n, r] = e.length > 0 ? e[0] : [null, null]; + if (n && r) { + (o.add(r), l.add(n)); + break; + } + } + } + if (o.size < g) { + const e = r(g - o.size); + o = o.union(e); + } + return Array.from(o); + }, + findArticleFromMetadata: function (e) { + var t = this.contentDocument.querySelectorAll( + SchemaDotOrgArticleContainerSelector, + ); + if (1 === t.length) { + var n = t[0]; + if (n.matches("article, *[itemprop=articleBody]")) + if ( + (o = CandidateElement.candidateIfElementIsViable( + n, + this.contentDocument, + !0, + )) + ) + return e === FindArticleMode.ExistenceOfElement || o; + var i = n.querySelectorAll("article, *[itemprop=articleBody]"), + r = elementWithLargestAreaFromElements(i); + if (r) + if ( + (o = CandidateElement.candidateIfElementIsViable( + r, + this.contentDocument, + !0, + )) + ) + return e === FindArticleMode.ExistenceOfElement || o; + return new CandidateElement(n, this.contentDocument); + } + if ( + this.openGraphMetadataClaimsPageTypeIsArticle() && + !this.prismGenreClaimsPageIsHomepage() + ) { + var a = this.contentDocument.querySelectorAll("main article"), + l = elementWithLargestAreaFromElements(a); + if (l) + if ( + (o = CandidateElement.candidateIfElementIsViable( + l, + this.contentDocument, + !0, + )) + ) + return e === FindArticleMode.ExistenceOfElement || o; + var o, + s = this.contentDocument.querySelectorAll("article"); + if (1 === s.length) + if ( + (o = CandidateElement.candidateIfElementIsViable( + s[0], + this.contentDocument, + !0, + )) + ) + return e === FindArticleMode.ExistenceOfElement || o; + } + return null; + }, + articleTextContent: function () { + return ( + this._articleTextContent || this.adoptableArticle(), + this._articleTextContent + ); + }, + unformattedArticleTextContentIncludingMetadata: function (e) { + this.setSuppressBoundingRectCalculationForSkippedElements(!0); + var t = this.articleNode(); + if (t) { + if (!e) return t.innerText; + var n = "", + i = this.articleTitle(); + i && (n += i + "\n"); + var r = this.articleSubhead(); + r && (n += r + "\n"); + var a = this.adoptableMetadataBlock(); + return ( + a && + (n += + this.plaintextVersionOfNodeAppendingNewlinesBetweenBlockElements( + a, + ) + "\n"), + n + t.innerText + ); + } + }, + plaintextVersionOfNodeAppendingNewlinesBetweenBlockElements: function (e) { + var t = this.contentDocument.createTreeWalker( + e, + NodeFilter.SHOW_ELEMENT | NodeFilter.SHOW_TEXT, + null, + ), + n = ""; + for (t.currentNode = e; t.nextNode(); ) { + var i = t.currentNode; + if (i.nodeType !== Node.TEXT_NODE) { + var r = normalizedElementTagName(i); + ("p" !== r && "div" !== r) || (n += "\n"); + } else n += i.textContent; + } + return n; + }, + pageDescription: function (e) { + var t = e["name:description"] || e["property:og:description"]; + return (t && (t = t.trim()), t.length ? t : null); + }, + articleTitleAndSiteNameFromTitleString: function (e) { + const t = [" - ", " \u2013 ", " \u2014 ", ": ", " | ", " \xbb "], + n = t.length, + i = 0.6; + for ( + var r, + a, + l = this.contentDocument.location.host.replace( + /^(www|m|secure)\./, + "", + ), + o = l.replace(/\.(com|info|net|org|edu|gov)$/, "").toLowerCase(), + s = 0; + s < n; + ++s + ) { + var c = e.split(t[s]); + if (2 === c.length) { + var m = c[0].trim(), + d = c[1].trim(), + h = m.toLowerCase(), + u = d.toLowerCase(), + g = Math.max(stringSimilarity(h, l), stringSimilarity(h, o)), + f = Math.max(stringSimilarity(u, l), stringSimilarity(u, o)), + p = Math.max(g, f); + (!a || p > a) && + ((a = p), + (r = + g > f + ? { siteName: m, articleTitle: d } + : { siteName: d, articleTitle: m })); + } + } + return r && a >= i ? r : null; + }, + pageInformation: function (e, t) { + var n, + i = this.buildMapOfMetaTags(), + r = this.pageDescription(i), + a = !1; + this.adoptableArticle() + ? ((n = this.articleTitle()), + (r = r || this.articleTextContent()), + (a = !0)) + : ((n = this.contentDocument.title), + this.contentDocument.body && + (r = r || this.contentDocument.body.innerText)); + var l = "", + o = this.pageImageURLFromMetadata(i); + if (o) l = o; + else { + var s = this.mainImageNode(); + s && (l = s.src); + } + (n || (n = userVisibleURLString(this.contentDocument.location.href)), + (n = n.trim()), + e && (n = n.substring(0, e))); + var c = this.contentFromUniqueMetadataSelector( + this.contentDocument, + "head meta[property='og:site_name']", + ); + if (!c) { + var m = this.articleTitleAndSiteNameFromTitleString( + this.contentDocument.title, + ); + m && m.articleTitle === n && (c = m.siteName); + } + return ( + c || (c = ""), + (r = r ? r.trim() : ""), + t && (r = r.substring(0, t)), + { + title: n, + previewText: (r = r.replace(/[\s]+/g, " ")), + siteName: c, + mainImageURL: l, + isReaderAvailable: a, + } + ); + }, + readingListItemInformation: function () { + const e = 220, + t = 220; + return this.pageInformation(e, t); + }, + buildMapOfMetaTags: function () { + var e = {}; + const t = this.contentDocument.head.getElementsByTagName("meta"), + n = t.length; + for (var i = 0; i < n; ++i) { + const n = t[i], + r = n.content; + if (!r) continue; + if (this.elementAttributesContainImproperQuote(n)) continue; + n.name && (e["name:" + n.name.toLowerCase()] = r); + const a = n.getAttribute("property"); + a && (e["property:" + a.toLowerCase()] = r); + } + return e; + }, + longestPageMetadataDescriptionForTextAnalysis: function (e) { + var t = []; + const n = e["name:description"]; + n && n.length && t.push(n); + const i = e["property:og:description"]; + i && i.length && t.push(i); + const r = e["name:twitter:description"]; + return ( + r && r.length && t.push(r), + t.length + ? t.reduce(function (e, t) { + return e.length > t.length ? e : t; + }) + : null + ); + }, + pageTypeForTextAnalysis: function (e) { + const t = this.contentDocument.documentElement.getAttribute("itemtype"); + if ( + "http://schema.org/SearchResultsPage" === t || + "https://schema.org/SearchResultsPage" === t + ) + return PageType.searchResults; + const n = e["name:section"]; + if (n && "homepage" === n.toLowerCase()) return PageType.homepage; + const i = e["property:og:type"]; + if (i) { + const e = i.toLowerCase(); + if ("homepage" === e) return PageType.homepage; + if ("article" === e) return PageType.article; + } + const r = e["property:analytics-s-channel"]; + return r && "homepage" === r.toLowerCase() ? PageType.homepage : null; + }, + pageTitleForTextAnalysis: function (e) { + const t = this.contentDocument; + var n = e["property:og:title"]; + return ( + n || (n = e["name:twitter:title"]), + n || (n = e["name:sailthru.headline"]), + n || (n = t.title), + n + ); + }, + pageKeywordsForTextAnalysis: function (e) { + return e["name:keywords"]; + }, + pageAuthorForTextAnalysis: function (e) { + return e["name:author"] || e["property:author"]; + }, + pageMetadataCommonToTextAnalysisAndArticleContent: function () { + var e = {}; + const t = this.buildMapOfMetaTags(), + n = this.pageTitleForTextAnalysis(t); + n && (e.title = n); + const i = this.pageAuthorForTextAnalysis(t); + i && (e.author = i); + const r = this.pageImageURLFromMetadata(t); + return (r && (e.imageURL = r), e); + }, + pageMetadataForTextAnalysis: function () { + let e = this.pageMetadataCommonToTextAnalysisAndArticleContent(); + const t = this.pageTypeForTextAnalysis(metadataMap); + t && (e.type = t); + const n = this.longestPageMetadataDescriptionForTextAnalysis(metadataMap); + n && (e.description = n); + const i = this.pageKeywordsForTextAnalysis(metadataMap); + return (i && (e.keywords = i), e); + }, + extractedArticleContent: function () { + try { + const e = this.adoptableArticle(!0), + t = this.elementReaderUniqueIDAttributeKey(); + for (let n of e.getElementsByTagName("*")) n.removeAttribute(t); + let n = this.pageMetadataCommonToTextAnalysisAndArticleContent(); + if (e) { + const t = e.innerHTML; + n.body = t; + } + this.updateArticleBylineAndDateElementsIfNecessary(); + const i = this.articleDateElement(); + i && (n.publishedDate = trimmedInnerTextIgnoringTextTransform(i)); + const r = this.articleBylineElement(); + return ( + !n.author && + r && + (n.author = trimmedInnerTextIgnoringTextTransform(r)), + n + ); + } catch (e) { + let t = {}; + const n = e.message, + i = e.stack; + return (n && (t.error = n), i && (t.stack = i), t); + } + }, + readerUniqueIDOfElementPinnedToTopOfViewport: function () { + const e = 120; + if (window.scrollY < e) return null; + const t = this.articleNode(); + if (!t) return null; + const n = t.getBoundingClientRect(), + i = (n.left + n.right) / 2; + for (const e of [0, 15, 35, 50, 80, 110]) { + const n = t.ownerDocument.elementFromPoint(i, e); + if ( + n !== t && + (t.contains(n) || + n === this._articleTitleElement || + n === this._articleSubheadElement) + ) { + const e = this._weakMapOfOriginalElementToUniqueID.get(n); + if (e) return e; + } + } + return null; + }, + elementReaderUniqueIDAttributeKey: function () { + return "data-reader-unique-id"; + }, + titleUniqueID: function () { + return "titleElement"; + }, + subheadUniqueID: function () { + return "subheadElement"; + }, + rectOfElementWithReaderUniqueID: function (e) { + function t(e) { + return { + top: e.top + window.scrollY, + right: e.right + window.scrollX, + bottom: e.bottom + window.scrollY, + left: e.left + window.scrollX, + width: e.width, + height: e.height, + }; + } + if (!this._mapOfUniqueIDToOriginalElement) return null; + let n = this._mapOfUniqueIDToOriginalElement.get(e); + return n && n.parentElement ? t(n.getBoundingClientRect()) : null; + }, + scrollY: function () { + return window.scrollY; + }, + scrollToOffset: function (e) { + if ("number" == typeof e) + try { + (clearCachedElementBoundingRects(), + this.cacheWindowScrollPosition(), + (this.contentDocument.scrollingElement.scrollTop = e)); + } catch (e) {} + }, + documentURLString: function () { + return this.contentDocument.location.href; + }, + usesSearchEngineOptimizationMetadata: function () { + return !!document.head.querySelector('meta[property^="og:"]'); + }, + extractCanonicalLink: function () { + var e = document.head.querySelector("link[rel='canonical']"); + if (!e) return null; + var t = e.getAttribute("href"); + if (!t) return null; + var n = document.baseURI, + i = urlFromString(t, n); + return ("/" !== document.location.pathname && "/" === i.pathname) || + ("localhost" === i.hostname && + "localhost" !== document.location.hostname) + ? null + : i.href; + }, + setSuppressBoundingRectCalculationForSkippedElements: function (e) { + this._shouldSuppressBoundingRectCalculationForSkippedElements = e; + }, + shouldSuppressBoundingRectCalculationForSkippedElements: function () { + return !!this._shouldSuppressBoundingRectCalculationForSkippedElements; + }, + })); +var ReaderArticleFinderJS = new ReaderArticleFinder(document); diff --git a/js/reader/ReaderSharedUI.js b/js/reader/ReaderSharedUI.js new file mode 100644 index 0000000..72b7c55 --- /dev/null +++ b/js/reader/ReaderSharedUI.js @@ -0,0 +1,2419 @@ +//# sourceURL=__InjectedScript_ReaderSharedUI.js +/* Copyright (c) 2025 Apple Inc. All rights reserved. */ +// Copyright (c) 2013-2024 Apple Inc. All rights reserved. +function articleHeight() { + return ( + document.getElementById("article").offsetHeight + + 2 * + parseFloat(getComputedStyle(document.getElementById("article")).marginTop) + ); +} +function smoothScroll(e, t, n, i) { + function o(t, n) { + ((scrollEventIsSmoothScroll = !0), + (e.scrollTop = n), + setTimeout(function () { + scrollEventIsSmoothScroll = !1; + }, 0)); + } + const l = 1e3 / 60; + let r = e.scrollTop, + a = r + t, + s = 0, + d = articleHeight() - window.innerHeight; + if ((a < s && (a = s), a > d && (a = d), r == a)) return; + let m = Math.abs(a - r); + if ( + (m < Math.abs(t) && (n = (n * m) / Math.abs(t)), smoothScrollingAnimator) + ) { + let e = smoothScrollingAnimator.animations[0].progress, + t = e > 0.5 ? 1 - e : e, + s = n / (1 - t), + d = -t * s, + m = Math.sin((Math.PI / 2) * t), + c = m * m, + u = (r - a * c) / (1 - c); + return ( + abortSmoothScroll(), + (smoothScrollingAnimator = new AppleAnimator(s, l, i)), + (smoothScrollingAnimation = new AppleAnimation(u, a, o)), + smoothScrollingAnimator.addAnimation(smoothScrollingAnimation), + void smoothScrollingAnimator.start(d) + ); + } + ((smoothScrollingAnimator = new AppleAnimator(n, l, i)), + (smoothScrollingAnimation = new AppleAnimation(r, a, o)), + smoothScrollingAnimator.addAnimation(smoothScrollingAnimation), + smoothScrollingAnimator.start()); +} +function abortSmoothScroll() { + (smoothScrollingAnimator.stop(AnimationTerminationCondition.Interrupted), + (smoothScrollingAnimator = null), + (smoothScrollingAnimation = null)); +} +function articleScrolled() { + (!scrollEventIsSmoothScroll && smoothScrollingAnimator && abortSmoothScroll(), + ReaderJSController.articleScrolled()); +} +function traverseReaderContent(e, t) { + if (!e) return; + let n = e.offsetTop, + i = document.createTreeWalker( + document.getElementById("article"), + NodeFilter.SHOW_ELEMENT, + { + acceptNode: function (e) { + let t = e.classList; + return t.contains("page-number") || + t.contains("float") || + t.contains("page") || + t.contains("scrollable") || + "HR" === e.tagName || + 0 === e.offsetHeight || + "inline" === getComputedStyle(e).display || + n === e.offsetTop + ? NodeFilter.FILTER_SKIP + : NodeFilter.FILTER_ACCEPT; + }, + }, + ); + return ((i.currentNode = e), i[t]()); +} +function nextReaderContentElement(e) { + return traverseReaderContent(e, "nextNode"); +} +function previousReaderContentElement(e) { + return traverseReaderContent(e, "previousNode"); +} +function articleTitleElement() { + return document.querySelector("#article .page .title"); +} +function articleTitleContainer() { + return document.querySelector('[data-reader-unique-id="titleElement"]'); +} +function mediaElementIsPlaying(e) { + return !!(e.currentTime > 0 && !e.paused && !e.ended && e.readyState > 2); +} +function keyDown(e) { + let t = !(e.metaKey || e.altKey || e.ctrlKey || e.shiftKey), + n = !e.metaKey && !e.altKey && !e.ctrlKey && e.shiftKey; + switch (e.keyCode) { + case 8: + (n ? ReaderJSController.goForward() : t && ReaderJSController.goBack(), + e.preventDefault()); + break; + case 74: + ContentAwareScrollerJS.scroll(ContentAwareNavigationDirection.Down); + break; + case 75: + ContentAwareScrollerJS.scroll(ContentAwareNavigationDirection.Up); + break; + case 82: + t && ReaderJS.reloadArticlePreservingScrollPosition(); + } +} +function getArticleScrollPosition() { + ((scrollInfo = {}), (scrollInfo.version = 1)); + let e = document.getElementsByClassName("page"), + t = e.length; + if (!t) return ((scrollInfo.pageIndex = 0), scrollInfo); + scrollInfo.pageIndex = e.length - 1; + let n = window.scrollY; + for (let i = 0; i < t; i++) { + let t = e[i]; + if (t.offsetTop + t.offsetHeight >= n) { + scrollInfo.pageIndex = i; + break; + } + } + return scrollInfo; +} +function restoreInitialArticleScrollPosition() { + let e = + document.getElementsByClassName("page")[initialScrollPosition.pageIndex]; + e && (document.scrollingElement.scrollTop = e.offsetTop); +} +function restoreInitialArticleScrollPositionIfPossible() { + if (didRestoreInitialScrollPosition) return; + if ( + !initialScrollPosition && + ((initialScrollPosition = + ReaderJSController.initialArticleScrollPosition()), + !initialScrollPosition || !initialScrollPosition.pageIndex) + ) + return void (didRestoreInitialScrollPosition = !0); + let e = document.getElementsByClassName("page-number").length; + initialScrollPosition.pageIndex >= e || + (setTimeout( + restoreInitialArticleScrollPosition, + DelayBeforeRestoringScrollPositionInMs, + ), + (didRestoreInitialScrollPosition = !0)); +} +function makeWideElementsScrollable() { + let e = document.querySelectorAll("table, pre"); + for (let t of e) { + if (t.classList.contains("float")) continue; + if (t.parentElement.classList.contains("scrollable")) continue; + let e = document.createElement("div"); + (t.parentElement.insertBefore(e, t), + t.remove(), + e.appendChild(t), + e.classList.add("scrollable")); + } +} +function fontSettings(e) { + function t(e) { + return e.replace(/\W/g, "").toLowerCase(); + } + const n = [15, 16, 17, 18, 19, 20, 21, 23, 26, 28, 37, 46], + i = [ + "25px", + "26px", + "27px", + "28px", + "29px", + "30px", + "31px", + "33px", + "37px", + "39px", + "51px", + "62px", + ]; + let o = { + System: { + lineHeights: [ + "25px", + "26px", + "27px", + "29px", + "30px", + "31px", + "32px", + "33px", + "38px", + "39px", + "51px", + "62px", + ], + usesSystemFont: !0, + }, + Charter: { + lineHeights: [ + "25px", + "26px", + "27px", + "28px", + "29px", + "30px", + "32px", + "34px", + "38px", + "39px", + "51px", + "62px", + ], + }, + Georgia: { + lineHeights: [ + "25px", + "26px", + "27px", + "28px", + "29px", + "30px", + "32px", + "34px", + "38px", + "41px", + "51px", + "62px", + ], + }, + "Iowan Old Style": { + lineHeights: [ + "25px", + "26px", + "27px", + "28px", + "29px", + "30px", + "32px", + "34px", + "38px", + "39px", + "51px", + "62px", + ], + }, + Palatino: { + lineHeights: [ + "25px", + "26px", + "27px", + "28px", + "29px", + "30px", + "31px", + "34px", + "37px", + "40px", + "51px", + "62px", + ], + }, + Seravek: { + lineHeights: [ + "25px", + "26px", + "27px", + "28px", + "28px", + "30px", + "31px", + "34px", + "37px", + "39px", + "51px", + "62px", + ], + }, + "Hiragino Sans W3": { + lineHeights: [ + "1.85em", + "1.78em", + "1.74em", + "1.71em", + "1.72em", + "1.73em", + "1.75em", + "1.76em", + "1.78em", + "1.9em", + "1.92em", + "2em", + ], + }, + "Hiragino Kaku Gothic ProN": { + lineHeights: [ + "1.85em", + "1.78em", + "1.74em", + "1.7em", + "1.69em", + "1.68em", + "1.69em", + "1.7em", + "1.74em", + "1.85em", + "1.9em", + "2em", + ], + }, + "Hiragino Mincho ProN": { + lineHeights: [ + "1.75em", + "1.72em", + "1.69em", + "1.66em", + "1.64em", + "1.56em", + "1.53em", + "1.56em", + "1.6em", + "1.65em", + "1.69em", + "1.72em", + ], + }, + "Hiragino Maru Gothic ProN": { + lineHeights: [ + "1.85em", + "1.78em", + "1.74em", + "1.7em", + "1.69em", + "1.68em", + "1.69em", + "1.7em", + "1.74em", + "1.85em", + "1.9em", + "2em", + ], + }, + "PingFang SC": { + lineHeights: [ + "1.85em", + "1.78em", + "1.74em", + "1.7em", + "1.69em", + "1.68em", + "1.69em", + "1.7em", + "1.74em", + "1.85em", + "1.9em", + "2em", + ], + usesSystemFont: !0, + }, + "Heiti SC": { + lineHeights: [ + "1.85em", + "1.78em", + "1.74em", + "1.7em", + "1.7em", + "1.71em", + "1.72em", + "1.75em", + "1.8em", + "1.9em", + "1.95em", + "2em", + ], + }, + "Songti SC": { + lineHeights: [ + "1.8em", + "1.78em", + "1.74em", + "1.72em", + "1.71em", + "1.72em", + "1.73em", + "1.75em", + "1.8em", + "1.9em", + "1.95em", + "1.96em", + ], + }, + "Kaiti SC": { + lineHeights: [ + "1.75em", + "1.72em", + "1.69em", + "1.66em", + "1.64em", + "1.56em", + "1.53em", + "1.56em", + "1.6em", + "1.65em", + "1.69em", + "1.72em", + ], + }, + "Yuanti SC": { + lineHeights: [ + "1.95em", + "1.93em", + "1.9em", + "1.87em", + "1.85em", + "1.8em", + "1.83em", + "1.85em", + "1.88em", + "1.9em", + "1.91em", + "1.92em", + ], + }, + "Libian SC": { + fontSizes: [27, 28, 29, 30, 31, 32, 33, 35, 37, 40, 42, 46], + lineHeights: [ + "1.65em", + "1.63em", + "1.62em", + "1.61em", + "1.6em", + "1.6em", + "1.61em", + "1.62em", + "1.63em", + "1.64em", + "1.64em", + "1.65em", + ], + }, + "Weibei SC": { + fontSizes: [21, 22, 23, 24, 25, 26, 27, 29, 32, 34, 39, 43], + lineHeights: [ + "1.65em", + "1.63em", + "1.62em", + "1.61em", + "1.6em", + "1.6em", + "1.61em", + "1.62em", + "1.63em", + "1.64em", + "1.64em", + "1.65em", + ], + }, + "Yuppy SC": { + lineHeights: [ + "1.75em", + "1.73em", + "1.7em", + "1.67em", + "1.65em", + "1.6em", + "1.63em", + "1.65em", + "1.68em", + "1.7em", + "1.71em", + "1.72em", + ], + }, + "PingFang TC": { + lineHeights: [ + "1.85em", + "1.78em", + "1.75em", + "1.72em", + "1.7em", + "1.7em", + "1.7em", + "1.72em", + "1.75em", + "1.82em", + "1.85em", + "1.9em", + ], + usesSystemFont: !0, + }, + "Heiti TC": { + lineHeights: [ + "1.85em", + "1.78em", + "1.75em", + "1.72em", + "1.71em", + "1.71em", + "1.72em", + "1.75em", + "1.78em", + "1.82em", + "1.86em", + "1.9em", + ], + }, + "Songti TC": { + lineHeights: [ + "1.8em", + "1.78em", + "1.74em", + "1.73em", + "1.72em", + "1.72em", + "1.73em", + "1.75em", + "1.8em", + "1.9em", + "1.95em", + "1.96em", + ], + }, + "Kaiti TC": { + fontSizes: [20, 21, 22, 23, 24, 25, 26, 28, 31, 33, 38, 43], + lineHeights: [ + "1.63em", + "1.62em", + "1.62em", + "1.6em", + "1.56em", + "1.53em", + "1.5em", + "1.53em", + "1.56em", + "1.6em", + "1.62em", + "1.63em", + ], + }, + "Yuanti TC": { + lineHeights: [ + "1.95em", + "1.93em", + "1.9em", + "1.87em", + "1.85em", + "1.8em", + "1.83em", + "1.85em", + "1.88em", + "1.9em", + "1.91em", + "1.92em", + ], + }, + "Libian TC": { + fontSizes: [27, 28, 29, 30, 31, 32, 33, 35, 37, 40, 42, 46], + lineHeights: [ + "1.65em", + "1.63em", + "1.62em", + "1.61em", + "1.6em", + "1.6em", + "1.61em", + "1.62em", + "1.63em", + "1.64em", + "1.64em", + "1.65em", + ], + }, + "Weibei TC": { + fontSizes: [21, 22, 23, 24, 25, 26, 27, 29, 32, 34, 39, 43], + lineHeights: [ + "1.65em", + "1.63em", + "1.62em", + "1.61em", + "1.6em", + "1.6em", + "1.61em", + "1.62em", + "1.63em", + "1.64em", + "1.64em", + "1.65em", + ], + }, + "Yuppy TC": { + lineHeights: [ + "1.75em", + "1.73em", + "1.7em", + "1.67em", + "1.65em", + "1.6em", + "1.63em", + "1.65em", + "1.68em", + "1.7em", + "1.71em", + "1.72em", + ], + }, + "Noto Nastaliq Urdu": { + lineHeights: [ + "2.6em", + "2.7em", + "2.8em", + "2.8em", + "2.8em", + "2.8em", + "2.8em", + "2.6em", + "2.5em", + "2.5em", + "2.5em", + "2.6em", + ], + }, + }[e]; + return ( + o || (o = {}), + (o.cssClassName = t(e)), + o.usesSystemFont || (o.fontFamilyName = e), + o.fontSizes || (o.fontSizes = n), + o.lineHeights || (o.lineHeights = i), + o + ); +} +function prepareTweetsInPrintingMailingFrame(e) { + let t = e.querySelectorAll(".tweet-wrapper"); + for (let e of t) { + let t = e.querySelector("iframe"); + t && t.remove(); + let n = e.querySelector(".simple-tweet"); + n && n.classList.remove("hidden"); + } +} +function urlFromString(e) { + try { + return new URL(e); + } catch (e) { + return null; + } +} +function stopExtendingElementBeyondTextColumn(e) { + (e.classList.remove("extendsBeyondTextColumn"), + e.style && + (e.style.removeProperty("width"), + e.style.removeProperty("-webkit-margin-start"))); +} +function leadingMarginAndPaddingAppliedToElementFromAncestors(e) { + let t = 0, + n = e.parentElement; + for (; n && !n.classList.contains("page"); ) { + let e = getComputedStyle(n); + ((t += + parseFloat(e["-webkit-padding-start"]) + + parseFloat(e["-webkit-margin-start"])), + (n = n.parentElement)); + } + return t; +} +function extendElementBeyondTextColumn(e, t, n) { + (e.classList.add("extendsBeyondTextColumn"), + e.style && + (e.style.setProperty("width", t + "px"), + e.style.setProperty( + "-webkit-margin-start", + (n - t) / 2 - + leadingMarginAndPaddingAppliedToElementFromAncestors(e) + + "px", + ))); +} +function removeAllZeroWidthSpace() { + document.querySelectorAll("*").forEach((e) => { + e.childNodes.forEach((e) => { + e.nodeType === Node.TEXT_NODE && + (e.textContent = e.textContent.replace(/\u200B/g, "")); + }); + }); +} +function markWithZeroWidthSpaceDelimiterIfNeeded(e) { + if (!e) return; + let t = "\u200b", + n = document.createElement("p"); + ((n.innerText = t), + (n.style.height = "0px"), + (n.style.width = "0px"), + (n.style.margin = "0px")); + let i = document.createElement("p"); + ((i.innerText = t), + (i.style.height = "0px"), + (i.style.width = "0px"), + (i.style.margin = "0px")); + let o = e.firstChild, + l = e.lastChild; + (o && "\u200b" != o.innerText && e.insertBefore(n, o), + l && "\u200b" != l.innerText && e.appendChild(i)); +} +function containsAssistantContent() { + return ReaderController.hasAssistantContent; +} +function shouldShowAssistantSidebar() { + let e = window.innerWidth, + t = e - document.getElementById("article").offsetWidth, + n = document.getElementById("assistant-container").offsetWidth; + return e > 1e3 && t > n + 100; +} +function layoutAssistantContent() { + let e = document.getElementById("sidebarButton"), + t = document.getElementById("assistant-container"), + n = window.innerWidth, + i = document.getElementById("article"), + o = document.getElementById("summary-collapsible"), + l = document.getElementById("summary-collapsedContent"), + r = document.getElementById("tableOfContentsInsideArticleHeader"), + a = document.getElementById("tableOfContentsInsideArticle-list"), + s = document.getElementById("tableOfContents-container"), + d = document.getElementById("summary-container"), + m = document.getElementById("innerAssistantContainer"), + c = null != o, + u = null != a, + g = document.getElementById("onDeviceSummaryButton"), + h = null != g && null != g, + p = ReaderController.isShowingOnDeviceSummary; + if ( + ((t.style.display = "inline-block"), + (t.style.height = "100%"), + (t.style.padding = "50 px"), + (t.style.minWidth = "300px"), + (t.style.overflowY = "scroll"), + (t.style.overflowX = "hidden"), + (t.style.position = "fixed"), + (t.style.zIndex = "1"), + (i.style.zIndex = "2"), + h && c && "none" != g.style.display && (g.style.display = "none"), + markWithZeroWidthSpaceDelimiterIfNeeded(t), + markWithZeroWidthSpaceDelimiterIfNeeded(m), + shouldShowAssistantSidebar() && (u || (c && !p))) + ) { + if ( + ((e.style.display = "block"), + (e.style.right = "0px"), + (e.style.top = "0px"), + (e.style.zIndex = "3"), + (e.style.position = "fixed"), + (e.style.display = "block"), + (e.style.paddingLeft = "1.25em"), + (e.style.paddingRight = "1em"), + c && !p && ((o.style.display = "none"), (l.style.display = "none")), + u && ((a.style.display = "none"), (r.style.display = "none")), + (m.style.display = "none"), + "true" === e.getAttribute("data-isHidingSidebar")) + ) + return ( + (t.style.right = "-400px"), + void (i.style.left = (n - i.offsetWidth) / 2 + "px") + ); + ((i.style.position = "absolute"), + (i.style.left = (n - t.offsetWidth - i.offsetWidth) / 2 + "px"), + (t.style.right = "0px"), + (t.style.display = "inline-block"), + c && !p && (d.style.display = "block"), + u && (s.style.display = "block"), + c && !p + ? (d.style.paddingTop = "0.75em") + : u && (s.style.paddingTop = "0.75em")); + } else + (e && (e.style.display = "none"), + (i.style.position = "static"), + (i.style.left = (n - i.offsetWidth) / 2 + "px"), + (t.style.display = "none"), + m && (m.style.display = "block"), + c && + ((o.style.display = "block"), + (l.style.display = "block"), + ReaderController.summaryNeedsLayout && + (document + .getElementById("summary-collapsible") + .classList.toggle("expandedContent"), + (l.style.maxHeight = l.scrollHeight + "px"), + (l.style.paddingBottom = "1.125em"), + (ReaderController.summaryNeedsLayout = !1)), + l.style.maxHeight && (l.style.maxHeight = l.scrollHeight + "px")), + u && + ((r.style.display = "block"), + (a.style.display = "block"), + a.style.maxHeight && (a.style.maxHeight = a.scrollHeight + "px")), + (s.style.display = "none"), + (d.style.display = "none")); +} +function monitorMouseDownForPotentialDeactivation(e) { + lastMouseDownWasOutsideOfPaper = + e && + ReaderAppearanceJS.usesPaperAppearance() && + !document.getElementById("article").contains(e.target) && + !document.getElementById("assistant-container").contains(e.target); +} +function deactivateIfEventIsOutsideOfPaperContainer(e) { + let t = !1, + n = document.getElementById("sidebarButton"); + (n && (t = n.contains(e.target)), + lastMouseDownWasOutsideOfPaper && + e && + ReaderAppearanceJS.usesPaperAppearance() && + !document.getElementById("article").contains(e.target) && + !document.getElementById("assistant-container").contains(e.target) && + !t && + ReaderJSController.requestDeactivationFromUserAction()); +} +function updatePageNumbers() { + let e = document.getElementsByClassName("page-number"), + t = e.length, + n = ReaderJS.isLoadingNextPage(); + for (let i = 0; i < t; ++i) + e[i].textContent = n + ? getLocalizedString("Page %@").format(i + 1) + : getLocalizedString("Page %@ of %@").format(i + 1, t); +} +function incomingPagePlaceholder() { + return document.getElementById("incoming-page-placeholder"); +} +function addIncomingPagePlaceholder(e) { + let t = document.createElement("div"); + ((t.className = "page"), (t.id = "incoming-page-placeholder")); + let n = document.createElement("div"); + n.id = "incoming-page-corner"; + let i = document.createElement("div"); + ((i.id = "incoming-page-text"), + (i.innerText = getLocalizedString( + e + ? "Loading Next Page\u2026" + : "Connect to the internet to view remaining pages.", + )), + n.appendChild(i), + t.appendChild(n), + document.getElementById("article").appendChild(t)); +} +function removeIncomingPagePlaceholder() { + let e = incomingPagePlaceholder(); + e.parentNode.removeChild(e); +} +function nextPageContainer() { + return document.getElementById("next-page-container"); +} +function getLocalizedString(e) { + let t = localizedStrings[e]; + return t || e; +} +function nextPageLoadComplete() { + if ( + (nextPageContainer().removeEventListener("load", nextPageLoadComplete, !1), + ReaderJS.pageNumber++, + ReaderJS.readerOperationMode == ReaderOperationMode.OffscreenFetching) + ) { + let e = ReaderJS.pageURLs[ReaderJS.pageURLs.length - 1]; + ReaderJSController.nextPageLoadComplete( + ReaderJS.pageNumber, + e, + "next-page-container", + ); + } + ReaderJSController.prepareNextPageFrame("next-page-container"); + let e = ReaderJSController.nextPageArticleFinder(); + ((e.pageNumber = ReaderJS.pageNumber), + (e.suggestedRouteToArticle = ReaderJS.routeToArticle), + (e.previouslyDiscoveredPageURLStrings = ReaderJS.pageURLs)); + let t = e.adoptableArticle(); + (t && + (ReaderJS.createPageFromNode(t), + (ReaderJS.routeToArticle = e.routeToArticleNode())), + nextPageContainer().removeAttribute("src"), + ReaderJSController.clearNextPageArticleFinder(), + ReaderJS.canLoadNextPage() + ? ReaderJS.setNextPageURL(e.nextPageURL()) + : ReaderJS.setCachedNextPageURL(e.nextPageURL()), + updatePageNumbers(), + restoreInitialArticleScrollPositionIfPossible(), + ReaderJS.isLoadingNextPage() || ReaderJS.doneLoadingAllPages()); +} +function firstContentElementAfterTopOfViewport() { + let e, + t = Number.MAX_VALUE; + const n = window.innerWidth / 2; + for (let i = 0; i <= 10; ++i) { + const o = document + .elementFromPoint(n, 4 * i) + .closest("[data-reader-unique-id]"); + if (!o) continue; + const l = o.offsetHeight; + l < t && ((e = o), (t = l)); + } + if (e) return e; + let i = articleTitleElement(); + if (!i) return null; + do { + if (i.getBoundingClientRect().bottom >= 0) return i; + } while ((i = nextReaderContentElement(i))); + return null; +} +function setConfiguration(e) { + ReaderAppearanceJS.applyConfiguration(e); +} +function setReaderIsActive(e) { + ReaderJS.setReaderIsActive(e); +} +function setArticleLocale(e) { + ((document.getElementById("article").style.webkitLocale = `'${e}'`), + ReaderAppearanceJS.applyConfiguration(ReaderAppearanceJS.configuration)); +} +function setTableOfContentsWith(e, t, n, i, o) { + for (var l = n.length - 1; l >= 0; --l) + (document.body.textContent.includes(decodeURIComponent(n[l])) && + document.body.textContent.includes(decodeURIComponent(o[l]))) || + (n.splice(l, 1), o.splice(l, 1), i.splice(l, 1)); + if (n.length < 2) return; + let r = document.createElement("button"); + ((r.id = "tableOfContentsInsideArticleHeader"), + r.classList.toggle("collapsible"), + r.classList.toggle("vision", isPlatformVision), + r.classList.toggle("eligible-for-border-corner", isPlatformVision)); + articleTitleContainer(); + document.getElementById("innerAssistantContainer").appendChild(r); + let a = + ' ', + s = document.createElement("ol"); + ((s.id = "tableOfContentsInsideArticle-list"), + s.classList.toggle("collapsedContent"), + (r.innerHTML = a + " " + e), + r.parentNode.insertBefore(s, r.nextSibling), + (s.style.display = "none"), + isPlatformVision && (r.style.backgroundColor = "#00000001")); + let d = 1.4 + 0.45 * Math.floor(Math.log10(n.length)) + "em"; + for (l = 0; l < n.length; ++l) { + let e = document.createElement("li"); + (e.classList.toggle("innerTableOfContents-listItem"), + (e.id = "item" + n[l]), + e.setAttribute("toc-item-index", l), + e.addEventListener("click", function () { + ReaderJSController.reportReaderEvent( + ReaderEventType.ClickOnTableOfContentsLink, + { + index: parseInt(e.getAttribute("toc-item-index")), + length: n.length, + }, + ); + })); + var m = document.createElement("a"); + ((m.href = t + "#:~:text=" + n[l] + ",-" + o[l]), + (m.textContent = decodeURIComponent(n[l])), + (e.style.marginLeft = d), + e.appendChild(m), + document + .getElementById("tableOfContentsInsideArticle-list") + .appendChild(e)); + } + (r.addEventListener("click", function () { + const e = r.classList.toggle("expandedContent"); + (s.style.maxHeight + ? ((s.style.maxHeight = null), + (s.style.marginBottom = "0px"), + s.classList.toggle("eligible-for-border-corner", !1), + isPlatformVision && + setTimeout(() => { + ((s.style.borderTop = null), (s.style.paddingTop = null)); + }, 200)) + : ((s.style.maxHeight = s.scrollHeight + "px"), + (s.style.marginBottom = "0.75em"), + s.classList.toggle("eligible-for-border-corner", isPlatformVision), + isPlatformVision && + ((s.style.borderTop = "0.1em solid var(--separator-color)"), + (s.style.paddingTop = "1em"))), + ReaderJSController.reportReaderEvent( + ReaderEventType.ClickOnTableOfContentsHeader, + { expanded: e }, + )); + }), + (tableOfContentslistItemMarginLeft = + 1.4 + 0.45 * Math.floor(Math.log10(n.length)) + "em"), + (document.getElementById("tableOfContents-header").innerHTML = + a + " " + e)); + for (l = 0; l < n.length; ++l) { + let e = document.createElement("li"); + e.id = "ToCItem" + n[l]; + var c = document.createElement("a"); + ((c.href = t + "#:~:text=" + n[l] + ",-" + o[l]), + (c.textContent = decodeURIComponent(n[l])), + (e.style.marginLeft = tableOfContentslistItemMarginLeft), + e.appendChild(c), + e.setAttribute("toc-item-index", l), + e.addEventListener("click", function () { + ReaderJSController.reportReaderEvent( + ReaderEventType.ClickOnTableOfContentsLink, + { + index: parseInt(e.getAttribute("toc-item-index")), + length: n.length, + }, + ); + }), + document.getElementById("tableOfContents-list").appendChild(e)); + } + ReaderJSController.reportReaderEvent(ReaderEventType.SetTableOfContents, { + length: n.length, + }); +} +function setSummaryTextWith(e, t, n, i) { + let o = + '', + l = document.getElementById("innerAssistantContainer"), + r = document.getElementById("summary-collapsible"), + a = document.getElementById("summary-collapsible-text-id-1"); + (a || + ((a = document.createElement("p")), + (a.id = "summary-collapsible-text-id-1"), + a.classList.toggle("vision", isPlatformVision)), + n + ? ((a.style.opacity = "0.5"), + (a.style.visibility = "hidden"), + a.classList.add("system")) + : a.classList.remove("system"), + (a.innerText = e)); + var s = "clock" === i, + d = "shield" === i, + m = s || d || "localized-error" === i; + if (s || d) { + document.createElement("attributionIcon"); + let e = s + ? '' + : ''; + a.innerHTML = e + a.innerHTML; + } + if ( + ((a.style.textAlign = m ? "initial" : "inherit"), + (a.tabIndex = -1), + (a.style.outline = "none"), + setTimeout(() => { + a.focus(); + }, 0), + !r) + ) { + ((r = document.createElement("button")), + r.classList.toggle("collapsible"), + r.classList.toggle("vision", isPlatformVision), + r.classList.toggle("eligible-for-border-corner", isPlatformVision), + (r.id = "summary-collapsible"), + (r.innerHTML = o + " " + t), + isPlatformVision && (r.style.backgroundColor = "#00000001"), + l.appendChild(r)); + let e = document.createElement("div"); + ((e.id = "summary-collapsedContent"), + e.appendChild(a), + e.classList.toggle("collapsedContent"), + e.classList.toggle("vision", isPlatformVision), + l.appendChild(e), + r.parentNode.insertBefore(e, r.nextSibling), + r.addEventListener("click", function (t) { + const n = r.classList.toggle("expandedContent"); + ((e.style.overflow = "auto"), + e.style.maxHeight + ? ((e.style.maxHeight = null), + (e.style.marginBottom = "0px"), + e.classList.toggle("eligible-for-border-corner", !1)) + : ((e.style.maxHeight = e.scrollHeight + "px"), + (e.style.marginBottom = "12px"), + e.classList.toggle( + "eligible-for-border-corner", + isPlatformVision, + )), + t.preventDefault(), + ReaderJSController.reportReaderEvent( + ReaderEventType.ClickOnSummaryHeader, + { expanded: n }, + )); + })); + } + let c = document.getElementById("summary-collapsedContent"); + c && c.appendChild(a); + let u = document.getElementById("summary-attribution"); + (u || + !i || + s || + d || + ((u = document.createElement("div")), + (u.id = "summary-attribution"), + (u.innerHTML = `${i}`), + c.appendChild(u)), + (document.getElementById("sidebar-summary-text-id-1").innerText = e), + (document.getElementById("summary-header").innerHTML = o + " " + t)); +} +function updateSummaryTextVisibility(e) { + document.getElementById("summary-collapsible-text-id-1").style.visibility = e + ? "visible" + : "hidden"; +} +function insertSummaryTextPlaceholder() { + const e = + (document.getElementById("summary-collapsible-text-id-1").clientWidth * + 2.5) / + 9; + (setSummaryTextWith( + "\udbc2\udfb7".repeat(e), + getLocalizedString("Summary"), + !0, + ), + layoutAssistantContent()); +} +function setArticleSummary(e, t, n, i, o, l, r, a) { + let s = null != e && e.length > 0, + d = null != o && o.length > 0; + if (!s && !d) return; + removeAllZeroWidthSpace(); + let m = document.getElementById("innerAssistantContainer"); + m || + ((m = document.createElement("div")), + (m.id = "innerAssistantContainer"), + (m.style.display = "none")); + let c = articleTitleContainer(); + c.parentNode.insertBefore(m, c.nextSibling); + let u = document.getElementById("article"); + ((u.style.left = (window.innerWidth - u.offsetWidth) / 2 + "px"), + (ReaderController.hasAssistantContent = !0)); + let g = document.getElementById("summary-collapsible-text-id-1"); + s && + (g && (g.style.opacity = "1"), + setSummaryTextWith(e, t, !1, a), + "true" != m.getAttribute("showedSummary") && + (ReaderJSController.reportReaderEvent(ReaderEventType.SetSummary, {}), + m.setAttribute("showedSummary", !0))); + let h = document.getElementById("tableOfContentsInsideArticle-list"), + p = document.getElementById("tableOfContents-list"), + C = p && p.children.length; + (!d || h || C || setTableOfContentsWith(n, i, o, l, r), + document.getElementById("sidebarButton") || setSidebarButton(), + layoutAssistantContent()); +} +function setSidebarButton() { + let e = document.getElementById("assistant-container"), + t = document.createElementNS("http://www.w3.org/2000/svg", "svg"); + (t.setAttribute("width", "1.5em"), + t.setAttribute("height", "1.5em"), + t.setAttribute("viewbox", "0 0 24 24"), + t.setAttribute("fill", "#000000"), + t.setAttribute("xmlns", "http://www.w3.org/2000/svg")); + let n = document.createElementNS("http://www.w3.org/2000/svg", "path"); + (n.setAttribute( + "d", + "M3.06641 17.998L19.9609 17.998C22.0117 17.998 23.0273 16.9824 23.0273 14.9707L23.0273 3.04688C23.0273 1.03516 22.0117 0.0195312 19.9609 0.0195312L3.06641 0.0195312C1.02539 0.0195312 0 1.02539 0 3.04688L0 14.9707C0 16.9922 1.02539 17.998 3.06641 17.998ZM3.08594 16.4258C2.10938 16.4258 1.57227 15.9082 1.57227 14.8926L1.57227 3.125C1.57227 2.10938 2.10938 1.5918 3.08594 1.5918L19.9414 1.5918C20.9082 1.5918 21.4551 2.10938 21.4551 3.125L21.4551 14.8926C21.4551 15.9082 20.9082 16.4258 19.9414 16.4258ZM14.082 16.7285L15.6152 16.7285L15.6152 1.29883L14.082 1.29883ZM17.4902 5.21484L19.5801 5.21484C19.8828 5.21484 20.1367 4.95117 20.1367 4.66797C20.1367 4.375 19.8828 4.12109 19.5801 4.12109L17.4902 4.12109C17.1973 4.12109 16.9336 4.375 16.9336 4.66797C16.9336 4.95117 17.1973 5.21484 17.4902 5.21484ZM17.4902 7.74414L19.5801 7.74414C19.8828 7.74414 20.1367 7.48047 20.1367 7.1875C20.1367 6.89453 19.8828 6.65039 19.5801 6.65039L17.4902 6.65039C17.1973 6.65039 16.9336 6.89453 16.9336 7.1875C16.9336 7.48047 17.1973 7.74414 17.4902 7.74414ZM17.4902 10.2637L19.5801 10.2637C19.8828 10.2637 20.1367 10.0195 20.1367 9.72656C20.1367 9.43359 19.8828 9.17969 19.5801 9.17969L17.4902 9.17969C17.1973 9.17969 16.9336 9.43359 16.9336 9.72656C16.9336 10.0195 17.1973 10.2637 17.4902 10.2637Z", + ), + n.setAttribute("fill", "var(--body-font-color)"), + t.appendChild(n)); + let i = t; + (isPlatformVision && + (t.setAttribute("width", "24px"), + t.setAttribute("height", "24px"), + (i = document.createElement("button")), + (i.style.borderStyle = "none"), + (i.style.borderRadius = "8px"), + (i.style.backgroundColor = "#00000001"), + (i.style.paddingTop = "0.8em"), + i.appendChild(t)), + (i.id = "sidebarButton"), + i.setAttribute("data-isHidingSidebar", "false"), + i.addEventListener("click", function () { + let e = "true" === i.getAttribute("data-isHidingSidebar"); + (i.setAttribute("data-isHidingSidebar", (!e).toString()), + ReaderJSController.reportReaderEvent( + ReaderEventType.ClickOnSideBarButton, + { expanded: e }, + ), + layoutAssistantContent()); + }), + e.parentNode.appendChild(i)); +} +function resetToSummarizeButton() { + let e = document.getElementById("onDeviceSummaryButton"), + t = document.getElementById("summary-collapsible"), + n = document.getElementById("summary-collapsedContent"); + (n.parentNode.removeChild(n), + t && t.parentNode.removeChild(t), + e && (e.classList.remove("hiddenButton"), (e.style.display = "block"))); + let i = document.getElementById("innerAssistantContainer"); + i && i.remove(); +} +function setOnDeviceSummaryButtonWithTitle(e) { + let t = document.getElementById("summary-collapsible"), + n = document.getElementById("summary-collapsible-text-id-1"), + i = n && n.innerText.includes("\udbc2\udfb7"), + o = n && n.innerText.length; + if (t && o && !i) return; + let l = document.getElementById("onDeviceSummaryButton"); + if (i || (!o && t)) return void resetToSummarizeButton(); + if (null != l && null != l) + return ( + l.classList.remove("hiddenButton"), + void (l.style.display = "block") + ); + ((l = document.createElement("button")), + removeAllZeroWidthSpace(), + (l.id = "onDeviceSummaryButton")); + let r = + ''; + l.innerHTML = r + " " + e; + let a = articleTitleContainer(); + a.parentNode.insertBefore(l, a.nextSibling); + let s = "\u200b", + d = document.createElement("p"); + ((d.innerText = s), + (d.style.height = "0px"), + (d.style.width = "0px"), + (d.style.margin = "0px")); + let m = document.createElement("p"); + ((m.innerText = s), + (m.style.height = "0px"), + (m.style.width = "0px"), + (m.style.margin = "0px"), + l.parentNode.insertBefore(d, l), + l.parentNode.insertBefore(m, l.nextSibling), + l.addEventListener("click", function (e) { + (l.classList.add("hiddenButton"), + showOnDeviceSummaryPlaceholderWithTitle(), + setSummaryTextWith(" ", getLocalizedString("Summary")), + layoutAssistantContent(), + ReaderJSController.requestOnDeviceSummary(), + e.preventDefault()); + })); +} +function showOnDeviceSummaryPlaceholderWithTitle() { + if (document.getElementById("first-placeholder-line")) + return void resetToSummarizeButton(); + let e = document.createElement("button"); + (e.classList.toggle("collapsible"), + e.classList.toggle("vision", isPlatformVision), + e.classList.toggle("eligible-for-border-corner", isPlatformVision), + (e.id = "summary-collapsible")); + let t = + ''; + ((e.innerHTML = t + " \u200b" + getLocalizedString("Summary") + "\u200b"), + isPlatformVision && (e.style.backgroundColor = "#00000001")); + let n = document.createElement("div"); + (n.classList.toggle("shimmer-container"), + (n.id = "summary-collapsedContent"), + n.classList.toggle("collapsedContent"), + n.classList.toggle("vision", isPlatformVision), + n.classList.toggle("eligible-for-border-corner", isPlatformVision), + (n.style.overflow = "visible")); + let i = document.getElementById("innerAssistantContainer"); + if (!i) { + ((i = document.createElement("div")), + (i.id = "innerAssistantContainer"), + (i.style.display = "none")); + let e = articleTitleContainer(); + e.parentNode.insertBefore(i, e.nextSibling); + } + (i.appendChild(e), + i.appendChild(n), + (i.style.display = "block"), + (i.style.opacity = "0"), + i.offsetWidth, + i.offsetHeight, + (i.style.opacity = "1"), + (ReaderController.isShowingOnDeviceSummary = !0), + e.addEventListener("click", function () { + const t = e.classList.toggle("expandedContent"); + ((n.style.overflow = "auto"), + n.style.maxHeight + ? ((n.style.maxHeight = null), + (n.style.marginBottom = "0px"), + n.classList.toggle("eligible-for-border-corner", !1)) + : ((n.style.maxHeight = n.scrollHeight + "px"), + (n.style.marginBottom = "0.75em"), + n.classList.toggle("eligible-for-border-corner", isPlatformVision)), + ReaderJSController.reportReaderEvent( + ReaderEventType.ClickOnSummaryHeader, + { expanded: t }, + )); + }), + e.classList.toggle("expandedContent"), + (n.style.maxHeight = n.scrollHeight + "px"), + (n.style.marginBottom = "0.75em")); +} +function handleVisibilityChange() { + ReaderJS.setDocumentIsVisible(!document.hidden); +} +const LoadNextPageDelay = 250, + MaxNumberOfNextPagesToLoad = 80, + ReaderOperationMode = { Normal: 0, OffscreenFetching: 1, ArchiveViewing: 2 }, + ReaderEventType = { + SetSummary: 0, + SetTableOfContents: 1, + ClickOnSummaryHeader: 2, + ClickOnTableOfContentsHeader: 3, + ClickOnTableOfContentsLink: 4, + ClickOnSideBarButton: 5, + }, + LoadingMode = { Normal: 0, Reload: 1 }, + DelayBeforeRestoringScrollPositionInMs = 1e3; +String.prototype.format = function () { + let e = this.split("%@"); + for (let t = 0, n = arguments.length; t < n; ++t) + e.splice(2 * t + 1, 0, arguments[t].toString()); + return e.join(""); +}; +const debounceTimeoutSymbol = Symbol("debounce-timeout"), + debounceSoonProxySymbol = Symbol("debounce-soon-proxy"); +(Object.defineProperty(Object.prototype, "debounce", { + value(e) { + return new Proxy(this, { + get: + (t, n) => + (...i) => { + let o = t[n]; + o[debounceTimeoutSymbol] && clearTimeout(o[debounceTimeoutSymbol]); + let l = () => { + ((o[debounceTimeoutSymbol] = void 0), o.apply(t, i)); + }; + o[debounceTimeoutSymbol] = setTimeout(l, e); + }, + }); + }, +}), + Object.defineProperty(Function.prototype, "cancelDebounce", { + value() { + this[debounceTimeoutSymbol] && + (clearTimeout(this[debounceTimeoutSymbol]), + (this[debounceTimeoutSymbol] = void 0)); + }, + })); +const AnimationTerminationCondition = { + Interrupted: 0, + CompletedSuccessfully: 1, +}; +((AppleAnimator = function (e, t, n) { + ((this.startTime = 0), + (this.duration = e), + (this.interval = t), + (this.animations = []), + (this.animationFinishedCallback = n), + (this.currentFrameRequestID = null), + (this._firstTime = !0)); + let i = this; + this.animate = function () { + function e(e, t, n) { + return e < t ? t : e > n ? n : e; + } + let t, + n, + o, + l = new Date().getTime(), + r = i.duration; + ((t = e(l - i.startTime, 0, r)), + (l = t / r), + (n = 0.5 - 0.5 * Math.cos(Math.PI * l)), + (o = t >= r)); + let a = i.animations, + s = a.length, + d = i._firstTime; + for (let e = 0; e < s; ++e) a[e].doFrame(i, n, d, o, l); + o + ? i.stop(AnimationTerminationCondition.CompletedSuccessfully) + : ((i._firstTime = !1), + (this.currentFrameRequestID = requestAnimationFrame(i.animate))); + }; +}), + (AppleAnimator.prototype = { + start: function (e) { + let t = new Date().getTime(), + n = this.interval; + ((this.startTime = t - n), + e && (this.startTime += e), + (this.currentFrameRequestID = requestAnimationFrame(this.animate))); + }, + stop: function (e) { + (this.animationFinishedCallback && this.animationFinishedCallback(e), + this.currentFrameRequestID && + cancelAnimationFrame(this.currentFrameRequestID)); + }, + addAnimation: function (e) { + this.animations[this.animations.length] = e; + }, + }), + (AppleAnimation = function (e, t, n) { + ((this.from = e), + (this.to = t), + (this.callback = n), + (this.now = e), + (this.ease = 0), + (this.progress = 0)); + }), + (AppleAnimation.prototype = { + doFrame: function (e, t, n, i, o) { + let l; + ((l = i ? this.to : this.from + (this.to - this.from) * t), + (this.now = l), + (this.ease = t), + (this.progress = o), + this.callback(e, l, n, i)); + }, + })); +let smoothScrollingAnimator, + smoothScrollingAnimation, + isPlatformVision = !1, + scrollEventIsSmoothScroll = !1; +window.addEventListener("scroll", articleScrolled, { + capture: !1, + passive: !0, +}); +const ContentAwareNavigationMarker = "reader-content-aware-navigation-marker", + ContentAwareNavigationAnimationDuration = 200, + ContentAwareNavigationElementOffset = 8, + ContentAwareNavigationDirection = { Up: 0, Down: 1 }; +((ContentAwareScroller = function () { + this._numberOfContentAwareScrollAnimationsInProgress = 0; +}), + (ContentAwareScroller.prototype = { + _contentElementAtTopOfViewport: function () { + let e = articleTitleElement(); + do { + if ( + !(e.getBoundingClientRect().top < ContentAwareNavigationElementOffset) + ) + return e; + } while ((e = nextReaderContentElement(e))); + return null; + }, + _clearTargetOfContentAwareScrolling: function () { + let e = document.getElementById(ContentAwareNavigationMarker); + e && e.removeAttribute("id"); + }, + _contentAwareScrollFinished: function (e) { + e === AnimationTerminationCondition.CompletedSuccessfully && + (--this._numberOfContentAwareScrollAnimationsInProgress, + this._numberOfContentAwareScrollAnimationsInProgress || + ((smoothScrollingAnimator = null), + (smoothScrollingAnimation = null), + this._clearTargetOfContentAwareScrolling())); + }, + scroll: function (e) { + let t, + n, + i = document.getElementById(ContentAwareNavigationMarker), + o = i || this._contentElementAtTopOfViewport(); + if (e === ContentAwareNavigationDirection.Down) { + let e = + Math.abs( + o.getBoundingClientRect().top - ContentAwareNavigationElementOffset, + ) < 1; + t = i || e ? nextReaderContentElement(o) : o; + } else if (e === ContentAwareNavigationDirection.Up) + if (o === articleTitleElement()) { + if (0 === document.scrollingElement.scrollTop) return; + n = -1 * document.scrollingElement.scrollTop; + } else t = previousReaderContentElement(o); + (t && + (n = + t.getBoundingClientRect().top - ContentAwareNavigationElementOffset), + ++this._numberOfContentAwareScrollAnimationsInProgress, + smoothScroll( + document.scrollingElement, + n, + ContentAwareNavigationAnimationDuration, + this._contentAwareScrollFinished.bind(this), + ), + this._clearTargetOfContentAwareScrolling(), + t && (t.id = ContentAwareNavigationMarker)); + }, + }), + window.addEventListener("keydown", keyDown, !1)); +let initialScrollPosition, + didRestoreInitialScrollPosition = !1; +const ThemeSettings = { + White: { cssClassName: "white" }, + Gray: { cssClassName: "gray", tweetTheme: "dark" }, + Sepia: { cssClassName: "sepia" }, + Night: { cssClassName: "night", tweetTheme: "dark" }, + }, + ShouldRestoreReadingPosition = { No: !1, Yes: !0 }, + MinTextZoomIndex = 0, + MaxTextZoomIndex = 11, + MaximumWidthOfImageOrVideoExtendingBeyondTextContainer = 1050, + ReaderConfigurationJavaScriptEnabledKey = "javaScriptEnabled"; +((ReaderAppearanceController = function () { + ((this._shouldUsePaperAppearance = function () { + const e = 70; + return this.articleWidth() + 2 * e < this.documentElementWidth(); + }), + (this._isOLEDDisplay = function () { + return !1; + }), + (this._tryApplyStaticConfiguration = function () { + return !1; + }), + (this._defaultFontFamilyName = "System"), + (this._defaultThemeName = "White"), + (this.configuration = {}), + (this._textSizeIndex = null), + (this._fontFamilyName = this._defaultFontFamilyName), + (this._themeName = this._defaultThemeName)); +}), + (ReaderAppearanceController.prototype = { + initialize: function () { + (this.applyConfiguration(ReaderJSController.initialConfiguration()), + this._isOLEDDisplay() + ? document.body.classList.add("oled") + : isPlatformVision && document.body.classList.add("vision")); + }, + applyConfiguration: function (e) { + if (this._tryApplyStaticConfiguration()) return void this.layOutContent(); + let t = this._locale(); + this.setLocale(t); + for (let n of [ + e.fontFamilyNameForLanguageTag[t], + e.defaultFontFamilyNameForLanguage[t], + "System", + ]) + if (n && this.setFontFamily(n)) break; + for (let t of [e.themeName, "White"]) if (t && this.setTheme(t)) break; + (this.setCurrentTextSizeIndex(e.fontSizeIndex), + (this.configuration = e), + this.layOutContent(), + containsAssistantContent() && layoutAssistantContent(), + (isPlatformVision = !!e.isPlatformVision)); + }, + articleWidth: function () { + return document.getElementById("article").getBoundingClientRect().width; + }, + _textColumnWidthInPoints: function () { + return parseFloat( + getComputedStyle(document.querySelector("#article .page")).width, + ); + }, + documentElementWidth: function () { + return document.documentElement.clientWidth; + }, + setCurrentTextSizeIndex: function (e) { + ((this._textSizeIndex = e), this._rebuildDynamicStyleSheet()); + }, + currentFontCSSClassName: function () { + return this._currentFontSettings().cssClassName; + }, + currentFontCSSFontFamilyName: function () { + return this._currentFontSettings().fontFamilyName; + }, + currentFontUsesSystemFont: function () { + return this._currentFontSettings().usesSystemFont; + }, + _currentFontSettings: function () { + return fontSettings(this._fontFamilyName); + }, + setLocale: function (e) { + if (e === this._lastSetLocale) return; + let t = document.body.classList; + const n = "locale-"; + (t.remove(n + this._lastSetLocale), + t.add(n + e), + (this._lastSetLocale = e)); + }, + setFontFamily: function (e) { + let t = document.body, + n = fontSettings(e); + if (!n) return !1; + if (this._fontFamilyName) { + let e = fontSettings(this._fontFamilyName); + (t.classList.remove(e.cssClassName), + (t.style.fontFamily = null), + e.usesSystemFont && t.classList.remove("system")); + } + return ( + "function" == typeof ReaderJSController.makeFontAvailableIfNecessary && + ReaderJSController.makeFontAvailableIfNecessary(e), + t.classList.add(n.cssClassName), + n.fontFamilyName && (t.style.fontFamily = n.fontFamilyName), + n.usesSystemFont && t.classList.add("system"), + (this._fontFamilyName = e), + !0 + ); + }, + _theme: function () { + return ThemeSettings[this._themeName]; + }, + setTheme: function (e) { + let t = document.body, + n = ThemeSettings[e]; + return ( + !!n && + (t.classList.contains(n.cssClassName) || + (this._theme() && t.classList.remove(this._theme().cssClassName), + t.classList.add(n.cssClassName), + (this._themeName = e)), + !0) + ); + }, + usesPaperAppearance: function () { + return document.documentElement.classList.contains("paper"); + }, + layOutContent: function (e = ShouldRestoreReadingPosition.Yes) { + document.querySelector("#article .page") && + (this._shouldUsePaperAppearance() + ? document.documentElement.classList.add("paper") + : document.documentElement.classList.remove("paper"), + makeWideElementsScrollable(), + this._layOutImagesAndVideoElementsBeyondTextColumn(), + this._layOutElementsContainingTextBeyondTextColumn(), + this._layOutVideos(), + this._layOutMetadataBlock(), + e === ShouldRestoreReadingPosition.Yes && + ReadingPositionStabilizerJS.restorePosition()); + }, + _layOutMetadataBlock: function () { + let e = document.querySelector(".metadata"); + if (!e) return; + let t = e.querySelector(".byline"), + n = e.querySelector(".date"); + if (!t || !n) return void e.classList.add("singleline"); + let i = 0; + for (let e of t.getClientRects()) i += e.width; + for (let e of n.getClientRects()) i += e.width; + i + 25 > this._textColumnWidthInPoints() + ? e.classList.remove("singleline") + : e.classList.add("singleline"); + }, + _layOutImagesAndVideoElementsBeyondTextColumn: function () { + let e = this.canLayOutContentMaintainingAspectRatioBeyondTextColumn(), + t = document.getElementById("article").querySelectorAll("img, video"); + for (let n of t) + this.setImageOrVideoShouldLayOutBeyondTextColumnIfAppropriate(n, e); + }, + _layOutElementsContainingTextBeyondTextColumn: function () { + const e = { PRE: !0, TABLE: !1 }, + t = 22; + let n = document.querySelectorAll(".scrollable pre, .scrollable table"); + for (let i of n) { + let n = i.parentElement; + for (let e = n; e; e = e.parentElement) + "BLOCKQUOTE" === e.tagName && e.classList.add("simple"); + stopExtendingElementBeyondTextColumn(n); + let o = i.scrollWidth, + l = this._textColumnWidthInPoints(); + if (o <= l) continue; + let r = getComputedStyle(document.querySelector(".page")), + a = 0; + if (e[i.tagName]) { + let e = + parseFloat(r["-webkit-padding-start"]) + + parseFloat(r["-webkit-margin-start"]); + a = Math.min(e, t); + } + extendElementBeyondTextColumn( + n, + Math.min(o, this._widthAvailableForLayout() - 2 * a), + l, + ); + } + }, + _layOutVideos: function () { + function e(e) { + return ( + e.src && + /^(.+\.)?(youtube(-nocookie)?|vimeo)\.com\.?$/.test( + urlFromString(e.src).hostname, + ) + ); + } + const t = 16 / 9; + let n, + i, + o = + ReaderAppearanceJS.canLayOutContentMaintainingAspectRatioBeyondTextColumn(); + for (let l of document + .getElementById("article") + .querySelectorAll("iframe")) { + const r = l.parentElement.classList.contains("iframe-wrapper"); + if (!r && !e(l)) continue; + let a; + if ( + (r + ? (a = l.parentElement) + : ((a = document.createElement("div")), + (a.className = "iframe-wrapper"), + l.nextSibling + ? l.parentNode.insertBefore(a, l.nextSibling) + : l.parentNode.appendChild(a), + a.appendChild(l)), + n || + (n = Math.min( + MaximumWidthOfImageOrVideoExtendingBeyondTextContainer, + this._widthAvailableForLayout(), + )), + i || (i = this._textColumnWidthInPoints()), + o && n > i) + ) { + ((a.style.height = n / t + "px"), + extendElementBeyondTextColumn(a, n, i), + (l.style.height = "100%")); + let e = this.usesPaperAppearance() ? 2 : 0; + l.style.width = n - e + "px"; + } else + (stopExtendingElementBeyondTextColumn(a), + (a.style.width = "100%"), + (a.style.height = i / t + "px")); + } + }, + canLayOutContentMaintainingAspectRatioBeyondTextColumn: function () { + const e = 700; + if (window.innerHeight >= e) return !0; + const t = 1.25; + return window.innerWidth / window.innerHeight <= t; + }, + setImageOrVideoShouldLayOutBeyondTextColumnIfAppropriate: function (e, t) { + if (t && !e.closest("blockquote, table, .float")) { + let t, + n = this._textColumnWidthInPoints(), + i = parseFloat(e.getAttribute("width")); + t = isNaN(i) ? e.naturalWidth : i; + let o = Math.min( + t, + Math.min( + MaximumWidthOfImageOrVideoExtendingBeyondTextContainer, + this._widthAvailableForLayout(), + ), + ); + if (o > n) return void extendElementBeyondTextColumn(e, o, n); + } + stopExtendingElementBeyondTextColumn(e); + }, + _widthAvailableForLayout: function () { + return this.usesPaperAppearance() + ? this.articleWidth() + : this.documentElementWidth(); + }, + _rebuildDynamicStyleSheet: function () { + let e = document.getElementById("dynamic-article-content").sheet; + for (; e.cssRules.length; ) e.removeRule(0); + let t = this._currentFontSettings().fontSizes[this._textSizeIndex] + "px", + n = this._currentFontSettings().lineHeights[this._textSizeIndex]; + e.insertRule( + "#article { font-size: " + t + "; line-height: " + n + "; }", + ); + }, + _locale: function () { + let e = document.getElementById("article").style.webkitLocale; + return e && e.length ? ('"' != e[0] ? e : e.substr(1, e.length - 2)) : ""; + }, + })); +let lastMouseDownWasOutsideOfPaper = !1; +((ReaderController = function () { + ((this.pageNumber = 1), + (this.pageURLs = []), + (this.articleIsLTR = !0), + (this.loadingNextPage = !1), + (this.loadingNextPageManuallyStopped = !1), + (this.cachedNextPageURL = null), + (this.lastKnownDocumentElementWidth = 0), + (this._readerWillBecomeVisible = function () {}), + (this._readerWillEnterBackground = function () {}), + (this._distanceFromBottomOfArticleToStartLoadingNextPage = function () { + return NaN; + }), + (this._clickingOutsideOfPaperRectangleDismissesReader = !1), + (this._shouldSkipActivationWhenPageLoads = function () { + return !1; + }), + (this._shouldConvertRelativeURLsToAbsoluteURLsWhenPrintingOrMailing = !1), + (this._deferSendingContentIsReadyForDisplay = !1), + (this._isJavaScriptEnabled = function () { + return !0; + }), + (this._readerIsActive = !0), + (this._documentIsVisible = !document.hidden)); +}), + (ReaderController.prototype = { + setOriginalURL: function (e) { + ((this.originalURL = e), + this.pageURLs.push(e), + (document.head.getElementsByTagName("base")[0].href = this.originalURL), + ReaderJSController.setArticleBaseURLString(e)); + }, + setNextPageURL: function (e) { + if ( + !e || + -1 !== this.pageURLs.indexOf(e) || + this.pageNumber + 1 === MaxNumberOfNextPagesToLoad + ) + return void this.setLoadingNextPage(!1); + (this.setLoadingNextPage(!0), this.pageURLs.push(e)); + let t = function () { + (nextPageContainer().addEventListener("load", nextPageLoadComplete, !1), + (nextPageContainer().src = e)); + }; + this.readerOperationMode == ReaderOperationMode.OffscreenFetching + ? t() + : (this.nextPageLoadTimer = setTimeout(t, LoadNextPageDelay)); + }, + pauseLoadingNextPage: function () { + this.readerOperationMode == ReaderOperationMode.Normal && + (nextPageContainer().removeEventListener( + "load", + nextPageLoadComplete, + !1, + ), + this.cachedNextPageURL || + (this.cachedNextPageURL = this.pageURLs.pop()), + (nextPageContainer().src = null), + this.nextPageLoadTimer && clearTimeout(this.nextPageLoadTimer), + ReaderJSController.didChangeNextPageLoadingState(!1)); + }, + stopLoadingNextPage: function () { + (nextPageContainer().removeEventListener( + "load", + nextPageLoadComplete, + !1, + ), + (nextPageContainer().src = null), + this.nextPageLoadTimer && clearTimeout(this.nextPageLoadTimer), + this.isLoadingNextPage() && + (this.setLoadingNextPage(!1), + (this.loadingNextPageManuallyStopped = !0))); + }, + isLoadingNextPage: function () { + return this.loadingNextPage; + }, + setLoadingNextPage: function (e) { + this.loadingNextPage != e && + (e + ? addIncomingPagePlaceholder(window.navigator.onLine) + : removeIncomingPagePlaceholder(), + (this.loadingNextPage = e), + ReaderJSController.didChangeNextPageLoadingState(this.loadingNextPage)); + }, + doneLoadingAllPages: function () { + ReaderJSController.doneLoadingReaderPage(); + }, + loaded: function () { + this.readerOperationMode = ReaderJSController.readerOperationMode(); + const e = ReaderJSController.originalArticleFinder(); + if (!e || this._shouldSkipActivationWhenPageLoads()) + return void ReaderJSController.deactivateNow(); + this.loadArticle(); + let t = ReaderJSController.cachedTopScrollOffset(); + (t > 0 + ? (document.scrollingElement.scrollTop = t) + : requestAnimationFrame(function () { + ReadingPositionStabilizerJS.applyScrollPositionFromOriginalPage(); + }), + ReadingPositionStabilizerJS.initialize(), + this._clickingOutsideOfPaperRectangleDismissesReader && + (document.documentElement.addEventListener( + "mousedown", + monitorMouseDownForPotentialDeactivation, + ), + document.documentElement.addEventListener( + "click", + deactivateIfEventIsOutsideOfPaperContainer, + )), + window.addEventListener("resize", this.windowDidResize.bind(this), !1)); + var n = "", + i = e.articleTitle(); + i && (n += i + " \n"); + var o = e.articleSubhead(); + o && (n += o + " \n"); + let l = n + e.adoptableArticle().textContent; + l = l.toString().replace(/(<([^>]+)>)/gi, ""); + let r = function () { + ReaderJSController.contentIsReadyForDisplay(l); + }; + this._deferSendingContentIsReadyForDisplay ? setTimeout(r, 0) : r(); + }, + windowDidResize: function () { + let e = ReaderAppearanceJS.documentElementWidth(); + e !== this.lastKnownDocumentElementWidth && + ((this.lastKnownDocumentElementWidth = e), + ReaderAppearanceJS.layOutContent(), + ReadingPositionStabilizerJS.windowDidResize(), + layoutAssistantContent()); + }, + loadArticle: function (e = LoadingMode.Normal) { + const t = ReaderJSController.originalArticleFinder(); + if ((t.article || t.articleNode(!0), !t.article)) + return ( + this.setOriginalURL(t.contentDocument.baseURI), + void this.doneLoadingAllPages() + ); + ((this.routeToArticle = t.routeToArticleNode()), + (this.displayTitleInformation = t.articleTitleInformation()), + (this._snapshotOfArticleTitle = t.articleTitle()), + (this.displaySubhead = t.articleSubhead()), + (this.metadataElement = t.adoptableMetadataBlock()), + (this.articleIsLTR = t.articleIsLTR())); + const n = t.articleNode(); + this._heightOfArticleNodeOnOriginalPage = + n.getBoundingClientRect().height; + let i = t.adoptableArticle(); + this._snapshotOfAdoptableArticle = i.cloneNode(!0); + let o, + l = i.ownerDocument; + if ( + ((document.title = l.title), + this.setOriginalURL(l.baseURI), + this.readerOperationMode != ReaderOperationMode.ArchiveViewing) + ) { + if (this._isJavaScriptEnabled()) + ((o = t.nextPageURL()), this.setNextPageURL(o)); + else { + for (let e of i.querySelectorAll("iframe")) e.remove(); + this.stopLoadingNextPage(); + } + (e !== LoadingMode.Reload && ReaderAppearanceJS.initialize(), + this.createAssistantElements(), + this.createPageFromNode(i), + o || + (t + .adoptableMultiPageContentElements() + .forEach(this.createPageFromNode, this), + updatePageNumbers()), + this.isLoadingNextPage() || this.doneLoadingAllPages(), + e === LoadingMode.Reload && + setTimeout(function () { + ReadingPositionStabilizerJS.contentWasReloaded(); + }, 0)); + } else ReaderAppearanceJS.layOutContent(); + }, + reloadArticlePreservingScrollPositionIfArticleNodeContentHasChanged: + function () { + const e = ReaderJSController.originalArticleFinder(); + if (!e) return; + const t = e.documentURLString(), + n = 30; + for (const e of document.querySelectorAll("audio, video")) + if (mediaElementIsPlaying(e)) return; + const i = e.articleNode(); + if (!i) return; + if ( + i.getBoundingClientRect().height < + this._heightOfArticleNodeOnOriginalPage - n + ) + return; + if (this.originalURL !== t) return; + e.reset(); + const o = e.articleNode(); + if (i !== o && !o.contains(i)) return; + const l = e.adoptableArticle(); + if ( + this._adoptableArticlesAreUserVisiblyEquivalent( + this._snapshotOfAdoptableArticle, + l, + ) + ) + return; + const r = e.articleTitle(); + this._snapshotOfArticleTitle === r && + this.reloadArticlePreservingScrollPosition(); + }, + _adoptableArticlesAreUserVisiblyEquivalent: function (e, t) { + function n(e, t) { + let o = e.nodeType; + if (o !== t.nodeType) return !1; + switch (o) { + case Node.ELEMENT_NODE: + if (e.tagName !== t.tagName) return !1; + let n = e.attributes; + if (n.length !== t.attributes.length) return !1; + let o = t.attributes; + for (let e of n) + if (e.name !== i && e.value !== o[e.name].value) return !1; + break; + case Node.TEXT_NODE: + case Node.COMMENT_NODE: + if (e.data !== t.data) return !1; + break; + default: + return !1; + } + let l = e.firstChild, + r = t.firstChild; + for (; l; ) { + if (!n(l, r)) return !1; + ((l = l.nextSibling), (r = r.nextSibling)); + } + return !r; + } + const i = + ReaderJSController.originalArticleFinder().elementReaderUniqueIDAttributeKey(); + return n(e, t); + }, + reloadArticlePreservingScrollPosition: function () { + this._reloadArticleAndPreserveScrollPosition(!0); + }, + loadNewArticle: function () { + this._reloadArticleAndPreserveScrollPosition(!1); + }, + _reloadArticleAndPreserveScrollPosition: function (e) { + if (!ReaderJSController.originalArticleFinder()) + return void ReaderJSController.deactivateNow(); + ReadingPositionStabilizerJS.setTrackPosition(!1); + const [t, n] = [scrollX, scrollY], + [i, o] = + ReadingPositionStabilizerJS.uniqueIDAndScrollRatioOfElementPinnedToTop(); + let l = document.getElementById("article"); + for ( + l.style.minHeight = l.getBoundingClientRect().height + "px"; + l.childNodes.length >= 1; + ) + l.removeChild(l.firstChild); + if ( + (this.reinitialize(), + e || (document.scrollingElement.scrollTop = 0), + this.loadArticle(LoadingMode.Reload), + e) + ) { + let e; + (i && + (e = ReadingPositionStabilizerJS.tryToScrollToUniqueIDAndRatio(i, o)), + e || scrollTo(t, n)); + } + (ReadingPositionStabilizerJS.setTrackPosition(!0), + setTimeout(function () { + l.style.minHeight = null; + }, 0)); + }, + reinitialize: function () { + ((this.pageNumber = 1), + (this.pageURLs = []), + (this.articleIsLTR = !0), + (this.loadingNextPage = !1), + (this.loadingNextPageManuallyStopped = !1), + (this.routeToArticle = void 0), + (this.displayTitleInformation = void 0), + (this.displaySubhead = void 0), + (this.originalURL = void 0), + (this.nextPageLoadTimer = void 0), + (this.readerOperationMode = ReaderJSController.readerOperationMode()), + (this.cachedNextPageURL = null)); + }, + createAssistantElements: function () { + let e = document.createElement("div"); + ((e.id = "assistant-container"), (e.style.display = "none")); + let t = document.createElement("div"); + ((t.id = "summary-container"), (t.style.display = "none")); + let n = document.createElement("H3"); + ((n.id = "summary-header"), t.appendChild(n)); + let i = document.createElement("p"); + ((i.id = "sidebar-summary-text-id-1"), t.appendChild(i)); + let o = document.createElement("div"); + ((o.id = "tableOfContents-container"), (o.style.display = "none")); + let l = document.createElement("H3"); + ((l.id = "tableOfContents-header"), o.appendChild(l)); + let r = document.createElement("ol"); + ((r.id = "tableOfContents-list"), + o.appendChild(r), + e.appendChild(t), + e.appendChild(o), + document.body.appendChild(e)); + }, + createPageFromNode: function (e) { + const t = ReaderJSController.originalArticleFinder(); + let n = document.createElement("div"); + ((n.className = "page"), this.articleIsLTR || n.classList.add("rtl")); + let i = document.createElement("div"); + ((i.className = "page-number"), n.appendChild(i)); + let o = this.displayTitleInformation, + l = document.createElement("h1"); + if ( + ((l.className = "title"), + (l.textContent = o.titleText), + o.linkURL && o.linkIsForExternalPage) + ) { + let e = document.createElement("a"); + ((e.href = o.linkURL), + o.linkIsTargetBlank && e.setAttribute("target", "_blank"), + e.appendChild(l), + (l = e)); + } + const r = t.elementReaderUniqueIDAttributeKey(); + if ( + (l.setAttribute(r, t.titleUniqueID()), + n.appendChild(l), + this.displaySubhead) + ) { + let e = document.createElement("h2"); + ((e.className = "subhead"), + (e.textContent = this.displaySubhead), + e.setAttribute(r, t.subheadUniqueID()), + n.appendChild(e)); + } + if (this.metadataElement && this.metadataElement.innerText) { + let e = document.createElement("div"); + for (e.className = "metadata"; this.metadataElement.firstChild; ) + e.appendChild(this.metadataElement.firstChild); + n.appendChild(e); + } + let a = e.tagName; + if ("PRE" === a || "CODE" === a) n.appendChild(e); + else for (; e.firstChild; ) n.appendChild(e.firstChild); + (document + .getElementById("article") + .insertBefore(n, incomingPagePlaceholder()), + ReaderJS._isJavaScriptEnabled() && + ReaderJSController.replaceSimpleTweetsWithRichTweets( + this.optionsForTweetCreation(), + ), + ReaderAppearanceJS.layOutContent(ShouldRestoreReadingPosition.No), + updatePageNumbers(), + restoreInitialArticleScrollPositionIfPossible()); + for (let e of n.querySelectorAll("img")) + e.onload = function (e) { + let t = e.target; + (ReaderAppearanceJS.setImageOrVideoShouldLayOutBeyondTextColumnIfAppropriate( + t, + ReaderAppearanceJS.canLayOutContentMaintainingAspectRatioBeyondTextColumn(), + ), + (t.onload = null)); + }; + this._fixImageElementsWithinPictureElements(); + }, + optionsForTweetCreation: function () { + let e = { dnt: !0 }, + t = ReaderAppearanceJS._theme(); + return (t && t.tweetTheme && (e.theme = t.tweetTheme), e); + }, + removeAttribute: function (e, t) { + let n = e.querySelectorAll("[" + t + "]"); + for (let e of n) e.removeAttribute(t); + }, + preparePrintingMailingFrame: function () { + let e = this.printingMailingFrameElementId(), + t = document.getElementById(e); + (t && document.body.removeChild(t), + (t = this.sanitizedFullArticleFrame()), + (t.id = e)); + }, + sanitizedFullArticleFrame: function () { + let e = document.createElement("iframe"); + ((e.style.display = "none"), + (e.style.position = "absolute"), + document.body.appendChild(e)); + let t = e.contentDocument, + n = document.createElement("base"); + ((n.href = this.originalURL), t.head.appendChild(n)); + let i = document.createElement("div"); + i.className = "original-url"; + let o = document.createElement("a"); + ((o.href = this.originalURL), + (o.textContent = this.originalURL), + i.appendChild(document.createElement("br")), + i.appendChild(o), + i.appendChild(document.createElement("br")), + i.appendChild(document.createElement("br")), + t.body.appendChild(i), + t.body.appendChild(this.sanitizedFullArticle()), + t.head.appendChild(document.getElementById("print").cloneNode(!0))); + let l = t.createElement("title"); + return ((l.innerText = document.title), t.head.appendChild(l), e); + }, + getArticleHeadingElements: function () { + const e = ReaderJSController.originalArticleFinder(); + var t = {}; + let n = e.articleSubhead(); + n && (t.subheadline = n); + let i = e.adoptableMetadataBlock(); + return ( + i && + (t.articleMetadata = + e.plaintextVersionOfNodeAppendingNewlinesBetweenBlockElements(i)), + t + ); + }, + sanitizedFullArticle: function () { + let e = document.getElementById("article").cloneNode(!0); + e.removeAttribute("tabindex"); + const t = e.querySelectorAll(".title"); + for (let e = 1, n = t.length; e < n; ++e) t[e].remove(); + for (let t of e.querySelectorAll( + ".page-number, #incoming-page-placeholder, #onDeviceSummaryButton", + )) + t.remove(); + if ( + (prepareTweetsInPrintingMailingFrame(e), + this._shouldConvertRelativeURLsToAbsoluteURLsWhenPrintingOrMailing) + ) { + const t = /^http:\/\/|^https:\/\/|^data:/i; + let n = e.querySelectorAll("img, video, audio, source"); + for (let e of n) { + let n = e.getAttribute("src"); + t.test(n) || e.setAttribute("src", e.src); + } + } + for (let t of e.querySelectorAll(".extendsBeyondTextColumn")) + stopExtendingElementBeyondTextColumn(t); + for (let t of e.querySelectorAll(".delimeter")) t.innerText = "\u2022"; + e.classList.add(ReaderAppearanceJS.currentFontCSSClassName()); + let n = ReaderAppearanceJS.currentFontCSSFontFamilyName(); + (n && (e.style.fontFamily = n), + ReaderAppearanceJS.currentFontUsesSystemFont() && + e.classList.add("system"), + e.classList.add("exported")); + const i = + ReaderJSController.originalArticleFinder().elementReaderUniqueIDAttributeKey(); + for (let t of e.getElementsByTagName("*")) t.removeAttribute(i); + let o = document.getElementById("article-content").sheet.cssRules, + l = o.length; + for (let t = 0; t < l; ++t) { + let n = o[t].selectorText, + i = o[t].style; + if (!i) continue; + let l = i.cssText; + e.matches(n) && e.style && (e.style.cssText += l); + for (let t of e.querySelectorAll(n)) t.style && (t.style.cssText += l); + } + return e; + }, + printingMailingFrameElementId: function () { + return "printing-mailing-frame"; + }, + canLoadNextPage: function () { + if (this.readerOperationMode != ReaderOperationMode.Normal) return !0; + let e = document.querySelectorAll(".page"), + t = e[e.length - 1].getBoundingClientRect(), + n = this._distanceFromBottomOfArticleToStartLoadingNextPage(); + return !!isNaN(n) || !(t.bottom - window.scrollY > n); + }, + setCachedNextPageURL: function (e) { + e + ? ((this.cachedNextPageURL = e), + ReaderJSController.didChangeNextPageLoadingState(!1)) + : this.setNextPageURL(e); + }, + loadNextPage: function () { + null != this.cachedNextPageURL && + (this.setNextPageURL(this.cachedNextPageURL), + (this.cachedNextPageURL = null), + ReaderJSController.didChangeNextPageLoadingState(!0)); + }, + resumeCachedNextPageLoadIfNecessary: function () { + ReaderJS.cachedNextPageURL && + ReaderJS.canLoadNextPage() && + ReaderJS.loadNextPage(); + }, + setDocumentIsVisible: function (e) { + ((this._documentIsVisible = e), + this._readerForegroundednessMayHaveChanged(), + e && ReaderAppearanceJS.layOutContent()); + }, + setReaderIsActive: function (e) { + ((this._readerIsActive = e), + this._readerForegroundednessMayHaveChanged()); + }, + readerIsForeground: function () { + return this._documentIsVisible && this._readerIsActive; + }, + _readerForegroundednessMayHaveChanged: function () { + let e = this.readerIsForeground(); + this._readerIsForeground !== e && + (e ? this.readerWillBecomeVisible() : this.readerWillEnterBackground(), + ReadingPositionStabilizerJS.setTrackPosition(e), + (this._readerIsForeground = e)); + }, + readerWillBecomeVisible: function () { + (document.body.classList.remove("cached"), + this.resumeCachedNextPageLoadIfNecessary(), + this._readerWillBecomeVisible(), + this._readerIsActive && + requestAnimationFrame(function () { + ReadingPositionStabilizerJS.applyScrollPositionFromOriginalPage(); + })); + }, + readerWillEnterBackground: function () { + (ReaderJS.isLoadingNextPage() || + ReaderJS.loadingNextPageManuallyStopped) && + this.pauseLoadingNextPage(); + for (let e of document.querySelectorAll("audio")) e.pause(); + for (let e of document.querySelectorAll("video")) + e.hasAttribute("data-reader-silent-looped-animation") || e.pause(); + this._readerWillEnterBackground(); + }, + _fixImageElementsWithinPictureElements: function () { + requestAnimationFrame(function () { + let e = !1, + t = document.querySelectorAll("#article picture img"); + for (let n of t) { + let t = n.previousElementSibling; + if (t) (n.remove(), t.after(n), (e = !0)); + else { + let t = n.parentElement; + (n.remove(), t.appendChild(n), (e = !0)); + } + } + e && ReaderAppearanceJS.layOutContent(); + }); + }, + }), + (ReadingPositionStabilizer = function () { + ((this.elementTouchingTopOfViewport = null), + (this.elementTouchingTopOfViewportOffsetFromTopOfElementRatio = 0), + (this._trackingScrolling = !1), + (this._hasEverScrolled = !1)); + }), + (ReadingPositionStabilizer.prototype = { + initialize: function () { + this.setTrackPosition(!0); + const e = 250; + ((this._checkForUpdatedContentSoon = + this.debounce(e)._checkForUpdatedContentNow), + (this.windowDidResize = this.debounce(e)._windowDidResize)); + }, + setTrackPosition: function (e) { + if (e === this._trackingScrolling) return; + this._trackingScrolling = e; + const t = 250; + (this._debouncedDidScroll || + (this._debouncedDidScroll = this.debounce(t)._didScroll), + e + ? window.addEventListener("scroll", this._debouncedDidScroll, { + capture: !1, + passive: !0, + }) + : window.removeEventListener("scroll", this._debouncedDidScroll, { + capture: !1, + passive: !0, + })); + }, + _windowDidResize: function () { + this._hasEverScrolled && this._updatePosition(!1); + }, + contentWasReloaded: function () { + this._updatePosition(!1); + }, + _didScroll: function () { + this._trackingScrolling && + ((this._hasEverScrolled = !0), this._updatePosition(!1)); + }, + _updatePosition: function (e = !0) { + let t = firstContentElementAfterTopOfViewport(); + if (!t) return void (this.elementTouchingTopOfViewport = null); + this.elementTouchingTopOfViewport = t; + let n = this.elementTouchingTopOfViewport.getBoundingClientRect(); + ((this.elementTouchingTopOfViewportOffsetFromTopOfElementRatio = + n.height > 0 ? n.top / n.height : 0), + this._originalPageScrollSyncAndContentRefreshIsAllowed() && + ReaderJS.readerIsForeground() && + (this._pushScrollPositionToOriginalPage(), + e && this._checkForUpdatedContentSoon())); + }, + _pushScrollPositionToOriginalPage: function () { + const e = ReaderJSController.originalArticleFinder(), + [t, n] = this.uniqueIDAndScrollRatioOfElementPinnedToTop(), + i = e.rectOfElementWithReaderUniqueID(t); + if (!i || !i.top || isNaN(i.top) || !i.height || isNaN(i.height)) return; + const o = -n * i.height; + e.scrollToOffset(i.top + o); + }, + applyScrollPositionFromOriginalPage: function () { + const e = ReaderJSController.originalArticleFinder(), + t = e.readerUniqueIDOfElementPinnedToTopOfViewport(); + if (!t) return; + const n = e.rectOfElementWithReaderUniqueID(t); + if (!n || !n.top || isNaN(n.top) || !n.height || isNaN(n.height)) return; + const i = (n.top - e.scrollY()) / n.height; + this.tryToScrollToUniqueIDAndRatio(t, i); + }, + _checkForUpdatedContentNow: function () { + ReaderJS.reloadArticlePreservingScrollPositionIfArticleNodeContentHasChanged(); + }, + restorePosition: function () { + if (!this.elementTouchingTopOfViewport) return; + let e = this.elementTouchingTopOfViewport.getBoundingClientRect(), + t = + document.scrollingElement.scrollTop + + e.top - + e.height * + this.elementTouchingTopOfViewportOffsetFromTopOfElementRatio; + (t > 0 && (document.scrollingElement.scrollTop = t), + this._updatePosition()); + }, + uniqueIDAndScrollRatioOfElementPinnedToTop: function () { + if (!this.elementTouchingTopOfViewport) return [null, null]; + const e = ReaderJSController.originalArticleFinder(); + return [ + this.elementTouchingTopOfViewport.getAttribute( + e.elementReaderUniqueIDAttributeKey(), + ), + this.elementTouchingTopOfViewportOffsetFromTopOfElementRatio, + ]; + }, + tryToScrollToUniqueIDAndRatio: function (e, t) { + const n = ReaderJSController.originalArticleFinder(), + i = document.querySelector( + "[" + n.elementReaderUniqueIDAttributeKey() + "='" + e + "']", + ); + if (!i) return !1; + const o = i.getBoundingClientRect(); + return ( + !!o.height && + ((document.scrollingElement.scrollTop = + o.top - t * o.height + window.scrollY), + this._updatePosition(!1), + !0) + ); + }, + _originalPageScrollSyncAndContentRefreshIsAllowed: function () { + return !document.body.classList.contains("watch"); + }, + }), + document.addEventListener("visibilitychange", handleVisibilityChange, !1)); +var ContentAwareScrollerJS = new ContentAwareScroller(), + ReaderAppearanceJS = new ReaderAppearanceController(), + ReadingPositionStabilizerJS = new ReadingPositionStabilizer(), + ReaderJS = new ReaderController(); +window.addEventListener( + "load", + function () { + ReaderJS.loaded(); + }, + !1, +); \ No newline at end of file diff --git a/js/reader/ReaderSharedUINormalWorld.js b/js/reader/ReaderSharedUINormalWorld.js new file mode 100644 index 0000000..93d3bc6 --- /dev/null +++ b/js/reader/ReaderSharedUINormalWorld.js @@ -0,0 +1,37 @@ +//# sourceURL=__InjectedScript_ReaderSharedUINormalWorld.js +/* Copyright (c) 2025 Apple Inc. All rights reserved. */ +function loadTwitterJavaScript() { + window.twttr || + (window.twttr = (function (e, t, r) { + var i, + a, + d = e.getElementsByTagName(t)[0]; + if (!e.getElementById(r)) + return ( + ((a = e.createElement(t)).id = r), + (a.src = "https://platform.twitter.com/widgets.js"), + d.parentNode.insertBefore(a, d), + window.twttr || + (i = { + _e: [], + ready: function (e) { + i._e.push(e); + }, + }) + ); + })(document, "script", "twitter-wjs")); +} +function richTweetWasCreatedFromSimpleTweet(e) { + e.parentNode.querySelector(".simple-tweet").classList.add("hidden"); +} +function replaceSimpleTweetsWithRichTweets(e) { + let t = document.querySelectorAll("[data-reader-tweet-id]"); + t.length && + (loadTwitterJavaScript(), + twttr.ready(function (r) { + for (let i of t) + r.widgets + .createTweet(i.getAttribute("data-reader-tweet-id"), i, e) + .then(richTweetWasCreatedFromSimpleTweet); + })); +} \ No newline at end of file diff --git a/js/schema/SchemaDataExtractor.js b/js/schema/SchemaDataExtractor.js new file mode 100644 index 0000000..bf79490 --- /dev/null +++ b/js/schema/SchemaDataExtractor.js @@ -0,0 +1,249 @@ +//# sourceURL=__InjectedScript_SchemaDataExtractor.js +/* Copyright (c) 2025 Apple Inc. All rights reserved. */ +var SchemaDataExtractor = function () {}; +((SchemaDataExtractor.validAddressProperties = { + addressCountry: 1, + addressLocality: 1, + addressRegion: 1, + postOfficeBoxNumber: 1, + postalCode: 1, + streetAddress: 1, +}), + (SchemaDataExtractor.validParentSchemaTypes = { + "http://schema.org/Person": 1, + "https://schema.org/Person": 1, + "http://schema.org/LocalBusiness": 1, + "https://schema.org/LocalBusiness": 1, + "http://schema.org/Organization": 1, + "https://schema.org/Organization": 1, + "http://schema.org/Restaurant": 1, + "https://schema.org/Restaurant": 1, + "http://schema.org/Corporation": 1, + "https://schema.org/Corporation": 1, + "http://schema.org/EducationalOrganization": 1, + "https://schema.org/EducationalOrganization": 1, + "http://schema.org/GovernmentOrganization": 1, + "https://schema.org/GovernmentOrganization": 1, + "http://schema.org/MedicalOrganization": 1, + "https://schema.org/MedicalOrganization": 1, + "http://schema.org/AnimalShelter": 1, + "https://schema.org/AnimalShelter": 1, + "http://schema.org/AutomotiveBusiness": 1, + "https://schema.org/AutomotiveBusiness": 1, + "http://schema.org/ChildCare": 1, + "https://schema.org/ChildCare": 1, + "http://schema.org/DryCleaningOrLaundry": 1, + "https://schema.org/DryCleaningOrLaundry": 1, + "http://schema.org/EmergencyService": 1, + "https://schema.org/EmergencyService": 1, + "http://schema.org/EmploymentAgency": 1, + "https://schema.org/EmploymentAgency": 1, + "http://schema.org/EntertainmentBusiness": 1, + "https://schema.org/EntertainmentBusiness": 1, + "http://schema.org/FinancialService": 1, + "https://schema.org/FinancialService": 1, + "http://schema.org/FoodEstablishment": 1, + "https://schema.org/FoodEstablishment": 1, + "http://schema.org/GovernmentOffice": 1, + "https://schema.org/GovernmentOffice": 1, + "http://schema.org/HealthAndBeautyBusiness": 1, + "https://schema.org/HealthAndBeautyBusiness": 1, + "http://schema.org/HomeAndConstructionBusiness": 1, + "https://schema.org/HomeAndConstructionBusiness": 1, + "http://schema.org/InternetCafe": 1, + "https://schema.org/InternetCafe": 1, + "http://schema.org/LegalService": 1, + "https://schema.org/LegalService": 1, + "http://schema.org/Library": 1, + "https://schema.org/Library": 1, + "http://schema.org/LodgingBusiness": 1, + "https://schema.org/LodgingBusiness": 1, + "http://schema.org/ProfessionalService": 1, + "https://schema.org/ProfessionalService": 1, + "http://schema.org/RadioStation": 1, + "https://schema.org/RadioStation": 1, + "http://schema.org/RealEstateAgent": 1, + "https://schema.org/RealEstateAgent": 1, + "http://schema.org/RecyclingCenter": 1, + "https://schema.org/RecyclingCenter": 1, + "http://schema.org/SelfStorage": 1, + "https://schema.org/SelfStorage": 1, + "http://schema.org/ShoppingCenter": 1, + "https://schema.org/ShoppingCenter": 1, + "http://schema.org/SportsActivityLocation": 1, + "https://schema.org/SportsActivityLocation": 1, + "http://schema.org/Store": 1, + "https://schema.org/Store": 1, + "http://schema.org/TelevisionStation": 1, + "https://schema.org/TelevisionStation": 1, + "http://schema.org/TouristInformationCenter": 1, + "https://schema.org/TouristInformationCenter": 1, + "http://schema.org/TravelAgency": 1, + "https://schema.org/TravelAgency": 1, + }), + (SchemaDataExtractor.validBaseSchemaTypes = { + "http://schema.org/PostalAddress": 1, + "https://schema.org/PostalAddress": 1, + }), + (SchemaDataExtractor.containsSchemaOrgKey = "containsSchemaOrg"), + (SchemaDataExtractor.containsMicrodataKey = "containsMicrodata"), + (SchemaDataExtractor.schemaOrgTypeDomain = "schema.org"), + (SchemaDataExtractor.prototype = { + isValidParentSchemaType: function (t) { + return SchemaDataExtractor.validParentSchemaTypes[t]; + }, + isValidBaseSchemaType: function (t) { + return SchemaDataExtractor.validBaseSchemaTypes[t]; + }, + extractFilteredSchemaValuesFromMicroData: function () { + const t = document.querySelectorAll("[itemscope]"); + let e = [], + r = [], + a = !1; + for (let o of t) { + let t = o.getAttribute("itemType"); + t && + (this.isValidParentSchemaType(t) && e.push(o), + this.isValidBaseSchemaType(t) && r.push(o), + !a && + t.includes(SchemaDataExtractor.schemaOrgTypeDomain) && + (a = !0)); + } + let o = {}; + if (!a) return o; + if (((o[SchemaDataExtractor.containsSchemaOrgKey] = !0), 1 !== r.length)) + return o; + const s = r[0], + c = s.getAttribute("itemtype"); + if (!c || -1 === c.indexOf("PostalAddress")) return o; + const n = s.querySelectorAll("[itemprop]"); + for (let t of n) { + let e = t.getAttribute("itemprop"); + e && + SchemaDataExtractor.validAddressProperties[e] && + (o[e] = t.textContent ? t.textContent : t.getAttribute("content")); + } + let h = s.parentNode; + for (; null !== h && -1 === e.indexOf(h); ) h = h.parentNode; + const i = s.querySelectorAll("[itemprop='telephone']"); + if (null !== h) { + let t = h.querySelectorAll("[itemprop='name']"); + (t.length && (o.name = t[0].textContent), + 0 === i.length && (i = h.querySelectorAll("[itemprop='telephone']"))); + } + return (i.length && (o.telephone = i[0].textContent), o); + }, + extractAllSchemaValuesFromMicroData: function () { + const t = document.querySelectorAll("[itemscope]"); + let e = [], + r = !1; + for (let a of t) { + const t = a.getAttribute("itemType"); + t && + (e.push(a), + !r && + t.includes(SchemaDataExtractor.schemaOrgTypeDomain) && + (r = !0)); + } + let a = {}; + if (!r) return a; + if (((a[SchemaDataExtractor.containsSchemaOrgKey] = !0), 1 !== e.length)) + return a; + const o = e[0], + s = (o.getAttribute("itemtype"), o.querySelectorAll("[itemprop]")); + for (let t of s) { + let e = t.getAttribute("itemprop"); + e && (a[e] = t.textContent ? t.textContent : t.getAttribute("content")); + } + return a; + }, + extractFilteredSchemaValuesFromJSONLD: function () { + let t = {}; + const e = document.querySelector('script[type="application/ld+json"]'); + if (!e) return t; + let r; + try { + r = JSON.parse(e.text); + } catch (e) { + return t; + } + let a = r["@context"]; + if ("http://schema.org" !== a && "https://schema.org" !== a) return t; + t[SchemaDataExtractor.containsSchemaOrgKey] = !0; + let o = []; + for (o.unshift(r); o.length; ) { + let e = o.shift(); + if (null != e) { + if ( + (Object.prototype.hasOwnProperty.call(e, "telephone") && + (t.telephone = e.telephone), + "PostalAddress" === e["@type"]) + ) { + for (let r in e) + SchemaDataExtractor.validAddressProperties[r] && (t[r] = e[r]); + break; + } + for (let t in e) { + let r = e[t]; + "object" == typeof r && o.push(r); + } + } + } + return t; + }, + extractAllSchemaValuesFromJSONLD: function () { + let t = {}; + const e = document.querySelector('script[type="application/ld+json"]'); + if (!e) return t; + let r, a; + try { + r = JSON.parse(e.text); + } catch (e) { + return t; + } + if ( + ((a = Array.isArray(r) ? r[0]["@context"] : r["@context"]), + "http://schema.org" !== a && "https://schema.org" !== a) + ) + return t; + t[SchemaDataExtractor.containsSchemaOrgKey] = !0; + let o = []; + o.unshift(r); + const s = o.shift(); + for (let e in s) t[e] = s[e]; + return t; + }, + resultHasAddressOrTelephone: function (t) { + return ( + null != t && + (Object.prototype.hasOwnProperty.call(t, "streetAddress") || + Object.prototype.hasOwnProperty.call(t, "telephone")) + ); + }, + resultHasSchemaOrgInfo: function (t) { + return ( + null != t && + Object.prototype.hasOwnProperty.call( + t, + SchemaDataExtractor.containsSchemaOrgKey, + ) + ); + }, + extractSchemaValuesFromSchemaOrg: function () { + let t = this.extractAllSchemaValuesFromMicroData(), + e = this.extractFilteredSchemaValuesFromMicroData(); + return ( + this.resultHasAddressOrTelephone(e) || + (e = this.extractFilteredSchemaValuesFromJSONLD()), + this.resultHasAddressOrTelephone(t) || + (t = this.extractAllSchemaValuesFromJSONLD()), + (this.resultHasAddressOrTelephone(e) || + this.resultHasSchemaOrgInfo(e)) && + (e.url = location.href), + [e, t] + ); + }, + }), + "undefined" == typeof SchemaDataExtractorJS && + (SchemaDataExtractorJS = new SchemaDataExtractor()), + SchemaDataExtractorJS.extractSchemaValuesFromSchemaOrg()); diff --git a/js/schema/SchemaOrgMarkupChecker.js b/js/schema/SchemaOrgMarkupChecker.js new file mode 100644 index 0000000..1d436fb --- /dev/null +++ b/js/schema/SchemaOrgMarkupChecker.js @@ -0,0 +1,20 @@ +//# sourceURL=__InjectedScript_SchemaOrgMarkupChecker.js +/* Copyright (c) 2025 Apple Inc. All rights reserved. */ +(function () { + const e = "schema.org"; + var t = document.querySelectorAll('script[type="application/ld+json"]'); + for (let o of t) { + var r; + try { + r = JSON.parse(o.text); + } catch (e) { + continue; + } + if (r["@context"].toLowerCase().includes(e)) return !0; + } + var o = document.querySelectorAll("[itemscope]"); + for (let t of o) { + var c = t.getAttribute("itemType"); + if (c && c.toLowerCase().includes(e)) return !0; + } +})(); diff --git a/js/search/OpenSearchURLFinder.js b/js/search/OpenSearchURLFinder.js new file mode 100644 index 0000000..338f34e --- /dev/null +++ b/js/search/OpenSearchURLFinder.js @@ -0,0 +1,22 @@ +//# sourceURL=__InjectedScript_OpenSearchURLFinder.js +/* Copyright (c) 2025 Apple Inc. All rights reserved. */ +var OpenSearchURLFinder = function () {}; +OpenSearchURLFinder.prototype = { + firstOpenSearchURLString: function () { + if (!document.head) return null; + for ( + var e = document.head.getElementsByTagName("link"), r = e.length, n = 0; + n < r; + ++n + ) { + var t = e[n]; + if ( + "search" === t.getAttribute("rel") && + "application/opensearchdescription+xml" === t.getAttribute("type") + ) + return t.href; + } + return null; + }, +}; +var OpenSearchURLFinderJS = new OpenSearchURLFinder(); diff --git a/js/translation/Translation.js b/js/translation/Translation.js new file mode 100644 index 0000000..d680420 --- /dev/null +++ b/js/translation/Translation.js @@ -0,0 +1,3 @@ +//# sourceURL=__InjectedScript_Translation.js +/* Copyright (c) 2025 Apple Inc. All rights reserved. */ +function updateLanguageAttributesForTranslation(n){document.documentElement.lang&&(document.documentElement.lang=n)} \ No newline at end of file diff --git a/js/utilities/NodePath.js b/js/utilities/NodePath.js new file mode 100644 index 0000000..2bb82ae --- /dev/null +++ b/js/utilities/NodePath.js @@ -0,0 +1,749 @@ +//# sourceURL=__InjectedScript_NodePath.js +/* Copyright (c) 2025 Apple Inc. All rights reserved. */ +// Copyright (C) 2023-2024 Apple Inc. All rights reserved. +"use strict"; +(globalThis.WAS || (globalThis.WAS = {}), + (WAS.NodePath = class { + static { + function e(e, t) { + if (e === t) return 0; + for ( + var n = e.length, o = t.length, a = new Array(n + 1), i = 0; + i < n + 1; + ++i + ) + ((a[i] = new Array(o + 1)), (a[i][0] = i)); + for (var s = 0; s < o + 1; ++s) a[0][s] = s; + for (s = 1; s < o + 1; ++s) { + let o = t[s - 1]; + for (i = 1; i < n + 1; ++i) + if (e[i - 1] === o) a[i][s] = a[i - 1][s - 1]; + else { + var d = a[i - 1][s] + 1, + r = a[i][s - 1] + 1, + h = a[i - 1][s - 1] + 1; + a[i][s] = Math.min(d, r, h); + } + } + return a[n][o]; + } + ((WAS.Assert = + WAS.Assert || + class { + static isTrue(e, t, ...n) {} + static isType(e, ...t) {} + static optionalIsType(e, ...t) {} + static arrayContentIsType(e, ...t) {} + static optionalArrayContentIsType(e, ...t) {} + static isEnum(e, t) {} + static optionalIsEnum(e, t) {} + static isSubclass(e, t) {} + static notReached(e, ...t) {} + }), + Object.defineProperties(CharacterData, { + nodePath_isCharacterData: { + value(e) { + switch (Node.nodePath_nodeType(e)) { + case Node.TEXT_NODE: + case Node.CDATA_SECTION_NODE: + case Node.PROCESSING_INSTRUCTION_NODE: + case Node.COMMENT_NODE: + return !0; + default: + return !1; + } + }, + }, + nodePath_data: { + value: (e) => + CharacterData.nodePath_isCharacterData(e) + ? Object.nodePath_get(e, CharacterData, "data") + : null, + }, + }), + Object.defineProperties(Document, { + nodePath_isDocument: { + value: (e) => Node.nodePath_nodeType(e) === Node.DOCUMENT_NODE, + }, + nodePath_defaultView: { + value: (e) => + Document.nodePath_isDocument(e) + ? Object.nodePath_get(e, Document, "defaultView") + : null, + }, + }), + Object.defineProperties(Element, { + nodePath_isElement: { + value: (e) => Node.nodePath_nodeType(e) === Node.ELEMENT_NODE, + }, + nodePath_tagName: { + value: (e) => + Element.nodePath_isElement(e) + ? Object.nodePath_get(e, Element, "tagName") + : null, + }, + nodePath_id: { + value: (e) => + Element.nodePath_isElement(e) + ? Object.nodePath_get(e, Element, "id") + : null, + }, + nodePath_className: { + value: (e) => + Element.nodePath_isElement(e) + ? Object.nodePath_get(e, Element, "className") + : null, + }, + nodePath_shadowRoot: { + value: (e) => + Element.nodePath_isElement(e) + ? Object.nodePath_get(e, Element, "shadowRoot") + : null, + }, + nodePath_querySelectorAll: { + value: (e, t) => + Element.nodePath_isElement(e) + ? Element.prototype.querySelectorAll.call(e, t) + : null, + }, + }), + Object.defineProperties(HTMLIFrameElement, { + nodePath_isHTMLIFrameElement: { + value: (e) => + Node.nodePath_nodeType(e) === Node.ELEMENT_NODE && + "HTMLIFrameElement" === Object.getPrototypeOf(e).constructor.name, + }, + nodePath_contentWindowDocument: { + value(e) { + if (!HTMLIFrameElement.nodePath_isHTMLIFrameElement(e)) + return null; + try { + return Object.nodePath_get( + e, + HTMLIFrameElement, + "contentWindow", + ).document; + } catch (e) { + return null; + } + }, + }, + }), + Object.defineProperties(Node, { + nodePath_nodeType: { + value: (e) => ( + WAS.Assert.isType(e, Node), + Object.nodePath_get(e, Node, "nodeType") + ), + }, + nodePath_firstChild: { + value: (e) => ( + WAS.Assert.isType(e, Node), + Object.nodePath_get(e, Node, "firstChild") + ), + }, + nodePath_nextSibling: { + value: (e) => ( + WAS.Assert.isType(e, Node), + Object.nodePath_get(e, Node, "nextSibling") + ), + }, + nodePath_previousSibling: { + value: (e) => ( + WAS.Assert.isType(e, Node), + Object.nodePath_get(e, Node, "previousSibling") + ), + }, + nodePath_childNodes: { + value: (e) => ( + WAS.Assert.isType(e, Node), + Object.nodePath_get(e, Node, "childNodes") + ), + }, + nodePath_textContent: { + value: (e) => ( + WAS.Assert.isType(e, Node), + Object.nodePath_get(e, Node, "textContent") + ), + }, + nodePath_cloneNode: { + value: (e, { shouldIncludeSubtree: t }) => ( + WAS.Assert.isType(e, Node), + Node.prototype.cloneNode.call(e, t) + ), + }, + nodePath_isEmptyTextNode: { + value: (e) => + Text.nodePath_isText(e) && + CharacterData.nodePath_data(e) + .nodePath_isEmptyExcludingWhitespace, + }, + nodePath_siblingIndexOfNode: { + value(e) { + let t = 0; + for ( + let n = Node.nodePath_previousSibling(e); + n; + n = Node.nodePath_previousSibling(n) + ) + Node.nodePath_includeWhenComputingSiblingIndex(n) && ++t; + return t; + }, + }, + nodePath_includeWhenComputingSiblingIndex: { + value: (e) => + !( + Node.nodePath_isEmptyTextNode(e) || + (Element.nodePath_isElement(e) && + "SCRIPT" === Element.nodePath_tagName(e).toUpperCase()) + ), + }, + nodePath_immediateSourceMarkupOfNode: { + value: (e) => + Node.nodePath_nodeType(e) === Node.DOCUMENT_FRAGMENT_NODE + ? null + : Node.nodePath_cloneNode(e, { shouldIncludeSubtree: !1 }) + .outerHTML, + }, + nodePath_immediateInnerTextOfNode: { + value(e) { + if (!Node.prototype.hasChildNodes.call(e)) + return Node.nodePath_textContent(e)?.trim(); + let t = ""; + for (let n of Node.nodePath_childNodes(e)) + Text.nodePath_isText(n) && + (t += CharacterData.nodePath_data(n)); + return t.trim(); + }, + }, + nodePath_getBoundingClientRect: { + value(e) { + if ((WAS.Assert.isType(e, Node, Range), e instanceof Range)) + return e.getBoundingClientRect(); + if (Text.nodePath_isText(e)) { + let t = new Range(); + return ( + t.setStart(e, 0), + t.setEnd(e, CharacterData.nodePath_data(e).length), + t.getBoundingClientRect() + ); + } + return Element.nodePath_isElement(e) + ? Element.prototype.getBoundingClientRect.call(e) + : null; + }, + }, + }), + Object.defineProperties(Object, { + nodePath_get: { + value: (e, t, n) => + Object.getOwnPropertyDescriptor(t.prototype, n)?.get?.call?.(e), + }, + }), + Object.defineProperties(Range, { + nodePath_fromNode: { + value(e) { + let t = new Range(); + return (t.selectNode(e), t); + }, + }, + nodePath_isSingleElementRange: { + value: (e) => + e.startContainer === e.endContainer && + !Text.nodePath_isText(e.commonAncestorContainer) && + 1 === Math.abs(e.endOffset - e.startOffset), + }, + nodePath_singleElementFromRange: { + value: (e) => + Range.nodePath_isSingleElementRange(e) + ? Node.nodePath_childNodes(e.commonAncestorContainer)[ + e.startOffset + ] + : null, + }, + nodePath_startNodeFromRange: { + value: (e) => + Text.nodePath_isText(e.startContainer) + ? null + : Node.nodePath_childNodes(e.startContainer)[e.startOffset], + }, + nodePath_endNodeFromRange: { + value: (e) => + Text.nodePath_isText(e.endContainer) + ? Node.nodePath_childNodes(e.endContainer)[e.endOffset - 1] + : null, + }, + }), + Object.defineProperties(Range.prototype, { + nodePath_equals: { + value(e) { + return ( + this.commonAncestorContainer === e.commonAncestorContainer && + 0 === this.compareBoundaryPoints(Range.START_TO_START, e) && + 0 === this.compareBoundaryPoints(Range.END_TO_END, e) + ); + }, + }, + }), + Object.defineProperties(ShadowRoot, { + nodePath_isShadowRoot: { + value: (e) => + Node.nodePath_nodeType(e) === Node.DOCUMENT_FRAGMENT_NODE && + "ShadowRoot" === Object.getPrototypeOf(e).constructor.name, + }, + nodePath_host: { + value: (e) => + ShadowRoot.nodePath_isShadowRoot(e) + ? Object.nodePath_get(e, ShadowRoot, "host") + : null, + }, + }), + Object.defineProperties(String, { + _nodePath_matchAnyNonWhitespaceRegex: { value: /\S/ }, + }), + Object.defineProperties(String.prototype, { + nodePath_isEmptyExcludingWhitespace: { + get() { + return ( + !this.length || + !String._nodePath_matchAnyNonWhitespaceRegex.test(this) + ); + }, + }, + nodePath_similarityTo: { + value(t) { + if (!t) return this.length ? 0 : 1; + let n = Math.max(this.length, t.length); + return n ? (n - e(this, t)) / n : 0; + }, + }, + }), + Object.defineProperties(Text, { + nodePath_isText: { + value: (e) => Node.nodePath_nodeType(e) === Node.TEXT_NODE, + }, + })); + } + static ObjectRepresentationCodableInfo = { classPath: "WAS.NodePath" }; + static #e = class { + #t; + #n; + #o; + #a; + #i; + #s; + #d; + #r; + constructor( + e, + t, + { + tag: n, + id: o, + classes: a, + text: i, + sourceMarkup: s, + boundingClientRect: d, + } = {}, + ) { + (WAS.Assert.isType(e, Number), + WAS.Assert.isType(t, Number), + WAS.Assert.optionalIsType(n, String), + WAS.Assert.optionalIsType(o, String), + WAS.Assert.optionalIsType(a, String), + WAS.Assert.optionalIsType(i, String), + WAS.Assert.optionalIsType(s, String), + WAS.Assert.optionalIsType(d, Object), + (this.#t = e), + (this.#n = t), + (this.#d = s), + (this.#r = d), + e === Node.ELEMENT_NODE + ? (WAS.Assert.isTrue(n, "Tag must be present for ELEMENT_NODEs"), + (this.#o = n), + (this.#a = o?.length ? o : void 0), + (this.#i = a?.length ? a : void 0), + (this.#s = i)) + : e === Node.TEXT_NODE && (this.#s = i)); + } + static fromNode(e) { + WAS.Assert.isType(e, Node); + let t = Node.nodePath_nodeType(e), + n = Node.nodePath_siblingIndexOfNode(e), + o = {}; + if (Element.nodePath_isElement(e)) { + ((o.tag = Element.nodePath_tagName(e)), + (o.id = Element.nodePath_id(e)), + (o.classes = Element.nodePath_className(e))); + let t = Node.nodePath_immediateInnerTextOfNode(e); + t.length && (o.text = t); + } else + Text.nodePath_isText(e) && (o.text = CharacterData.nodePath_data(e)); + o.sourceMarkup = Node.nodePath_immediateSourceMarkupOfNode(e); + let a = Node.nodePath_getBoundingClientRect(e); + return ( + a && + (o.boundingClientRect = { + x: a.x, + y: a.y, + width: a.width, + height: a.height, + }), + new WAS.NodePath.#e(t, n, o) + ); + } + static fromObjectRepresentation(e) { + return ( + WAS.Assert.isType(e, Object), + new WAS.NodePath.#e(e.type, e.index, e) + ); + } + get objectRepresentation() { + return { + type: this.#t, + index: this.#n, + tag: this.#o, + id: this.#a, + classes: this.#i, + text: this.#s, + sourceMarkup: this.#d, + boundingClientRect: this.#r, + }; + } + get type() { + return this.#t; + } + get index() { + return this.#n; + } + get tag() { + return this.#o; + } + get id() { + return this.#a; + } + get classes() { + return this.#i; + } + get text() { + return this.#s; + } + toElementCSSSelector() { + if (this.type !== Node.ELEMENT_NODE) return null; + let e = CSS.escape(this.tag); + this.id && (e += `#${CSS.escape(this.id)}`); + for (let t of this.classes?.split(" ") ?? []) + t.length && (e += `.${CSS.escape(t)}`); + return e; + } + toString() { + return JSON.stringify(this.objectRepresentation); + } + equals(e) { + return ( + WAS.Assert.optionalIsType(e, WAS.NodePath.#e), + !!e && + this.#t === e.#t && + this.#n === e.#n && + this.#o === e.#o && + this.#a === e.#a && + this.#i === e.#i && + this.#s === e.#s + ); + } + }; + static #h = 1e3; + static #l = 500; + static #c = 200; + static #m = 200; + static #N = 100; + static #p = 10; + #u; + #C; + #_; + #P; + #A; + #f; + constructor( + e, + { + startContainerAdditionalComponents: t, + startContainerOffset: n, + endContainerAdditionalComponents: o, + endContainerOffset: a, + } = {}, + ) { + (WAS.Assert.arrayContentIsType(e, WAS.NodePath.#e), + WAS.Assert.isTrue( + e[0]?.type == Node.DOCUMENT_NODE, + "First path component should always be a document node.", + ), + (this.#u = e), + (this.#_ = t), + (this.#P = n), + (this.#A = o), + (this.#f = a)); + } + static #g(e, t) { + WAS.Assert.isType(e, Node); + let n = [], + o = e, + a = 0; + for (; o && (++a, !(a > 512)); ) { + let e; + for ( + ; + o && (n.push(WAS.NodePath.#e.fromNode(o)), (e = o), o !== t); + o = o.parentNode + ); + if (e === t) break; + let a = Document.nodePath_defaultView(e); + if (a) { + o = a.frameElement; + continue; + } + let i = ShadowRoot.nodePath_host(e); + i && (o = i); + } + return n.toReversed(); + } + static from(e, t) { + return e instanceof Range + ? WAS.NodePath.fromRange(e, t) + : WAS.NodePath.fromNode(e, t); + } + static fromNode(e, t) { + let n = new WAS.NodePath(WAS.NodePath.#g(e, t)); + return ((n.#C = new WeakRef(Range.nodePath_fromNode(e))), n); + } + static fromRange(e, t) { + let n = Range.nodePath_singleElementFromRange(e); + if (n) return WAS.NodePath.fromNode(n, t); + let o, + a, + i, + s, + d = WAS.NodePath.#g(e.commonAncestorContainer, t), + r = Range.nodePath_startNodeFromRange(e); + r + ? (o = WAS.NodePath.#g(r, e.commonAncestorContainer).toSpliced(0, 1)) + : e.startContainer !== e.commonAncestorContainer + ? ((o = WAS.NodePath.#g( + e.startContainer, + e.commonAncestorContainer, + ).toSpliced(0, 1)), + (a = e.startOffset)) + : (o = []); + let h = Range.nodePath_endNodeFromRange(e); + h + ? (i = WAS.NodePath.#g(h, e.commonAncestorContainer).toSpliced(0, 1)) + : e.endContainer !== e.commonAncestorContainer + ? ((i = WAS.NodePath.#g( + e.endContainer, + e.commonAncestorContainer, + ).toSpliced(0, 1)), + (s = e.endOffset)) + : (i = []); + let l = new WAS.NodePath(d, { + startContainerAdditionalComponents: o, + startContainerOffset: a, + endContainerAdditionalComponents: i, + endContainerOffset: s, + }); + return ((l.#C = new WeakRef(e)), l); + } + static fromObjectRepresentation(e) { + const t = (e) => ( + WAS.Assert.isType(e, Array), + e.map((e) => WAS.NodePath.#e.fromObjectRepresentation(e)) + ); + return Array.isArray(e) + ? new WAS.NodePath(t(e)) + : (WAS.Assert.isType(e, Object), + new WAS.NodePath(t(e.pathComponents), { + startContainerAdditionalComponents: + e.startContainerAdditionalComponents + ? t(e.startContainerAdditionalComponents) + : void 0, + startContainerOffset: e.startContainerOffset ?? void 0, + endContainerAdditionalComponents: e.endContainerAdditionalComponents + ? t(e.endContainerAdditionalComponents) + : void 0, + endContainerOffset: e.endContainerOffset ?? void 0, + })); + } + get objectRepresentation() { + const e = (e) => ( + WAS.Assert.isType(e, Array), + e.map((e) => e.objectRepresentation) + ); + return { + pathComponents: e(this.#u), + startContainerAdditionalComponents: this.#_ ? e(this.#_) : void 0, + startContainerOffset: this.#P, + endContainerAdditionalComponents: this.#A ? e(this.#A) : void 0, + endContainerOffset: this.#f, + }; + } + static nodePathIsKnownFormControlInputElement(e) { + let t = e?.pathComponents.at(-1)?.tag?.toUpperCase(); + switch (t) { + case "INPUT": + case "SELECT": + case "TEXTAREA": + return !0; + default: + return !1; + } + } + get pathComponents() { + return this.#u; + } + get userFriendlySummary() { + let e = this.#u.at(-1); + return e.type === Node.TEXT_NODE + ? e.text.trim() + : e.text + ? `${e.tag.toLowerCase()}: "${e.text.trim()}"` + : e.tag.toLowerCase(); + } + toString() { + return JSON.stringify(this.objectRepresentation); + } + equals(e) { + if ((WAS.Assert.optionalIsType(e, WAS.NodePath), !e)) return !1; + if (this.#u.length !== e.#u.length) return !1; + for (let t = 0; t < this.#u.length; ++t) + if (!this.#u[t].equals(e.#u[t])) return !1; + if (this.#_?.length !== e.#_?.length) return !1; + for (let t = 0; t < this.#_?.length; ++t) + if (!this.#_[t].equals(e.#_[t])) return !1; + if (this.#A?.length !== e.#A?.length) return !1; + for (let t = 0; t < this.#A?.length; ++t) + if (!this.#A[t].equals(e.#A[t])) return !1; + return this.#P === e.#P && this.#f === e.#f; + } + resolvedRangeInDocument(e) { + let t = this.#C?.deref(); + if (t?.intersectsNode(e)) return t; + if (this.#_ && this.#A) { + let t = WAS.NodePath.#E(e, [...this.#u, ...this.#_]), + n = WAS.NodePath.#E(e, [...this.#u, ...this.#A]); + if (!t || !n) return null; + let o = new Range(); + return ( + this.#P ? o.setStart(t, this.#P) : o.setStartBefore(t), + this.#f ? o.setEnd(n, this.#f) : o.setEndAfter(n), + (this.#C = new WeakRef(o)), + o + ); + } + let n = WAS.NodePath.#E(e, this.#u); + if (!n) return null; + let o = Range.nodePath_fromNode(n); + return ((this.#C = new WeakRef(o)), o); + } + static #E(e, t) { + (WAS.Assert.isType(e, Node), + WAS.Assert.isTrue( + Document.nodePath_isDocument(e), + "Must provide root document node in which to resolve this NodePath.", + )); + let n = e; + e: for (let e = 1; e < t.length && n; ++e) { + let o = t[e], + a = -1, + i = null; + const s = () => { + n = i; + let o = t.length > e ? t[e + 1] : null; + return n && + HTMLIFrameElement.nodePath_isHTMLIFrameElement(n) && + o?.type === Node.DOCUMENT_NODE + ? (++e, + void (n = HTMLIFrameElement.nodePath_contentWindowDocument(n))) + : n && o?.type === Node.DOCUMENT_FRAGMENT_NODE + ? (++e, void (n = Element.nodePath_shadowRoot(n))) + : void 0; + }; + if (Element.nodePath_isElement(n)) { + let o = [], + a = e; + for (; a < t.length; ++a) { + let e = t[a]; + if (e.type !== Node.ELEMENT_NODE) break; + o.push(e.toElementCSSSelector()); + } + if (o.length) { + const t = (e) => o.slice(0, o.length - e).join(" > "); + let d = null; + for (let r = 0; r < o.length; ++r) + if ( + ((d = Element.nodePath_querySelectorAll(n, t(r))), + 1 === d.length) + ) { + ((i = d.item(0)), (e = a - r - 1), s()); + continue e; + } + } + } + let d = 0; + for ( + let e = Node.nodePath_firstChild(n); + e; + e = Node.nodePath_nextSibling(e) + ) { + if (!Node.nodePath_includeWhenComputingSiblingIndex(e)) continue; + let t = Number.MIN_VALUE, + n = !0; + const s = (e, o) => { + e ? (t += o) : (n = !1); + }, + r = (e, o) => { + (1 !== e && (n = !1), (t += e * o)); + }, + h = (e) => { + e && ((n = !1), (t -= e)); + }; + if ( + (s(Node.nodePath_nodeType(e) === o.type, WAS.NodePath.#h), + Element.nodePath_isElement(e)) + ) { + (s(Element.nodePath_tagName(e) == o.tag, WAS.NodePath.#l), + s(Element.nodePath_id(e) == o.id, WAS.NodePath.#c)); + let t = Element.nodePath_className(e)?.split(" ") ?? [], + n = t.length, + a = o.classes?.split(" ") ?? [], + i = a.length; + for (let e = 0; e < a.length; ++e) { + let n = a[e], + o = t.indexOf(n); + -1 !== o && (t.splice(o, 1), a.splice(e, 1), --e); + } + (r( + (n ? (n - t.length) / n : 1) * (i ? (i - a.length) / i : 1), + WAS.NodePath.#N, + ), + r( + Node.nodePath_immediateInnerTextOfNode(e).nodePath_similarityTo( + o.text, + ), + WAS.NodePath.#m, + )); + } else if (Text.nodePath_isText(e)) { + let t = CharacterData.nodePath_data(e)?.nodePath_similarityTo( + o.text, + ); + r(t, WAS.NodePath.#m); + } + if ((h(Math.abs(d - o.index) * WAS.NodePath.#p), n)) { + ((a = Number.NaN), (i = e)); + break; + } + t > a ? ((a = t), (i = e)) : t === a && ++d; + } + s(); + } + return n; + } + })); diff --git a/js/utilities/SavePageInliningOrDiscardingExternalResources.js b/js/utilities/SavePageInliningOrDiscardingExternalResources.js new file mode 100644 index 0000000..23bca4b --- /dev/null +++ b/js/utilities/SavePageInliningOrDiscardingExternalResources.js @@ -0,0 +1,145 @@ +//# sourceURL=__InjectedScript_SavePageInliningOrDiscardingExternalResources.js +/* Copyright (c) 2025 Apple Inc. All rights reserved. */ +function copyPage() { + function e(e) { + function t(e) { + var t = document.createElement("a"); + return ((t.href = e), t); + } + function r(e) { + var t = e.pathname.substring(1).split("/"); + return (t[t.length - 1] || t.pop(), t); + } + function n(e) { + var t = r(e); + return t.length ? t[t.length - 1] : null; + } + return n(t(e)); + } + function t(t) { + const r = /url\((.*?\/.*?)\)/gi; + for (;;) { + var n = r.exec(t); + if (!n) break; + t = t.replace(n[0], "url(" + e(n[1]) + ")"); + } + return t; + } + function r(e) { + function r(e, n) { + if (e) { + var i, o; + try { + i = e.rules; + } catch (e) { + i = null; + } + if (!i) { + var u = e.ownerNode; + if (!u) return; + var c = u.parentNode; + if (!c) return; + var l = u.nextSibling; + return (c.removeChild(u), r(e, n), void c.insertBefore(u, l)); + } + for (var d = i.length, s = 0; s < d; ++s) { + var m = i[s]; + m.type !== CSSRule.IMPORT_RULE + ? (o || + ((o = document.createElement("style")), + e.media && + e.media.length > 0 && + o.setAttribute("media", e.media.mediaText), + n && n.media && o.setAttribute("media", n.media.mediaText), + a.push(o)), + o.appendChild(document.createTextNode(t(m.cssText) + "\n"))) + : r(m.styleSheet, m); + } + } + } + for (var n = e.styleSheets, a = [], i = n.length, o = 0; o < i; ++o) + r(n[o]); + return a; + } + function n(e, r) { + for (var n = e.attributes, a = n.length, i = 0; i < a; ++i) { + var o = n[i], + u = o.name.toLowerCase(); + if ("on" !== u.substr(0, 2)) { + var c = o.value; + "style" === u && (c = t(c)); + try { + r.setAttribute(o.name, c); + } catch (e) {} + } + } + } + function a(e, t) { + for (var r = e.childNodes, n = r.length, a = 0; a < n; ++a) { + var o = i(r[a]); + o && t.appendChild(o); + } + } + function i(t) { + if (!t) return t; + if (t.nodeType === Node.TEXT_NODE) return document.createTextNode(t.data); + if (t.nodeType !== Node.ELEMENT_NODE) return null; + const c = new Set(["AUDIO", "OBJECT", "SCRIPT", "STYLE", "VIDEO"]); + var l = t.tagName.toUpperCase(); + if (c.has(l)) return null; + if ("LINK" === l && "STYLESHEET" === t.rel.toUpperCase()) return null; + if ("META" === l && "CONTENT-TYPE" === t.httpEquiv.toUpperCase()) + return null; + var d = document.createElement(t.tagName); + if ( + (n(t, d), + a(t, d), + "IMG" === l || ("INPUT" === l && "IMAGE" === t.type.toUpperCase())) + ) + return ( + (d.src = e(t.src)), + d.setAttribute("width", t.width), + d.setAttribute("height", t.height), + d + ); + if ("IFRAME" === l) { + try { + var s = i(t.contentDocument.documentElement); + if (s) { + var m = "iframe_" + u + ".html"; + ((d.src = m), + (s.dataset.originalSource = t.src), + (o[m] = s.outerHTML), + u++); + } + } catch (e) { + ((d.src = ""), + d.appendChild( + document.createTextNode( + "Failed to copy