fixing youtube because apparently my life is pain

This commit is contained in:
Kebo 2025-06-23 11:04:22 -05:00
parent d316dfd01e
commit 4e8103b692
2 changed files with 11 additions and 5 deletions

View file

@ -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.

View file

@ -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;
}
}