-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
436 lines (400 loc) · 20.2 KB
/
Copy pathindex.html
File metadata and controls
436 lines (400 loc) · 20.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<title>Text Diff & Compare Tool Online — Free Side-by-Side Comparison | BeLikeNative</title>
<meta name="description" content="Free online text diff tool. Compare two texts side-by-side, see additions, deletions, and changes highlighted. Line-by-line and word-level diff views. No signup required.">
<meta name="keywords" content="text diff online, compare two texts, text comparison tool, diff checker, text difference, online diff tool">
<meta name="author" content="BeLikeNative">
<meta name="robots" content="index, follow">
<link rel="canonical" href="https://theluckystrike.github.io/bln-text-diff/">
<meta property="og:title" content="Text Diff & Compare Tool Online — Free | BeLikeNative">
<meta property="og:description" content="Compare two texts side-by-side. See additions, deletions, and changes highlighted instantly. Free, no signup.">
<meta property="og:type" content="website">
<meta property="og:url" content="https://theluckystrike.github.io/bln-text-diff/">
<style>
*{margin:0;padding:0;box-sizing:border-box}
body{font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,sans-serif;background:#0f1117;color:#e1e4e8;min-height:100vh;display:flex;flex-direction:column}
header{background:#161b22;border-bottom:1px solid #30363d;padding:12px 20px;display:flex;align-items:center;justify-content:space-between;flex-wrap:wrap;gap:8px}
.logo{font-size:18px;font-weight:700;color:#58a6ff}
.logo span{color:#f0883e}
.toolbar{display:flex;gap:6px;flex-wrap:wrap;align-items:center}
.toolbar button{background:#21262d;color:#c9d1d9;border:1px solid #30363d;padding:6px 14px;border-radius:6px;cursor:pointer;font-size:13px;transition:background .2s}
.toolbar button:hover{background:#30363d}
.toolbar button.primary{background:#238636;border-color:#2ea043;color:#fff}
.toolbar button.primary:hover{background:#2ea043}
.toolbar select{background:#21262d;color:#c9d1d9;border:1px solid #30363d;padding:6px 10px;border-radius:6px;font-size:13px;cursor:pointer}
.input-area{display:flex;gap:0;flex:0 0 auto}
.input-pane{flex:1;display:flex;flex-direction:column;min-width:0}
.input-pane-header{background:#161b22;padding:8px 16px;font-size:13px;font-weight:600;color:#8b949e;border-bottom:1px solid #30363d}
.input-pane textarea{width:100%;height:220px;background:#0d1117;color:#c9d1d9;border:none;border-right:1px solid #30363d;padding:12px;font-family:'SF Mono',Monaco,Consolas,monospace;font-size:13px;line-height:1.5;resize:vertical;outline:none}
.input-pane:last-child textarea{border-right:none}
.stats-bar{background:#161b22;border-top:1px solid #30363d;border-bottom:1px solid #30363d;padding:8px 16px;display:flex;gap:16px;flex-wrap:wrap;font-size:13px;align-items:center}
.stat{display:inline-flex;align-items:center;gap:4px}
.stat-add{color:#3fb950}
.stat-del{color:#f85149}
.stat-same{color:#8b949e}
.stat-pct{color:#58a6ff;font-weight:600}
.diff-output{flex:1;overflow:auto;padding:0;background:#0d1117}
.diff-table{width:100%;border-collapse:collapse;font-family:'SF Mono',Monaco,Consolas,monospace;font-size:13px;line-height:1.5}
.diff-table td{padding:1px 10px;vertical-align:top;white-space:pre-wrap;word-break:break-word}
.diff-table .line-num{color:#484f58;text-align:right;width:40px;min-width:40px;user-select:none;padding-right:8px;border-right:1px solid #21262d}
.diff-table .line-add{background:#0d2818;color:#aff5b4}
.diff-table .line-del{background:#2d0000;color:#ffa198}
.diff-table .line-same{color:#8b949e}
.diff-table .line-add .line-num{background:#04260f;color:#3fb950}
.diff-table .line-del .line-num{background:#2a0000;color:#f85149}
.word-add{background:#196c2e;color:#aff5b4;border-radius:2px;padding:0 1px}
.word-del{background:#8e1519;color:#ffa198;border-radius:2px;padding:0 1px;text-decoration:line-through}
.empty-state{text-align:center;padding:60px 20px;color:#484f58;font-size:15px}
.empty-state h3{color:#8b949e;margin-bottom:8px}
.cta-banner{background:#161b22;border:1px solid #30363d;border-radius:8px;margin:12px 16px;padding:14px 20px;display:flex;align-items:center;justify-content:space-between;flex-wrap:wrap;gap:8px}
.cta-banner p{font-size:13px;color:#c9d1d9}
.cta-banner a{background:#1f6feb;color:#fff;padding:6px 14px;border-radius:6px;text-decoration:none;font-size:13px;white-space:nowrap}
.cta-banner a:hover{background:#388bfd}
footer{background:#161b22;border-top:1px solid #30363d;padding:16px 20px;text-align:center;font-size:12px;color:#8b949e}
footer a{color:#58a6ff;text-decoration:none;margin:0 8px}
footer a:hover{text-decoration:underline}
.toast{position:fixed;bottom:20px;right:20px;background:#238636;color:#fff;padding:10px 18px;border-radius:8px;font-size:13px;z-index:200;opacity:0;transition:opacity .3s}
.toast.show{opacity:1}
@media(max-width:768px){
.input-area{flex-direction:column}
.input-pane textarea{height:150px;border-right:none;border-bottom:1px solid #30363d}
.cta-banner{flex-direction:column;text-align:center}
}
</style>
<script type="application/ld+json">
{
"@context":"https://schema.org",
"@type":"WebApplication",
"name":"Text Diff & Compare Tool Online",
"url":"https://theluckystrike.github.io/bln-text-diff/",
"description":"Free online text diff tool. Compare two texts side-by-side with highlighted additions, deletions, and changes. Line-by-line and word-level diff.",
"applicationCategory":"DeveloperApplication",
"operatingSystem":"Any",
"offers":{"@type":"Offer","price":"0","priceCurrency":"USD"},
"author":{"@type":"Organization","name":"BeLikeNative","url":"https://belikenative.com"}
}
</script>
<script type="application/ld+json">
{
"@context":"https://schema.org",
"@type":"FAQPage",
"mainEntity":[
{"@type":"Question","name":"How does this text diff tool work?","acceptedAnswer":{"@type":"Answer","text":"Paste your original text in the left box and the modified text in the right box, then click Compare. The tool uses a longest common subsequence algorithm to identify additions (green), deletions (red), and unchanged lines (gray)."}},
{"@type":"Question","name":"Can I compare word-by-word differences?","acceptedAnswer":{"@type":"Answer","text":"Yes. Use the view mode selector to switch between line-level and word-level diff views. Word-level view highlights individual word changes within each line."}},
{"@type":"Question","name":"Is there a size limit for text comparison?","acceptedAnswer":{"@type":"Answer","text":"The tool supports up to 1,000 lines per text input. All processing happens locally in your browser for privacy and speed."}},
{"@type":"Question","name":"Is this text comparison tool free?","acceptedAnswer":{"@type":"Answer","text":"Yes, completely free with no signup required. Your texts are never sent to any server — all diffing happens in your browser."}}
]
}
</script>
</head>
<body>
<header>
<div class="logo">Text <span>Diff</span></div>
<div class="toolbar">
<button class="primary" onclick="DiffApp.compare()">Compare</button>
<select id="viewMode" onchange="DiffApp.compare()">
<option value="line">Line-by-line</option>
<option value="word">Word-level</option>
</select>
<button onclick="DiffApp.swap()">Swap</button>
<button onclick="DiffApp.loadExample()">Example</button>
<button onclick="DiffApp.clearAll()">Clear</button>
</div>
</header>
<div class="input-area">
<div class="input-pane">
<div class="input-pane-header">Original Text</div>
<textarea id="textA" placeholder="Paste your original text here..." spellcheck="false"></textarea>
</div>
<div class="input-pane">
<div class="input-pane-header">Modified Text</div>
<textarea id="textB" placeholder="Paste your modified text here..." spellcheck="false"></textarea>
</div>
</div>
<div class="stats-bar" id="statsBar">
<span class="stat stat-add" id="statAdd">+0 added</span>
<span class="stat stat-del" id="statDel">-0 removed</span>
<span class="stat stat-same" id="statSame">0 unchanged</span>
<span class="stat stat-pct" id="statSim">Similarity: —</span>
</div>
<div class="diff-output" id="diffOutput">
<div class="empty-state">
<h3>Paste two texts above and click Compare</h3>
<p>See additions, deletions, and changes highlighted side by side.</p>
<p style="margin-top:12px;color:#58a6ff">Use case: Compare before/after writing improvements, code changes, document revisions</p>
</div>
</div>
<div class="cta-banner" id="ctaBanner" style="display:none">
<p>Want AI-powered writing improvements? BeLikeNative fixes grammar, tone, and clarity in real time.</p>
<a href="https://chromewebstore.google.com/detail/belikenative-ai-grammar-w/jbgkpmllnihjlkndomhgdpjfjbkdmoal" target="_blank" rel="noopener">Get BeLikeNative Free</a>
</div>
<div class="toast" id="toast"></div>
<footer>
<a href="https://belikenative.com" target="_blank" rel="noopener">BeLikeNative</a>
<a href="https://chromewebstore.google.com/detail/belikenative-ai-grammar-w/jbgkpmllnihjlkndomhgdpjfjbkdmoal" target="_blank" rel="noopener">Chrome Extension</a>
<a href="https://theluckystrike.github.io/bln-readability-analyzer/" target="_blank" rel="noopener">Readability Analyzer</a>
<a href="https://theluckystrike.github.io/bln-email-subject-tester/" target="_blank" rel="noopener">Email Subject Tester</a>
<a href="https://theluckystrike.github.io/bln-markdown-preview/" target="_blank" rel="noopener">Markdown Preview</a>
<a href="https://theluckystrike.github.io/bln-writing-guide/" target="_blank" rel="noopener">Writing Guide</a>
<span style="margin-left:8px">© 2026 BeLikeNative. Free developer tools.</span>
</footer>
<script>
"use strict";
var DiffApp = (function() {
/* ── Constants ── */
var MAX_LINES = 1000;
var MAX_WORDS = 5000;
/* ── Assertions ── */
function assert(cond, msg) {
if (!cond) { console.error("Assertion failed: " + msg); }
}
/* ── Toast ── */
function showToast(msg) {
var t = document.getElementById("toast");
t.textContent = msg;
t.classList.add("show");
setTimeout(function() { t.classList.remove("show"); }, 2000);
}
/* ── Escape HTML ── */
function esc(s) {
assert(typeof s === "string", "esc expects string");
return s.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">");
}
/* ── LCS for arrays of strings ── */
function computeLCS(a, b) {
assert(Array.isArray(a) && Array.isArray(b), "LCS expects arrays");
var m = a.length;
var n = b.length;
if (m === 0 || n === 0) { return []; }
/* Build DP table */
var dp = new Array(m + 1);
for (var i = 0; i <= m && i <= MAX_LINES + 1; i++) {
dp[i] = new Uint16Array(n + 1);
}
for (var i2 = 1; i2 <= m; i2++) {
for (var j = 1; j <= n; j++) {
if (a[i2 - 1] === b[j - 1]) {
dp[i2][j] = dp[i2 - 1][j - 1] + 1;
} else {
dp[i2][j] = dp[i2 - 1][j] > dp[i2][j - 1] ? dp[i2 - 1][j] : dp[i2][j - 1];
}
}
}
/* Backtrack to find LCS */
var lcs = [];
var x = m;
var y = n;
var safety = 0;
while (x > 0 && y > 0 && safety < MAX_LINES * 3) {
safety++;
if (a[x - 1] === b[y - 1]) {
lcs.unshift(a[x - 1]);
x--; y--;
} else if (dp[x - 1][y] > dp[x][y - 1]) {
x--;
} else {
y--;
}
}
return lcs;
}
/* ── Build diff operations from LCS ── */
function buildDiffOps(a, b, lcs) {
assert(Array.isArray(a), "buildDiffOps: a must be array");
assert(Array.isArray(b), "buildDiffOps: b must be array");
var ops = [];
var ai = 0, bi = 0, li = 0;
var safety = 0;
while ((ai < a.length || bi < b.length) && safety < MAX_LINES * 3) {
safety++;
if (li < lcs.length && ai < a.length && a[ai] === lcs[li] && bi < b.length && b[bi] === lcs[li]) {
ops.push({ type: "same", lineA: ai + 1, lineB: bi + 1, text: a[ai] });
ai++; bi++; li++;
} else if (li < lcs.length && ai < a.length && a[ai] !== lcs[li]) {
ops.push({ type: "del", lineA: ai + 1, lineB: null, text: a[ai] });
ai++;
} else if (li < lcs.length && bi < b.length && b[bi] !== lcs[li]) {
ops.push({ type: "add", lineA: null, lineB: bi + 1, text: b[bi] });
bi++;
} else if (li >= lcs.length && ai < a.length) {
ops.push({ type: "del", lineA: ai + 1, lineB: null, text: a[ai] });
ai++;
} else if (li >= lcs.length && bi < b.length) {
ops.push({ type: "add", lineA: null, lineB: bi + 1, text: b[bi] });
bi++;
}
}
return ops;
}
/* ── Word-level diff for a single pair of lines ── */
function wordDiff(lineA, lineB) {
assert(typeof lineA === "string", "wordDiff: lineA must be string");
assert(typeof lineB === "string", "wordDiff: lineB must be string");
var wordsA = lineA.split(/(\s+)/);
var wordsB = lineB.split(/(\s+)/);
if (wordsA.length > MAX_WORDS) { wordsA = wordsA.slice(0, MAX_WORDS); }
if (wordsB.length > MAX_WORDS) { wordsB = wordsB.slice(0, MAX_WORDS); }
var lcs = computeLCS(wordsA, wordsB);
var htmlDel = "";
var htmlAdd = "";
var ai = 0, bi = 0, li = 0;
var safety = 0;
while ((ai < wordsA.length || bi < wordsB.length) && safety < MAX_WORDS * 3) {
safety++;
if (li < lcs.length && ai < wordsA.length && wordsA[ai] === lcs[li] && bi < wordsB.length && wordsB[bi] === lcs[li]) {
htmlDel += esc(wordsA[ai]);
htmlAdd += esc(wordsB[bi]);
ai++; bi++; li++;
} else if (li < lcs.length && ai < wordsA.length && wordsA[ai] !== lcs[li]) {
htmlDel += '<span class="word-del">' + esc(wordsA[ai]) + '</span>';
ai++;
} else if (li < lcs.length && bi < wordsB.length && wordsB[bi] !== lcs[li]) {
htmlAdd += '<span class="word-add">' + esc(wordsB[bi]) + '</span>';
bi++;
} else if (li >= lcs.length && ai < wordsA.length) {
htmlDel += '<span class="word-del">' + esc(wordsA[ai]) + '</span>';
ai++;
} else if (li >= lcs.length && bi < wordsB.length) {
htmlAdd += '<span class="word-add">' + esc(wordsB[bi]) + '</span>';
bi++;
}
}
return { del: htmlDel, add: htmlAdd };
}
/* ── Render line-level diff ── */
function renderLineDiff(ops) {
assert(Array.isArray(ops), "renderLineDiff expects array");
var html = '<table class="diff-table">';
for (var i = 0; i < ops.length && i < MAX_LINES * 2; i++) {
var op = ops[i];
var cls = "line-" + op.type;
var numA = op.lineA !== null ? op.lineA : "";
var numB = op.lineB !== null ? op.lineB : "";
var prefix = op.type === "add" ? "+" : op.type === "del" ? "-" : " ";
html += '<tr class="' + cls + '">';
html += '<td class="line-num">' + numA + '</td>';
html += '<td class="line-num">' + numB + '</td>';
html += '<td>' + prefix + ' ' + esc(op.text) + '</td>';
html += '</tr>';
}
html += '</table>';
return html;
}
/* ── Render word-level diff ── */
function renderWordDiff(opsRaw, linesA, linesB) {
assert(Array.isArray(opsRaw), "renderWordDiff expects array");
var html = '<table class="diff-table">';
/* Group consecutive add/del ops for word-level comparison */
var i = 0;
while (i < opsRaw.length && i < MAX_LINES * 2) {
var op = opsRaw[i];
if (op.type === "same") {
html += '<tr class="line-same">';
html += '<td class="line-num">' + op.lineA + '</td>';
html += '<td class="line-num">' + op.lineB + '</td>';
html += '<td> ' + esc(op.text) + '</td></tr>';
i++;
continue;
}
/* Collect consecutive del+add for paired word diff */
var dels = [];
var adds = [];
while (i < opsRaw.length && opsRaw[i].type === "del") { dels.push(opsRaw[i]); i++; }
while (i < opsRaw.length && opsRaw[i].type === "add") { adds.push(opsRaw[i]); i++; }
var pairCount = Math.min(dels.length, adds.length);
for (var p = 0; p < pairCount; p++) {
var wd = wordDiff(dels[p].text, adds[p].text);
html += '<tr class="line-del"><td class="line-num">' + dels[p].lineA + '</td><td class="line-num"></td>';
html += '<td>- ' + wd.del + '</td></tr>';
html += '<tr class="line-add"><td class="line-num"></td><td class="line-num">' + adds[p].lineB + '</td>';
html += '<td>+ ' + wd.add + '</td></tr>';
}
for (var d = pairCount; d < dels.length; d++) {
html += '<tr class="line-del"><td class="line-num">' + dels[d].lineA + '</td><td class="line-num"></td>';
html += '<td>- ' + esc(dels[d].text) + '</td></tr>';
}
for (var a = pairCount; a < adds.length; a++) {
html += '<tr class="line-add"><td class="line-num"></td><td class="line-num">' + adds[a].lineB + '</td>';
html += '<td>+ ' + esc(adds[a].text) + '</td></tr>';
}
}
html += '</table>';
return html;
}
/* ── Main compare function ── */
function compare() {
var textA = document.getElementById("textA").value;
var textB = document.getElementById("textB").value;
var output = document.getElementById("diffOutput");
if (!textA.trim() && !textB.trim()) {
showToast("Enter text in both boxes");
return;
}
var linesA = textA.split("\n").slice(0, MAX_LINES);
var linesB = textB.split("\n").slice(0, MAX_LINES);
var lcs = computeLCS(linesA, linesB);
var ops = buildDiffOps(linesA, linesB, lcs);
/* Stats */
var added = 0, deleted = 0, same = 0;
for (var s = 0; s < ops.length; s++) {
if (ops[s].type === "add") { added++; }
else if (ops[s].type === "del") { deleted++; }
else { same++; }
}
var total = Math.max(linesA.length, linesB.length);
var similarity = total > 0 ? ((same / total) * 100).toFixed(1) : "100.0";
document.getElementById("statAdd").textContent = "+" + added + " added";
document.getElementById("statDel").textContent = "-" + deleted + " removed";
document.getElementById("statSame").textContent = same + " unchanged";
document.getElementById("statSim").textContent = "Similarity: " + similarity + "%";
/* Render */
var mode = document.getElementById("viewMode").value;
if (mode === "word") {
output.innerHTML = renderWordDiff(ops, linesA, linesB);
} else {
output.innerHTML = renderLineDiff(ops);
}
/* Show CTA */
document.getElementById("ctaBanner").style.display = "flex";
}
/* ── Swap ── */
function swap() {
var a = document.getElementById("textA");
var b = document.getElementById("textB");
var tmp = a.value;
a.value = b.value;
b.value = tmp;
showToast("Texts swapped");
}
/* ── Clear ── */
function clearAll() {
document.getElementById("textA").value = "";
document.getElementById("textB").value = "";
document.getElementById("diffOutput").innerHTML = '<div class="empty-state"><h3>Paste two texts above and click Compare</h3><p>See additions, deletions, and changes highlighted side by side.</p></div>';
document.getElementById("statAdd").textContent = "+0 added";
document.getElementById("statDel").textContent = "-0 removed";
document.getElementById("statSame").textContent = "0 unchanged";
document.getElementById("statSim").textContent = "Similarity: \u2014";
document.getElementById("ctaBanner").style.display = "none";
}
/* ── Load example ── */
function loadExample() {
document.getElementById("textA").value = "The quick brown fox jumps over the lazy dog.\nThis sentance has a few grammer mistakes.\nYou should of checked your writing before submitting.\nTheir going to notice the errors right away.\nIts important to proofread you're work carefully.\nThe deadline is on monday at 3pm.\nPlease send me a email when your done.";
document.getElementById("textB").value = "The quick brown fox jumps over the lazy dog.\nThis sentence has a few grammar mistakes.\nYou should have checked your writing before submitting.\nThey're going to notice the errors right away.\nIt's important to proofread your work carefully.\nThe deadline is on Monday at 3 PM.\nPlease send me an email when you're done.";
compare();
showToast("Example loaded: before/after writing improvement");
}
/* ── Public API ── */
return {
compare: compare,
swap: swap,
clearAll: clearAll,
loadExample: loadExample
};
})();
</script>
</body>
</html>