Skip to content

Commit 2816446

Browse files
author
hoang.tran12
committed
show image on hover link
1 parent 46acf78 commit 2816446

File tree

3 files changed

+139
-0
lines changed

3 files changed

+139
-0
lines changed

popup/tabs.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -551,6 +551,7 @@ const tabs = [
551551
s.smoothScroll,
552552
s.magnify_image,
553553
s.auto_redirectLargestImageSrc,
554+
s.showImageOnHoverLink,
554555
s.remove_tracking_in_url,
555556
s.prevent_closeBrowser_lastTab,
556557
s.chongLuaDao,
@@ -884,6 +885,22 @@ const tabs = [
884885
),
885886
},
886887
},
888+
{
889+
id: "recommend_cssloaders",
890+
icon: "https://css-loaders.com/fav.png",
891+
name: {
892+
en: "CSS Loaders - 600+ css loader",
893+
vi: "CSS Loaders - 600+ css loading",
894+
},
895+
description: {
896+
en: "The Biggest Collection of Loading Animations. Over 600+ CSS-only loaders made using a single element",
897+
vi: "Hơn 600 animation loading css miễn phí",
898+
},
899+
badges: [BADGES.recommend],
900+
popupScript: {
901+
onClick: () => window.open("https://css-loaders.com/"),
902+
},
903+
},
887904
{
888905
id: "recommend_uiverse",
889906
icon: "https://uiverse.io/favicon.ico",

scripts/_index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,3 +170,4 @@ export { default as github_openRepoPages } from "./github_openRepoPages.js";
170170
export { default as screenshotVisiblePage } from "./screenshotVisiblePage.js";
171171
export { default as fb_stopNewFeed } from "./fb_stopNewFeed.js";
172172
export { default as github_HTMLPreview } from "./github_HTMLPreview.js";
173+
export { default as showImageOnHoverLink } from "./showImageOnHoverLink.js";

scripts/showImageOnHoverLink.js

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
export default {
2+
icon: '<i class="fa-solid fa-arrow-pointer fa-lg"></i>',
3+
name: {
4+
en: "Show image on hover link",
5+
vi: "Hiện ảnh khi di chuột qua link",
6+
},
7+
description: {
8+
en: "Show preview image when you hover mouse over an image link",
9+
vi: "Xem trước hình ảnh khi bạn đưa chuột qua link hình ảnh",
10+
},
11+
12+
changeLogs: {
13+
"2024-06-19": "init",
14+
},
15+
16+
contentScript: {
17+
onDocumentStart_: (details) => {
18+
function isImgUrl(url) {
19+
return url.match(/\.(jpeg|jpg|gif|png)$/) != null;
20+
}
21+
22+
const id = "show-image-on-hover-link";
23+
let div = document.createElement("div");
24+
div.id = id;
25+
26+
let appended = false;
27+
28+
let img = document.createElement("img");
29+
div.appendChild(img);
30+
31+
let style = document.createElement("style");
32+
style.textContent = `
33+
#${id} {
34+
hidden: true;
35+
position: fixed;
36+
top: 0;
37+
left: 0;
38+
z-index: 9999999999999;
39+
transform: translate(10px, 10px);
40+
transition: all 0.1s ease;
41+
}
42+
#${id} img {
43+
max-width: 400px;
44+
max-height: 400px;
45+
}
46+
#${id} .loader {
47+
width: 50px;
48+
aspect-ratio: 1;
49+
display: grid;
50+
border-radius: 50%;
51+
background:
52+
linear-gradient(0deg ,rgb(200 200 200 /50%) 30%,#0000 0 70%,rgb(200 200 200 /100%) 0) 50%/8% 100%,
53+
linear-gradient(90deg,rgb(200 200 200 /25%) 30%,#0000 0 70%,rgb(200 200 200 /75% ) 0) 50%/100% 8%;
54+
background-repeat: no-repeat;
55+
animation: l23 1s infinite steps(12);
56+
}
57+
#${id} .loader::before,
58+
#${id} .loader::after {
59+
content: "";
60+
grid-area: 1/1;
61+
border-radius: 50%;
62+
background: inherit;
63+
opacity: 0.915;
64+
transform: rotate(30deg);
65+
}
66+
#${id} .loader::after {
67+
opacity: 0.83;
68+
transform: rotate(60deg);
69+
}
70+
@keyframes l23 {
71+
100% {transform: rotate(1turn)}
72+
}
73+
`;
74+
div.appendChild(style);
75+
76+
let loader = document.createElement("div");
77+
loader.classList.add("loader");
78+
div.appendChild(loader);
79+
80+
let timeout;
81+
82+
window.addEventListener("mouseover", (e) => {
83+
if (e.target.tagName === "A") {
84+
let href = e.target.href;
85+
if (href && isImgUrl(href)) {
86+
if (!appended) {
87+
document.body.appendChild(div);
88+
appended = true;
89+
}
90+
91+
clearTimeout(timeout);
92+
div.hidden = false;
93+
loader.hidden = false;
94+
img.hidden = true;
95+
96+
let image = new Image();
97+
image.src = href;
98+
image.onload = function () {
99+
img.src = href;
100+
loader.hidden = true;
101+
img.hidden = false;
102+
};
103+
104+
div.style.top = e.clientY + "px";
105+
div.style.left = e.clientX + "px";
106+
107+
e.target.addEventListener(
108+
"mouseleave",
109+
(e) => {
110+
timeout = setTimeout(() => {
111+
div.hidden = true;
112+
}, 500);
113+
},
114+
{ once: true }
115+
);
116+
}
117+
}
118+
});
119+
},
120+
},
121+
};

0 commit comments

Comments
 (0)