Користувач:Sergento/imgsHighlighter.js

Матеріал з Вікіпедії — вільної енциклопедії.
Перейти до навігації Перейти до пошуку

Увага: Після публікування слід очистити кеш браузера, щоб побачити зміни.

  • Firefox / Safari: тримайте Shift, коли натискаєте Оновити, або натисніть Ctrl-F5 чи Ctrl-Shift-R (⌘-R на Apple Mac)
  • Google Chrome: натисніть Ctrl-Shift-R (⌘-Shift-R на Apple Mac)
  • Internet Explorer / Edge: тримайте Ctrl, коли натискаєте Оновити, або натисніть Ctrl-F5
  • Opera: натисніть Ctrl-F5
// ПІДСВІТКА ЛОКАЛЬНИХ ЗОБРАЖЕНЬ
//
// Патрулювання (рамка):
// 		невідпатрульоване - салатовий
// 		патрулюване - блакитний
// 		застаріле - оранжевий
//
// Ліцензування (нижня грань):
//		без ліцензії - чорний
//		вільна ліцензія - аквамарин
//		невільна ліцензія з ОДВ - зелений
// 		невільна ліцензія без ОДВ - сірий
//
// Commons (ліва грань):
//		Move to Commons - фіолетовий
//		NowCommons або
//		Db-commons - червоний
//		NoCommons - синій
//		Move manual - жовтий
//
// Видалення (права грань):
//		швидке вилучення - чорний
//		повільне вилучення - червоний
//			(Disputed-fairuse, Без ліцензії, Nothost, Без джерела)

function highlightImages()
{
var ff = $('img[src*="\\/wikipedia\\/uk\\/"]');
re = new RegExp("\/wikipedia\/[^\/]*?\/(?:thumb\/|)(?:[^\/]*?\/){2}([^\/]*?)(?:[\/\"]|$)");
var fileDict = [];
for (var i = 0; i < ff.length; i++)
{
	var m = re.exec(ff[i].src);
	if (m) 
		if (m[1]) 
		{ var dfn = decodeURIComponent(m[1]);
			if (fileDict[dfn] === undefined)
				fileDict[dfn] = [];//m[1]
			fileDict[dfn].push(ff[i]);
		}
}

for (var fn in fileDict)
{
	$.get("https://uk.wikipedia.org/w/api.php?action=query&prop=flagged&format=json", {titles:"Файл:"+fn}, function(data)
		{
			var color = 'lime';
			var imgName = '';
			var pId;
			for(pId in data.query.pages);
			var p = data.query.pages[pId];
			
			if (p.title)
				imgName = p.title.substring(p.title.indexOf(':')+1).replace(/ /g,"_");
			if (p.invalid)
				color = 'gray';
			if (p.flagged) 
				if (p.flagged.pending_since) 
					color = 'orange'; 
				else color = 'cyan'; 
					
			if (imgName.length>0)
			{
				for (var cnt in fileDict[imgName])
					fileDict[imgName][cnt].style.border = "3px solid " + color;
				if (p.invalid)
					return;
					
				$.get("https://uk.wikipedia.org/w/api.php?action=query&prop=templates&tllimit=50&format=json", {titles:"Файл:"+imgName}, function(data)
				{
					var pId2;
					for (pId2 in data.query.pages);
					var p2 = data.query.pages[pId2];
					if (p2.title)
						imgName = p2.title.substring(p2.title.indexOf(':')+1).replace(/ /g,"_");
					if (imgName.length <1) return;
					var commonsColor;
					var delColor;
					var licColor;
						
					var templates = jQuery.makeArray(p2.templates);
					
					// commons
					if ( templates.filter(function(index, element){
						return /(c|C)ommons/.test(index.title);
					}).length > 0 )
						{
							if ( templates.filter(function(index){
								return "Шаблон:Move to Commons" == index.title;
									}).length > 0 )
										commonsColor = 'violet';
							if ( templates.filter(function(index){
								return ["Шаблон:NowCommons", "Шаблон:Db-commons"].indexOf(index.title) > -1;
							}).length > 0 )
									commonsColor = 'red';
							if ( templates.filter(function(index){
								return "Шаблон:Move manual" == index.title;
									}).length > 0 )
										commonsColor = 'yellow';
							if ( templates.filter(function(index){
								return "Шаблон:NoCommons" == index.title;
									}).length > 0 )
										commonsColor = 'blue';
						}
						
					// deletion
					if ( templates.filter(function(index, element){
						return /\b(D|d)b\b/.test(index.title);
					}).length > 0 )
							delColor = 'black';
						else
							if ( templates.filter(function(index, element){
								return ["Шаблон:Disputed-fairuse", "Шаблон:Без ліцензії","Шаблон:Nothost","Шаблон:Без джерела",].indexOf(index.title) > -1;
							}).length > 0 )
								delColor = 'red';
					
					// licence
					if ( templates.filter(function(index, element){
						return "Шаблон:Non-free media" == index.title;
					}).length > 0 )
						{
							if ( templates.filter(function(index, element){
								return "Шаблон:Обґрунтування добропорядного використання" == index.title;
								}).length > 0 )
								licColor = 'green';
								else
								licColor = 'gray';
						}
						else
							if ( templates.filter(function(index, element){
								return "Шаблон:Free media" == index.title;
							}).length > 0 )
								licColor = 'aquamarine';
							else
								licColor = 'black';
						
					for (var cnt in fileDict[imgName])
					{
						if (commonsColor)
							fileDict[imgName][cnt].style.borderLeftColor = commonsColor;
						if (delColor)
							fileDict[imgName][cnt].style.borderRightColor = delColor;
						if (licColor)
							fileDict[imgName][cnt].style.borderBottomColor = licColor;
					}
				});
			}
		});
}
}

$( document ).ready(function () {
	highlightImages();
});