From 4e8103b69299a8357c7ce1b60dfca5995c2b8778 Mon Sep 17 00:00:00 2001 From: Kebo Date: Mon, 23 Jun 2025 11:04:22 -0500 Subject: [PATCH] fixing youtube because apparently my life is pain --- README.md | 2 +- popup.js | 14 ++++++++++---- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index b4afe7f..7434cf3 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ moffsoft icon to indicate that additional autofill is available. - GitHub: Title and author fields are autofilled from scraping the page. - Medium: Title, author, and date published fields are autofilled from the handy [`NewsArticle` JSON-LD schema](https://schema.org/NewsArticle) included on every page. -- Youtube: Title, author, and date published fields are autofilled from the `watch7-content` metadata. +- Youtube: Title, author, and date published fields are autofilled from either the `watch7-content` metadata or the [`VideoObject` JSON-LD schema](https://schema.org/VideoObject). - Forgejo instances (except codeberg for now ;3;): Title and author fields are autofilled from metadata. Currently, only `git.eleboog.com` triggers the supported site badge, but other Forgejo instances should work too. diff --git a/popup.js b/popup.js index 37634e8..5a51c7f 100644 --- a/popup.js +++ b/popup.js @@ -11,14 +11,20 @@ function parsePage() { entry.url = entry.url.replace('https://freedium.cfd/', ''); } - // if schema.org NewsArticle JSON-LD is present, read that data + // if schema.org JSON-LD is present, read that data const jsonLDElem = document.querySelector('script[type="application/ld+json"]'); if (jsonLDElem) { const jsonLDObj = JSON.parse(jsonLDElem.textContent); - if (jsonLDObj['@type'] == 'NewsArticle') { + if (jsonLDObj['@type'] == 'NewsArticle') { // medium, etc. entry.publishedDate = jsonLDObj.datePublished?.slice(0, 19); - entry.author = jsonLDObj.author?.name - entry.title = jsonLDObj.headline + entry.author = jsonLDObj.author?.name; + entry.title = jsonLDObj.headline; + } + if (jsonLDObj['@type'] == 'VideoObject') { // youtube, etc. + entry.url = jsonLDObj['@id']; // url fix + entry.publishedDate = jsonLDObj.uploadDate?.slice(0, 19); + entry.author = jsonLDObj.author; + entry.title = jsonLDObj.name; } }