feat: youtube + github support & logo gets excited when you're on a supported autofill site
This commit is contained in:
parent
b2a71cebda
commit
16f506b0f5
4 changed files with 66 additions and 7 deletions
|
@ -10,10 +10,13 @@ This is just a tool I made for myself, but if you want to use it for your own im
|
|||
## Supported Sites
|
||||
|
||||
You can technically use this extension on *any* site, as it will always automatically fill in the URL and date accessed fields for you.
|
||||
However, I've built in additional autofill support for certain websites.
|
||||
However, I've built in additional autofill support for certain websites. When you visit one of these sites, a badge will appear on the
|
||||
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.
|
||||
|
||||
## Wait, what is this even for?
|
||||
|
||||
|
|
|
@ -1,13 +1,17 @@
|
|||
{
|
||||
"name": "Sharefeed Entry Tool",
|
||||
"description": "Creates a sharefeed entry based on the current webpage.",
|
||||
"version": "1.0",
|
||||
"version": "1.1",
|
||||
"manifest_version": 3,
|
||||
"action": {
|
||||
"default_icon": "moffsoft_64.png",
|
||||
"default_popup": "popup.html"
|
||||
},
|
||||
"background": {
|
||||
"service_worker": "service-worker.js"
|
||||
},
|
||||
"permissions": [
|
||||
"tabs",
|
||||
"activeTab",
|
||||
"scripting"
|
||||
]
|
||||
|
|
31
popup.js
31
popup.js
|
@ -2,7 +2,8 @@ function parsePage() {
|
|||
let entry = {
|
||||
url: window.location.href,
|
||||
title: "",
|
||||
publishedDate: ""
|
||||
publishedDate: "",
|
||||
author: "",
|
||||
};
|
||||
|
||||
// fix the URL's of certain websites
|
||||
|
@ -10,17 +11,37 @@ function parsePage() {
|
|||
entry.url = entry.url.replace('https://freedium.cfd/', '');
|
||||
}
|
||||
|
||||
// if schema.org JSON-LD is present, read that data
|
||||
// if schema.org NewsArticle 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') {
|
||||
entry.publishedDate = jsonLDObj.datePublished?.slice(0, 19) ?? "";
|
||||
entry.author = jsonLDObj.author?.name ?? ""
|
||||
entry.title = jsonLDObj.headline ?? ""
|
||||
entry.publishedDate = jsonLDObj.datePublished?.slice(0, 19);
|
||||
entry.author = jsonLDObj.author?.name
|
||||
entry.title = jsonLDObj.headline
|
||||
}
|
||||
}
|
||||
|
||||
// youtube specific data section
|
||||
const youtubeMetaElem = document.getElementById('watch7-content');
|
||||
if (youtubeMetaElem) {
|
||||
// url fix
|
||||
entry.url = document.querySelector('link[itemprop="url"]').getAttribute('href');
|
||||
entry.title = document.querySelector('meta[itemprop="name"]').getAttribute('content');
|
||||
entry.author = document.querySelector('span[itemprop="author"] link[itemprop="name"]').getAttribute('content');
|
||||
entry.publishedDate = document.querySelector('meta[itemprop="datePublished"]').getAttribute('content').slice(0, 19);
|
||||
}
|
||||
|
||||
// github scraping
|
||||
const githubIdentElem = document.getElementById('repository-container-header');
|
||||
if (githubIdentElem) {
|
||||
githubRepoName = document.querySelector('strong[itemprop="name"] a').textContent;
|
||||
githubRepoDesc = document.querySelector('div#responsive-meta-container div p').textContent;
|
||||
|
||||
entry.title = githubRepoName + ' - ' + githubRepoDesc.slice(9, -6);
|
||||
entry.author = document.querySelector('a[rel="author"]').textContent.slice(9);
|
||||
}
|
||||
|
||||
return entry;
|
||||
}
|
||||
|
||||
|
|
31
service-worker.js
Normal file
31
service-worker.js
Normal file
|
@ -0,0 +1,31 @@
|
|||
chrome.tabs.onActivated.addListener((activeInfo) => {
|
||||
chrome.tabs.query({
|
||||
active: true,
|
||||
currentWindow: true
|
||||
}, tabs => {
|
||||
const supportedUrls = [
|
||||
'medium.com',
|
||||
'youtube.com',
|
||||
'github.com'
|
||||
];
|
||||
|
||||
let supportedSite = false;
|
||||
|
||||
for (const i in supportedUrls) {
|
||||
//console.log(supportedUrls[i]);
|
||||
const pattern = new URLPattern({ hostname: `{*.}?${supportedUrls[i]}` });
|
||||
console.log(tabs[0].url);
|
||||
supportedSite = pattern.test(tabs[0].url);
|
||||
if (supportedSite) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (supportedSite) {
|
||||
chrome.action.setBadgeText({text: ':o'});
|
||||
chrome.action.setBadgeBackgroundColor({color: "#8F8"});
|
||||
} else {
|
||||
chrome.action.setBadgeText({});
|
||||
}
|
||||
});
|
||||
});
|
Loading…
Add table
Reference in a new issue