att. to fix chrome extension?
build Details
--> Linted: DOCKERFILE_HADOLINT No errors were found in the linting process Details
--> Linted: EDITORCONFIG No errors were found in the linting process Details
--> Linted: GITHUB_ACTIONS No errors were found in the linting process Details
--> Linted: GITLEAKS No errors were found in the linting process Details
--> Linted: JSON No errors were found in the linting process Details
--> Linted: YAML No errors were found in the linting process Details
lint Details

This commit is contained in:
Chase 2023-08-22 15:34:47 -05:00
parent b381fcd4fe
commit 2de9c49897
Signed by: chase
GPG Key ID: 9EC29E797878008C
4 changed files with 97 additions and 1 deletions

View File

@ -2,7 +2,8 @@
"env": {
"es2021": true,
"node": true,
"browser": true
"browser": true,
"webextensions": true
},
"extends": [
"chase"

View File

@ -0,0 +1,81 @@
/* eslint-disable no-unused-vars */
const redditUrls = [
`https://www.reddit.com/`,
`https://old.reddit.com/`,
`https://reddit.com/`,
];
const hackerNewsUrls = [
`https://news.ycombinator.com/`,
`https://hn.algolia.com/`,
];
const allMonitoredUrls = [
...redditUrls,
...hackerNewsUrls,
];
chrome.tabs.onUpdated.addListener(async (tabId, changeInfo, tab) =>
{
const { lifeapiApikey } = await chrome.storage.sync.get([`lifeapiApikey`]);
if (!lifeapiApikey) throw new Error(`No API Key set! Try: chrome.storage.sync.set({ lifeapiApikey: 'asdf' })`);
if (changeInfo.status !== `complete`)
return;
try
{
if (redditUrls.some((url) => tab.url.startsWith(url)))
{
console.log(`Setting Activity to: Reading Reddit`);
await fetch(`https://life-api.chse.dev/manual?apikey=${ lifeapiApikey }&message=${ encodeURIComponent(`Reading: Reddit`) }`, {
method: `POST`,
});
}
if (hackerNewsUrls.some((url) => tab.url.startsWith(url)))
{
console.log(`Setting Activity to: Reading Hacker News`);
await fetch(`https://life-api.chse.dev/manual?apikey=${ lifeapiApikey }&message=${ encodeURIComponent(`Reading: Hacker News`) }`, {
method: `POST`,
});
}
}
catch
{
// Do Nothing
}
});
chrome.tabs.onRemoved.addListener(async (tabId, removeInfo) =>
{
const { lifeapiApikey } = await chrome.storage.sync.get([`lifeapiApikey`]);
if (!lifeapiApikey) throw new Error(`No API Key set! Try: chrome.storage.sync.set({ lifeapiApikey: 'asdf' })`);
// Fetch the URL of the closed tab
chrome.tabs.get(tabId, async (tab) =>
{
if (chrome.runtime.lastError || !tab)
{
console.error(`Error getting closed tab:`, chrome.runtime.lastError);
return;
}
try
{
// if the page we just closed was one we are monitoring, then clear status.
if (allMonitoredUrls.some((url) => tab.url.startsWith(url)))
{
console.log(`Clearing Activity as we just closed: ${ tab.url }`);
await fetch(`https://life-api.chse.dev/manual/clear?apikey=${ lifeapiApikey }`, {
method: `POST`,
});
}
}
catch
{
// Do Nothing
}
});
});

View File

@ -0,0 +1,13 @@
{
"name": "lifeapi",
"version": "1.0",
"description": "Helpful tools for the Life API Project.",
"manifest_version": 3,
"permissions": [
"tabs",
"storage"
],
"background": {
"service_worker": "background.js"
}
}

View File

@ -22,6 +22,7 @@ app.use(helmet({
"script-src": [`'self'`, `blob:`, `https://*.chse.dev`],
"default-src": [`'self'`, `blob:`, `https://*.chse.dev`],
},
crossOriginEmbedderPolicy: false,
},
})); // Apply helmet to all requests
const limiter = rateLimit({