ميدياويكي:Gadget-copySectionLink.js

من ويكيبيديا، الموسوعة الحرة

ملاحظة: بعد الحفظ، قد يلزمك إفراغ الكاش لرؤية التغييرات.

//[[kk:mediawiki:Gadget-copySectionLink.js]]
$( function copySectionLink() {
	$( '.mw-headline' ).each( function () {
		$( '<span class="noprint">#</span>' )
			.appendTo( $( this ).parent().append( ' ' ) )
			.attr( 'title', 'نسخ وصلة عنوان القسم' )
			.css( { fontSize: 'small', color: '#0645ad', cursor: 'pointer' } )
			.click( function () {
				if ( $( '#copyAnchor' ).is( ':visible' ) ) {
					return;
				}
				var headerText = $( this ).siblings().first().text().match( /[0-9.]{1,5} (.*)|(.*)/ );
				headerText = headerText[1] || headerText[2];
				
				var copyText = mw.config.get('wgPageName').replace( '_', ' ' ) + '#' +
					( ( $( this ).parent().find( '.editsection a' ).length )
						? $( this ).parent().find( '.editsection a' ).attr( 'title' ).match( /: (.*)/ )[1] 
						: headerText 
				);
				
				if ( window.clipboardData ) {
					window.clipboardData.setData( 'Text', copyText ); //IE
				} else {
					$( this ).parent().append(
						$( "<span id='copyAnchor'>" ).append(
							$( '<input>' ).attr( 'size', copyText.length )
								.val( copyText )
								.click( function () { this.select() } ),
							$( '<input>' ).attr( 'type', 'button' )
								.val( 'تم' )
								.click( function () { $( '#copyAnchor' ).remove() } )
				        )
					);
				}
			} );
	} );
} );