Wikipedysta:Persino/Gadget-StronicowyParser.js/Moduł.js

Z Wikibooks, biblioteki wolnych podręczników.

Uwaga: aby zobaczyć zmiany po opublikowaniu, może zajść potrzeba wyczyszczenia pamięci podręcznej przeglądarki.

  • Firefox / Safari: Przytrzymaj Shift podczas klikania Odśwież bieżącą stronę, lub naciśnij klawisze Ctrl+F5, lub Ctrl+R (⌘-R na komputerze Mac)
  • Google Chrome: Naciśnij Ctrl-Shift-R (⌘-Shift-R na komputerze Mac)
  • Internet Explorer / Edge: Przytrzymaj Ctrl, jednocześnie klikając Odśwież, lub naciśnij klawisze Ctrl+F5
  • Opera: Naciśnij klawisze Ctrl+F5.
StronicowyParser.ZamienLinkiNaLinkiDoStronyAktualnej=function(element,title,titles){
	let a=element.getElementsByTagName('a');
	if((a!==null)&&(a.length>0)){
	    let lena=a.length;
	    for(let i=0;i<lena;++i){
	        let element_a=a[i];
		    let href=StronicowyParser.kodowanie.DecodeHtml(element_a.getAttribute('href'));
		    if(href!==null){
		    	let re=/^[^\?]+\?[^&]+=[^&]*&?/g;
		    	if(!re.test(href)){
					let re2=/#/g;
					let s=href.search(re2);
					if(s!=-1){
						let re=/^\/wiki\//g;
						if(re.test(href)){
							let href2=href.substring(6,s);
							href2=href2.replace(/^[_\s]*/g,"").replace(/[_\s]*$/g,"").replace(/[_\s]+/g,"_");
							for(let p=0;p<titles.length;++p){
								let strona_bez_hash=titles[p].replace(/^([^#]*)#(.*)$/g,"$1");
								let strona=strona_bez_hash.replace(/^[_\s]*/g,"").replace(/[_\s]*$/g,"").replace(/[_\s]+/g,"_");
								if(href2==strona){
									let href3=href.replace(/^[^#]*/g,"");
									element_a.setAttribute('href',StronicowyParser.kodowanie.EncodeHtml(href3));
									element_a.setAttribute("title","");
									element_a.setAttribute("old_href",href);
								}
							}
						}
						if(s==0){
								element_a.setAttribute("old_href","/wiki/"+title+href);
						}
					}else{
						let re=/^\/wiki\//g;
						if(re.test(href)){
						    let hrefs=href.replace(re,"");
						    hrefs=hrefs.replace(/^[_\s]*/g,"").replace(/[_\s]*$/g,"").replace(/[_\s]+/g,"_");
							for(let p=0;p<titles.length;++p){
								let strona_bez_hash=titles[p].replace(/^([^#]*)#(.*)$/g,"$1");
								let strona=strona_bez_hash.replace(/^[_\s]*/g,"").replace(/[_\s]*$/g,"").replace(/[_\s]+/g,"_");
						    	if(hrefs==strona){
						    		let hrefs2=hrefs.replace(/^[^\/]*\//g,"");
						    		element_a.setAttribute('href',StronicowyParser.kodowanie.EncodeHtml('#'+hrefs2));
						    		element_a.setAttribute("title","");
						    		element_a.setAttribute("old_href",href);
						    	}
						    }
						}
					}
				}
		    }
		}
	}
}
StronicowyParser.CzyWlaczycSideBarTOC=function(elements,czy_numerowac){
	
	let toc_nowy_vector=$('.mw-table-of-contents-container > .mw-sticky-header-element');
	if((toc_nowy_vector==null)||(toc_nowy_vector.length==0)){return false;}
	
	if(!elements){
		let sidebartoc=$('.mw-table-of-contents-container > .mw-sticky-header-element > .sidebar-toc');
		if((sidebartoc!==null)&&(sidebartoc.length>0)){return true;}
	}
		
	if(!czy_numerowac){return false;}
	
	let rodzic=$('body:not(.ns-6) #mw-content-text .mw-parser-output, body.ns-6 #mw-content-text');
	
	let toc_stary_vector=rodzic.find('.toc, .toc_spis, .toc_wykaz');
	let style_lub_link=rodzic.children('style, link');
	let wszystkie_dzieci=rodzic.children();
	/**/
	let strona_start_jedyne_dziecko=$('#mw-content-text .mw-parser-output > .strona_start:only-child');
	let strona_start=$('#mw-content-text .mw-parser-output  .strona_start');
	let action_view_i_submit=document.querySelector('body.action-view:not(.ns-special), body.action-submit');
	if(action_view_i_submit){
		if(((strona_start_jedyne_dziecko!==null)&&(strona_start_jedyne_dziecko.length>0))
		     ||((strona_start===null)||(strona_start.length==0))
		     ||((strona_start!==null)&&(style_lub_link!==null)&&(wszystkie_dzieci!==null)&&(strona_start.length==1)&&(wszystkie_dzieci.length-style_lub_link.length==1))
		  ){
			if((toc_stary_vector)&&(toc_stary_vector.length>0)){
				let w_strona_start=toc_stary_vector.parents('.strona_start');
				if((w_strona_start!==null)&&(w_strona_start.length>0)){
					return false;
				}else{
					if((toc_stary_vector!==null)&&(toc_stary_vector.length>0)){
						return false;
					}else{
						return true;
					}
				}
			}else{return true;}
		}else if((strona_start!==null)&&(strona_start.length>0)){
			let pole=$('#mw-content-text .mw-parser-output').find('h1,h2,h3,h4,h5,h6');
			function NaglowkiNiektorePozaStronaStart(){
				if(elements){return false;}
				for(let i=0;i<pole.length;++i){
					let s=strona_start.find(pole[i]);
					if((s===null)||(s.length==0)){
						return true;
					}
				}
				return false;
			}
			if(NaglowkiNiektorePozaStronaStart()){
				if((toc_stary_vector)&&(toc_stary_vector.length>0)){
					for(let i=0;i<toc_stary_vector.length;++i){
						let strona_start=$(toc_stary_vector[i]).parents('.strona_start');
						if((strona_start===null)||(strona_start.length==0)){
							return false;
						}
					}
					return true;
				}else{
					return true;
				}
			}else{
				if((strona_start!==null)&&(strona_start.length==1)){
					if((toc_stary_vector)&&(toc_stary_vector.length>0)){
						for(let i=0;i<toc_stary_vector.length;++i){
							let toc=strona_start.find(toc_stary_vector[i]);
							if((toc!==null)&&(toc.length>0)){
								return false;
							}
						}
						return true;
					}else{
						return true;
					}
				}else{
					return false;		
				}	
			}
		}
	}
}
StronicowyParser.ListaNodeTOC=function(elements,czy_numerowac){
	let rodzic=$('body:not(.ns-6) #mw-content-text .mw-parser-output, body.ns-6 #mw-content-text');
	let toc_stary_vector;
	let zaaktualizowany=$('.rodzic_szablon_subst_js');
	if((zaaktualizowany!==null)&&(zaaktualizowany.length>0)){
		let rodzic_szablon_subst_js=$('.rodzic_szablon_subst_js:not(.szablon_subst_js_zanalizowany)');
		if((rodzic_szablon_subst_js===null)||(rodzic_szablon_subst_js.length==0)){
			toc_stary_vector=rodzic.find('.toc:not(.toc_ukończony), .toc_spis:not(.toc_ukończony)');
		}else{
			toc_stary_vector=rodzic.find('.toc, .toc_spis');
		}
	}else{
		toc_stary_vector=rodzic.find('.toc, .toc_spis');
	}
	
	let czy_sidebartoc=StronicowyParser.CzyWlaczycSideBarTOC(elements,czy_numerowac);
	let toc_nowy_vector=((czy_sidebartoc)?$('.mw-table-of-contents-container > .mw-sticky-header-element'):undefined);
	
	this.CzyJestSideBarToc=function(){
		return (((toc_nowy_vector)&&(toc_nowy_vector.length>0))?true:false);
	}
	this.CzyJestTOC=function(){
		return (((toc_stary_vector)&&(toc_stary_vector.length>0))?true:false);
	}
	this.CzySideBarToc=function(elem){
		if(toc_nowy_vector){
			for(let i=0;i<toc_nowy_vector.length;++i){
				if(elem==toc_nowy_vector[i]){
					return true;
				}
			}
		}
		return false;
	}
	if(this.CzyJestSideBarToc()){
		this.toc=new Array();for(let i=0;i<toc_stary_vector.length;++i){this.toc.push(toc_stary_vector[i]);};
		for(let i=0;i<toc_nowy_vector.length;++i){this.toc.push(toc_nowy_vector[i]);};
	}else{
		this.toc=toc_stary_vector;
	}
}
StronicowyParser.AktualizujSpisTresciModuluStrony=function(elements,tabs,strona_hash,stronasubst_tablica_alternatywnych_nazw,stronasubst_tablica_tych_samych,stronasubst_tablica_rozdzialow,czy_numerowac,stronasubst_latex,stronasubst_mathml,czy_szablon_subst){
	
	let toc_fun=new StronicowyParser.ListaNodeTOC(elements,czy_numerowac);
	/**/
	if((toc_fun.toc!==null)&&(toc_fun.toc.length>0)){
		/**/
		let element_strona_hash=stronasubst_tablica_alternatywnych_nazw[strona_hash];
	                    	        			
	    let strona_title_hash;let title_2;
	                    	        			
	    if(element_strona_hash===undefined){
	         strona_title_hash=strona_hash.replace(/^([^#]*)#(.*)$/g,"$2").replace(/&amp;/g,"&").replace(/&nbsp;/g,"_");
	         title_2=strona_title_hash.match(/[^\/]+$/g).toString().replace(/^[_\s]*/g,"").replace(/[_\s]*$/g,"");
	    }else{
	         strona_title_hash=element_strona_hash.replace(/&amp;/g,"&").replace(/&nbsp;/g,"_");
	         title_2=strona_title_hash.replace(/^[_\s]*/g,"").replace(/[_\s]*$/g,"");
	    }
	    let title2=title_2.replace(/[_\s]+/g," ");
	    let title2_href=title_2.replace(/[_\s]+/g,"_");
	    
		/**/
		let re=/^([^#]*)#(.*)$/g;
		let subtabe;
		if(re.test(strona_hash)){
			subtitle=strona_hash.replace(/^([^#]*)#(.*)$/g,"$2");
		}else{
			subtitle=strona_hash.match(/[^\/]+$/g).toString();
		}
			
		if(czy_szablon_subst){
			if(elements===undefined){
				elements=new Array();
				elements[0]=document.querySelector("body:not(.ns-6) #mw-content-text .mw-parser-output, body.ns-6 #mw-content-text");
			}
		}
			
		for(let q in elements){
			let element=elements[q];
			let powtorka=1;
			let vv=0;
			let numer_artykulu;
			for(let e=0;e<tabs.length;++e){
				if(tabs[e]==strona_hash){
					if(q==vv){
						numer_artykulu=e;
						let subtabe;
						for(let ee=0;ee<e;++ee){
							if(re.test(tabs[ee])){
								subtitle=tabs[ee].replace(/^([^#]*)#(.*)$/g,"$2");
							}else{
								subtabe=tabs[ee].match(/[^\/]+$/g).toString();
							}
							if(subtabe==subtitle){
								++powtorka;
							}
						}
						break;
					}
					++vv;
				}
			}
			let strona_start;
			let strona_start_s=$('.strona_start');
			for(let i=0;i<strona_start_s.length;++i){
				if(strona_start_s[i]==element){
					strona_start=$(element);
					break;
				}
			}
	        if(!strona_start){
	        	strona_start=$(element).parents(".strona_start");
	        }
	               	
	        let ile_stronasubst_tablica_tych_samych=0;
	        for(let gg=0;gg<numer_artykulu;++gg){
	            let element_stronasubst_tablica_tych_samych=stronasubst_tablica_tych_samych[gg];
	            if(element_stronasubst_tablica_tych_samych!=null){
	                 let element_stronasubst_tablica_tych_samych_title=element_stronasubst_tablica_tych_samych[title2];
	                 ile_stronasubst_tablica_tych_samych+=((element_stronasubst_tablica_tych_samych_title!=null)?element_stronasubst_tablica_tych_samych_title:0);
	            }
	        }
	    	let ile_powtorek=powtorka+ile_stronasubst_tablica_tych_samych;
			/**/

			let num=new Array("numer");
			let headline=element.getElementsByClassName("mw-headline");
			if((headline!==null)&&(headline.length>0)){
				let HNumer=StronicowyParser.hnumer.LiczonyHNumer();
				let len=headline.length;
				let naglowek="";
				let naglowek2="";
				let liczba_ulozenia_w_menu_spisu_tresci=1;
						
				for (let k=0;k<len;++k){
					let element2=headline[k];
						
					if((strona_start===null)||(strona_start.length==0)){
						let czy_naglowek_wewnatrz_strony=$('.strona_start .ciało_strona').find(element2);
						if((czy_naglowek_wewnatrz_strony!==null)&&(czy_naglowek_wewnatrz_strony.length>0)){
							continue;
						}
					}else{
						let strona_start2=$('.strona_start .ciało_strona').find(element2).parents('.strona_start');
						if(strona_start[0]!=strona_start2[0]){continue;}
					}
					let hparent=element2.parentNode;
					if(hparent!==null){
						let h=hparent.tagName.toUpperCase();
						if(h.match(/^H\d+$/g)){
							let nag2=element2.getAttribute('id');
							if(nag2!==null){
								nag2=StronicowyParser.style.UsunStyle(nag2).replace(/&amp;/g,"&").replace(/&nbsp;/g,"_");
								let nag_poczatkowe=StronicowyParser.style.UsunStyle(element2.innerHTML);
								//nag_poczatkowe=nag_poczatkowe.replace(/^([^#]*)#(.*)$/g,"$2");
								let nag=nag_poczatkowe.replace(/<[^<>]+>/g,"").replace(/^[_\s]*/g,"").replace(/[_\s]*$/g,"").replace(/[_\s]+/g," ");
								if(stronasubst_latex){
									nag_poczatkowe=nag_poczatkowe.replace(/<[^<>]+>/g,"").replace(/^\s*/g,"").replace(/\s*$/g,"").replace(/\s+/g," ");
								}else{
									nag_poczatkowe=nag_poczatkowe.replace(/<a\s+[^<>]+>/g,"").replace(/<a\s*>/g,"").replace(/<\/a\s*>/g,"").replace(/^\s*/g,"").replace(/\s*$/g,"").replace(/\s+/g," ");
									let div=document.createElement('div');
									div.innerHTML=nag_poczatkowe;
									$(div).find('*').each((i,element)=>{
										element.removeAttribute('id');
									})
									nag_poczatkowe=div.innerHTML;
								}
								if(stronasubst_tablica_tych_samych[numer_artykulu]==null){
									stronasubst_tablica_tych_samych[numer_artykulu]=new Array();
									stronasubst_tablica_tych_samych[numer_artykulu][nag]=1;
								}else{
									if(stronasubst_tablica_tych_samych[numer_artykulu][nag]!=null){
										stronasubst_tablica_tych_samych[numer_artykulu][nag]+=1;
									}else{
										stronasubst_tablica_tych_samych[numer_artykulu][nag]=1;
									}
								}
								let h_numer=StronicowyParser.hnumer.PoziomNaglowka(hparent);
								h_numer=HNumer(h_numer);
								
                    			if(k==0){
                    				num.push(1);
                    				if(toc_fun.CzyJestTOC()){
                    					let w_a="<span class=\"tocnumber\">"+num.join('.')+"</span><span class=\"toctext"+((stronasubst_mathml)?" mathml":"")+"\">"+nag_poczatkowe+"</span>";
                    					naglowek+="<ul><li><a href=\""+StronicowyParser.kodowanie.EncodeHtml("#"+nag2)+"\">"+w_a+"</a>";
                    				}
                    				if(toc_fun.CzyJestSideBarToc()){
                    					let w_a="<div class=\"sidebar-toc-text"+((stronasubst_mathml)?" mathml":"")+"\"><span class=\"sidebar-toc-numb\">"+num.join('.')+"</span>"+nag_poczatkowe+"</div>";
                    					naglowek2+="<ul><li id=\"toc-"+nag2+"\" class=\"sidebar-toc-list-item\"><a class=\"sidebar-toc-link\" href=\""+StronicowyParser.kodowanie.EncodeHtml("#"+nag2)+"\">"+w_a+"</a>";
                    				}
                    			}else{
                    				if(h_numer==liczba_ulozenia_w_menu_spisu_tresci){
                    					num[num.length-1]+=1;
                    					if(toc_fun.CzyJestTOC()){
                    						let w_a="<span class=\"tocnumber\">"+num.join('.')+"</span><span class=\"toctext"+((stronasubst_mathml)?" mathml":"")+"\">"+nag_poczatkowe+"</span>";
                    						naglowek+="</li><li><a href=\""+StronicowyParser.kodowanie.EncodeHtml("#"+nag2)+"\">"+w_a+"</a>";
                    					}
                    					if(toc_fun.CzyJestSideBarToc()){
                    					    let w_a="<div class=\"sidebar-toc-text"+((stronasubst_mathml)?" mathml":"")+"\"><span class=\"sidebar-toc-numb\">"+num.join('.')+"</span>"+nag_poczatkowe+"</div>";
                    						naglowek2+="</li><li id=\"toc-"+nag2+"\" class=\"sidebar-toc-list-item\"><a class=\"sidebar-toc-link\"  href=\""+StronicowyParser.kodowanie.EncodeHtml("#"+nag2)+"\">"+w_a+"</a>";
                    					}
                					}else{
                						if(h_numer>liczba_ulozenia_w_menu_spisu_tresci){
                							num.push(1);
                							if(toc_fun.CzyJestTOC()){
                								let w_a="<span class=\"tocnumber\">"+num.join('.')+"</span><span class=\"toctext"+((stronasubst_mathml)?" mathml":"")+"\">"+nag_poczatkowe+"</span>";
                    							naglowek+="<ul><li><a href=\""+StronicowyParser.kodowanie.EncodeHtml("#"+nag2)+"\">"+w_a+"</a>";
                							}
                							if(toc_fun.CzyJestSideBarToc()){
                    							let w_a="<div class=\"sidebar-toc-text"+((stronasubst_mathml)?" mathml":"")+"\"><span class=\"sidebar-toc-numb\">"+num.join('.')+"</span>"+nag_poczatkowe+"</div>";
                    							naglowek2+="<ul><li id=\"toc-"+nag2+"\" class=\"sidebar-toc-list-item\"><a class=\"sidebar-toc-link\"  href=\""+StronicowyParser.kodowanie.EncodeHtml("#"+nag2)+"\">"+w_a+"</a>";
                    						}
                    						liczba_ulozenia_w_menu_spisu_tresci=h_numer;
                						}else{
                							if(h_numer<liczba_ulozenia_w_menu_spisu_tresci){
                								num.splice(num.length-liczba_ulozenia_w_menu_spisu_tresci+h_numer,liczba_ulozenia_w_menu_spisu_tresci-h_numer);
                								num[num.length-1]+=1;
                								if(toc_fun.CzyJestTOC()){
                									let w_a="<span class=\"tocnumber\">"+num.join('.')+"</span><span class=\"toctext"+((stronasubst_mathml)?" mathml":"")+"\">"+nag_poczatkowe+"</span>";
                    								naglowek+=('</li></ul>'.repeat(liczba_ulozenia_w_menu_spisu_tresci-h_numer))+"</li><li><a href=\""+StronicowyParser.kodowanie.EncodeHtml("#"+nag2)+"\">"+w_a+"</a>";
                								}
                								if(toc_fun.CzyJestSideBarToc()){
                    								let w_a="<div class=\"sidebar-toc-text"+((stronasubst_mathml)?" mathml":"")+"\"><span class=\"sidebar-toc-numb\">"+num.join('.')+"</span>"+nag_poczatkowe+"</div>";
                    								naglowek2+=('</li></ul>'.repeat(liczba_ulozenia_w_menu_spisu_tresci-h_numer))+"</li><li id=\"toc-"+nag2+"\" class=\"sidebar-toc-list-item\"><a class=\"sidebar-toc-link\" href=\""+StronicowyParser.kodowanie.EncodeHtml("#"+nag2)+"\">"+w_a+"</a>";
                    							}
                    							liczba_ulozenia_w_menu_spisu_tresci=h_numer;
                							}
                						}
                					}
                				}
                			}
                    	}
					}
				}
				
				if(((naglowek!=null)&&(naglowek!=""))||((naglowek2!=null)&&(naglowek2!=""))){
	                naglowek+=(((naglowek)&&(naglowek!=""))?('</li></ul>'.repeat(liczba_ulozenia_w_menu_spisu_tresci)):"");
	            	naglowek2+=(((naglowek2)&&(naglowek2!=""))?('</li></ul>'.repeat(liczba_ulozenia_w_menu_spisu_tresci)):"");
	                
	                function UzupelnijSideBarTOC(rodzic){
	                	let li=$(rodzic).find('ul > li');
	                	if((li==null)||(li.length==0)){return;}
	                	for(let i=0;i<li.length;++i){
	                		let ul_dziecko=$(li[i]).children('ul').find('*');
	                		if((ul_dziecko!==null)&&(ul_dziecko.length>0)){
	                			li[i].classList.add('sidebar-toc-list-item-expanded');
	                		}
	                	}
	                	li=$(rodzic).find('.sidebar-toc > ul > li:first-child');
	                	if((li===null)||(li.length==0)){return;}
	                	let ul=$(rodzic).find('.sidebar-toc > ul');
	                	
	                	ul[0].setAttribute('class','sidebar-toc-contents');
	                	if(li[0].getAttribute('id')!="toc-mw-content-text"){
	                		let li=document.createElement('li');
	                		li.setAttribute('id',"toc-mw-content-text");
	                		li.setAttribute('class','sidebar-toc-list-item');
	                		let a=document.createElement('a');
	                		a.setAttribute('href','#top-page');
	                		a.setAttribute('class','sidebar-toc-link');
	                		let div=document.createElement('div');
	                		div.setAttribute('class','sidebar-toc-text');
	                		div.innerHTML="Początek";
	                		a.appendChild(div);
	                		li.appendChild(a);
	                		li=ul[0].insertBefore(li,ul[0].firstChild);
	                	}
	                	let a=$(rodzic).find('li#toc-mw-content-text ~ li a.sidebar-toc-link');
	                	if((a==null)||(a.length==0)){return;}
	                	for(let i=0;i<a.length;++i){
	                		let ul=$(a[i]).siblings('ul');
	                		let href=a[i].getAttribute('href').replace(/^#/g,"");
	                		if((ul!==null)&&(ul.length>0)){
	                			ul[0].setAttribute('class','sidebar-toc-list')
	                			ul[0].setAttribute('id','toc-'+href+'-sublist')
	                			continue;
	                		}
	                		ul=document.createElement('ul');
	                		ul.setAttribute('class','sidebar-toc-list');
	                		ul.setAttribute('id','toc-'+href+'-sublist')
	                		a[i].parentNode.appendChild(ul);
	                	}
	                	a=$(rodzic).find('li#toc-mw-content-text ~ li > a.sidebar-toc-link');
	                	if((a==null)||(a.length==0)){return;}
	                	for(let i=0;i<a.length;++i){
	                		let ul=$(a[i]).siblings('ul');
	                		let href=a[i].getAttribute('href').replace(/^#/g,"");
	                		if((ul!==null)&&(ul.length>0)){
	                			let child=$(ul[0]).children();
	                			if((child==null)||(child.length==0)){continue;}
	                		    let buttons=$(a[i]).siblings('button');
	                		    if((buttons!==null)&&(buttons.length>0)){continue;}
	                		    button=document.createElement('button');
	                		    button.setAttribute('aria-controls','toc-'+href+'-sublist')
	                		    button.setAttribute('class','mw-ui-icon mw-ui-icon-wikimedia-expand mw-ui-icon-small sidebar-toc-toggle');
	                		    button.setAttribute('aria-expanded','true');
	                		    button.innerHTML="Przełącz podsekcję "+href.replace(/[_\s]+/g," ");
	                		    a[i].parentNode.insertBefore(button,ul[0]);
	                			continue;
	                		}
	                	}
	                }
	                
	                for(let b=0;b<toc_fun.toc.length;++b){
	                    if(!czy_szablon_subst){
	                    	let czy_side_bar_toc=toc_fun.CzySideBarToc(toc_fun.toc[b]);
	                    	let ile=ile_powtorek;
	                    	let a2=toc_fun.toc[b].getElementsByTagName('a');
	                    	if((a2!==null)&&(a2.length>0)){
	                    		let tab_a2=new Array();
	                    		for(let x=0;x<a2.length;++x){tab_a2[x]=a2[x];}
	                    	    for(let y=0;y<tab_a2.length;++y){
	                    	    	function CzyTitleNaglowek(){
	                    	    		let element_tab_a2=tab_a2[y];
		                    	        let href2=StronicowyParser.kodowanie.DecodeHtml(element_tab_a2.getAttribute('href'));
		                    	        if(href2!==null){
	    	                	        	href2=href2.replace(/^#/g,"").replace(/^[_\s]*/g,"").replace(/[_\s]*$/g,"").replace(/[_\s]+/g,"_");
	    	                	        	let tocnumber;let toctext_wartosc;
	    	                	        	if(czy_side_bar_toc){
	    	                	        		tocnumber=element_tab_a2.querySelector('.sidebar-toc-numb');
	    	                	        		if(!tocnumber){return true;}
												toctext_wartosc=element_tab_a2.querySelector('.sidebar-toc-text').innerHTML.replace(new RegExp(StronicowyParser.wzor.BezZnakowSpecjalnych(tocnumber.outerHTML),"g"),"");
	    	                	        	}else{
	        	            	        		tocnumber=element_tab_a2.querySelector('.tocnumber');
	            	        	        		toctext_wartosc=element_tab_a2.querySelector('.toctext').innerHTML;
	    	                	        	}
	                	    	        	if((tocnumber!==null)&&(toctext_wartosc!==null)){
		                    	        		let element_toctext=StronicowyParser.style.UsunStyle(toctext_wartosc).replace(/<[^<>]+>/g,"").replace(/^[_\s]*/g,"").replace(/[_\s]*$/g,"").replace(/[_\s]+/g," "	);
	                    	        		   	//let element_tocnumber=tocnumber;//.innerHTML.replace(/^[_\s]*/g,"").replace(/[_\s]*$/g,"");
		                    	        		let tab=stronasubst_tablica_rozdzialow[element_toctext];
	    	                	        		if((tab!=null)&&(tab.length>0)){
	        	            	        		   	for(let m in tab){
	            	        	        		   		if(tab[m]==tocnumber){
	                	    	        		   			return true;
	                    		        		   		}
	                    		        		   	}
	                    	    	    		}
	                    	        		}
	                    	        	}
	                    	        	return false;
		                    	    }
	                    	    		
		                    	    if(CzyTitleNaglowek()){continue;}
	                    	    		
		                    	    let parent=tab_a2[y].parentNode;
	    	                	    if((parent!==null)&&(parent.tagName.toUpperCase()=="LI")){
	        	            	        let href=StronicowyParser.kodowanie.DecodeHtml(tab_a2[y].getAttribute('href'));
	            	        	        if(href!==null){
	                	    	        	href=href.replace(/^#/g,"").replace(/^[_\s]*/g,"").replace(/[_\s]*$/g,"").replace(/[_\s]+/g,"_").replace(/&amp;/g,"&").replace(/&nbsp;/g,"_");
	                    		        	/**/
	                    		        	let dodatek=0;
	                    	    	    	let czy_naglowki=false;
	                    	        		for(let ff in stronasubst_tablica_rozdzialow){czy_naglowki=true;break;}
	                    	        		if(czy_naglowki){
	                    	        			for(let ss=0;ss<y;++ss){
	                    	        				let element_tab_a2=tab_a2[ss];
	                    	        		   		let href2=StronicowyParser.kodowanie.DecodeHtml(element_tab_a2.getAttribute('href'));
	                    	        		   		if(href2!==null){
	                    	        		   			href2=href2.replace(/^#/g,"").replace(/^[_\s]*/g,"").replace(/[_\s]*$/g,"").replace(/[_\s]+/g,"_");
	                    	        		   			let tocnumber;let toctext_wartosc;
	    	                	        				if(czy_side_bar_toc){
	    	                	        					tocnumber=element_tab_a2.querySelector('.sidebar-toc-numb');
															if(!tocnumber){continue;}
															toctext_wartosc=element_tab_a2.querySelector('.sidebar-toc-text').innerHTML.replace(new RegExp(StronicowyParser.wzor.BezZnakowSpecjalnych(tocnumber.outerHTML),"g"),"");
	    	                	        				}else{
	        	            	        					tocnumber=element_tab_a2.querySelector('.tocnumber');
	            	        	        					toctext_wartosc=element_tab_a2.querySelector('.toctext').innerHTML;
	    	                	        				}
	                    	        		   			if((tocnumber!==null)&&(toctext_wartosc!==null)){
	                    	        		   				let element_toctext=StronicowyParser.style.UsunStyle(toctext_wartosc).replace(/<[^<>]+>/g,"").replace(/^[_\s]*/g,"").replace(/[_\s]*$/g,"").replace(/[_\s]+/g," ");
	                    	        		   				//let element_tocnumber=tocnumber;//.innerHTML.replace(/^[_\s]*/g,"").replace(/[_\s]*$/g,"");
	                    	        		   			    let tab=stronasubst_tablica_rozdzialow[element_toctext];
	                    	        		   		    	if((tab!=null)&&(tab.length>0)){
	                    	        		   					for(let m in tab){
	                    	        		   						if(tab[m]==tocnumber){
	                    	        		   							let ile2=ile+dodatek;
	                    	        		   							if(href2==(title2_href+((ile2>1)?("_"+ile2):""))){
	                    	        		   								dodatek+=1;
	                    	        		   							}
	                    	        		   						}
	                    	        		   					}
	                    	        		   		    	}
	                    	        		   			}
	                    	        		   		}
	                    	        			}
	                    	        		}
	                    	        		ile+=dodatek;
	                    	        		if(href==(title2_href+((ile>1)?("_"+ile):""))){
	                    	        			let tab_naglowki=new Array(naglowek,naglowek2);
	                    	        			for(let dd=0;dd<tab_naglowki.length;++dd){
	                    	        				let naglowek=tab_naglowki[dd];
	                    	        				if((naglowek!="")&&(((dd==0)&&(!toc_fun.CzySideBarToc(toc_fun.toc[b])))||((dd==1)&&(toc_fun.CzySideBarToc(toc_fun.toc[b]))))){
	                    	        					let div=document.createElement('div');
	                    	        					div.innerHTML=naglowek;
	                    	        					let ul=parent.querySelector('ul');
	                    	        					if(ul!==null){
	                    	        						let element_li=ul.querySelector('li');
	                    	        						function WsadzDoSpisuTresciTOC(){
	                    	        				    		let ul_jeden=div.querySelector('ul');
	                    	        							let lis=ul_jeden.getElementsByTagName('li');
	                    	        							let element_li_przed=element_li;
	                    	        							for(let ff=lis.length-1;ff>=0;--ff){
	                    	        								let element_lis=lis[ff];
	                    	        								if(element_lis.parentNode==ul_jeden){
	                    	        				       				element_li_przed=ul.insertBefore(element_lis,element_li_przed);
	                    	        								}
	                    	        							}
	                    	        						}
	                    	        						if(element_li!==null){
		                    	        						 WsadzDoSpisuTresciTOC();
	                    	        						}else{
	                    	        				    		 parent.removeChild(ul);
	                    	        				    		 parent.appendChild(div.querySelector('ul'));
	                    	        						}
	                    	        					}else{
	                    	        						parent.appendChild(div.querySelector('ul'));
	                    	        					}
	                    	        				}
	                    	        			}
	                    	        			if(toc_fun.CzySideBarToc(toc_fun.toc[b])){
	                    	        				UzupelnijSideBarTOC(toc_fun.toc[b]);
	                    	        			}
	                    	        			break;
	                    	        		}
	            	        	        }
	                	    	    }
	                    	    }
	                    	}
	                    }else{
	                    	if(!toc_fun.CzySideBarToc(toc_fun.toc[b])){
	                    		if((strona_start!==null)&&(strona_start.length>0)){
	                    			let czy_toc=strona_start.find(toc_fun.toc[b]);
	                    			if((czy_toc===null)||(czy_toc.length==0)){continue;}
	                    			let strona_start2=$(toc_fun.toc[b]).parents('.strona_start');
	                    			if(strona_start2[0]!=strona_start[0]){continue;}
	                    		}else{
	                    			let toc_strona_start=$(toc_fun.toc[b]).parents('.strona_start');
	                    			if((toc_strona_start!==null)&&(toc_strona_start.length>0)){continue;}
	                    		}
	                    		
	                    		toc_fun.toc[b].classList.add('toc_ukończony');
	                    		
	                    		let ul=toc_fun.toc[b].querySelector("ul");
	                    		let div=document.createElement('div');
	                    		div.innerHTML=naglowek;
	                    		$(ul).parent().each((i,rodzic)=>{
									rodzic.replaceChild(div.querySelector("ul"),ul);
								});

	                    	}else{ 
	                    		let nav=document.createElement('nav');
	                    		nav.setAttribute('id','mw-panel-toc');
	                    		nav.setAttribute('class','sidebar-toc');
	                    		nav.setAttribute('role','navigation');
	                    		nav.setAttribute('aria-labelledby','sidebar-toc-label');
	                    		nav.setAttribute('data-event-name','ui.sidebar-toc');
	                    		let div=document.createElement('div');
	                    		div.setAttribute('id','sidebar-toc-label');
	                    		div.setAttribute('class','sidebar-toc-header');
	                    		let p=document.createElement('p');
	                    		p.setAttribute('class','sidebar-toc-title');
	                    		let zawartosc=document.createTextNode(" Zawartość ")
	                    		p.appendChild(zawartosc);
	                    		
	                    		let button=document.createElement('div');
	                    		button.setAttribute('class','vector-toc-uncollapse-button');
	                    		button.innerHTML='przenieś do paska bocznego';
	                    		p.appendChild(button);
	                    		let button2=document.createElement('button');
	                    		button2.setAttribute('class','vector-toc-collapse-button');
	                    		let ukryj=document.createTextNode(" ukryj ")
	                    		button2.appendChild(ukryj);
	                    		p.appendChild(button2);
	                    		
	                    		div.appendChild(p)
	                    		nav.appendChild(div);
	                    		let div2=document.createElement('div');
	                    		div2.innerHTML=naglowek2;
	                    		nav.appendChild(div2.querySelector('ul'));
	                    		toc_fun.toc[b].innerHTML="";
	                    		toc_fun.toc[b].appendChild(nav);
	                    		toc_fun.toc[b].classList.add('sidebar_obecny');
	                    		UzupelnijSideBarTOC(toc_fun.toc[b]);
	                    	}
	                    }
	                }
				}
			}
		}
	}
	if((toc_fun.toc!==null)&&(toc_fun.toc.length>0)){
		for(let w=0;w<toc_fun.toc.length;++w){
			let li=toc_fun.toc[w].getElementsByTagName('li');
			let poziom;
            let section=1;
            let toc_section;let toc_level;let toc_section_wzor;let toc_level_wzor;
            if(toc_fun.CzySideBarToc(toc_fun.toc[w])){
            	toc_section="sidebar-toc-section";toc_level="sidebar-toc-level";
            	toc_section_wzor="sidebar\\-toc\\-section\\-\\d+";toc_level_wzor="sidebar\\-toc\\-level-\\d+";
            }else{
            	toc_section="tocsection";toc_level="toclevel";
            	toc_section_wzor="tocsection\\-\\d+";toc_level_wzor="toclevel\\-\\d+";
            }
            if((li!==null)&&(li.length>0)){
            	for(let z=0;z<li.length;++z){
            		let element_li=li[z];
            		if((element_li.tagName.toUpperCase()=="LI")
            			&&(element_li.parentNode!==null)
            				&&(element_li.parentNode.tagName.toUpperCase()=="UL")
            					&&(element_li.parentNode.parentNode!==null)
            						&&(element_li.parentNode.parentNode.tagName.toUpperCase()=="LI")
            		){
            			let parent=element_li.parentNode.parentNode;
            			let klasa=parent.getAttribute('class');
            			if(klasa!==null){
            				let klasy=parent.classList;
            				poziom=undefined;
            				for(let m in klasy){
            					let poziom_pasujacy=klasy[m].match(new RegExp("^"+toc_level_wzor+"$","g"));
            					if(poziom_pasujacy!==null){
            						poziom=parseInt(poziom_pasujacy.toString().match(/\d+$/).toString())+1;
            						break;
            					}
            				}
            				poziom=((poziom!==undefined)?poziom:1);
            			}else{poziom=1;}
            		}else{poziom=1;}
            		let klasa=element_li.getAttribute('class');
            		if(klasa!==null){
            			let czy_section=klasa.match(new RegExp(toc_section_wzor));
            			if(czy_section!==null){
            				klasa=klasa.replace(new RegExp(toc_section_wzor,"g"),toc_section+"-"+section);
            				element_li.setAttribute('class',klasa);
            			}else{
            				element_li.classList.add(toc_section+"-"+section);
            			}
            			let czy_level=klasa.match(new RegExp(toc_level_wzor,"g"));
            			if(czy_level!==null){
            				klasa=element_li.getAttribute('class');
            				if(klasa!==null){
            					klasa=klasa.replace(new RegExp(toc_level_wzor,"g"),toc_level+"-"+poziom);
            					element_li.setAttribute('class',klasa);
            				}
            			}else{
            				element_li.classList.add(toc_level+"-"+poziom);
            			}
            		}else{
            			element_li.setAttribute('class',toc_level+"-"+poziom+" "+toc_section+"-"+section)
            		}
            		section=section+1;
            	}
			}
        }
        //Poczatek ustalania num
        for(let w=0;w<toc_fun.toc.length;++w){
        	let tocnumer;
            if(toc_fun.CzySideBarToc(toc_fun.toc[w])){
            	tocnumber=toc_fun.toc[w].getElementsByClassName('sidebar-toc-numb');
				if(!tocnumber){continue;}
            }else{
            	tocnumber=toc_fun.toc[w].getElementsByClassName('tocnumber');
            }
            if((tocnumber!==null)&&(tocnumber.length>0)){
            	let ostatnie;
            	for(let hh=0;hh<tocnumber.length;++hh){
            		let element_tocnumber=tocnumber[hh];
            		let zawartosc=element_tocnumber.innerHTML;
            		if(zawartosc.match(/^numer\./g)){
            			if(ostatnie!=null){
            				element_tocnumber.innerHTML=zawartosc.replace(/^numer\./g,ostatnie+".");
            			}else{
            				element_tocnumber.innerHTML=zawartosc.replace(/^numer\./g,"");
            			}
            		}else{
            			ostatnie=zawartosc;
            		}
            	}	
            }
       }
       //Koniec ustalania num
	}
}
StronicowyParser.PrzeIndeksujWszystkieTOC=function(element,czy_numerowac){
	let toc_fun=new StronicowyParser.ListaNodeTOC(element,czy_numerowac);
	
	let rodzic=((element)?element:(document.querySelector("body:not(.ns-6) #mw-content-text .mw-parser-output, body.ns-6 #mw-content-text")));
	if((toc_fun.toc!==null)&&(toc_fun.toc.length>0)){
		for(let d=0;d<toc_fun.toc.length;++d){
			let toc=toc_fun.toc[d];
			let czy_side_bar_toc=toc_fun.CzySideBarToc(toc);
			if(!czy_side_bar_toc){
				let potomek=$(rodzic).find(toc);
				if((potomek===null)||(potomek.length==0)){
					continue;
				}
			}
			let a=toc.getElementsByTagName('a');
			if((a!==null)&&(a.length>0)){
				for(let p=0;p<a.length;++p){
					let element_a=a[p];
					let poczatek=element_a.parentNode.getAttribute('id');
					if(poczatek=='toc-mw-content-text'){continue;}
					if(!element){
						let tab_a=$('.strona_start .ciało_strona').find(element_a);
						if((tab_a!==null)&&(tab_a.length>0)){
							continue;
						}
					}
					let element_toctext;
					let text;
					if(czy_side_bar_toc){
						element_toctext=element_a.querySelector('.sidebar-toc-text');
						let num=element_toctext.querySelector('.sidebar-toc-numb');
						if(!num){continue;}
						text=element_toctext.innerHTML.replace(new RegExp(StronicowyParser.wzor.BezZnakowSpecjalnych(num.outerHTML),"g"),"");
					}else{
						element_toctext=element_a.querySelector('.toctext');
						text=element_toctext.innerHTML;
					}
					if(element_toctext!==null){
						let strona=StronicowyParser.style.UsunStyle(text).replace(/<[^<>]+>/g,"").replace(/^[_\s]*/g,"").replace(/[_\s]*$/g,"").replace(/[_\s]+/g,"_").replace(/&amp;/g,"&").replace(/&nbsp;/g,"_");
						let c=1;
						for(let v=0;v<p;++v){
							let element_a2=a[v];
							
							let poczatek=element_a2.parentNode.getAttribute('id');
							if(poczatek=='toc-mw-content-text'){continue;}
							
							let element_toctext2;
							let text2;
							if(czy_side_bar_toc){
								element_toctext2=element_a2.querySelector('.sidebar-toc-text');
								let num=element_toctext2.querySelector('.sidebar-toc-numb');
								if(!num){continue;}
								text2=element_toctext2.innerHTML.replace(new RegExp(StronicowyParser.wzor.BezZnakowSpecjalnych(num.outerHTML),"g"),"");
							}else{
								element_toctext2=element_a2.querySelector('.toctext');
								text2=element_toctext2.innerHTML;
							}
							if(element_toctext2!==null){
								let strona2=StronicowyParser.style.UsunStyle(text2).replace(/<[^<>]+>/g,"").replace(/^[_\s]*/g,"").replace(/[_\s]*$/g,"").replace(/[_\s]+/g,"_").replace(/&amp;/g,"&").replace(/&nbsp;/g,"_");
								if(strona==strona2){
									++c;	
								}
							}else{
								c=undefined;
								break;
							}
						}
						if(c!==undefined){
							if(c==1){
								element_a.setAttribute('href',StronicowyParser.kodowanie.EncodeHtml("#"+strona));
							}else{
								element_a.setAttribute('href',StronicowyParser.kodowanie.EncodeHtml("#"+strona)+"_"+c);
							}
						   }
					}
				}
			}
		}
	}
}
StronicowyParser.IndeksujHeadLine=function(element){
	let strona_start=$('.strona_start');
	for(let i=0;i<strona_start.length;++i){
		if(strona_start[i]==element){
			let cialo=$(element).find('.ciało_strona');
			if((cialo!==null)&&(cialo.length>0)){
				element=cialo[0];
			}
			break;
		}
	}
	let headline=((element)?element:(document.querySelector("body:not(.ns-6) #mw-content-text .mw-parser-output, body.ns-6 #mw-content-text"))).getElementsByClassName('mw-headline');
	if((headline!==null)&&(headline.length>0)){
		for(let i=0;i<headline.length;++i){
			let el=headline[i];
			
			if(!element){
				let tab_a=$('.strona_start .ciało_strona').find(el);
				if((tab_a!==null)&&(tab_a.length>0)){
					continue;
				}
			}
			let id0=StronicowyParser.style.UsunStyle(el.innerHTML)
									.replace(/<[^<>]+>/g,"").replace(/^[_\s]*/g,"").replace(/[_\s]*$/g,"").replace(/[_\s]+/g,"_").replace(/<i>/g,"").replace(/<\/i>/g,"").replace(/<b>/g,"").replace(/<\/b>/g,"").replace(/&nbsp;/g,"_").replace(/&amp;/g,"&");
			let c=1;									
			for(let j=0;j<i;++j){
				let el1=headline[j];
				let id1=StronicowyParser.style.UsunStyle(el1.innerHTML)
					                     .replace(/<[^<>]+>/g,"").replace(/^[_\s]*/g,"").replace(/[_\s]*$/g,"").replace(/[_\s]+/g,"_").replace(/<i>/g,"").replace(/<\/i>/g,"").replace(/<b>/g,"").replace(/<\/b>/g,"").replace(/&nbsp;/g,"_").replace(/&amp;/g,"&");
				if(id0==id1){
					++c;
				}
			}
			let span=null;
			if((el.parentNode!==null)&&(el.parentNode.tagName.toUpperCase().match(/^H\d+$/g))){
				span=el.parentNode.querySelector('span.numeracja');
				if(span===null){
					span=el.parentNode.querySelector('span');
				}else{
					span=span.nextElementSibling;
				}
			}
			function IdNazwa(id0){
				el.setAttribute('id',id0);
				if((span!==null)&&(span!=el)){
					var id1=StronicowyParser.kodowanie.EncodeHtml(id0,false,true).replace(/%/g,".");
					if(id0!=id1){
						span.setAttribute('id',StronicowyParser.kodowanie.EncodeHtml(id0,false,true).replace(/%/g,"."));
					}
				}
			}
			if(c==1){IdNazwa(id0);}else{IdNazwa(id0+"_"+c);}
		}
	}
}
StronicowyParser.PoprawRozdzialyStron=function(element_analizowany){
	let parent=element_analizowany.parentNode;
	let headline=parent.querySelector('.mw-headline');
	let h_numer_tag=headline.parentNode;
	let h_numer=StronicowyParser.hnumer.PoziomNaglowka(h_numer_tag);
	if(h_numer===null){return;}
	let headline_element=element_analizowany.getElementsByClassName('mw-headline');
	if((headline_element!==null)&&(headline_element.length>0)){
		let HNumer=StronicowyParser.hnumer.LiczonyHNumer();
		let h_numer_old=h_numer;
		let tab_headline_element=new Array();
		for (let i=0;i<headline_element.length;++i){tab_headline_element[i]=headline_element[i];}
		for(let i=0;i<tab_headline_element.length;++i){
			let h_element=tab_headline_element[i].parentNode;
			let h_numer_element=StronicowyParser.hnumer.PoziomNaglowka(h_element);
			let h_numer=HNumer(h_numer_element)+h_numer_old;
			if(h_numer_element!=h_numer){
				let outerHTML=h_element.outerHTML;
				outerHTML=outerHTML.replace(/^<[Hh]\d+/g,"<H"+((h_numer<=6)?h_numer:6));
				outerHTML=outerHTML.replace(/<\/[Hh]\d+>$/g,"</H"+((h_numer<=6)?h_numer:6)+">");
				h_element.outerHTML=outerHTML;
				h_element.classList.remove('mw-hnumber-'+h_numer_element);
				if(h_numer>6){
					h_element.classList.add('mw-hnumber-'+h_numer);
				}
			}
		}
	}
}
StronicowyParser.ZamieniajNazwyLinkuTOC=function(hn_element,czy_numerowac,stronasubst_latex){
	let id_stara_nazwa=hn_element.getAttribute('id');
	if(id_stara_nazwa===null){console.log("Nie znalazłem id element nagłówka.");return;}
	let nowa_nazwa=StronicowyParser.style.UsunStyle(hn_element.innerHTML);
	if(stronasubst_latex){
		nowa_nazwa=nowa_nazwa.replace(/<[^<>]+>/g,"").replace(/^\s*/g,"").replace(/\s*$/g,"").replace(/\s+/g," ");
	}else{
		nowa_nazwa=nowa_nazwa.replace(/<a\s+[^<>]+>/g,"").replace(/<a\s*>/g,"").replace(/<\/a\s*>/g,"").replace(/^\s*/g,"").replace(/\s*$/g,"").replace(/\s+/g," ");
	}
	
	let rodzic=undefined;
	let tab_rodzic=$(hn_element).parents(".strona_start");
	
	if((tab_rodzic!==null)&&(tab_rodzic.length>0)){
		rodzic=tab_rodzic[0];
	}
	
	let toc_fun=new StronicowyParser.ListaNodeTOC(rodzic,czy_numerowac);
	
	if((toc_fun.toc!==null)&&(toc_fun.toc.length>0)){
		for(let w=0;w<toc_fun.toc.length;++w){
			let toc=toc_fun.toc[w];
			let czy_side_bar_toc=toc_fun.CzySideBarToc(toc);
			if((!czy_side_bar_toc)&&(rodzic)){
				let potomek=$(rodzic).find(toc);
				if((potomek===null)||(potomek.length==0)){
					continue;
				}
			}
			let a=toc.getElementsByTagName('a');
			if((a!==null)&&(a.length>0)){
				for(let p=0;p<a.length;++p){
					let element_a=a[p];
					let poczatek=element_a.parentNode.getAttribute('id')
					if(poczatek=='toc-mw-content-text'){continue;}
					
					let innerhref=StronicowyParser.style.UsunStyle(StronicowyParser.kodowanie.DecodeHtml(a[p].getAttribute('href'),false).replace(/^#/g,""));
					if(innerhref==id_stara_nazwa){
						let toctext;
						if(czy_side_bar_toc){
							toctext=a[p].querySelector('.sidebar-toc-text');
						}else{
							toctext=a[p].querySelector('.toctext');
						}
						if(toctext!==null){
							if(czy_side_bar_toc){
								let num=toctext.querySelector('.sidebar-toc-numb');
								if(!num){continue;}
								toctext.innerHTML=num.outerHTML+nowa_nazwa;
							}else{
								toctext.innerHTML=nowa_nazwa;
							}
						}
						break;
					}
				}
			}
		}
	}
	StronicowyParser.IndeksujHeadLine(rodzic);
	StronicowyParser.PrzeIndeksujWszystkieTOC(rodzic,czy_numerowac);
}
StronicowyParser.LimitTOC=function(czy_numerowac,stronasubst_ukrywaj_toc){
	let rodzic=$('body:not(.ns-6) #mw-content-text .mw-parser-output, body.ns-6 #mw-content-text');
	function TOC_ukrywaj(numer){
		if(numer>1){
			let toc_fun=new StronicowyParser.ListaNodeTOC(rodzic,czy_numerowac);
			if((toc_fun.toc!==null)&&(toc_fun.toc.length>0)){
				for(let w=0;w<toc_fun.toc.length;++w){
					toc_fun.toc[w].classList.add('toclimit');
					toc_fun.toc[w].classList.add('toclimit-'+numer);
				}
			}
		}
	}
	TOC_ukrywaj(stronasubst_ukrywaj_toc);
}
StronicowyParser.DodawajRozdzialyDoTOCSpisTresci=function(element,czy_numerowac,stronasubst_latex,stronasubst_mathml){
	StronicowyParser.AktualizujSpisTresciModuluStrony(((element)?(new Array(element)):undefined),new Array(),StronicowyParser.pageinfo.fullname,new Array(),new Array(),new Array(),czy_numerowac,stronasubst_latex,stronasubst_mathml,true);
	StronicowyParser.IndeksujHeadLine(element);
	StronicowyParser.PrzeIndeksujWszystkieTOC(element,czy_numerowac);
}
StronicowyParser.NaprawNaglowkiStrony=function(element,czy_numerowac){
	let rodzic=$('body:not(.ns-6) #mw-content-text .mw-parser-output, body.ns-6 #mw-content-text');
	if((rodzic==null)||(rodzic.length==0)){return;}
	if(element){
		if(element!=document){
			rodzic=rodzic.find(element);
			if((rodzic==null)||(rodzic.length==0)){return;}
		}
	}
	
	let h=rodzic.find("h1, h2, h3, h4, h5, h6");
	if((h!==null)&&(h.length>0)){
		let czy_indeksuj=undefined;
		for(let i=0;i<h.length;++i){
			let element_h=h[i];
			let h_toc=rodzic.find('.toc, .toc_spis').find(element_h);
			if((h_toc!==null)&&(h_toc.length>0)){continue;}
			let headline=element_h.querySelector(".mw-headline");
			if(headline===null){
				let id=element_h.innerHTML.replace(/[\s_]+/g,"_");
				let nowe_id=StronicowyParser.kodowanie.EncodeHtml(id,false,true).replace(/%/g,".");
				let element_span_przed=((id!=nowe_id)?(mw.html.element("span",{id:nowe_id},"")):"");
				let element_span=mw.html.element("span",{class:"mw-headline",id:id},element_h.innerHTML);
				let h_id=element_h.getAttribute("id");
				let element_nowe_h=mw.html.element(element_h.tagName,((h_id)?{id:h_id}:null),new mw.html.Raw(element_span_przed+element_span));
				element_h.outerHTML=element_nowe_h;
				czy_indeksuj=true;
			}
		}
		if(czy_indeksuj){
			StronicowyParser.IndeksujHeadLine(rodzic[0]);
			StronicowyParser.PrzeIndeksujWszystkieTOC(rodzic[0],czy_numerowac);
		}
	}
}
StronicowyParser.ZmieniajNazwyLinkowNaLinkiPodrecznika=function(rodzic){
	if(!rodzic){
		let $rodzic=$('body:not(.ns-6) #mw-content-text .mw-parser-output, body.ns-6 #mw-content-text');
		if(($rodzic==null)||($rodzic.length==0)){return;}
		rodzic=$rodzic[0];
	}
	let a=$(rodzic).find('a');
	if((a!==null)&&(a.length>0)){
		let bookname=StronicowyParser.pageinfo.bookname.replace(/[\s_]+/g," ");
		let re_str=StronicowyParser.wzor.BezZnakowSpecjalnych(bookname);
		re_str=re_str.replace(/^(.)/g,function(s){
			return "["+s.toLowerCase()+s.toUpperCase()+"]";
		})
		re_str="^"+re_str+"\\/";
		let re=new RegExp(re_str);
		
		for(let i=0;i<a.length;++i){
			let element_a=a[i];
			let parents=$(element_a).parents('.mw-other-articles');
			if((parents!==null)&&(parents.length>0)){continue;}
			let nazwa=element_a.innerHTML.replace(/[\s_]+/g," ");
			let href=element_a.getAttribute('href');
			let strona=href?StronicowyParser.kodowanie.DecodeHtml(href,true).replace(/^\/wiki\//g,""):href;
			if((strona)&&(nazwa==strona)&&(re.test(nazwa))){
				nazwa=nazwa.replace(re,"");
				element_a.innerHTML=nazwa;
			}
		}
	}
}