diff options
| author | Leonardo Bishop <me@leonardobishop.net> | 2025-09-17 20:14:09 +0100 |
|---|---|---|
| committer | Leonardo Bishop <me@leonardobishop.net> | 2025-09-17 20:14:09 +0100 |
| commit | 61e27eef33da20a9f174d2debee151cb8b100389 (patch) | |
| tree | 454fcbe8fdac7c9e306a7df3c7bcaa907eb5a65f /content.js | |
Initial commit
Diffstat (limited to 'content.js')
| -rw-r--r-- | content.js | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/content.js b/content.js new file mode 100644 index 0000000..545fa6d --- /dev/null +++ b/content.js @@ -0,0 +1,23 @@ +function getMetaValue(propName) { + const meta = Array.from(document.getElementsByTagName("meta")).find( + (meta) => + meta.getAttribute("property") === propName || + meta.getAttribute("name") === propName + ); + return meta ? meta.getAttribute("content") : undefined; +} + +function extractMetadata() { + const title = document.title; + const url = window.location.href; + const description = + getMetaValue("og:description") || getMetaValue("description"); + + return { title, url, description }; +} + +browser.runtime.onMessage.addListener(function (request, sender, sendResponse) { + if (request.action === "getMetadata") { + sendResponse(extractMetadata()); + } +}); |
