summaryrefslogtreecommitdiffstats
path: root/content.js
diff options
context:
space:
mode:
Diffstat (limited to 'content.js')
-rw-r--r--content.js23
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());
+ }
+});