User:DaxServer/test.js

//

$.when(   $.ready,    mw.loader.using([ "mediawiki.util", "oojs-ui-core", "oojs-ui-widgets" ]) ).then(function  {    function makeContent( pageName, id, hash ) {        let wikitext = "" + (pageName + hash).replace( /_/g, " " ).replace( /</g, '&lt;' ) + "";        let copyId = `copy-section-wikilink-${id}-${hash.substring(1)}`;

return $( ' ', { "class": "copy-section-link-content" } ).append(           $( " ", { "id":  copyId} ).text( wikitext ),            $( " " )                .text( "Copy" )                .css( { "padding": "0.5em", "cursor": "pointer", "margin-left": "0.5em" } )                .click( function  { navigator.clipboard.writeText( $( `#${copyId}` ).text ); } ),           " external"        ); }

let pageName = mw.config.get( 'wgPageName' ); let oldid = mw.util.getParamValue( 'oldid' ); let curid = mw.config.get( 'wgCurRevisionId' ); let generalCss = { 'font-size': '0.9rem', 'font-family': 'sans-serif' };

$( "span.mw-headline" ).each( function {        $( this ).after( " ", $( "", { "class": "copy-section-link-pilcrow" } ) .text( "¶" ) .click( function {                    let hash = "#" + $( this ).prev.attr( "id" ).replace( /</g, '&lt;' );                    let popupContent, index;

if ( oldid ) { popupContent = makeContent( `Special:Permalink/${oldid}`, 'oldid', hash ); popupContent.css( generalCss ); popupContent.css( { 'padding-top': '0.5em', 'font-weight': 'normal' } ); } else { let normalPanel = new OO.ui.TabPanelLayout( 'normal', {                           label: 'Link',                            $content: makeContent( pageName, 'normal', hash )                        } ); let permalinkPanel = new OO.ui.TabPanelLayout( 'permalink', {                           label: 'Permalink',                            $content: makeContent( `Special:Permalink/${curid}`, 'permalink', hash )                        } );

index = new OO.ui.IndexLayout; index.addTabPanels( [ normalPanel, permalinkPanel ] ); popupContent = index.$element; }

let popup = new OO.ui.PopupWidget( {                       $content: popupContent,                        $floatableContainer: $( this ),                        padded: true,                        width: 400,                        height: 190,                        align: 'forwards',                        autoClose: true,                    } );

$( this ).after( popup.$element );

if ( index ) { index.$menu.find( 'span.oo-ui-labelElement-label' ).css( generalCss ); index.$content.css( generalCss ); }

popup.toggle( true ); } ) )       ;    } );    mw.util.addCSS( "h2 .copy-section-link-pilcrow," + "h3 .copy-section-link-pilcrow," + "h4 .copy-section-link-pilcrow," + "h5 .copy-section-link-pilcrow," + "h6 .copy-section-link-pilcrow" + "{ color: lightgray }" + "h2:hover .copy-section-link-pilcrow," + "h3:hover .copy-section-link-pilcrow," + "h4:hover .copy-section-link-pilcrow," + "h5:hover .copy-section-link-pilcrow," + "h6:hover .copy-section-link-pilcrow" + "{ color: inherit }" );

});

//