beautifying shitpost mode even more!
This commit is contained in:
@@ -325,6 +325,20 @@ window.initUploadForm = (selector) => {
|
|||||||
|
|
||||||
lastFetchedUrl = currentVal;
|
lastFetchedUrl = currentVal;
|
||||||
|
|
||||||
|
// In shitpost mode: fetch silently (cache only, badge stays hidden)
|
||||||
|
if (isShitpost) {
|
||||||
|
try {
|
||||||
|
const resp = await fetch(`/api/v2/meta/fetch?url=${encodeURIComponent(currentVal)}`);
|
||||||
|
const data = await resp.json();
|
||||||
|
if (data.success && data.meta) {
|
||||||
|
const fields = extractFieldsFromMeta(data.meta);
|
||||||
|
metaCache.set(currentVal, fields);
|
||||||
|
fields.forEach(v => addMetaSuggestion(v));
|
||||||
|
}
|
||||||
|
} catch (e) { console.error('[META FETCH ERROR]', e); }
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (urlBadge) {
|
if (urlBadge) {
|
||||||
const originalText = urlBadge.textContent;
|
const originalText = urlBadge.textContent;
|
||||||
const originalClass = urlBadge.className;
|
const originalClass = urlBadge.className;
|
||||||
@@ -376,8 +390,8 @@ window.initUploadForm = (selector) => {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update badge for URL type
|
// Update badge for URL type (non-shitpost only)
|
||||||
if (urlBadge) {
|
if (urlBadge && !isShitpost) {
|
||||||
if (ytRegex.test(val) && window.f0ckEnableYoutubeUpload !== false) {
|
if (ytRegex.test(val) && window.f0ckEnableYoutubeUpload !== false) {
|
||||||
urlBadge.textContent = '▶ YouTube';
|
urlBadge.textContent = '▶ YouTube';
|
||||||
urlBadge.className = 'url-type-badge youtube';
|
urlBadge.className = 'url-type-badge youtube';
|
||||||
@@ -425,7 +439,7 @@ window.initUploadForm = (selector) => {
|
|||||||
handleFile();
|
handleFile();
|
||||||
});
|
});
|
||||||
|
|
||||||
if (urlBadge) {
|
if (urlBadge && !isShitpost) {
|
||||||
urlBadge.addEventListener('click', () => {
|
urlBadge.addEventListener('click', () => {
|
||||||
const val = urlInput.value.trim();
|
const val = urlInput.value.trim();
|
||||||
if (val && /^https?:\/\//i.test(val)) {
|
if (val && /^https?:\/\//i.test(val)) {
|
||||||
@@ -643,7 +657,8 @@ window.initUploadForm = (selector) => {
|
|||||||
if (fileInput) fileInput.style.display = 'none';
|
if (fileInput) fileInput.style.display = 'none';
|
||||||
if (filePreview) {
|
if (filePreview) {
|
||||||
filePreview.style.display = 'flex';
|
filePreview.style.display = 'flex';
|
||||||
filePreview.innerHTML = '';
|
// Do NOT clear innerHTML here — existing rendered items stay in place.
|
||||||
|
// Only new (un-rendered) items will be appended below.
|
||||||
}
|
}
|
||||||
|
|
||||||
if (statusDiv) {
|
if (statusDiv) {
|
||||||
@@ -661,8 +676,9 @@ window.initUploadForm = (selector) => {
|
|||||||
activeMode = 'file';
|
activeMode = 'file';
|
||||||
}
|
}
|
||||||
|
|
||||||
// Build preview items
|
// Build preview items — skip items already rendered (append-only)
|
||||||
selectedFiles.forEach((item, index) => {
|
selectedFiles.forEach((item, index) => {
|
||||||
|
if (item._rendered) return; // already in DOM, don't touch it
|
||||||
const isUrl = isShitpost && item.type === 'url';
|
const isUrl = isShitpost && item.type === 'url';
|
||||||
const file = isUrl ? null : (isShitpost ? item.file : item);
|
const file = isUrl ? null : (isShitpost ? item.file : item);
|
||||||
const previewItem = document.createElement('div');
|
const previewItem = document.createElement('div');
|
||||||
@@ -1028,10 +1044,27 @@ window.initUploadForm = (selector) => {
|
|||||||
removeBtn.innerHTML = '✕';
|
removeBtn.innerHTML = '✕';
|
||||||
removeBtn.onclick = (e) => {
|
removeBtn.onclick = (e) => {
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
selectedFiles.splice(index, 1);
|
// Remove by reference (index may have shifted after prior removals)
|
||||||
handleFile(); // Rebuild UI
|
const idx = selectedFiles.indexOf(item);
|
||||||
|
if (idx !== -1) selectedFiles.splice(idx, 1);
|
||||||
|
item._rendered = false;
|
||||||
|
previewItem.remove();
|
||||||
|
|
||||||
|
if (selectedFiles.length === 0) {
|
||||||
|
// Reset to empty state
|
||||||
|
if (filePreview) { filePreview.style.display = 'none'; filePreview.innerHTML = ''; }
|
||||||
|
if (dropZonePrompt) dropZonePrompt.style.display = 'block';
|
||||||
|
if (fileInput) { fileInput.value = ''; fileInput.style.display = 'inline-block'; }
|
||||||
|
} else {
|
||||||
|
// Ensure the "Add more" button is still last
|
||||||
|
const addMoreEl = filePreview?.querySelector('.add-more-item');
|
||||||
|
if (addMoreEl) filePreview.appendChild(addMoreEl);
|
||||||
|
}
|
||||||
|
updateSubmitButton();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
item._rendered = true;
|
||||||
|
|
||||||
// Append media column (URL items) or raw media element (file items)
|
// Append media column (URL items) or raw media element (file items)
|
||||||
if (mediaCol) {
|
if (mediaCol) {
|
||||||
previewItem.appendChild(mediaCol);
|
previewItem.appendChild(mediaCol);
|
||||||
@@ -1043,13 +1076,16 @@ window.initUploadForm = (selector) => {
|
|||||||
if (filePreview) filePreview.appendChild(previewItem);
|
if (filePreview) filePreview.appendChild(previewItem);
|
||||||
});
|
});
|
||||||
|
|
||||||
// "Add more" button for Shitpost Mode
|
// "Add more" button for Shitpost Mode — reuse existing or create once, always move to end
|
||||||
if (isShitpost) {
|
if (isShitpost && filePreview) {
|
||||||
const addMoreItem = document.createElement('div');
|
let addMoreItem = filePreview.querySelector('.add-more-item');
|
||||||
|
if (!addMoreItem) {
|
||||||
|
addMoreItem = document.createElement('div');
|
||||||
addMoreItem.className = 'file-preview-item add-more-item';
|
addMoreItem.className = 'file-preview-item add-more-item';
|
||||||
addMoreItem.innerHTML = `<span>${window.f0ckI18n?.upload_add_more || 'Add more'}</span>`;
|
addMoreItem.innerHTML = `<span>${window.f0ckI18n?.upload_add_more || 'Add more'}</span>`;
|
||||||
addMoreItem.onclick = () => fileInput && fileInput.click();
|
addMoreItem.onclick = () => fileInput && fileInput.click();
|
||||||
if (filePreview) filePreview.appendChild(addMoreItem);
|
}
|
||||||
|
filePreview.appendChild(addMoreItem); // moves it to end if already present
|
||||||
}
|
}
|
||||||
|
|
||||||
// Legacy Global Meta Sync (Non-Shitpost Mode)
|
// Legacy Global Meta Sync (Non-Shitpost Mode)
|
||||||
|
|||||||
@@ -24,6 +24,7 @@
|
|||||||
<!-- Preview Container -->
|
<!-- Preview Container -->
|
||||||
<div class="file-preview" style="display: none;">
|
<div class="file-preview" style="display: none;">
|
||||||
<!-- Video will be injected here via JS -->
|
<!-- Video will be injected here via JS -->
|
||||||
|
@if(!shitpost_mode)
|
||||||
<div class="file-meta-row">
|
<div class="file-meta-row">
|
||||||
<div class="file-info">
|
<div class="file-info">
|
||||||
<span class="file-name"></span>
|
<span class="file-name"></span>
|
||||||
@@ -31,6 +32,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<button type="button" class="btn-remove" title="{{ t('upload.remove_file') }}">✕</button>
|
<button type="button" class="btn-remove" title="{{ t('upload.remove_file') }}">✕</button>
|
||||||
</div>
|
</div>
|
||||||
|
@endif
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user