-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
99 lines (86 loc) · 2.67 KB
/
script.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
const img = document.getElementById("myImage");
img.addEventListener("click", () => {
// Check if fullscreen API is supported
if (img.requestFullscreen) {
img.requestFullscreen();
} else if (img.webkitRequestFullscreen) {
// Safari
img.webkitRequestFullscreen();
} else if (img.msRequestFullscreen) {
// IE/Edge
img.msRequestFullscreen();
}
// Apply temporary styles for fullscreen mode
img.style.position = "static";
img.style.width = "100%";
img.style.height = "100%";
img.style.objectFit = "contain";
});
// Listen for exit from fullscreen to restore styles
document.addEventListener("fullscreenchange", () => {
if (!document.fullscreenElement) {
restoreImageStyles();
}
});
document.addEventListener("webkitfullscreenchange", () => {
if (!document.webkitFullscreenElement) {
restoreImageStyles();
}
});
document.addEventListener("msfullscreenchange", () => {
if (!document.msFullscreenElement) {
restoreImageStyles();
}
});
function restoreImageStyles() {
// Restore original styles when exiting fullscreen
img.style.position = "absolute";
img.style.width = "100%";
img.style.height = "100%";
img.style.objectFit = "cover";
img.style.objectPosition = "center top";
img.style.top = "12px";
}
// Disable default right-click menu
document.addEventListener("contextmenu", (event) => {
event.preventDefault();
showCustomMenu(event);
});
// Show custom context menu
function showCustomMenu(event) {
const menu = document.getElementById("customMenu");
menu.style.top = `${event.clientY}px`;
menu.style.left = `${event.clientX}px`;
menu.style.display = "block";
}
// Hide custom context menu
document.addEventListener("click", () => {
const menu = document.getElementById("customMenu");
menu.style.display = "none";
});
// Download image function
function downloadImage() {
const link = document.createElement("a");
link.href = document.getElementById("myImage").src;
link.download = "Arun.png";
link.click();
}
// Download HTML as PDF function
async function downloadHtmlAsPdf() {
const menu = document.getElementById("customMenu");
menu.style.display = "none";
const { jsPDF } = window.jspdf;
const element = document.body;
const canvas = await html2canvas(element, { scale: 2 });
const imgData = canvas.toDataURL("image/png");
const pdf = new jsPDF("p", "mm", "a4");
const imgProps = pdf.getImageProperties(imgData);
const pdfWidth = pdf.internal.pageSize.getWidth();
const pdfHeight = (imgProps.height * pdfWidth) / imgProps.width;
pdf.addImage(imgData, "PNG", 0, 0, pdfWidth, pdfHeight);
pdf.save("Arun_Resume.pdf");
}
// Open link function
function openLink(url) {
window.open(url, "_blank");
}