MediaViki:Gadget-shiftrefs.js

Vikipediya, azad ensiklopediya
Naviqasiyaya keç Axtarışa keç

Qeyd: Dəyişiklikləri yayımladıqdan sonra etdiyiniz dəyişikliklərin görünməsi üçün brauzerinizin keşinin təmizlənməsi lazım ola bilər.

  • Firefox / Safari: Reload düyməsinə basılı tutarkən Shift düyməsinə basın, və ya Ctrl+F5 və ya Ctrl+R (Mac üçün ⌘-R )
  • Google Chrome: Ctrl-Shift-R (Mac üçün ⌘-Shift-R)
  • Internet Explorer / Edge: Ctrl düyməsini basılı tutarkən Refresh düyməsinə basın, və ya sadəcə Ctrl+F5
  • Opera: Ctrl+F5.
// Copy from https://ru.wikipedia.org/wiki/Участник:Ignatus/shiftrefs.js
// Authors: https://ru.wikipedia.org/wiki/Участник:Ignatus/shiftrefs.js?action=history

/*************************************************************/
/*****      İstinadları nöqtədən sonraya keçirir      *****/
/*************************************************************/
function lebedevrefs() {
	var diglasttext;
	var getsimpletext;
	diglasttext = function ( n ) {
		return n.lastChild ? diglasttext( n.lastChild ) : n;
	};
	getsimpletext = function ( n ) {
		return n.innerHTML.replace( /<(?:"(?:\\\\|\\"|\\[^"]|[^\\"])*"|'(?:\\\\|\\'|\\[^']|[^\\'])*'|[^"'>])+>/ig, '' ); //'
	};
	var zone = document.getElementById( 'wikiPreview' ) || document.getElementById( 'bodyContent' )
		|| document.getElementById( 'mw_contentholder' ) || document.getElementById( 'article' );

	var alles = Array();
	{
		var j = zone.getElementsByTagName( '*' );
		for ( var i = 0; i < j.length; i++ ) {
			alles[ i ] = j[ i ];
		}
	}
	var getdots = /^([\s\S]*?)([.,…]*)$/;
	var i = 0;
	var f = function () {
		if ( i < alles.length ) {
			var ch = alles[ i ].childNodes;
			for ( var j = 0; j < ch.length; j++ ) {
				var l = 0;
				while ( j + l < ch.length // &&
					&& ( ch[ j + l ].nodeType == 1 ) 
					&& /(^|\s)reference(\s|$)/i.test( ch[ j + l ].className )
				) {
					l++;
				}
				if ( l ) {//есть группа
					var grp = document.createElement( 'span' );
					for ( var k = 0; k < l; k++ ) {
						ch[ j ].style.position = 'relative';
						grp.appendChild( ch[ j ] );
					}
					if ( j < ch.length ) {
						alles[ i ].insertBefore( grp, ch[ j ] );
					} else {
						alles[ i ].appendChild( grp );
					}
					grp.style.whiteSpace = 'nowrap';
					var ppw = 0.;
					if ( j ) {
						if ( ch[ j - 1 ].nodeType == 3 ) { 
							var a = /^([\S\s]*\s)?(\S*?)([.,…]*)?$/.exec( ch[ j - 1 ].nodeValue );
							ch[ j - 1 ].nodeValue = a[ 1 ] || '';
							var b = document.createElement( 'span' );
							var t = document.createTextNode( a[ 3 ] || a[ 2 ] );
							b.appendChild( t );
							grp.insertBefore( b, grp.firstChild );
							if ( a[ 3 ] ) {
								b.style.marginRight = '-' + b.offsetWidth + 'px';
								t.nodeValue = a[ 2 ] + t.nodeValue;
							}
							ppw = b.offsetWidth;
						} else {
							var lt = diglasttext( ch[ j - 1 ] );
							var a = getdots.exec( lt.nodeValue );
							if ( a[ 2 ] ) {
								lt.nodeValue = a[ 1 ];
								var b = document.createElement( 'span' );
								b.appendChild( document.createTextNode( a[ 2 ] ) );
								lt.parentNode.appendChild( b );
								ppw = b.offsetWidth;
								b.style.marginRight = '-' + ppw + 'px';
							}
							if ( /nowrap|pre$/.test( ch[ j - 1 ].style.whiteSpace ) || !/\s/.test( getsimpletext( ch[ j - 1 ] ) ) ) {
								grp.insertBefore( ch[ j - 1 ], grp.firstChild );
								ppw += grp.firstChild.offsetWidth;
							}
						}//else
					}//if ( j )
					if ( grp.nextSibling ) {
						if ( grp.nextSibling.nodeType == 3 ) {
							var a = /^([.,…]*)([\s\S]*?)$/.exec( grp.nextSibling.nodeValue );
							if ( a[ 1 ] ) {
								grp.nextSibling.nodeValue = a[ 2 ];
								var b = document.createElement( 'span' );
								b.appendChild( document.createTextNode( a[ 1 ] ) );
								grpw = grp.offsetWidth;
								grp.appendChild( b );
								b.previousSibling.style.marginRight = ( ppw - grpw ) + 'px';
								b.previousSibling.style.position = 'relative';
								b.style.marginRight = ( grpw - ppw - b.offsetWidth ) + 'px';
							}//if(a[1])
						}//if( grp.nextSibling.nodeType==3 )
					}//if(grp.nextSibling)
				}//if(l)
			}//for(ch)
			i++;
			window.setTimeout( f, 0 );
		} else {//(i>=alles.length)
			f = null;
		}//if(i<alles.length)
	};//f
	if ( alles.length ) {
		f();
	}
}

if ( mw.config.get( 'wgNamespaceNumber' ) >= 0 ) {
	$( lebedevrefs );
}