This repository has been archived by the owner on Apr 29, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
117 lines (101 loc) · 2.82 KB
/
index.html
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
<!DOCTYPE html>
<html>
<head>
<title>Image Gallery</title>
<style>
body {
background-color: #1f1f1f;
color: #fff;
font-family: Arial, sans-serif;
}
.container {
display: flex;
flex-wrap: wrap;
justify-content: center;
margin: 20px;
}
.image-wrapper {
margin: 10px;
width: 200px;
height: 200px;
overflow: hidden;
position: relative;
}
.image-wrapper img {
width: 100%;
height: 100%;
object-fit: cover;
transition: transform 0.3s;
}
.image-wrapper:hover img {
transform: scale(1.1);
}
.download-button {
position: absolute;
bottom: 5px;
right: 5px;
background-color: #4caf50;
color: #fff;
border: none;
padding: 5px 10px;
cursor: pointer;
}
.download-button:hover {
background-color: #45a049;
}
</style>
</head>
<body>
<h1>Image Gallery</h1>
<form id="urlForm">
<input type="text" id="urlInput" placeholder="Enter URL">
<button type="submit">Load Images</button>
</form>
<div id="imageContainer" class="container"></div>
<script>
const urlForm = document.getElementById('urlForm');
const urlInput = document.getElementById('urlInput');
const imageContainer = document.getElementById('imageContainer');
urlForm.addEventListener('submit', function (event) {
event.preventDefault();
const url = urlInput.value;
loadImages(url);
});
function loadImages(url) {
fetch(url)
.then(response => response.text())
.then(data => {
const parser = new DOMParser();
const doc = parser.parseFromString(data, 'text/html');
const images = doc.querySelectorAll('img');
imageContainer.innerHTML = '';
images.forEach(image => {
const imageWrapper = document.createElement('div');
imageWrapper.className = 'image-wrapper';
const img = document.createElement('img');
img.src = image.src;
const downloadButton = document.createElement('button');
downloadButton.className = 'download-button';
downloadButton.textContent = 'Download';
downloadButton.addEventListener('click', function () {
downloadImage(image.src);
});
imageWrapper.appendChild(img);
imageWrapper.appendChild(downloadButton);
imageContainer.appendChild(imageWrapper);
});
})
.catch(error => {
console.error(error);
imageContainer.innerHTML = '<p>Error loading images.</p>';
});
}
function downloadImage(url) {
const link = document.createElement('a');
link.href = url;
link.download = '';
link.click();
}
</script>
</body>
</html>