Content deleted Content added
Polygnotus (talk | contribs) No edit summary |
Polygnotus (talk | contribs) No edit summary |
||
(7 intermediate revisions by the same user not shown) | |||
Line 1:
// https://github.com/google/diff-match-patch
$.ajax('https://cdn.jsdelivr.net/gh/google/diff-match-patch@master/javascript/diff_match_patch.js', {
dataType: 'script',
cache: true
}).then(function () {
console.log('diff_match_patch library loaded successfully');▼
const DEBUG = false;
function debug(...args) {
debug('[DiffCompare]', ...args);
}
}
if (typeof diff_match_patch === 'undefined') {
Line 11 ⟶ 23:
function showDiff(text1, text2) {
const dmp = new diff_match_patch();
const diffs = dmp.diff_main(text1, text2);
dmp.diff_cleanupSemantic(diffs);
let html = '';
for (let i = 0; i < diffs.length; i++) {
const data
continue;▼
▲ }
switch (op) {
case
html += '<ins style="background-color: #e6ffe6;">' + escapeHtml(data) + '</ins>';▼
break;▼
html += '<del style="background-color: #ffe6e6;">' + escapeHtml(data) + '</del>';
break;
case
▲ html += '<ins style="background-color: #e6ffe6;">' + escapeHtml(data) + '</ins>';
html += '<span>' + escapeHtml(data) + '</span>';
break;
Line 44 ⟶ 53:
}
}
return html;
}
Line 61 ⟶ 70:
try {
const diffHtml = showDiff(oldText, newText);
// $('#diff-output').html(diffHtml);▼
const diffContainer = $('<div>')
.css({
'border': '1px solid #a2a9b1',
'padding': '10px',
'margin-bottom': '20px',
'background-color': '#f8f9fa'
})
.html('<strong>Diff Result:</strong><br>' + diffHtml);
$('#bodyContent').prepend(diffContainer);
} catch (error) {
console.error('Error generating diff:', error);
|