Adding option to log users ips

This commit is contained in:
2026-05-11 07:45:00 +02:00
parent 862b145c77
commit 1221e0580f
16 changed files with 306 additions and 38 deletions

View File

@@ -23,6 +23,14 @@ window.cancelAnimFrame = (function () {
return div.innerHTML;
};
window.getCurrentItemId = () => {
const path = window.location.pathname;
// Explicitly ignore admin/mod/settings paths to avoid false positives from user IDs, etc.
if (path.includes('/admin/') || path.includes('/mod/') || path.includes('/settings') || path.includes('/user/')) return null;
const match = path.match(/\/(\d+)\/?$/);
return match ? match[1] : null;
};
// OS and Browser detection for CSS targeting
const ua = navigator.userAgent;
const htmlEl = document.documentElement;
@@ -120,9 +128,7 @@ window.cancelAnimFrame = (function () {
});
// Refresh background canvas if it matches the current item
const pathParts = window.location.pathname.split('/');
const numParts = pathParts.filter(s => /^\d+$/.test(s));
const currentId = numParts.length > 0 ? numParts[numParts.length - 1] : null;
const currentId = window.getCurrentItemId();
if (currentId === idStr && window.initBackground) {
window.initBackground();
}
@@ -943,9 +949,7 @@ window.cancelAnimFrame = (function () {
// Always use the thumbnail first for instant backdrop — thumbnails are tiny,
// often browser-cached from grid view, and give us a frame-0 equivalent for GIFs too.
// Extract item ID from URL for thumbnail path.
const pathParts = window.location.pathname.split('/');
const numParts = pathParts.filter(s => /^\d+$/.test(s));
const itemId = numParts.length > 0 ? numParts[numParts.length - 1] : null;
const itemId = window.getCurrentItemId();
const showCanvas = () => {
canvas.classList.remove('fader-out', 'fast-fade');
@@ -1055,9 +1059,7 @@ window.cancelAnimFrame = (function () {
if (background) {
canvas._bgFadingOut = false;
// Draw the item thumbnail if we have an item ID in the URL
const pathParts = window.location.pathname.split('/');
const numParts = pathParts.filter(s => /^\d+$/.test(s));
const itemId = numParts.length > 0 ? numParts[numParts.length - 1] : null;
const itemId = window.getCurrentItemId();
if (itemId) {
const context = canvas.getContext('2d');
const cw = canvas.width = canvas.clientWidth | 0;

View File

@@ -1,11 +1,11 @@
const escapeHtmlUpload = (unsafe) => {
window.escapeHtmlUpload = window.escapeHtmlUpload || ((unsafe) => {
return (unsafe || '').toString()
.replace(/&/g, "&")
.replace(/</g, "&lt;")
.replace(/>/g, "&gt;")
.replace(/"/g, "&quot;")
.replace(/'/g, "&#039;");
};
});
window.initUploadForm = (selector) => {
const form = (typeof selector === 'string') ? document.querySelector(selector) : selector;
@@ -749,7 +749,7 @@ window.initUploadForm = (selector) => {
chip.className = 'tag-chip';
chip.style.cursor = 'pointer';
chip.title = 'Click to edit prefix or tag';
chip.innerHTML = `<span class="tag-text">${escapeHtmlUpload(tagName)}</span><button type="button">&times;</button>`;
chip.innerHTML = `<span class="tag-text">${window.escapeHtmlUpload(tagName)}</span><button type="button">&times;</button>`;
// Remove button logic
chip.querySelector('button').addEventListener('click', (e) => {
@@ -867,7 +867,7 @@ window.initUploadForm = (selector) => {
const sug = document.createElement('div');
sug.className = 'meta-suggestion';
sug.setAttribute('data-text', text);
sug.innerHTML = `<i class="fa fa-plus-circle" style="user-select:none"></i> <span>${escapeHtmlUpload(text)}</span>`;
sug.innerHTML = `<i class="fa fa-plus-circle" style="user-select:none"></i> <span>${window.escapeHtmlUpload(text)}</span>`;
sug.addEventListener('mouseup', (ev) => {
const sel = window.getSelection?.()?.toString().trim();
@@ -976,7 +976,7 @@ window.initUploadForm = (selector) => {
const scoreStr = typeof s.score === 'number' ? s.score.toFixed(2) : '0.00';
html += `
<div class="tag-suggestion-item">
<span class="tag-suggestion-name">${escapeHtmlUpload(s.tag)}</span>
<span class="tag-suggestion-name">${window.escapeHtmlUpload(s.tag)}</span>
<span class="tag-suggestion-meta">${s.tagged || 0}× · ${scoreStr}</span>
</div>
`;