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
|
@echo off
|
||||||
setlocal enabledelayedexpansion
|
setlocal enabledelayedexpansion
|
||||||
|
|
||||||
rem Directory where the Go files are located
|
rem Use the current directory where the script is executed
|
||||||
set GO_DIR=C:\path\to\your\go\files
|
pushd %~dp0
|
||||||
|
|
||||||
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 Collect all .go files in the current directory
|
||||||
|
set GO_FILES=
|
||||||
for %%f in (*.go) do (
|
for %%f in (*.go) do (
|
||||||
set file=%%~nxf
|
set GO_FILES=!GO_FILES! %%f
|
||||||
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"
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
rem Run the Go program with the specified files first, followed by the remaining files
|
rem Run the Go program with all the .go files
|
||||||
go run %FILES% %OTHER_GO_FILES%
|
go run !GO_FILES!
|
||||||
|
|
||||||
rem Return to the original directory
|
rem Return to the original directory
|
||||||
popd
|
popd
|
||||||
|
|
33
run.sh
33
run.sh
|
@ -1,34 +1,7 @@
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
# Explicitly list the main files in the required order
|
# List all go files in this directory
|
||||||
FILES="
|
GO_FILES=$(find . -name '*.go' -print)
|
||||||
./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)
|
|
||||||
|
|
||||||
# Run the Go program with the specified files first, followed by the remaining files
|
# 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';
|
loadingIndicator.style.display = 'none';
|
||||||
const parser = new DOMParser();
|
const parser = new DOMParser();
|
||||||
const doc = parser.parseFromString(data, 'text/html');
|
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 noResultsMessage = `No results found for '${query}'. Try different keywords.`;
|
||||||
const endOfResultsMessage = "Looks like this is the end of results.";
|
const endOfResultsMessage = "Looks like this is the end of results.";
|
||||||
const serverError = "Internal Server Error";
|
const serverError = "Internal Server Error";
|
||||||
|
|
||||||
if (newResults.includes(noResultsMessage) || newResults.includes(endOfResultsMessage) || newResults.includes(serverError)) {
|
const resultsContainer = document.getElementById('results');
|
||||||
document.getElementById('results').innerHTML += newResults;
|
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;
|
hasMoreResults = false;
|
||||||
} else {
|
} else {
|
||||||
document.getElementById('results').innerHTML += newResults;
|
|
||||||
page = newPage;
|
page = newPage;
|
||||||
// Automatically load more results if content height is less than window height
|
// Automatically load more results if content height is less than window height
|
||||||
checkIfMoreResultsNeeded();
|
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,118 +217,15 @@
|
||||||
<script defer src="/static/js/dynamicscrolling.js"></script>
|
<script defer src="/static/js/dynamicscrolling.js"></script>
|
||||||
<script defer src="/static/js/autocomplete.js"></script>
|
<script defer src="/static/js/autocomplete.js"></script>
|
||||||
<script defer src="/static/js/imagetitletrim.js"></script>
|
<script defer src="/static/js/imagetitletrim.js"></script>
|
||||||
<script>
|
<script defer src="/static/js/imageviewer.js"></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>
|
|
||||||
<!-- JavaScript to Load Images -->
|
<!-- JavaScript to Load Images -->
|
||||||
<script>
|
<script>
|
||||||
document.addEventListener("DOMContentLoaded", function() {
|
document.addEventListener("DOMContentLoaded", function() {
|
||||||
const templateData = document.getElementById('template-data');
|
const templateData = document.getElementById('template-data');
|
||||||
const hardCacheEnabled = templateData.getAttribute('data-hard-cache-enabled') === 'true';
|
const hardCacheEnabled = templateData.getAttribute('data-hard-cache-enabled') === 'true';
|
||||||
|
|
||||||
if (hardCacheEnabled) {
|
if (hardCacheEnabled) {
|
||||||
// Hard cache is disabled, so skip polling and load images directly
|
// Immediate loading of images
|
||||||
const images = document.querySelectorAll("img[data-id]");
|
const images = document.querySelectorAll("img[data-id]");
|
||||||
images.forEach((img) => {
|
images.forEach((img) => {
|
||||||
// Use the ProxyFull URL directly
|
// Use the ProxyFull URL directly
|
||||||
|
@ -342,12 +239,11 @@
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let imageMap = {}; // Map of image IDs to img elements
|
let imageMap = {}; // Map of image IDs to img elements
|
||||||
let loadedImageIDs = new Set(); // Keep track of loaded image IDs
|
let loadedImageIDs = new Set(); // Keep track of loaded image IDs
|
||||||
let pollingInterval = 2000; // Initial polling interval in milliseconds
|
let pollingInterval = 2000; // Polling interval in milliseconds
|
||||||
let polling = false;
|
|
||||||
|
|
||||||
function initializeImages() {
|
function initializeImages() {
|
||||||
const images = document.querySelectorAll("img[data-id]");
|
const images = document.querySelectorAll("img[data-id]");
|
||||||
images.forEach((img) => {
|
images.forEach((img) => {
|
||||||
|
@ -357,10 +253,10 @@
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initialize with images present at page load
|
// Initialize with images present at page load
|
||||||
initializeImages();
|
initializeImages();
|
||||||
|
|
||||||
// Set up MutationObserver to detect new images added to the DOM
|
// Set up MutationObserver to detect new images added to the DOM
|
||||||
const observer = new MutationObserver((mutationsList) => {
|
const observer = new MutationObserver((mutationsList) => {
|
||||||
for (let mutation of mutationsList) {
|
for (let mutation of mutationsList) {
|
||||||
|
@ -373,9 +269,6 @@
|
||||||
if (!imageMap[id]) {
|
if (!imageMap[id]) {
|
||||||
imageMap[id] = img;
|
imageMap[id] = img;
|
||||||
console.log('New image added:', id);
|
console.log('New image added:', id);
|
||||||
if (!polling) {
|
|
||||||
checkImageStatus(); // Start polling if not already started
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Check for nested images within added nodes
|
// Check for nested images within added nodes
|
||||||
|
@ -386,9 +279,6 @@
|
||||||
if (!imageMap[id]) {
|
if (!imageMap[id]) {
|
||||||
imageMap[id] = img;
|
imageMap[id] = img;
|
||||||
console.log('New nested image added:', id);
|
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 });
|
observer.observe(document.body, { childList: true, subtree: true });
|
||||||
|
|
||||||
function checkImageStatus() {
|
function checkImageStatus() {
|
||||||
polling = true;
|
|
||||||
const imageIDs = Object.keys(imageMap).filter(id => !loadedImageIDs.has(id));
|
const imageIDs = Object.keys(imageMap).filter(id => !loadedImageIDs.has(id));
|
||||||
if (imageIDs.length === 0) {
|
if (imageIDs.length === 0) {
|
||||||
polling = false;
|
|
||||||
console.log('All images loaded.');
|
console.log('All images loaded.');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -454,8 +342,11 @@
|
||||||
setTimeout(checkImageStatus, pollingInterval * 2);
|
setTimeout(checkImageStatus, pollingInterval * 2);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Start polling
|
// Start polling every pollingInterval milliseconds
|
||||||
|
const pollingIntervalId = setInterval(checkImageStatus, pollingInterval);
|
||||||
|
|
||||||
|
// Optionally, call checkImageStatus immediately
|
||||||
checkImageStatus();
|
checkImageStatus();
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
Loading…
Add table
Reference in a new issue