Skip to content

Commit 1545a8f

Browse files
committed
refactor: Simplify gallery carousel to viewing-only mode
- Fix carousel close button with stopPropagation - Remove all action buttons from carousel (copy, delete, source) - Move download button to top-right of image (floating) - Remove copy button from gallery grid items - Simplify carousel to just image viewing with navigation - Update counter styling to bottom center - Increase image max height to 85vh for better viewing
1 parent 8f86c8d commit 1545a8f

4 files changed

Lines changed: 97 additions & 116 deletions

File tree

bookmarks.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,17 @@ function renderBookmarks() {
4141
const displayUrl = new URL(bookmark.url).hostname;
4242
return `
4343
<a href="${bookmark.url}" class="bookmark-item" target="_blank">
44-
<img src="${favicon}" class="bookmark-favicon" onerror="this.style.display='none'">
44+
<img src="${favicon}" class="bookmark-favicon">
4545
<span class="bookmark-title">${escapeHtml(bookmark.title || bookmark.url)}</span>
4646
<span class="bookmark-url">${displayUrl}</span>
4747
</a>
4848
`;
4949
}).join('');
50+
document.querySelectorAll('.bookmark-favicon').forEach(img => {
51+
img.addEventListener('error', function() {
52+
this.style.display = 'none';
53+
});
54+
});
5055
}
5156
function escapeHtml(text) {
5257
const div = document.createElement('div');

gallery.js

Lines changed: 39 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ function loadImages() {
1313
renderGallery();
1414
});
1515
}
16+
function refreshGallery() {
17+
loadImages();
18+
}
1619
function saveImages() {
1720
chrome.storage.local.set({ chaosGallery: images });
1821
}
@@ -86,9 +89,6 @@ function renderGallery() {
8689
<i data-lucide="download"></i>
8790
</button>
8891
<div class="gallery-overlay">
89-
<button class="gallery-action-btn gallery-copy-btn" data-image-url="${escapeHtml(image.url)}">
90-
<i data-lucide="copy"></i>
91-
</button>
9292
<button class="gallery-action-btn gallery-delete-btn delete" data-image-id="${image.id}">
9393
<i data-lucide="trash-2"></i>
9494
</button>
@@ -123,13 +123,6 @@ function attachGalleryEventListeners() {
123123
downloadImage(imageUrl, imageId);
124124
});
125125
});
126-
document.querySelectorAll('.gallery-copy-btn').forEach(btn => {
127-
btn.addEventListener('click', (e) => {
128-
e.stopPropagation();
129-
const imageUrl = btn.dataset.imageUrl;
130-
copyImageUrl(imageUrl);
131-
});
132-
});
133126
document.querySelectorAll('.gallery-delete-btn').forEach(btn => {
134127
btn.addEventListener('click', (e) => {
135128
e.stopPropagation();
@@ -185,6 +178,7 @@ function isThisYear(date) {
185178
return date.getFullYear() === new Date().getFullYear();
186179
}
187180
let currentCarouselIndex = 0;
181+
let carouselKeyHandler = null;
188182
function openCarousel(imageId) {
189183
currentCarouselIndex = images.findIndex(img => img.id === imageId);
190184
if (currentCarouselIndex === -1) currentCarouselIndex = 0;
@@ -195,52 +189,45 @@ function showCarousel() {
195189
if (!image) return;
196190
const existing = document.querySelector('.gallery-carousel');
197191
if (existing) existing.remove();
192+
if (carouselKeyHandler) {
193+
document.removeEventListener('keydown', carouselKeyHandler);
194+
}
198195
const carousel = document.createElement('div');
199196
carousel.className = 'gallery-carousel';
200197
carousel.innerHTML = `
201198
<div class="gallery-carousel-content">
202199
<button class="gallery-carousel-close">
203200
<i data-lucide="x"></i>
204201
</button>
202+
205203
${currentCarouselIndex > 0 ? `
206204
<button class="gallery-carousel-nav gallery-carousel-prev">
207205
<i data-lucide="chevron-left"></i>
208206
</button>
209207
` : ''}
208+
210209
${currentCarouselIndex < images.length - 1 ? `
211210
<button class="gallery-carousel-nav gallery-carousel-next">
212211
<i data-lucide="chevron-right"></i>
213212
</button>
214213
` : ''}
215-
<div class="gallery-carousel-image-container">
214+
215+
<div class="gallery-carousel-image-wrapper">
216216
<img src="${escapeHtml(image.url)}" alt="Gallery image" class="gallery-carousel-image">
217+
<button class="gallery-carousel-download-btn" data-image-url="${escapeHtml(image.url)}" data-image-id="${image.id}" title="Download image">
218+
<i data-lucide="download"></i>
219+
</button>
217220
</div>
218-
<div class="gallery-carousel-info">
219-
<div class="gallery-carousel-counter">${currentCarouselIndex + 1} / ${images.length}</div>
220-
<div class="gallery-carousel-title">${escapeHtml(image.pageTitle || 'Untitled')}</div>
221-
<div class="gallery-carousel-actions">
222-
${image.pageUrl ? `<a href="${escapeHtml(image.pageUrl)}" target="_blank" class="gallery-carousel-btn">
223-
<i data-lucide="external-link"></i> Source
224-
</a>` : ''}
225-
<button class="gallery-carousel-btn gallery-carousel-download" data-image-url="${escapeHtml(image.url)}" data-image-id="${image.id}">
226-
<i data-lucide="download"></i> Download
227-
</button>
228-
<button class="gallery-carousel-btn gallery-carousel-copy" data-image-url="${escapeHtml(image.url)}">
229-
<i data-lucide="copy"></i> Copy URL
230-
</button>
231-
<button class="gallery-carousel-btn gallery-carousel-delete delete" data-image-id="${image.id}">
232-
<i data-lucide="trash-2"></i> Delete
233-
</button>
234-
</div>
235-
</div>
221+
222+
<div class="gallery-carousel-counter">${currentCarouselIndex + 1} / ${images.length}</div>
236223
</div>
237224
`;
238225
carousel.addEventListener('click', (e) => {
239226
if (e.target === carousel) {
240227
closeCarousel();
241228
}
242229
});
243-
const handleKeyPress = (e) => {
230+
carouselKeyHandler = (e) => {
244231
if (e.key === 'Escape') {
245232
closeCarousel();
246233
} else if (e.key === 'ArrowLeft' && currentCarouselIndex > 0) {
@@ -249,52 +236,50 @@ function showCarousel() {
249236
nextImage();
250237
}
251238
};
252-
document.addEventListener('keydown', handleKeyPress);
253-
carousel.dataset.keyHandler = 'attached';
239+
document.addEventListener('keydown', carouselKeyHandler);
254240
document.body.appendChild(carousel);
255241
lucide.createIcons();
256242
attachCarouselEventListeners();
257243
}
258244
function attachCarouselEventListeners() {
259245
const closeBtn = document.querySelector('.gallery-carousel-close');
260246
if (closeBtn) {
261-
closeBtn.addEventListener('click', closeCarousel);
247+
closeBtn.addEventListener('click', (e) => {
248+
e.stopPropagation();
249+
closeCarousel();
250+
});
262251
}
263252
const prevBtn = document.querySelector('.gallery-carousel-prev');
264253
if (prevBtn) {
265-
prevBtn.addEventListener('click', prevImage);
254+
prevBtn.addEventListener('click', (e) => {
255+
e.stopPropagation();
256+
prevImage();
257+
});
266258
}
267259
const nextBtn = document.querySelector('.gallery-carousel-next');
268260
if (nextBtn) {
269-
nextBtn.addEventListener('click', nextImage);
261+
nextBtn.addEventListener('click', (e) => {
262+
e.stopPropagation();
263+
nextImage();
264+
});
270265
}
271-
const downloadBtn = document.querySelector('.gallery-carousel-download');
266+
const downloadBtn = document.querySelector('.gallery-carousel-download-btn');
272267
if (downloadBtn) {
273-
downloadBtn.addEventListener('click', () => {
268+
downloadBtn.addEventListener('click', (e) => {
269+
e.stopPropagation();
274270
const imageUrl = downloadBtn.dataset.imageUrl;
275271
const imageId = parseInt(downloadBtn.dataset.imageId);
276272
downloadImage(imageUrl, imageId);
277273
});
278274
}
279-
const copyBtn = document.querySelector('.gallery-carousel-copy');
280-
if (copyBtn) {
281-
copyBtn.addEventListener('click', () => {
282-
const imageUrl = copyBtn.dataset.imageUrl;
283-
copyImageUrl(imageUrl);
284-
});
285-
}
286-
const deleteBtn = document.querySelector('.gallery-carousel-delete');
287-
if (deleteBtn) {
288-
deleteBtn.addEventListener('click', () => {
289-
const imageId = parseInt(deleteBtn.dataset.imageId);
290-
deleteImageFromCarousel(imageId);
291-
});
292-
}
293275
}
294276
function closeCarousel() {
295277
const carousel = document.querySelector('.gallery-carousel');
296278
if (carousel) {
297-
document.removeEventListener('keydown', handleKeyPress);
279+
if (carouselKeyHandler) {
280+
document.removeEventListener('keydown', carouselKeyHandler);
281+
carouselKeyHandler = null;
282+
}
298283
carousel.remove();
299284
}
300285
}
@@ -412,7 +397,8 @@ window.galleryFunctions = {
412397
prevImage,
413398
deleteImageFromCarousel,
414399
downloadImage,
415-
downloadDateImages
400+
downloadDateImages,
401+
refreshGallery
416402
};
417403
chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
418404
if (request.action === 'addToGallery') {

newtab.html

Lines changed: 46 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1535,6 +1535,8 @@
15351535
.gallery-action-btn svg {
15361536
width: 18px;
15371537
height: 18px;
1538+
color: white;
1539+
stroke: white;
15381540
}
15391541

15401542
.gallery-info {
@@ -1722,6 +1724,13 @@
17221724
z-index: 5;
17231725
}
17241726

1727+
.gallery-download-btn svg {
1728+
width: 16px;
1729+
height: 16px;
1730+
color: white;
1731+
stroke: white;
1732+
}
1733+
17251734
.gallery-item:hover .gallery-download-btn {
17261735
opacity: 1;
17271736
}
@@ -1731,9 +1740,9 @@
17311740
border-color: rgba(139, 92, 246, 0.6);
17321741
}
17331742

1734-
.gallery-download-btn svg {
1735-
width: 16px;
1736-
height: 16px;
1743+
.gallery-download-btn:hover svg {
1744+
color: white;
1745+
stroke: white;
17371746
}
17381747

17391748
.gallery-image-wrapper {
@@ -1833,88 +1842,63 @@
18331842
right: 40px;
18341843
}
18351844

1836-
.gallery-carousel-image-container {
1845+
.gallery-carousel-image-wrapper {
1846+
position: relative;
18371847
max-width: 90vw;
1838-
max-height: 70vh;
1848+
max-height: 85vh;
18391849
display: flex;
18401850
align-items: center;
18411851
justify-content: center;
18421852
}
18431853

18441854
.gallery-carousel-image {
18451855
max-width: 100%;
1846-
max-height: 70vh;
1856+
max-height: 85vh;
18471857
object-fit: contain;
18481858
border-radius: 8px;
18491859
box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
18501860
}
18511861

1852-
.gallery-carousel-info {
1862+
.gallery-carousel-download-btn {
18531863
position: absolute;
1854-
bottom: 40px;
1855-
left: 50%;
1856-
transform: translateX(-50%);
1857-
background: rgba(24, 24, 27, 0.95);
1858-
border: 1px solid rgba(63, 63, 70, 0.6);
1859-
border-radius: 12px;
1860-
padding: 20px;
1861-
max-width: 800px;
1862-
width: 90%;
1863-
backdrop-filter: blur(16px);
1864-
}
1865-
1866-
.gallery-carousel-counter {
1867-
color: #71717a;
1868-
font-size: 12px;
1869-
margin-bottom: 8px;
1870-
text-align: center;
1871-
}
1872-
1873-
.gallery-carousel-title {
1874-
color: #fafafa;
1875-
font-size: 16px;
1876-
font-weight: 600;
1877-
margin-bottom: 16px;
1878-
text-align: center;
1879-
}
1880-
1881-
.gallery-carousel-actions {
1882-
display: flex;
1883-
gap: 8px;
1884-
justify-content: center;
1885-
flex-wrap: wrap;
1886-
}
1887-
1888-
.gallery-carousel-btn {
1864+
top: 20px;
1865+
right: 20px;
1866+
width: 48px;
1867+
height: 48px;
1868+
background: rgba(0, 0, 0, 0.7);
1869+
border: 1px solid rgba(255, 255, 255, 0.2);
1870+
border-radius: 8px;
1871+
color: white;
1872+
cursor: pointer;
18891873
display: flex;
18901874
align-items: center;
1891-
gap: 6px;
1892-
padding: 10px 16px;
1893-
background: rgba(63, 63, 70, 0.4);
1894-
border: 1px solid rgba(63, 63, 70, 0.6);
1895-
border-radius: 6px;
1896-
color: #a1a1aa;
1897-
font-size: 13px;
1898-
cursor: pointer;
1875+
justify-content: center;
18991876
transition: all 0.2s;
1900-
text-decoration: none;
1877+
z-index: 10;
19011878
}
19021879

1903-
.gallery-carousel-btn:hover {
1904-
background: rgba(63, 63, 70, 0.6);
1905-
color: #fafafa;
1906-
border-color: rgba(63, 63, 70, 0.8);
1880+
.gallery-carousel-download-btn:hover {
1881+
background: rgba(139, 92, 246, 0.9);
1882+
border-color: rgba(139, 92, 246, 0.6);
1883+
transform: scale(1.05);
19071884
}
19081885

1909-
.gallery-carousel-btn.delete:hover {
1910-
background: rgba(239, 68, 68, 0.2);
1911-
color: #ef4444;
1912-
border-color: rgba(239, 68, 68, 0.5);
1886+
.gallery-carousel-download-btn svg {
1887+
width: 22px;
1888+
height: 22px;
19131889
}
19141890

1915-
.gallery-carousel-btn svg {
1916-
width: 16px;
1917-
height: 16px;
1891+
.gallery-carousel-counter {
1892+
position: absolute;
1893+
bottom: 30px;
1894+
left: 50%;
1895+
transform: translateX(-50%);
1896+
color: #fafafa;
1897+
font-size: 14px;
1898+
background: rgba(0, 0, 0, 0.7);
1899+
padding: 8px 16px;
1900+
border-radius: 20px;
1901+
backdrop-filter: blur(8px);
19181902
}
19191903

19201904
.about-container {

tray.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ trayToggle.addEventListener('click', (e) => {
99
bottomTray.classList.toggle('collapsed');
1010
trayToggle.classList.toggle('expanded');
1111
chrome.storage.sync.set({ trayExpanded });
12+
if (trayExpanded && window.galleryFunctions) {
13+
window.galleryFunctions.refreshGallery();
14+
}
1215
});
1316
document.addEventListener('click', (e) => {
1417
if (trayExpanded && !bottomTray.contains(e.target) && e.target !== trayToggle) {
@@ -29,6 +32,9 @@ trayTabs.forEach(tab => {
2932
tabPanels.forEach(panel => panel.classList.remove('active'));
3033
document.getElementById(`${tabName}Panel`).classList.add('active');
3134
chrome.storage.sync.set({ activeTab: tabName });
35+
if (tabName === 'gallery' && window.galleryFunctions) {
36+
window.galleryFunctions.refreshGallery();
37+
}
3238
});
3339
});
3440
chrome.storage.sync.get(['trayExpanded', 'activeTab'], (result) => {

0 commit comments

Comments
 (0)