Content deleted Content added
1.1.3a (September 23, 2014) bugfix slideGaps |
1.1.4 (1.1.4) fix tab highlighting, update highlight handler for wikEd diff tool |
||
Line 2:
// ==UserScript==
// @name
// @version 1.1.
// @date September
// @description improved word-based diff library with block move detection
// @homepage https://en.wikipedia.org/wiki/User:Cacycle/diff
Line 108:
// JSHint options: W004: is already defined, W100: character may get silently deleted
/* jshint -W004, -W100, newcap:
/* global console */
Line 125:
// core diff settings
//
// Show complete unshortened diff text
if (wDiff.fullDiff === undefined) { wDiff.fullDiff = false; }
// enable block move layout with highlighted blocks and marks at their original positions
if (wDiff.showBlockMoves === undefined) { wDiff.showBlockMoves = true; }
//
if (wDiff.charDiff === undefined) { wDiff.charDiff = true; }
Line 135 ⟶ 138:
if (wDiff.recursiveDiff === undefined) { wDiff.recursiveDiff = true; }
//
if (wDiff.unlinkBlocks === undefined) { wDiff.unlinkBlocks = true; }
// do not reject blocks if longer than this number of real words
if (wDiff.blockMinLength === undefined) { wDiff.blockMinLength = 3; }
// display blocks in
if (wDiff.coloredBlocks === undefined) { wDiff.coloredBlocks = false; }
// show debug infos and stats (block and group data object) in browser console
if (wDiff.debug === undefined) { wDiff.debug = false; }
// show
if (wDiff.
// run unit tests to prove correct working, display results in browser console
if (wDiff.unitTesting === undefined) { wDiff.unitTesting = false; }
Line 303 ⟶ 306:
'.wDiffTab { position: relative; }' +
'.wDiffTabSymbol { position: absolute; top: -0.2em; }' +
'.wDiffTabSymbol:before { content: "→"; font-size: smaller
'.wDiffBlockLeft .wDiffTabSymbol:before, .wDiffBlockRight .wDiffTabSymbol:before { color: #aaa; }' +
'.wDiffBlockHighlight .wDiffTabSymbol:before { color: #aaa; }' +
Line 437 ⟶ 440:
// get mark/block elements
if (wDiff.showBlockMoves === false) {
return;▼
var number = element.id.replace(/\D/g, '');
var block = document.getElementById('wDiffBlock' + number);
Line 455 ⟶ 461:
element.onmouseover = function (event) { wDiff.blockHandler(event, element, 'mouseover'); };
// reset, allow outside container (e.g. legend)
// getElementsByClassName▼
var container = document.getElementById('wDiffContainer');▼
var spans = container.getElementsByTagName('span');▼
for (var i = 0; i < spans.length; i ++) {▼
if ( ( (spans[i] != block) && (spans[i] != mark) ) || (type != 'click') ) {▼
▲ // getElementsByClassName
if (spans[i].className.indexOf(' wDiffBlockHighlight') != -1) {▼
▲ var container = document.getElementById('wDiffContainer');
▲ spans[i].className = spans[i].className.replace(/ wDiffBlockHighlight/g, '');
if (container !== null) {
}▼
▲ var spans = container.getElementsByTagName('span');
else if (spans[i].className.indexOf(' wDiffMarkHighlight') != -1) {▼
▲ for (var i = 0; i < spans.length; i ++) {
▲ spans[i].className = spans[i].className.replace(/ wDiffMarkHighlight/g, '');
▲ if (spans[i].className.indexOf(' wDiffBlockHighlight') != -1) {
spans[i].className = spans[i].className.replace(/ wDiffBlockHighlight/g, '');
}
▲ else if (spans[i].className.indexOf(' wDiffMarkHighlight') != -1) {
spans[i].className = spans[i].className.replace(/ wDiffMarkHighlight/g, '');
}
▲ }
}
}
Line 550 ⟶ 564:
// wDiff.diff(): main method of wDiff, runs the diff and shortens the output
// called from: user land
// calls: new TextDiff, TextDiff.shortenOutput(), TextDiff.htmlFormat(), this.unitTests()
wDiff.diff = function (oldString, newString, full) {
Line 564 ⟶ 578:
// start timer
if (wDiff.
console.time('diff');
}
Line 572 ⟶ 586:
// start timer
if (wDiff.
console.timeEnd('diff');
}
// shorten output
if ( ( (full !== undefined) && (full !== true) ) || ( (full === undefined) && (wDiff.fullDiff !== true) ) ) {
▲ if (full !== true) {
// start timer
if (wDiff.
console.time('shorten');
}
Line 587 ⟶ 601:
// stop timer
if (wDiff.
console.timeEnd('shorten');
}
}
else {
}
// stop timer
if (wDiff.
console.timeEnd('diff');
}
Line 612 ⟶ 631:
// start timer
if (wDiff.
console.time('unit tests');
}
Line 652 ⟶ 671:
// stop timer
if (wDiff.
console.timeEnd('unit tests');
}
Line 1,355 ⟶ 1,374:
// start timer
if ( (wDiff.
console.time(level);
}
Line 1,784 ⟶ 1,803:
// stop timer
if ( (wDiff.
console.timeEnd(level);
}
Line 2,887 ⟶ 2,906:
// join fragments
this.html = htmlFrags.join('');
▲ this.htmlFormat();
return;
Line 2,972 ⟶ 2,988:
string = string.replace(/\n/g, wDiff.htmlNewline);
return string;
▲ };
▲ // TextDiff.htmlFormat(): markup tabs, add container
// changes: .diff▼
// called from: .diff(), .assembleDiff()▼
this.htmlFormat = function () {▼
this.html = this.html.replace(/\t/g, wDiff.htmlTab);▼
this.html = wDiff.htmlContainerStart + wDiff.htmlFragmentStart + this.html + wDiff.htmlFragmentEnd + wDiff.htmlContainerEnd;▼
▲ return;
};
Line 2,995 ⟶ 2,999:
var html = this.html;
var diff = '';
// scan for diff html tags
Line 3,316 ⟶ 3,314:
diff += wDiff.htmlFragmentStart + fragment + wDiff.htmlFragmentEnd;
}
this.html = diff;▼
//
this.htmlFormat();
return;
▲ this.html = diff;
};
// TextDiff.htmlFormat(): markup tabs, add container
▲ // changes: .diff
▲ this.htmlFormat = function () {
▲ this.html = this.html.replace(/\t/g, wDiff.htmlTab);
▲ this.html = wDiff.htmlContainerStart + wDiff.htmlFragmentStart + this.html + wDiff.htmlFragmentEnd + wDiff.htmlContainerEnd;
return;
};
|