Content deleted Content added
Polygnotus (talk | contribs) m Polygnotus moved page User:Polygnotus/test5.js to User:Polygnotus/Scripts/diffCompare.js |
Polygnotus (talk | contribs) No edit summary |
||
(3 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) {
if (DEBUG) {
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 op = diffs[i][0];
const data = diffs[i][1];
Line 41 ⟶ 53:
}
}
return html;
}
Line 58 ⟶ 70:
try {
const diffHtml = showDiff(oldText, newText);
const diffContainer = $('<div>')
|