You can edit the below JavaScript code to customize the image tool.
Apply Changes
async function processImage(originalImg, highlightColor = "#00FF00") {
// Create base canvas
const canvas = document.createElement("canvas");
canvas.width = originalImg.width;
canvas.height = originalImg.height;
const ctx = canvas.getContext("2d");
// Draw original image initially
ctx.drawImage(originalImg, 0, 0);
return new Promise((resolve) => {
// Function to run text detection and evaluation
const runScanner = () => {
window.Tesseract.recognize(originalImg, 'eng')
.then(({ data: { words } }) => {
const domainRegex = /^(?:https?:\/\/)?(?:www\.)?([a-zA-Z0-9-]+\.)+[a-zA-Z]{2,}(?:\/.*)?$/i;
let foundCount = 0;
const scaleFactor = Math.max(1, originalImg.width / 800);
ctx.lineWidth = Math.max(2, 3 * scaleFactor);
const labelSize = Math.max(12, 16 * scaleFactor);
ctx.font = `bold ${labelSize}px monospace`;
if (words && words.length > 0) {
words.forEach(word => {
if (!word || !word.text) return;
const text = word.text.trim();
if (text.length < 3) return;
// Check for Domain features
const hasDomainTld = /\.(com|net|org|io|co|us|uk|gov|edu|dev|app|ai)$/i.test(text);
const isDomain = domainRegex.test(text) || hasDomainTld || /^www\./i.test(text) || /^https?:\/\//i.test(text);
// Check for Identifier (UUIDs, Hashes, Session IDs) features
const isCommonWord = /^(password|username|login|submit|cancel|search|menu|home|about|contact|email|user|name|date|time|link)$/i.test(text);
const isNumberSequence = /^[0-9]+$/.test(text);
const hasNumbersOrSpecialChars = /[0-9_*-]/.test(text);
const isHex = /^[0-9A-Fa-f]{8,}$/.test(text);
const isIdentifier = (!isDomain && !isCommonWord) &&
(isHex || (text.length >= 8 && hasNumbersOrSpecialChars && !isNumberSequence) || /^[A-Z0-9_-]{10,}$/.test(text));
// If recognized, draw bounding box and label
if (isDomain || isIdentifier) {
foundCount++;
const { x0, y0, x1, y1 } = word.bbox;
// Box
ctx.strokeStyle = highlightColor;
ctx.strokeRect(x0, y0, x1 - x0, y1 - y0);
// Label Background
const label = isDomain ? `DOMAIN: ${text}` : `ID: ${text}`;
const textMeasure = ctx.measureText(label);
ctx.fillStyle = "rgba(0, 0, 0, 0.8)";
ctx.fillRect(x0, y0 - labelSize - 6, textMeasure.width + 10, labelSize + 6);
// Label Text
ctx.fillStyle = highlightColor;
ctx.textBaseline = "bottom";
ctx.fillText(label, x0 + 5, y0 - 2);
}
});
}
// Display fallback message if no domains or IDs are found
if (foundCount === 0) {
ctx.fillStyle = "rgba(0, 0, 0, 0.7)";
ctx.fillRect(0, 0, canvas.width, labelSize * 4);
ctx.fillStyle = "yellow";
ctx.textBaseline = "middle";
ctx.fillText("No Domains or Identifiers found in image.", 20, (labelSize * 4) / 2);
}
resolve(canvas);
})
.catch(err => {
console.error("Scanner Error:", err);
drawError("Scanner Error occurred during processing.");
resolve(canvas); // Resolve to allow pipeline to continue
});
};
const drawError = (msg) => {
const fontSize = Math.max(16, canvas.width / 40);
ctx.fillStyle = "rgba(0, 0, 0, 0.7)";
ctx.fillRect(0, 0, canvas.width, fontSize * 3);
ctx.fillStyle = "red";
ctx.font = `bold ${fontSize}px monospace`;
ctx.textBaseline = "middle";
ctx.fillText(msg, 20, (fontSize * 3) / 2);
};
// Dynamically load Tesseract.js if not available
if (window.Tesseract) {
runScanner();
} else {
const script = document.createElement("script");
script.src = "https://cdn.jsdelivr.net/npm/tesseract.js@4/dist/tesseract.min.js";
script.onload = () => runScanner();
script.onerror = () => {
drawError("Failed to load Text Scanner API Library.");
resolve(canvas);
};
document.head.appendChild(script);
}
});
}
Apply Changes