forgejo instance support + auto-escape double quotes in the note field just to prevent any bugs

This commit is contained in:
Kebo 2025-06-22 21:27:28 -05:00
parent 16f506b0f5
commit d316dfd01e
3 changed files with 14 additions and 2 deletions

View file

@ -17,6 +17,8 @@ moffsoft icon to indicate that additional autofill is available.
- 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.
- 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.
## Wait, what is this even for?

View file

@ -42,6 +42,13 @@ function parsePage() {
entry.author = document.querySelector('a[rel="author"]').textContent.slice(9);
}
// forgejo meta elements
const forgejoIdentElem = document.querySelector('meta[name="keywords"]');
if (forgejoIdentElem && forgejoIdentElem.content.includes('forgejo')) {
entry.title = document.querySelector('meta[name="description"]').content;
entry.author = document.querySelector('meta[name="author"]').content;
}
return entry;
}
@ -87,6 +94,8 @@ function generateJSON(event) {
const errorElem = document.getElementById('error');
const JSONElem = document.getElementById('generated');
const fixedNote = noteField.value.replace('"', '\\"');
// first, make sure all of our required fields are in place
if ((urlField.value == null || urlField.value == "") ||
(titleField.value == null || titleField.value == "") ||
@ -103,7 +112,7 @@ function generateJSON(event) {
"author": "${authorField.value}",
"publishedDate": "${publishedDateField.value.replace('T', ' ')}",
"accessedDate": "${accessedDateField.value.replace('T', ' ')}",
"note": "${noteField.value}"\n},`
"note": "${fixedNote}"\n},`
}
window.addEventListener('DOMContentLoaded', () => {

View file

@ -6,7 +6,8 @@ chrome.tabs.onActivated.addListener((activeInfo) => {
const supportedUrls = [
'medium.com',
'youtube.com',
'github.com'
'github.com',
'git.eleboog.com',
];
let supportedSite = false;