User:Alexis Jazz/CollaDiff.js

//CollaDiff: click a diff row on a history page in any non-link place to "uncollapse" the diff. CollaDiff is public domain, irrevocably released as WTFPL Version 2 by its author, Alexis Jazz. If you don't like that or think it's invalid where you live you may use CollaDiff under CC BY-SA 3.0, CC BY 2.5 or CC BY 4.0 instead. Your choice. window.CollaDiff = {}; var CollaDiff = window.CollaDiff; var mw = window.mw; var api = new mw.Api; if ( mw.config.get('wgAction') == 'history' ) { mw.util.addCSS('.CollaDiff{padding:0.5em} .CollaDiffNoDisplay{display:none}'); CollaDiff.diffDiv = {}; CollaDiff.appendDiff = function { if ( ! CollaDiff.diffCSSloaded ) { mw.loader.load('/w/load.php?lang=en&modules=mediawiki.diff.styles&only=styles&skin=' + mw.config.get('skin'),'text/css'); CollaDiff.diffCSSloaded = true; }		if ( document.activeElement.nodeName == 'A' ) { return; }		CollaDiff.diffRow = $('#pagehistory li:hover'); CollaDiff.diffRowCollaDiv = $('#pagehistory li:hover .CollaDiff'); CollaDiff.diffRowCollaDivHidden = $('#pagehistory li:hover .CollaDiffNoDisplay'); if ( CollaDiff.diffRowCollaDivHidden[0] ) { CollaDiff.diffRowCollaDivHidden.removeClass('CollaDiffNoDisplay'); return; } else if ( CollaDiff.diffRowCollaDiv[0] ) { CollaDiff.diffRowCollaDiv.addClass('CollaDiffNoDisplay'); return; }		CollaDiff.diffLink = CollaDiff.diffRow[0].querySelectorAll('A'); for(CollaDiff.diffLinkInt=0;CollaDiff.diffLinkInt<CollaDiff.diffLink.length;CollaDiff.diffLinkInt++) { CollaDiff.matchLink = CollaDiff.diffLink[CollaDiff.diffLinkInt].href.match(/diff=([0-9]+)&oldid=([0-9]+)/); if ( CollaDiff.matchLink && ( CollaDiff.diffRow[0] == $('#pagehistory li')[0] || Number(CollaDiff.matchLink[1]) != mw.config.get('wgCurRevisionId') ) ) { break; }		}		CollaDiff.diffDiv[CollaDiff.matchLink[1]] = document.createElement('div'); CollaDiff.diffDiv[CollaDiff.matchLink[1]].classList.add('CollaDiff'); api.get({'format':'json','action':'compare','fromrev':CollaDiff.matchLink[2],'torev':CollaDiff.matchLink[1]}).then(function(data) {			CollaDiff.diffHTML = ' ';			CollaDiff.diffDiv[CollaDiff.matchLink[1]].innerHTML = CollaDiff.diffHTML;			CollaDiff.diffRow.append(CollaDiff.diffDiv[CollaDiff.matchLink[1]]);		}); };	$('#pagehistory li').on('click',function {CollaDiff.appendDiff;}); console.log('CollaDiff loaded'); } //