User:Wotheina/diff-permalink.js

// // based on User:Enterprisey/diff-permalink.js 2022-06-12 // rev 2022-11-25 $.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("wgCanonicalSpecialPageName") === "ComparePages" ) {           suffix = mw.config.get( "wgDiffOldId" ) + "/" + suffix;        }

var editorDOM = document.getElementById("mw-diff-ntitle2"); var editorcontribs; var editorcontribsarray = editorDOM.getElementsByClassName( "mw-usertoollinks-contribs" ); // wiki site dependent if ( 1 <= editorcontribsarray.length ) { editorcontribs = editorcontribsarray[0].title; // wiki site dependent } else { editorcontribs = editorDOM.getElementsByClassName( "mw-userlink" )[0].title; // wiki site dependent }		var editornamei = editorcontribs.indexOf('/'); var editorname = editorcontribs.substring(editornamei+1); // exclude "Special:Contributions/". wiki site dependent

page = "Special:Diff/" + suffix + " by " + editorname + ""; } 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" ) + ": ",       $( " " )            .attr( { "id": "diff-permalink-link" } )            .attr( "size", page.length )            .val( page ),        $( " " )            .text( "Copy" )            .css( { "cursor": "pointer", "margin-left": "0.5em" } )            .click( function  { document.getElementById( "diff-permalink-link" ).select; document.execCommand( "copy" ); } ) );

if( suffix ) { $( "#bodyContent" ).prepend( permalinkEl ); } else { $( "#contentSub" ).after( permalinkEl ); }

//   $( "#diff-permalink-link" ).attr( "size", page.length ); // resize to diff length } ); //