blob: 545fa6d6e4276430c4bc1249e678474870ce604f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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());
}
});
|