User:Andrybak/global.js

// code adapted from https://en.wikipedia.org/wiki/User:Enterprisey/diff-permalink.js console.log("started permalink script"); $.when( $.ready, mw.loader.using( [ "mediawiki.util" ] ) ).then( function {    var suffix = mw.config.get( "wgDiffNewId" );    var page;    if( suffix ) {        if( document.getElementsByClassName( "diff-multi" ).length || mw.config.get("wgPageName") === "Special:ComparePages" ) {           suffix = mw.config.get( "wgDiffOldId" ) + "/" + suffix;        }        page = "Special:Diff/" + suffix;    } else {        var oldidMatch = mw.util.getParamValue( "oldid" );        if( oldidMatch ) {            page = "Special:Permalink/" + oldidMatch;        } else return; // nothing to do here    }

var permalinkEl = $( " " ).append(       "Permalink to this " + ( suffix ? "diff" : "oldid" ) + ": ",       $( " ", { "id": "diff-permalink-link" } )            .val( page ),        $( " " )            .text( "Copy" )            .css( { "padding": "0.5em", "cursor": "pointer", "margin-left": "0.5em" } )            .click( function  { document.getElementById( "diff-permalink-link" ).select; document.execCommand( "copy" ); } ) );   $( "#diff-permalink-link" ).attr( "size", page.length ) // resize to diff length if( suffix ) { $( "#WikiaMainContent" ).prepend( permalinkEl ); } else { $( "#PageHeader" ).after( permalinkEl ); }   console.log("set up permalink control"); } );