Wikipedysta: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]]
\*_____________________________________________________________________________________*/

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

	addOnloadHook(function () {

		mw.loader.using('ext.gadget.gConfig', function(){

			// settings
			gConfig.register(
				'watchCat',
				{
					name: 'watchCat',
					descriptionPage: 'Wikipedysta:Kaligula/js/watchCat'
				},
				[
					{
						name: 'invert',
						desc: 'Odwróć kolorowanie (zaznacza w kategorii artykuły nieobserwowane).',
						type: 'boolean',
						deflt: false,
						legacy: [window, 'watchCat_invert']
					},
					{
						name: 'pending',
						desc: 'Sprawdzaj od razu czy wersja oczekuje na przejrzenie (gdy odznaczone, dodany będzie link z funkcją sprawdzającą).',
						type: 'boolean',
						deflt: true,
						legacy: [window, 'watchCat_pending']
					},
					{
						name: 'changed',
						desc: 'Zaznacz artykuły zmienione od ostatniej wizyty.',
						type: 'boolean',
						deflt: true,
						legacy: [window, 'watchCat_changed']
					},
					{
						name: 'noCSS',
						desc: 'Wyłącz domyślny styl kolorowania (użytkownik musi określić własne style w CSS, np. w [[Specjalna:Moja strona/common.css|common.css]]).',
						descMode: 'wikitext',
						type: 'boolean',
						deflt: false,
						legacy: [window, 'watchCat_noCSS']
					}
				]
			);

			var watchCat_invert = gConfig.get('watchCat','invert');
			var watchCat_pending = gConfig.get('watchCat','pending');
			var watchCat_changed = gConfig.get('watchCat','changed');
			var watchCat_noCSS = gConfig.get('watchCat','noCSS');

			if(!watchCat_noCSS) importStylesheet('Wikipedysta:Kaligula/js/watchCat.css');

			$.ajax({
				url:location.protocol+'//pl.wikipedia.org/wiki/Specjalna:Edytuj_obserwowane/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('^'+'Kategoria:'+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+'//pl.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+'//pl.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→ <a href=# onclick="watchCatPend()">Sprawdź wersje oznaczone obserwowanych artykułów</a><br>\n→ Narzędzia zewnętrzne: <a href="http://toolserver.org/~magnus/deep_insight.php?language=pl&category=' + wgTitle + '&depth=10&mode=web&doit=Do+it" class="external text">wersje nieprzejrzane</a>/<a href="http://toolserver.org/~magnus/deep_out_of_sight.php?language=pl&category=' + wgTitle + '&depth=10&mode=web&doit=Do+it" class="external text">wersje oczekujące na ponowne przejrzenie</a>'
					}
				}
			});
		});
	});
//}

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.
Kembali kehalaman sebelumnya