Wikipedysta:Persino/Gadget-StronicowyParser.js/InitInfo.js
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.
/*
* pageInfo, instrukcja obsługi:
* pageInfo.namespace nazwa przestrzeni nazw
* pageInfo.namespacenumber numer przestrzeni nazw (równe wgNamespaceNumber)
* pageInfo.fullname pełna nazwa strony
* pageInfo.pagename nazwa strony
* pageInfo.bookname nazwa książki
* pageInfo.fullbookname pełna nazwa książki
* pageInfo.book tytuł książki
* pageinfo.articlename nazwa artykułu książki
* pageInfo.subpagename nazwa substrony strony
* pageInfo.action akcja taka jaka jest w adresie URL pod "action="
* pageInfo.diff różnice pomiędzy wersjami, jeżeli występuje w adresie URL, w przeciwnym wypadku przyjmuje wartość null
* pageinfo.oldid numer wersji, jeżeli występuje w adresie URL, w przeciwnym wypadku przyjmuje wartość null
*/
StronicowyParser.PageInfoInit=async function(){
let action_submit=$(':root > body.action-submit.ns-10, :root > body.action-submit.ns-828');
if((action_submit==null)||(action_submit.length==0)){
this.fullname = mw.config.get('wgPageName');
this.namespacenumber = mw.config.get('wgNamespaceNumber');
}else{
let strona_selector=document.querySelector('#mw-previewheader ~ .mw-message-box-warning a');
if(strona_selector){
let href=strona_selector.getAttribute('href');
let strona=href?StronicowyParser.kodowanie.DecodeHtml(href,true).replace(/^\/wiki\//g,""):href;
if((strona!==null)&&(!/^[_\s]*$/g.test(strona))&&(!/#/g.test(strona))){
try{
this.fullname=await StronicowyParser.nazwy["PEŁNANAZWASTRONY"](strona);
let nazwaprzestrzeni=await StronicowyParser.nazwy.NAZWAPRZESTRZENI(strona);
let id=await StronicowyParser.nazwy.Np(nazwaprzestrzeni,"tak");
this.namespacenumber=parseInt(id)||0;
}
catch(error){
this.fullname = strona;
this.namespacenumber = 0;
}
}else{
this.fullname = mw.config.get('wgPageName');
this.namespacenumber = mw.config.get('wgNamespaceNumber');
}
}else{
this.fullname = mw.config.get('wgPageName');
this.namespacenumber = mw.config.get('wgNamespaceNumber');
}
}
this.fullname=this.fullname.replace(/[\s_]+/g,"_");
if(this.namespacenumber !== 0){
let name_re=/^[^:\/]*:/g;
this.pagename=this.fullname.replace(name_re,'');
let namespace_re=/^[^:\/]*/g;
this.namespace=this.fullname.match(namespace_re).toString();
}else{
this.pagename=this.fullname;
this.namespace="";
}
let re,i;
if(this.namespacenumber === 0 || this.namespacenumber === 104) {
/*0=(main),104=Wikijunior*/
let re=/^[^\/]*/g;
this.bookname = this.pagename.match(re).toString();
this.book=this.bookname;
re=/^[^\/]*\//g;
this.articlename=re.test(this.pagename)?this.pagename.replace(re,''):"";
}else{
if(this.namespacenumber == 4){
/*4=Wikibooks, przestrzeń nazw: Wikibooks, i niby-przestrzeń nazwy Wikibooks:Brudnopis/*/
let re=/^Brudnopis\/[^\/]*\/[^\/]*/g;
this.bookname = this.pagename.match(re);
if(this.bookname === null){
/*Przestrzeń nazw:Wikibooks*/
this.bookname=this.pagename;
this.book=this.bookname;
let re=/^[^\/]*\//g;
this.articlename=re.test(this.pagename)?this.pagename.replace(re,''):"";
}else{
/*Niby-przestrzeń nazw:Wikibooks:Brudnopis/*/
let re=/\/[^\/]*$/g;
this.bookname=this.bookname.toString();
i=this.bookname.search(re);
this.book=this.bookname.slice(i+1);
re=/^Brudnopis\/[^\/]*\/[^\/]*\//g;
this.articlename=re.test(this.pagename)?this.pagename.replace(re,''):"";
}
}else{
if(this.namespacenumber == 2){
/*2=Wikipedysta, przestrzeń nazw: Wikipedysta:<nazwa użytkownika>:*/
let re=/\.(js|css)$/g;
if(! this.pagename.match(re)){
/*Strony niebędce oprogramowaniem interfejsu wiki na stronie użytkownika.*/
let re=/^[^\/]*\/[^\/]*/g;
this.bookname = this.pagename.match(re);
if(this.bookname === null){
/*Przestrzeń nazw: Wikipedysta:*/
this.bookname=this.pagename;
this.book=this.bookname;
this.articlename="";
}else{
/*Przestrzeń nazw: Wikipedysta:<nazwa użytkownika>:*/
let re=/\/[^\/]*$/g;
this.bookname=this.bookname.toString();
i=this.bookname.search(re);
this.book=this.bookname.slice(i+1);
re=/^[^\/]*\/[^\/]*\//g;
this.articlename=re.test(this.pagename)?this.pagename.replace(re,''):"";
}
}else{
/*Strony oprogramowania interfejsu wiki interjesu wiki*/
let re=/^[^\/]*/g;
this.bookname = this.pagename.match(re).toString();
this.book=this.bookname;
re=/^[^\/]*\//g;
this.articlename=re.test(this.pagename)?this.pagename.replace(re,''):"";
}
}else{
/*Pozostałe przestrzenie nazw*/
let re=/^[^\/]*/g;
this.bookname = this.pagename.match(re).toString();
this.book=this.bookname;
re=/^[^\/]*\//g;
this.articlename=re.test(this.pagename)?this.pagename.replace(re,''):"";
}
}
}
re=/\/[^\/]*$/g;
i = this.pagename.search(re);
this.subpagename = (i!=-1)?this.pagename.slice(i + 1):this.bookname;
this.fullbookname = (this.namespacenumber===0)?this.bookname:this.namespace+":"+this.bookname;
if ( /^[Hh][Tt][Tt][Pp][Ss]?:\/\/pl.wikibooks.org\/w\/index.php\?/g.test( document.URL ) ) {
let re = /[\&\?]diff=[^\&]*/g;
this.diff = document.URL.match(re);
if(this.diff === null ){
this.diff = null;
}else{
this.diff = this.diff[0].slice(6, this.diff[0].length);
}
re = /[\&\?]oldid=[^\&]*/g;
this.oldid = document.URL.match(re);
if ( this.oldid === null ) {
this.oldid = null;
} else {
this.oldid = this.oldid[0].slice(7, this.oldid[0].length);
}
re = /[\&\?]action=[^\&]*/g;
this.action = document.URL.match(re);
if ( this.action === null ) {
this.action = null;
} else {
this.action = this.action[0].slice(8, this.action[0].length);
}
} else {
this.diff = null;
this.action = null;
this.oldid = null;
}
return this;
}
StronicowyParser.PageInfoInit().then((dana)=>{StronicowyParser.pageinfo=dana;}).catch(()=>{});