mirror of
https://github.com/XFox111/TabsAsideExtension.git
synced 2026-04-22 07:58:01 +03:00
e21022d985
* Some features are now optional (#148) * fix(dev): yarn.lock tree fix * feat: bookmarks moved to optional permissions * fix: analytics not working in firefox * feat!: ability to turn off analytics (uses permissions on firefox) * feat: analytics tracker for bookmark export * feat: add privacy policy link in about section * docs: privacy policy update * feat: ability to chain multiple dialogs * fix(loc): analytics option translation * feat: settings review dialog * fix: background script fails to load because of frontend code * chore: use analytics permission as storage value * fix: inverted analytics value * feat!: option to disable thumbnail capture * fix(ci): sed typo * fix: minor fixes * fix(firefox): web-ext lint error fix * chore(ci): switch web-ext action * chore(lint): fix eslint warnings * chore(deps): monthly dependency bump (September 2025) (#149) * chore: 3.1.0 version bump * chore: minor cleanup * fix: allow analytics checkbox stays inactive after denying permission on firefox * fix(deps): yarn.lock rebuild * fix: type assertion for userId * fix: settings review dialog not showing if welcome dialog is not required * fix: analytics and thumbnail capture toggles react incorrectly if permission is denied
43 lines
1.5 KiB
TypeScript
43 lines
1.5 KiB
TypeScript
import getLogger from "@/utils/getLogger";
|
|
import { sendMessage } from "@/utils/messaging";
|
|
|
|
// This content script is injected into each browser tab.
|
|
// It's purpose is to retrive an OpenGraph thumbnail URL from the metadata
|
|
|
|
export default defineUnlistedScript({ main });
|
|
|
|
const logger = getLogger("contentScript");
|
|
|
|
async function main(): Promise<void>
|
|
{
|
|
logger("init");
|
|
|
|
// This method tries to sequentially retrieve thumbnails from all know meta tags.
|
|
// It stops on the first thumbnail found.
|
|
|
|
// The order of search is:
|
|
// 1. <meta property="og:image" content="https://example.com/image.jpg">
|
|
// 2. <meta name="twitter:image" content="https://example.com/image.jpg">
|
|
// 3. <link rel="thumbnail" href="https://example.com/thumbnail.jpg">
|
|
// 4. <link rel="image_src" href="https://example.com/image.jpg">
|
|
|
|
const thumbnailUrl: string | undefined =
|
|
document.querySelector<HTMLMetaElement>("head meta[property='og:image']")?.content ??
|
|
document.querySelector<HTMLMetaElement>("head meta[name='twitter:image']")?.content ??
|
|
document.querySelector<HTMLLinkElement>("head link[rel=thumbnail]")?.href ??
|
|
document.querySelector<HTMLLinkElement>("head link[rel=image_src]")?.href;
|
|
|
|
if (thumbnailUrl)
|
|
{
|
|
logger(`Found thumbnail for "${document.location.href}"`, thumbnailUrl);
|
|
await sendMessage("addThumbnail", {
|
|
url: document.location.href,
|
|
thumbnail: thumbnailUrl
|
|
});
|
|
}
|
|
else
|
|
logger(`No thumbnail found for "${document.location.href}"`);
|
|
|
|
logger("done");
|
|
}
|