User:Garzfoth/Scripts/CompareLink.js

// Migrated from https://en.wikipedia.org/wiki/User:Garzfoth/common.js on 2021-05-04

// Notes:
// • Variable naming: I believe I stripped the dollar sign prefixes for readability. IIRC they were only in use as an informal way to denote jQuery variables, and I believe they were being misused for sloppy variable declaration as well...
// • Major changes: Wrapped mw.util.addCSS() inside mw.loader expression

// FROM: https://en.wikipedia.org/wiki/User:Mattflaschen/Compare_link.js
// SINCE: 7/21/2015
/**
 * Convert the "Compare selected versions" button to a link
 * (Based on [[w:en:User:Superm401/Compare_link.js]])
 * @source: http://www.mediawiki.org/wiki/Snippets/Compare_link
 * @rev: 2
 * @see: [[bugzilla:16165]]
 * Copyright 2006-2013 Matthew Flaschen ([[User:Superm401]]), [[User:Helder.wiki]]
 */

function fixCompareSelectedVersionsButton() {
	var histForm = $('#mw-history-compare');
	var diffList = $('#pagehistory');
	var buttons = histForm.find('input.historysubmit');
	
	if (buttons.length === 0) {
		// Only one version, so do nothing
		return;
	}
	
	var buttonText = buttons.remove().first().val();
	
	var compareLink = $('<a></a>', {
		'class': 'compare-link',
		'text': buttonText
	});
	
	histForm.prepend(compareLink).append(compareLink.clone());
	
	var updateCompare = function (){
		var radio = histForm.find('input[type=radio]:checked');
		var genLink = mw.config.get('wgScript') + '?title=' + mw.util.wikiUrlencode(mw.config.get('wgPageName')) + '&diff=' + radio.eq(0).val() + '&oldid=' + radio.eq(1).val();
		$('.compare-link').each(function () {
			$(this).attr('href', genLink);
		});
	};
	
	updateCompare();
	diffList.change(updateCompare);
}

if (mw.config.get('wgAction') === 'history') {
	$.when( mw.loader.using( 'mediawiki.util' ), $.ready ).then( function () {
		mw.util.addCSS('.compare-link { border-radius:5px; color:black; text-decoration:none; border-width:1px 2px 2px 1px; border-style:solid; border-color:#DDDDDD #BBBBBB #BBBBBB #DDDDDD; padding:0.2em 1em; background-color:#EEEEEE; white-space:nowrap; } .compare-link:active{ border-width:0.1em; margin:0.1em; }');
	});
	$(fixCompareSelectedVersionsButton);
}

Content Disclaimer

Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.

  1. The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
  2. There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
  3. It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
  4. Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
  5. Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.