Content deleted Content added
1.2.2 (October 16, 2014) added new line split, sped-up word regexp and wordParse(), fixed slide gaps, more timers, freed memory of words arrays, cleaned-up code |
another background that could use some darkmode friendly color |
||
(5 intermediate revisions by 3 users not shown) | |||
Line 3:
// ==UserScript==
// @name wikEd diff
// @version 1.2.
// @date October
// @description improved word-based diff library with block move detection
// @homepage https://en.wikipedia.org/wiki/User:Cacycle/diff
Line 70:
* .newText new text
* .oldText old text
* .maxWords word count of longest linked block
* .html diff html
* .error
* .bordersDown[] linked region borders downwards, [new index, old index]
* .bordersUp[] linked region borders upwards, [new index, old index]
Line 109 ⟶ 110:
* .blockEnd last block index
* .unique contains unique linked token
* .maxWords word count of longest linked block
* .words word count
* .chars char count
Line 368 ⟶ 369:
'border-radius: 0.25em; padding: 0.2em 1px; margin: 0 1px; ' +
'} ' +
'.wikEdDiffBlock { color: #000; } ' +
'.wikEdDiffBlock0 { background-color: #ffff80; } ' +
'.wikEdDiffBlock1 { background-color: #d0ff80; } ' +
Line 407 ⟶ 408:
'.wikEdDiffContainer { } ' +
'.wikEdDiffFragment {' +
'white-space: pre-wrap; background-color: var(--background-color-base, #fff); border: #bbb solid; ' +
'border-width: 1px 1px 1px 0.5em; border-radius: 0.5em; font-family: sans-serif; ' +
'font-size: 88%; line-height: 1.6; box-shadow: 2px 2px 2px #ddd; padding: 1em; margin: 0; ' +
'} ' +
'.wikEdDiffNoChange { background: var(--background-color-interactive, #
'line-height: 1.6; box-shadow: 2px 2px 2px #ddd; padding: 0.5em; margin: 1em 0; ' +
'text-align: center; ' +
Line 853 ⟶ 854:
/** @var array blocks Block data (consecutive text tokens) in new text order */
this.blocks = [];
/** @var int maxWords Maximal detected word count of all linked blocks */
this.maxWords = 0;
/** @var array groups Section blocks that are consecutive in old text order */
Line 1,611 ⟶ 1,615:
}
//
var symbols;
var bordersDown;
Line 1,621 ⟶ 1,625:
}
//
else {
symbols = {
Line 1,633 ⟶ 1,637:
//
var bordersUpNext = [];
var bordersDownNext = [];
Line 1,672 ⟶ 1,676:
}
//
if ( up === false ) {
i = this.newText.tokens[i].next;
Line 1,719 ⟶ 1,723:
}
//
if ( up === false ) {
j = this.oldText.tokens[j].next;
Line 1,756 ⟶ 1,760:
symbols.linked = true;
//
bordersDown.push( [newToken, oldToken] );
bordersUp.push( [newToken, oldToken] );
Line 1,769 ⟶ 1,773:
var token = newTokenObj.token;
var words =
( token.match( this.config.regExp.countWords ) || [] ).
( token.match( this.config.regExp.countChunks ) || [] )
);
// Unique if longer than min block length
unique = true;
}
Line 1,779 ⟶ 1,785:
// Unique if it contains at least one unique word
else {
for ( var
if (
this.oldText.
this.newText.
Object.prototype.hasOwnProperty.call( this.oldText.words, word ) === true &&
Object.prototype.hasOwnProperty.call( this.newText.words, word ) === true
) {
unique = true;
Line 1,955 ⟶ 1,963:
}
//
if ( recursionLevel === 0 && repeating === false ) {
this.bordersDown = bordersDownNext;
Line 1,961 ⟶ 1,969:
}
//
else {
this.bordersDown = this.bordersDown.concat( bordersDownNext );
Line 2,099 ⟶ 2,107:
// Convert groups to insertions/deletions if maximum block length is too short
// Only for more complex texts that actually have blocks of minimum block length
var unlinkCount = 0;
if (
▲ if ( this.config.unlinkBlocks === true && this.config.blockMinLength > 0 ) {
this.config.unlinkBlocks === true &&
this.config.blockMinLength > 0 &&
this.maxWords >= this.config.blockMinLength
) {
if ( this.config.timer === true ) {
this.time( 'total unlinking' );
Line 2,119 ⟶ 2,132:
// Repeat block detection from start
this.maxWords = 0;
this.getSameBlocks();
this.getSections();
Line 2,389 ⟶ 2,403:
} );
block = groupEnd;
// Set global word count of longest linked block
if ( maxWords > this.maxWords ) {
this.maxWords = maxWords;
}
}
}
Line 3,611 ⟶ 3,630:
// Remove split element
fragments.splice( fragment, 1 );
fragmentsLength --;
// Add left text to fragments list
if ( rangeLeft !== null ) {
fragments.splice( fragment ++, 0, { text: textLeft, type: '=', color: null } );
fragmentsLength ++;
if ( omittedLeft !== null ) {
fragments.splice( fragment ++, 0, { text: '', type: omittedLeft, color: null } );
fragmentsLength ++;
}
}
Line 3,625 ⟶ 3,647:
fragments.splice( fragment ++, 0, { text: '', type: ',', color: null } );
fragments.splice( fragment ++, 0, { text: '', type: '[', color: null } );
fragmentsLength += 3;
}
Line 3,631 ⟶ 3,654:
if ( omittedRight !== null ) {
fragments.splice( fragment ++, 0, { text: '', type: omittedRight, color: null } );
fragmentsLength ++;
}
fragments.splice( fragment ++, 0, { text: textRight, type: '=', color: null } );
fragmentsLength ++;
}
}
Line 4,340 ⟶ 4,365:
this.text = text.replace( /\r\n?/g, '\n');
//
if ( this.parent.config.timer === true ) {
this.parent.time( 'wordParse' );
Line 4,362 ⟶ 4,387:
this.wordParse = function ( regExp ) {
var
if (
var
for (var i = 0; i <
var
if (
}
else {
}
}
|