User:Christo76/js/watchCat.js

/* \*_____________________________________________________________________________________*/
 * author:	Kaligula
 * license:	CC-BY-SA-3.0
 * version:	2.3.5
 * credits:	Matma Rex
 * Nux
 * _____________________________________________________________________________________
 * opis działania: Wikipedysta:Kaligula/js/watchCat
 * opis działania: Wikipedysta:Kaligula/js/watchCat
 * opis działania: Wikipedysta:Kaligula/js/watchCat

//if ( (wgNamespaceNumber==14 && wgAction=='view') || wgPageName=='Specjalna:GadgetPrefs' ) {

addOnloadHook(function {

importStylesheet('User:Christo76/js/watchCat.css');

$.ajax({				url:location.protocol+'//en.wikipedia.org/wiki/Special:EditWatchlist/raw'			}).done(function(html){				var wList = $(html).find('#mw-input-wpTitles').text;

$('#mw-pages a').each(function(i){					if ( (wList.match(new RegExp('^'+this.innerHTML.replace(/([\(\)\[\]\{\}\|\?\.\*\^\$\+])/g,'\\$1')+'$','m'))!=null) == (watchCat_invert == false)) {					//there's a match and we don't invert selection OR there's no match and we invert selection						$(this).toggleClass('watchCat-main');

}				});								$('#mw-subcategories a').each(function(i){ if ( (wList.match(new RegExp('^'+'Category:'+this.innerHTML.replace(/([\(\)\[\]\{\}\|\?\.\*\^\$\+])/g,'\\$1')+'$','m'))!=null) == (watchCat_invert == false)) { //there's a match and we don't invert selection OR there's no match and we invert selection $(this).toggleClass('watchCat-main');

}				});

if (watchCat_pending || watchCat_changed) {

function watchCatPendChanArr { var arr=[],j=0,i; $('#mw-pages a.watchCat-main').each(function(i){							if (i%50==0) { j=i/50; arr[j] = []; }							arr[j].push(this.innerHTML)						}) arr.forEach(function(el, i){ arr[i]=el.join('|'); }) return arr; }

if (watchCat_changed) { //					function watchCatChan { var arr = watchCatPendChanArr; window.watchCatStamps = {}; window.watchCatChanCounter = 0; arr.forEach(function(el, i){								$.ajax({ url:location.protocol+'//en.wikipedia.org/w/api.php?action=query&prop=info&format=json&inprop=watched%7Cnotificationtimestamp&indexpageids=&titles=' + encodeURI(arr[i]) }).done(function(data){ watchCatChanCounter++; data.query.pageids.forEach(function(elm, j){										if (data.query.pages[elm].watched == "") {											watchCatStamps[data.query.pages[elm].title] = (data.query.pages[elm].notificationtimestamp != "");										};									}); if (watchCatChanCounter==arr.length){ $('#mw-pages a.watchCat-main').each(function{											(watchCatStamps[this.innerHTML]) ? ($(this).toggleClass('watchCat-watched-changed')) : {};										}); }								});							});	//					}					}					function watchCatPend { var arr = watchCatPendChanArr; window.watchCatFlags = {}; window.watchCatPendCounter = 0; arr.forEach(function(el, i){							$.ajax({ url:location.protocol+'//en.wikipedia.org/w/api.php?action=query&indexpageids&prop=flagged&format=json&titles=' + encodeURI(arr[i]) }).done(function(data){ watchCatPendCounter++; data.query.pageids.forEach(function(elm, j){									watchCatFlags[data.query.pages[elm].title] = ( (!data.query.pages[elm].flagged) ? "watchCat-flagged-unreviewed" : ((data.query.pages[elm].flagged.pending_since) ? "watchCat-flagged-pending" : "watchCat-flagged-reviewed") );								}); if (watchCatPendCounter==arr.length){ $('#mw-pages a.watchCat-main').each(function(index){										$(this).toggleClass(watchCatFlags[this.innerHTML]);									}); }							});						});					}

if (watchCat_pending) { watchCatPend; }					else { $('#mw-pages > p')[0].outerHTML += '\n→ Sprawdź wersje oznaczone obserwowanych artykułów \n→ Narzędzia zewnętrzne: wersje nieprzejrzane/wersje oczekujące na ponowne przejrzenie' }				}			});		});	}); //}