first commit
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
// ═══════════════════════════════════════════════════════
|
||||
// Diff Checker
|
||||
// ═══════════════════════════════════════════════════════
|
||||
function computeDiff() {
|
||||
const a = document.getElementById('diffA').value.split('\n');
|
||||
const b = document.getElementById('diffB').value.split('\n');
|
||||
const max = Math.max(a.length, b.length);
|
||||
let html = '';
|
||||
for (let i = 0; i < max; i++) {
|
||||
const la = a[i] !== undefined ? a[i] : null;
|
||||
const lb = b[i] !== undefined ? b[i] : null;
|
||||
const esc = s => s.replace(/[<>&]/g, c => ({'<':'<','>':'>','&':'&'}[c]));
|
||||
if (la === null) html += `<div class="diff-line diff-add">+ ${esc(lb)}</div>`;
|
||||
else if (lb === null) html += `<div class="diff-line diff-del">- ${esc(la)}</div>`;
|
||||
else if (la === lb) html += `<div class="diff-line diff-same"> ${esc(la)}</div>`;
|
||||
else {
|
||||
html += `<div class="diff-line diff-del">- ${esc(la)}</div>`;
|
||||
html += `<div class="diff-line diff-add">+ ${esc(lb)}</div>`;
|
||||
}
|
||||
}
|
||||
document.getElementById('diffOutput').innerHTML = html || '<span style="color:var(--text-muted);">Texts are identical.</span>';
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user