clean up
This commit is contained in:
parent
81a1add837
commit
5a4be6dad6
5 changed files with 133 additions and 177 deletions
28
run.bat
28
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
|
||||
|
|
33
run.sh
33
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
|
||||
|
|
|
@ -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();
|
||||
|
|
101
static/js/imageviewer.js
Normal file
101
static/js/imageviewer.js
Normal file
|
@ -0,0 +1,101 @@
|
|||
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> FIX THIS LATER! --!>
|
||||
<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">
|
||||
<div class="view-image" id="viewer-image-container">
|
||||
<img id="viewer-image" class="view-image-img" src="" alt="">
|
||||
</div>
|
||||
</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>
|
||||
</p>
|
||||
</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 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();
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
|
@ -217,110 +217,7 @@
|
|||
<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" 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> FIX THIS LATER! --!>
|
||||
<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">
|
||||
<div class="view-image" id="viewer-image-container">
|
||||
<img id="viewer-image" class="view-image-img" src="" alt="">
|
||||
</div>
|
||||
</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>
|
||||
</p>
|
||||
</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 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();
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
</script>
|
||||
<script defer src="/static/js/imageviewer.js"></script>
|
||||
<!-- JavaScript to Load Images -->
|
||||
<script>
|
||||
document.addEventListener("DOMContentLoaded", function() {
|
||||
|
@ -328,7 +225,7 @@
|
|||
const hardCacheEnabled = templateData.getAttribute('data-hard-cache-enabled') === 'true';
|
||||
|
||||
if (hardCacheEnabled) {
|
||||
// Hard cache is disabled, so skip polling and load images directly
|
||||
// Immediate loading of images
|
||||
const images = document.querySelectorAll("img[data-id]");
|
||||
images.forEach((img) => {
|
||||
// Use the ProxyFull URL directly
|
||||
|
@ -345,8 +242,7 @@
|
|||
|
||||
let imageMap = {}; // Map of image IDs to img elements
|
||||
let loadedImageIDs = new Set(); // Keep track of loaded image IDs
|
||||
let pollingInterval = 2000; // Initial polling interval in milliseconds
|
||||
let polling = false;
|
||||
let pollingInterval = 2000; // Polling interval in milliseconds
|
||||
|
||||
function initializeImages() {
|
||||
const images = document.querySelectorAll("img[data-id]");
|
||||
|
@ -373,9 +269,6 @@
|
|||
if (!imageMap[id]) {
|
||||
imageMap[id] = img;
|
||||
console.log('New image added:', id);
|
||||
if (!polling) {
|
||||
checkImageStatus(); // Start polling if not already started
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Check for nested images within added nodes
|
||||
|
@ -386,9 +279,6 @@
|
|||
if (!imageMap[id]) {
|
||||
imageMap[id] = img;
|
||||
console.log('New nested image added:', id);
|
||||
if (!polling) {
|
||||
checkImageStatus(); // Start polling if not already started
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -403,10 +293,8 @@
|
|||
observer.observe(document.body, { childList: true, subtree: true });
|
||||
|
||||
function checkImageStatus() {
|
||||
polling = true;
|
||||
const imageIDs = Object.keys(imageMap).filter(id => !loadedImageIDs.has(id));
|
||||
if (imageIDs.length === 0) {
|
||||
polling = false;
|
||||
console.log('All images loaded.');
|
||||
return;
|
||||
}
|
||||
|
@ -455,7 +343,10 @@
|
|||
});
|
||||
}
|
||||
|
||||
// Start polling
|
||||
// Start polling every pollingInterval milliseconds
|
||||
const pollingIntervalId = setInterval(checkImageStatus, pollingInterval);
|
||||
|
||||
// Optionally, call checkImageStatus immediately
|
||||
checkImageStatus();
|
||||
});
|
||||
</script>
|
||||
|
|
Loading…
Add table
Reference in a new issue