User:Sumit.iitp/editlabels.js

function diff_lineMode(text1, text2) { var dmp = new diff_match_patch; var a = dmp.diff_linesToWords_(text1, text2); var lineText1 = a.chars1; var lineText2 = a.chars2; var lineArray = a.lineArray; var diffs = dmp.diff_main(lineText1, lineText2, false); dmp.diff_charsToLines_(diffs, lineArray); return diffs; }

var get_changes_for_para = function(deleted, added) { var d_regex = /<\/del> /gi var i_regex = /<\/ins> /gi if ( deleted !== false ) { var before = $(deleted).find('div').text; before = before.replace(d_regex, ' '); console.log(before); }	if ( added !== false ){ var after = $(added).find('div').text; // Collapse contiguous segments after = after.replace(i_regex, ' '); console.log(after); }	segment_regexp = RegExp('(.+?) ', 'g'); // var before = 0; // var after = -1; // while ((segment = segment_regexp.exec(text)) !== null) { // 	console.log(`Found ${segment[0]}. Next starts at ${segment_regexp.lastIndex}.`); // 	var start = text.indexOf(segment[0]); // 	var end = segment_regexp.lastIndex; // 	console.log(text.substring(segment_regexp.lastIndex)); // 	before = end; // } }

var label_edit = function { if ( $( '.diff' ).length > 0 ) { paragraph_operations = [] $('.diff').find('tr').each(function(idx) {			var added = false;			var deleted = false;			if ( $(this).children('.diff-addedline').length !== 0 ) {				added = $(this).children('.diff-addedline').first;			}			if ( $(this).children('.diff-deletedline').length !== 0 ) {				deleted = $(this).children('.diff-deletedline').first;			}			get_changes_for_para(deleted, added);		}); } }

label_edit;