fix dark reader plugin not working on map results

This commit is contained in:
partisan 2024-10-06 18:11:58 +02:00
parent 2425392767
commit f95636799d
4 changed files with 164 additions and 156 deletions

13
map.go
View file

@ -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")

View file

@ -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%);
}
}

View file

@ -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();
});

View file

@ -73,16 +73,10 @@
<div class="images images_viewer_hidden">
<!-- Images Grid -->
{{ range $index, $result := .Results }}
<div class="image" width="{{ .ThumbHeight }}">
<a class="clickable" href="{{ .Source }}" target="_blank">
<img
class="open-image-viewer"
src="{{ .ThumbProxy }}"
alt="{{ .Title }}"
data-media="{{ .Media }}"
/>
<div class="resolution">{{ .Width }} × {{ .Height }}</div>
<div class="details">
<div class="image">
<img src="{{ .ThumbProxy }}" alt="{{ .Title }}" data-media="{{ .Media }}" class="clickable">
<div class="resolution">{{ .Width }} × {{ .Height }}</div>
<div class="details">
<span class="img_title clickable">{{ .Title }}</span>
<a href="{{ .Source }}" target="_blank" class="img_source">Source</a>
</div>
@ -121,148 +115,105 @@
<div id="template-data" data-page="{{ .Page }}" data-query="{{ .Query }}" data-type="image"></div>
<script defer src="/static/js/dynamicscrolling.js"></script>
<script defer src="/static/js/autocomplete.js"></script>
<script defer src="/static/js/imagetitletrim.js"></script>
<script>
document.addEventListener('DOMContentLoaded', function() {
let viewerOpen = false;
const viewerOverlay = document.getElementById('image-viewer-overlay');
viewerOverlay.innerHTML = `
<div id="image-viewer">
<span id="viewer-close-button" class="material-icons">close</span>
<span id="viewer-prev-button" class="material-icons">arrow_back</span>
<span id="viewer-next-button" class="material-icons">arrow_forward</span>
<div id="viewer-image-container">
<img id="viewer-image" src="" alt="">
</div>
<div id="viewer-info">
<div id="viewer-title"></div>
<a id="viewer-source-button" href="" target="_blank">Visit Page</a>
</div>
document.addEventListener('DOMContentLoaded', function() {
let viewerOpen = false;
const viewerOverlay = document.getElementById('image-viewer-overlay');
viewerOverlay.innerHTML = `
<div id="image-viewer" class="image_view image_hide">
<div class="image-view-close">
<button class="btn-nostyle">
<div id="viewer-prev-button" class="material-icons-round icon_visibility clickable image-before">navigate_before</div>
</button>
<button class="btn-nostyle">
<div id="viewer-next-button" class="material-icons-round icon_visibility clickable image-next">navigate_next</div>
</button>
<button class="btn-nostyle">
<div id="viewer-close-button" class="material-icons-round icon_visibility clickable image-close">close</div>
</button>
</div>
<a class="image-viewer-link clickable" href="">
<div class="view-image" id="viewer-image-container">
<img id="viewer-image" class="view-image-img" src="" alt="">
</div>
`;
function openImageViewer(element) {
const parentImageDiv = element.closest('.image');
if (!parentImageDiv) return;
const imgElement = parentImageDiv.querySelector('img.clickable');
const mediaUrl = imgElement.dataset.media;
const title = imgElement.alt;
const sourceUrl = parentImageDiv.querySelector('.img_source').href;
if (!mediaUrl || viewerOpen) {
return; // Don't open if data is missing or viewer is already open
}
viewerOpen = true;
const viewerImage = document.getElementById('viewer-image');
const viewerTitle = document.getElementById('viewer-title');
const viewerSourceButton = document.getElementById('viewer-source-button');
viewerImage.src = mediaUrl;
viewerTitle.textContent = title;
viewerSourceButton.href = sourceUrl;
viewerOverlay.style.display = 'flex';
</a>
<p class="image-alt" id="viewer-title"></p>
<p>View source: <a id="viewer-source-button" class="image-source" href="" target="_blank"></a></p>
<p>
<a class="full-size" href="#">Show source website</a>
<a class="proxy-size" href="#">Show in fullscreen</a>
</div>
`;
const imageView = document.getElementById('image-viewer');
function openImageViewer(element) {
const parentImageDiv = element.closest('.image');
if (!parentImageDiv) return;
const imgElement = parentImageDiv.querySelector('img.clickable');
const mediaUrl = imgElement.dataset.media;
const title = imgElement.alt;
const sourceUrl = parentImageDiv.querySelector('.img_source').href;
if (!mediaUrl || viewerOpen) {
return; // Don't open if data is missing or viewer is already open
}
viewerOpen = true;
const viewerImage = document.getElementById('viewer-image');
const viewerTitle = document.getElementById('viewer-title');
const viewerSourceButton = document.getElementById('viewer-source-button');
viewerImage.src = mediaUrl;
viewerTitle.textContent = title;
viewerSourceButton.href = sourceUrl;
viewerOverlay.style.display = 'flex';
imageView.classList.remove('image_hide');
imageView.classList.add('image_show');
}
// Attach event listener to the document body
document.body.addEventListener('click', function(e) {
let target = e.target;
let clickableElement = target.closest('img.clickable, .img_title.clickable');
if (clickableElement) {
e.preventDefault();
openImageViewer(clickableElement);
}
});
function closeImageViewer() {
imageView.classList.remove('image_show');
imageView.classList.add('image_hide');
viewerOverlay.style.display = 'none';
viewerOpen = false;
}
// Close viewer on overlay or button click
document.getElementById('viewer-close-button').addEventListener('click', closeImageViewer);
viewerOverlay.addEventListener('click', function(e) {
if (e.target === viewerOverlay) {
closeImageViewer();
}
});
// Handle keyboard events for closing and navigation
document.addEventListener('keydown', function(e) {
if (viewerOverlay.style.display === 'flex') {
if (e.key === 'Escape') {
closeImageViewer();
}
// Attach event listener to the document body
document.body.addEventListener('click', function(e) {
let target = e.target;
let clickableElement = target.closest('img.clickable, .img_title.clickable');
if (clickableElement) {
e.preventDefault();
openImageViewer(clickableElement);
}
});
function closeImageViewer() {
viewerOverlay.style.display = 'none';
viewerOpen = false;
}
// Close viewer on overlay or button click
document.getElementById('viewer-close-button').addEventListener('click', closeImageViewer);
viewerOverlay.addEventListener('click', function(e) {
if (e.target === viewerOverlay) {
closeImageViewer();
}
});
// Handle keyboard events for closing and navigation
document.addEventListener('keydown', function(e) {
if (viewerOverlay.style.display === 'flex') {
if (e.key === 'Escape') {
closeImageViewer();
}
}
});
});
</script>
<script>
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();
});
}
});
});
</script>
<script>
// Check if JavaScript is enabled and modify the DOM accordingly
document.getElementById('content').classList.remove('js-enabled');
</script>
</body>
</html>
</html>