کاربر:Haghjoo/paksanj.js: تفاوت میان نسخه‌ها

از اسلامیکال
پرش به ناوبری پرش به جستجو
(ایجاد اسکریپت)
 
جز (#C4A484)
 
خط ۳۶: خط ۳۶:
var usage = $('a[href^="#' + id + '"]');
var usage = $('a[href^="#' + id + '"]');
if (usage.length < 1) {
if (usage.length < 1) {
$(cite).css('background-color', 'brown');
$(cite).css('background-color', '#C4A484');
}
}
});
});

نسخهٔ کنونی تا ‏۲۶ سپتامبر ۲۰۲۳، ساعت ۰۲:۲۱

/*
 * Paksanj
 * Author: User:Huji
 * License: MIT
 * More information: User:Huji/پک‌سنج
 */

mw.loader.using(['mediawiki.api', 'mediawiki.util'], function () {
	"use strict";
	
	function doCheck(){
		// find shorthand references that don't match a full citation
		$('.reference-text a').each(function(){
			var dest = $(this).attr('href');

			if ( dest.indexOf('#') !== 0 ) {
				return;
			}

			dest = dest.replace('#', '');

			if ( dest.indexOf('.') !== -1 ) {
				$(this).css('background-color', 'lightsalmon');
				return;
			}

			if ( $('span[id=' + dest + ']').length < 1 & $('cite[id=' + dest + ']').length < 1 ) {
				$(this).css('background-color', 'lightpink');
			}
		});
		
		// find full citations that don't appear to be connected to a shorthand citation
		if ( $.inArray("مقاله‌هایی که تجمیع ارجاع در آن‌ها ممنوع است", mw.config.get('wgCategories')) > -1 ) {
			$('li > cite').each(function(idx, cite){
				var id = $(cite).attr('id');
				var usage = $('a[href^="#' + id + '"]');
				if (usage.length < 1) {
					$(cite).css('background-color', '#C4A484');
				}
			});
		}
	}
	
  	var link = mw.util.addPortletLink(
		'p-tb',
		'#',
		'پک‌سنج',
		't-pk-check',
		'آزمایش مقصد پک‌ها'
	);
	$( link ).click( function (e) {
		e.preventDefault();
		doCheck();
	});
});