-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontentScript.js
42 lines (35 loc) · 1.06 KB
/
contentScript.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
38
39
40
41
42
const getMemeImage = async () => {
const res = await fetch("https://meme-api.com/gimme/wholesomememes");
const data = await res?.json();
return data;
};
chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
if (message?.type === "meme") {
const images = document.querySelectorAll("img");
if (images?.length > 0) {
for (let image of images) {
getMemeImage().then((data) => {
image.removeAttribute("srcset");
image.removeAttribute("data-src");
image.src = data?.url;
});
}
}
}
if (message?.type === "delete") {
const body = document.querySelector("body");
if (body) {
body.innerHTML = "";
}
body.style.display = "flex";
body.style.height = "100vh";
body.style.width = "100vw";
body.style.alignItems = "center";
body.style.justifyContent = "center";
const meme = document.createElement("img");
meme.src = "https://i.imgflip.com/74pyv1.jpg";
meme.style.height = "80vh";
meme.style.width = "80vw";
body.append(meme);
}
});