-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathcontent.js
67 lines (55 loc) · 1.68 KB
/
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
const spinnerStyles = `
@keyframes spin {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}
.spinner {
border: 16px solid #f3f3f3;
border-top: 16px solid #3498db;
border-radius: 50%;
width: 50px;
height: 50px;
animation: spin 2s linear infinite;
}
`;
const styleSheet = document.createElement("style");
styleSheet.type = "text/css";
styleSheet.innerText = spinnerStyles;
document.head.appendChild(styleSheet);
const anchors = document.querySelectorAll("a > img");
anchors.forEach((img) => {
img.parentElement.addEventListener("click", function (e) {
e.preventDefault();
const modal = document.createElement("div");
modal.style.position = "fixed";
modal.style.top = "0";
modal.style.left = "0";
modal.style.width = "100%";
modal.style.height = "100%";
modal.style.backgroundColor = "rgba(0, 0, 0, 0.7)";
modal.style.display = "flex";
modal.style.justifyContent = "center";
modal.style.alignItems = "center";
modal.style.zIndex = "9999";
const spinner = document.createElement("div");
spinner.className = "spinner";
modal.appendChild(spinner);
const largeImage = new Image();
largeImage.onload = function () {
// Hide spinner when image loads
spinner.style.display = "none";
};
let imgUrl = img.src;
if (imgUrl.endsWith("!s")) {
imgUrl = imgUrl.substring(0, imgUrl.length - 2);
}
largeImage.src = imgUrl;
largeImage.style.maxWidth = "90%";
largeImage.style.maxHeight = "90%";
modal.appendChild(largeImage);
modal.addEventListener("click", function () {
document.body.removeChild(modal);
});
document.body.appendChild(modal);
});
});