Jump to content

User:Enterprisey/diff-permalink.js

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Enterprisey (talk | contribs) at 04:24, 1 December 2020 (update again). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
// <nowiki>
( function () {
    $.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 = $( "<div>" ).append(
            $( "<input>", { "id": "diff-permalink-link" } )
                .val( page ),
            $( "<button>" )
                .text( "Copy" )
                .css( { "padding": "0.5em", "cursor": "pointer", "margin-left": "0.5em" } )
                .click( function () {
                    document.getElementById( "diff-permalink-link" ).select();
                    document.execCommand( "copy" );
                } ) );
        permalinkEl.attr( "size", permalinkEl.val().length ) // resize to diff length
        if( suffix ) {
            $( "#bodyContent" ).prepend( permalinkEl )
                .prepend( "Permalink to this diff: " );
        } else {
            $( "#contentSub" ).after( permalinkEl ).after( "Permalink to this oldid: " );
        }
    } );
} )();
// </nowiki>