First of all, thank you for a fantastic forum application. I've just made my forum. Hopefully the traffic will soon follow.
And as a thank you, I've made this script which can be placed in the forum html header.
When a post is opened, it injects a image upload button into the text area.
You'll need an API Key for it to work - add it to the code.
<div id="bbModal" style="display: none; position: fixed; z-index: 9999; left: 0; top: 0; width: 100%; height: 100%; background-color: rgba(0,0,0,0.7); backdrop-filter: blur(4px);">
<div style="display: flex; justify-content: center; align-items: center; width: 100%; height: 100%;">
<div style="background-color: #fff; border-radius: 8px; width: 420px; max-width: 92%; box-shadow: 0 10px 30px rgba(0,0,0,0.5); overflow: hidden;">
<div style="background: #2c3e50; color: white; padding: 15px; display: flex; justify-content: space-between; align-items: center;">
<span style="font-family: 'Segoe UI', sans-serif; font-weight: bold;">Image Uploader</span>
<span id="closeBB" style="cursor: pointer; font-size: 24px; line-height: 20px; padding: 5px;">×</span>
</div>
<div style="padding: 25px; text-align: center; font-family: 'Segoe UI', sans-serif;">
<div id="inputArea">
<input type="file" id="imgInput" accept="image/*" style="margin-bottom: 20px; width: 100%; font-size: 14px;">
<button id="sendToImgBB" style="background-color: #27ae60; color: white; padding: 12px; border: none; border-radius: 4px; cursor: pointer; width: 100%; font-weight: bold;">Upload Image</button>
</div>
<div id="bbStatus" style="margin-top: 15px; font-weight: bold; color: #3498db; min-height: 20px;"></div>
<div id="bbResult" style="display: none; margin-top: 10px; text-align: left;">
<div style="text-align: center; margin-bottom: 15px;">
<img id="imgPreview" src="" style="max-width: 100%; max-height: 120px; border-radius: 4px; border: 1px solid #ddd;">
</div>
<label style="font-size: 11px; font-weight: bold; color: #666; display: block; margin-bottom: 5px;">FORUM BBCODE:</label>
<textarea id="bbOutput" readonly style="width: 100%; height: 60px; font-family: monospace; font-size: 12px; padding: 10px; border: 1px solid #ddd; background: #f9f9f9; border-radius: 4px; width: 100%; box-sizing: border-box;"></textarea>
<div style="display: flex; gap: 10px; margin-top: 10px;">
<button id="copyBB" style="flex: 2; padding: 10px; background: #2c3e50; color: white; border: none; border-radius: 4px; font-weight: bold; cursor: pointer;">Copy to Clipboard</button>
<button id="resetBB" style="flex: 1; padding: 10px; background: #e74c3c; color: white; border: none; border-radius: 4px; font-weight: bold; cursor: pointer;">Clear</button>
</div>
</div>
</div>
</div>
</div>
</div>
<style>
#openImgBB { background: transparent; border: none; color: #667c99; padding: 5px; cursor: pointer; font-size: 18px; transition: color 0.2s; vertical-align: middle; }
#openImgBB:hover { color: #3498db; }
</style>
<div id="triggerWrapper" style="display: none; margin-right: 5px; vertical-align: middle;">
<button id="openImgBB" type="button" title="Upload Image">
<i class="fas fa-upload"></i>
</button>
</div>
<script>
const IMGBB_API_KEY = 'PASTE-YOUR-API-KEY-HERE';
function checkComposer() {
const target = document.querySelector('.Composer-footer .Composer-controls') || document.querySelector('.TextEditor-controls');
const trigger = document.getElementById('triggerWrapper');
if (target && trigger && !target.contains(trigger)) {
trigger.style.display = 'inline-block';
target.prepend(trigger);
}
}
setInterval(checkComposer, 500);
const modal = document.getElementById("bbModal");
const imgInput = document.getElementById("imgInput");
const status = document.getElementById("bbStatus");
document.getElementById("openImgBB").onclick = (e) => { e.preventDefault(); modal.style.display = "block"; };
document.getElementById("closeBB").onclick = () => { modal.style.display = "none"; fullReset(); };
window.onclick = (e) => { if (e.target == modal) modal.style.display = "none"; };
document.getElementById('sendToImgBB').onclick = async function() {
const file = imgInput.files[0];
if (!file) return alert("Please select an image first.");
status.style.color = "#3498db";
status.innerText = "Uploading...";
document.getElementById("inputArea").style.display = "none";
const formData = new FormData();
formData.append('image', file);
try {
const response = await fetch(`https://api.imgbb.com/1/upload?expiration=0&key=${IMGBB_API_KEY}`, {
method: 'POST',
body: formData
});
const data = await response.json();
if (data.success) {
status.style.color = "#27ae60";
status.innerText = "Upload successful!";
document.getElementById('imgPreview').src = data.data.thumb.url;
document.getElementById('bbOutput').value = `[img]${data.data.url}[/img]`;
document.getElementById('bbResult').style.display = "block";
} else {
status.style.color = "red";
status.innerText = "Error: " + data.error.message;
document.getElementById("inputArea").style.display = "block";
}
} catch (err) {
status.style.color = "red";
status.innerText = "Upload failed.";
document.getElementById("inputArea").style.display = "block";
}
};
function fullReset() {
status.innerText = "";
document.getElementById('bbResult').style.display = "none";
document.getElementById("inputArea").style.display = "block";
imgInput.value = "";
}
document.getElementById('resetBB').onclick = fullReset;
document.getElementById('copyBB').onclick = function() {
document.getElementById('bbOutput').select();
document.execCommand("copy");
alert("Copied to clipboard!");
};
</script>