MediaWiki:Gadget-false-blue-links.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.
/**
* Zaznacza innym kolorem linki do nieistniejących sekcji językowych istniejących haseł.
* Przeróbka autorstwa [[User:Olaf]] skryptu [[User:Beau]] do zabarwiania disambigów:
* https://pl.wikipedia.org/wiki/MediaWiki:Gadget-mark-disambigs.js
* Dalsze modyfikacje: [[User:Peter Bowman]]
*/
var fbl = mw.libs.falseBlueLinks = {
langSections: {},
ignoredClasses: [
'.new',
'.extiw',
'.external',
'.internal',
'.image',
'.mw-redirect',
'.cancelLink'
]
};
var api, worklist, pathPrefix;
var config = mw.config.get( [
'wgPageName',
'wgAction',
'wgNamespaceNumber',
'wgArticlePath',
'wgFormattedNamespaces',
'lang2code'
] );
function makeRequest( cont ) {
var query = $.extend( {
titles: config.wgPageName,
prop: 'categories',
cllimit: 'max',
clshow: '!hidden',
generator: 'links',
gpllimit: 'max',
gplnamespace: 0,
redirects: true
}, cont );
return api.get( query ).then( function ( data ) {
$.each( data.query && data.query.pages || [], function () {
var arr;
if ( !this.categories ) {
return true;
}
// Zabezpieczenie przed metodami Object.prototype.(un)watch pod FF
if ( worklist.hasOwnProperty( this.title ) ) {
arr = worklist[ this.title ];
} else {
arr = worklist[ this.title ] = [];
}
$.each( this.categories, function ( i, obj ) {
var formattedNs = config.wgFormattedNamespaces[ 14 ];
var title = obj.title.slice( formattedNs.length + 1 );
arr.push( title );
} );
} );
if ( data[ 'continue' ] ) {
return makeRequest( data[ 'continue' ] );
}
} );
}
function extractLangSections() {
var re = /^(.*?) \((?:indeks|formy fleksyjne)\)$/;
$.each( worklist, function ( title, categories ) {
$.each( categories, function ( i, cat ) {
var iso, m = cat.match( re );
if ( !m || !m[ 1 ] ) {
return true;
}
iso = config.lang2code[ m[ 1 ] ];
if ( iso ) {
iso = iso.replace( '-foreign', '' );
if ( !fbl.langSections.hasOwnProperty( title ) ) {
fbl.langSections[ title ] = {};
}
fbl.langSections[ title ][ iso ] = true;
}
} );
} );
}
function extractSelfSections( pageName, $content ) {
$content.find( '.primary-lang-code' ).each( function () {
var id = this.id;
if ( id ) {
id = id.replace( '-foreign', '' );
if ( !fbl.langSections.hasOwnProperty( pageName ) ) {
fbl.langSections[ pageName ] = {};
}
fbl.langSections[ pageName ][ id ] = true;
}
} );
}
function decodeFragment( s ) {
return decodeURIComponent(
s.replace( /\./g, '%' ).replace( /_/g, ' ' )
);
}
function extractArticleName( s ) {
return decodeURI(
s.replace( pathPrefix, '' ).replace( /_/g, ' ' )
);
}
function filterLinks( i, link ) {
var title, fragment, m, iso;
var uri = new mw.Uri( link.getAttribute( 'href' ) );
if (
!uri.fragment ||
!$.isEmptyObject( uri.query ) ||
uri.path.indexOf( ':' ) !== -1
) {
return false;
}
title = extractArticleName( uri.path );
fragment = decodeFragment( uri.fragment );
m = fragment.match( new RegExp( '^' + title + ' \\((?:język )?(.+)\\)$' ) );
iso = ( m && m[ 1 ] )
? config.lang2code[ m[ 1 ] ]
: fragment;
return (
iso &&
fbl.langSections.hasOwnProperty( title ) &&
!fbl.langSections[ title ][ iso ] &&
!fbl.langSections[ title ].inter &&
!(
( iso === 'zh' || iso === 'ja' ) &&
!fbl.langSections[ title ][ 'zh-char' ]
)
);
}
function onPageReady() {
var pageName = config.wgPageName.replace( /_/g, ' ' );
var $content = $( '#mw-content-text' );
if (
!fbl.langSections[ pageName ] &&
$content.find( '.selflink' ).length
) {
extractSelfSections( pageName, $content );
}
if ( !$.isEmptyObject( fbl.langSections ) ) {
$content
.find( mw.format(
'a[href^="$1"]:not($2)',
pathPrefix,
fbl.ignoredClasses.join( ', ' )
) )
.filter( filterLinks )
.addClass( 'mw-false-blue' );
}
}
if (
config.wgAction === 'view' &&
config.wgNamespaceNumber >= 0 &&
config.wgNamespaceNumber !== 14 // Kategoria
) {
api = new mw.Api();
worklist = {};
pathPrefix = mw.format( config.wgArticlePath, '' );
$.when(
makeRequest().done( extractLangSections ),
$.ready
).done( onPageReady );
}