מדיה ויקי:Gadget-QuickRCDiff.js

מתוך ויקימסע

הערה: לאחר הפרסום, ייתכן שיהיה צורך לנקות את זיכרון המטמון (cache) של הדפדפן כדי להבחין בשינויים.

  • פיירפוקס / ספארי: להחזיק את המקש Shift בעת לחיצה על טעינה מחדש (Reload) או ללחוץ על צירוף המקשים Ctrl-F5 או Ctrl-R (במחשב מק: ⌘-R).
  • גוגל כרום: ללחוץ על צירוף המקשים Ctrl-Shift-R (במחשב מק: ⌘-Shift-R).
  • אינטרנט אקספלורר / אדג': להחזיק את המקש Ctrl בעת לחיצה על רענן (Refresh) או ללחוץ על צירוף המקשים Ctrl-F5.
  • אופרה: ללחוץ על Ctrl-F5.
/*/*
check recentchanges/watchlist diffs directly without navigation to other pages.
Written by: [[User:ערן]]
*/
$(function(){
	if($.inArray(mw.config.get('wgCanonicalSpecialPageName'),['Watchlist','Recentchanges'])==-1) return;
	mw.loader.load(['mediawiki.action.history.diff','jquery.spinner']);
 
	var lastRequset, $diffDialog, $diffContent, rcid, patrolBtn;
	$('.mw-line-even,.mw-line-odd').click(function(e) {
		if (e.target !== this) { return; }
		//initalizations
		if (!$diffContent) $diffContent = $('<div>');
		if(!$diffDialog) {
			var buttons = {
			'!': 
				function(){
					if (!rcid){
						return;//nothing to do
					}
					var api=new mw.Api();
					api.post({
						action:'patrol',
						rcid: rcid,
						token: mw.user.tokens.get('patrolToken')
					}, function(data){
						if (data && data.patrol) {
							patrolBtn.hide();
							mw.notify('העריכה סומנה כבדוקה');
						}
						else {
							var desc = (data && data.error && data.error.info) || '';
							mw.notify('שגיאה:' + desc);
						}
					});
					rcid=0;//dont repost
				}
			};
			$diffDialog = $('<div>').append($diffContent).dialog({
				width: '100%',
				height: '300',
				draggable: false,
				resizable: false,
				buttons: buttons
			});
			$diffDialog.dialog('widget').css({
				position:'fixed',
				bottom: '0',
				top: ''
			});
			patrolBtn = $(":button:contains('!')");
		}
		var self = this,
		    title = $(this).find('.mw-changeslist-title').text(),
		    diffHref = $(this).find('a[tabindex]').prop('href'),
		    unpatrolled = $(this).find('.unpatrolled').length
		if (!diffHref) return;//no diff
		patrolBtn.hide();
		var diffId = diffHref.match(/&diff=(\d+)&oldid=/)[1];
		if(self == lastRequset) {
			return;
		}
		$diffContent.html($.createSpinner());
		$.getJSON('/w/api.php?action=query&prop=revisions&format=json&rvprop=timestamp&rvdiffto=prev&revids='+diffId, function(res)
		{
			if (unpatrolled) patrolBtn.show();
			rcid = unpatrolled && /rcid=([0-9]+)/.exec(diffHref);
			if (rcid) {
				rcid = rcid[1];
			}

			$(self).css('background','#fc6');
			if(lastRequset){
			$(lastRequset).css('background','#eee');
			}
			lastRequset = self;
			if(res == null)
			{
				$diffContent.html('Error');
				return false;
			}
			var diffString = res.query.pages[Object.keys(res.query.pages)[0]].revisions[0].diff["*"];
			if(diffString == null)
			{
				$diffContent.html('Error');
				return false;
			}

			var newTable = $('<table class="diff"></table>')
				.html('<colgroup><col class="diff-marker"><col class="diff-content"><col class="diff-marker"><col class="diff-content"></colgroup>')
				.append(diffString);
			$diffDialog.dialog('option','title',title);
			$diffContent.html(newTable);
			$diffDialog.dialog('isOpen') || $diffDialog.dialog('widget').show();
		});
	});
});