-
Notifications
You must be signed in to change notification settings - Fork 0
/
content.js
37 lines (34 loc) · 912 Bytes
/
content.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
chrome.runtime.sendMessage({
from: "content",
subject: "showPageAction",
});
async function getAltTags() {
var imgElms = document.querySelectorAll("img");
var imgGroup = [];
imgElms.forEach((el) => {
if (el.alt.length > 0 && el.attributes.src != null) {
let item = {
alt: el.attributes.alt.value,
src:
el.attributes.src.value[0] == "/"
? `${window.location.origin}${el.attributes.src.value}`
: el.attributes.src.value,
};
imgGroup.push(item);
}
});
return imgGroup;
}
chrome.runtime.onMessage.addListener(async function (
request,
sender,
sendResponse
) {
// console.log(
// sender.tab
// ? "from a content script:" + sender.tab.url
// : "from the extension: " + request.greeting
// );
let tags = await getAltTags();
if (request.greeting === "hello") sendResponse({ farewell: tags });
});