From 5a4be6dad687aaf2cc27d70356a6e6b4a53631a7 Mon Sep 17 00:00:00 2001 From: partisan Date: Tue, 22 Oct 2024 21:58:06 +0200 Subject: [PATCH] clean up --- run.bat | 28 ++----- run.sh | 33 +-------- static/js/dynamicscrolling.js | 13 +++- static/js/imageviewer.js | 101 +++++++++++++++++++++++++ templates/images.html | 135 ++++------------------------------ 5 files changed, 133 insertions(+), 177 deletions(-) create mode 100644 static/js/imageviewer.js diff --git a/run.bat b/run.bat index f0baf09..0f68a88 100755 --- a/run.bat +++ b/run.bat @@ -1,31 +1,17 @@ @echo off setlocal enabledelayedexpansion -rem Directory where the Go files are located -set GO_DIR=C:\path\to\your\go\files - -rem Explicitly list the main files in the required order -set FILES=main.go init.go text.go text-google.go text-librex.go text-brave.go text-duckduckgo.go common.go cache.go agent.go files.go files-thepiratebay.go files-torrentgalaxy.go forums.go get-searchxng.go imageproxy.go images.go images-imgur.go images-quant.go map.go node.go open-search.go video.go - -rem Change to the directory with the Go files -pushd %GO_DIR% - -rem Find all other .go files that were not explicitly listed -set OTHER_GO_FILES= +rem Use the current directory where the script is executed +pushd %~dp0 +rem Collect all .go files in the current directory +set GO_FILES= for %%f in (*.go) do ( - set file=%%~nxf - set found=0 - for %%i in (%FILES%) do ( - if /i "%%i"=="!file!" set found=1 - ) - if !found!==0 ( - set OTHER_GO_FILES=!OTHER_GO_FILES! "%%f" - ) + set GO_FILES=!GO_FILES! %%f ) -rem Run the Go program with the specified files first, followed by the remaining files -go run %FILES% %OTHER_GO_FILES% +rem Run the Go program with all the .go files +go run !GO_FILES! rem Return to the original directory popd diff --git a/run.sh b/run.sh index bf384d9..1c13eb4 100755 --- a/run.sh +++ b/run.sh @@ -1,34 +1,7 @@ #!/bin/sh -# Explicitly list the main files in the required order -FILES=" -./main.go -./init.go -./text.go -./text-google.go -./text-librex.go -./text-brave.go -./text-duckduckgo.go -./common.go -./cache.go -./agent.go -./files.go -./files-thepiratebay.go -./files-torrentgalaxy.go -./forums.go -./get-searchxng.go -./imageproxy.go -./images.go -./images-imgur.go -./images-quant.go -./map.go -./node.go -./open-search.go -./video.go -" - -# Find all other .go files that were not explicitly listed -OTHER_GO_FILES=$(find . -name '*.go' ! -name 'main.go' ! -name 'init.go' ! -name 'search-engine.go' ! -name 'text.go' ! -name 'text-google.go' ! -name 'text-librex.go' ! -name 'text-brave.go' ! -name 'text-duckduckgo.go' ! -name 'common.go' ! -name 'cache.go' ! -name 'agent.go' ! -name 'files.go' ! -name 'files-thepiratebay.go' ! -name 'files-torrentgalaxy.go' ! -name 'forums.go' ! -name 'get-searchxng.go' ! -name 'imageproxy.go' ! -name 'images.go' ! -name 'images-imgur.go' ! -name 'images-quant.go' ! -name 'map.go' ! -name 'node.go' ! -name 'open-search.go' ! -name 'video.go' -print) +# List all go files in this directory +GO_FILES=$(find . -name '*.go' -print) # Run the Go program with the specified files first, followed by the remaining files -go run $FILES $OTHER_GO_FILES +go run $FILES $GO_FILES diff --git a/static/js/dynamicscrolling.js b/static/js/dynamicscrolling.js index d5373cf..fb1ed87 100644 --- a/static/js/dynamicscrolling.js +++ b/static/js/dynamicscrolling.js @@ -32,16 +32,21 @@ document.addEventListener("DOMContentLoaded", function() { loadingIndicator.style.display = 'none'; const parser = new DOMParser(); const doc = parser.parseFromString(data, 'text/html'); - const newResults = doc.getElementById('results').innerHTML; + const newResultsHTML = doc.getElementById('results').innerHTML; const noResultsMessage = `No results found for '${query}'. Try different keywords.`; const endOfResultsMessage = "Looks like this is the end of results."; const serverError = "Internal Server Error"; - if (newResults.includes(noResultsMessage) || newResults.includes(endOfResultsMessage) || newResults.includes(serverError)) { - document.getElementById('results').innerHTML += newResults; + const resultsContainer = document.getElementById('results'); + const tempDiv = document.createElement('div'); + tempDiv.innerHTML = newResultsHTML; + while (tempDiv.firstChild) { + resultsContainer.appendChild(tempDiv.firstChild); + } + + if (newResultsHTML.includes(noResultsMessage) || newResultsHTML.includes(endOfResultsMessage) || newResultsHTML.includes(serverError)) { hasMoreResults = false; } else { - document.getElementById('results').innerHTML += newResults; page = newPage; // Automatically load more results if content height is less than window height checkIfMoreResultsNeeded(); diff --git a/static/js/imageviewer.js b/static/js/imageviewer.js new file mode 100644 index 0000000..ca54778 --- /dev/null +++ b/static/js/imageviewer.js @@ -0,0 +1,101 @@ +document.addEventListener('DOMContentLoaded', function() { + let viewerOpen = false; + + const viewerOverlay = document.getElementById('image-viewer-overlay'); + viewerOverlay.innerHTML = ` +
+
+ + +
+ +
+ +
+
+

+

View source:

+

+ Show source website + Show in fullscreen +

+
+ `; + + const imageView = document.getElementById('image-viewer'); + + function openImageViewer(element) { + const parentImageDiv = element.closest('.image'); + if (!parentImageDiv) return; + + const imgElement = parentImageDiv.querySelector('img.clickable'); + const fullImageUrl = imgElement.dataset.proxyFull; // Use data-proxy-full for ProxyFull + const thumbnailUrl = imgElement.src; // Use ProxyThumb for the thumbnail + const title = imgElement.alt; + const sourceUrl = parentImageDiv.querySelector('.img_source').href; // Source webpage URL + + if (!fullImageUrl || 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'); + const fullSizeLink = imageView.querySelector('.full-size'); + const proxySizeLink = imageView.querySelector('.proxy-size'); + + // Set the viewer image to ProxyFull + viewerImage.src = fullImageUrl; + viewerTitle.textContent = title; + viewerSourceButton.href = sourceUrl; + fullSizeLink.href = sourceUrl; // Link to the source website + proxySizeLink.href = fullImageUrl; // Link to the proxied full-size image + + 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(); + } + } + }); +}); diff --git a/templates/images.html b/templates/images.html index 0b77938..c5b7b62 100755 --- a/templates/images.html +++ b/templates/images.html @@ -217,118 +217,15 @@ - +