User:Sumit.iitp/editlabels.js

This is an old revision of this page, as edited by Sumit.iitp (talk | contribs) at 05:01, 8 September 2020. The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
var get_changes_for_para = function(paragraph) {
	var regex = /<\/ins> <ins class="diffchange diffchange-inline">/gi
	var text = $(paragraph).find('div').html();
	// Collapse contiguous segments
	text = text.replaceAll(regex, ' ');
	segment_regexp = RegExp('<ins class="diffchange diffchange-inline">(.+?)</ins>', 'g');
	while ((segment = segment_regexp.exec(text)) !== null) {
		console.log(`Found ${segment[0]}. Next starts at ${segment_regexp.lastIndex}.`);
		console.log(text.substring(segment_regexp.lastIndex));
		// expected output: "Found foo. Next starts at 9."
		// expected output: "Found foo. Next starts at 19."
	}
	// segments = text.split('<ins class="diffchange diffchange-inline">');
	// segments.forEach(function(segment, index){
	// 	console.log(segment);	
	// });
	// $(paragraph).find('ins').each(function(idx){
	// 	console.log($(this).text());
	// });
}

var label_edit = function() {
	if ( $( '.diff' ).length > 0  ) {
		paragraph_operations = []
		$('.diff').find('tr').each(function(idx) {
			if ( $(this).children('.diff-addedline').length === 0 ) {
				console.log('Skipping!');
				return;
			}
			get_changes_for_para($(this).children('.diff-addedline'));
		});
	}
}

label_edit();