From f95636799db09037bd2319fb29f052a4354b98c3 Mon Sep 17 00:00:00 2001 From: partisan Date: Sun, 6 Oct 2024 18:11:58 +0200 Subject: [PATCH] fix dark reader plugin not working on map results --- map.go | 13 +- static/css/style.css | 8 +- static/js/imagetitletrim.js | 56 +++++++++ templates/images.html | 243 ++++++++++++++---------------------- 4 files changed, 164 insertions(+), 156 deletions(-) create mode 100644 static/js/imagetitletrim.js diff --git a/map.go b/map.go index df3c7e8..1008353 100755 --- a/map.go +++ b/map.go @@ -54,12 +54,13 @@ func handleMapSearch(w http.ResponseWriter, settings UserSettings, query string) // Use a template to serve the map page data := map[string]interface{}{ - "Query": query, - "Latitude": latitude, - "Longitude": longitude, - "Found": found, - "Theme": settings.Theme, - "Safe": settings.SafeSearch, + "Query": query, + "Latitude": latitude, + "Longitude": longitude, + "Found": found, + "Theme": settings.Theme, + "Safe": settings.SafeSearch, + "IsThemeDark": settings.IsThemeDark, } tmpl, err := template.ParseFiles("templates/map.html") diff --git a/static/css/style.css b/static/css/style.css index f6bac09..9d3a351 100644 --- a/static/css/style.css +++ b/static/css/style.css @@ -2017,7 +2017,7 @@ body, h1, p, a, input, button { position: relative; max-width: 80%; max-height: 80%; - background: #fff; + background: var(--search-bg); padding: 20px; box-sizing: border-box; overflow: hidden; @@ -2035,12 +2035,12 @@ body, h1, p, a, input, button { #viewer-title { font-size: 18px; - color: #000; + color: var(--text-color); margin-bottom: 10px; } #viewer-source-button { - color: #1a0dab; + color: var(--link); text-decoration: none; font-size: 16px; } @@ -2070,4 +2070,4 @@ body, h1, p, a, input, button { right: 10px; top: 50%; transform: translateY(-50%); - } \ No newline at end of file + } diff --git a/static/js/imagetitletrim.js b/static/js/imagetitletrim.js new file mode 100644 index 0000000..cf388f0 --- /dev/null +++ b/static/js/imagetitletrim.js @@ -0,0 +1,56 @@ +document.addEventListener('DOMContentLoaded', function() { + let imagesContainer = document.querySelector('.images'); + let observer; + + // Function to trim image titles based on the image width + function trimTitles() { + const images = document.querySelectorAll('.images .image'); + images.forEach((element) => { + const imgElement = element.querySelector('img.clickable'); + const titleElement = element.querySelector('.img_title.clickable'); + const detailsElement = element.querySelector('.details'); + + if (imgElement.complete && imgElement.naturalWidth) { + const imageWidth = imgElement.clientWidth; + + // Set the width of the details div and title to match the image width + detailsElement.style.width = imageWidth + 'px'; + titleElement.style.maxWidth = imageWidth + 'px'; + } + + // // Add load event listener in case images load dynamically + // imgElement.addEventListener('load', function() { + // const imageWidth = imgElement.clientWidth; + // detailsElement.style.width = imageWidth + 'px'; + // titleElement.style.maxWidth = imageWidth + 'px'; + // }); + }); + } + + // Call trimTitles periodically to account for dynamic loading, not happy about this one + setInterval(() => { + trimTitles(); + }, 10); + + // Observe for dynamically added images + function observeNewImages() { + observer = new MutationObserver(function(mutations) { + mutations.forEach(function(mutation) { + mutation.addedNodes.forEach(function(node) { + if (node.nodeType === 1 && node.classList.contains('image')) { + trimTitles(); + } + }); + }); + }); + + // Observe the images container for changes + observer.observe(imagesContainer, { childList: true, subtree: true }); + } + + // Run initial title trimming after page load + trimTitles(); + + // Start observing for dynamic image loading + observeNewImages(); +}); \ No newline at end of file diff --git a/templates/images.html b/templates/images.html index 4a78bc5..a851258 100755 --- a/templates/images.html +++ b/templates/images.html @@ -73,16 +73,10 @@
{{ range $index, $result := .Results }} -
- - {{ .Title }} -
{{ .Width }} × {{ .Height }}
-
+
+ {{ .Title }} +
{{ .Width }} × {{ .Height }}
+
@@ -121,148 +115,105 @@
+ - - - - - + \ No newline at end of file