Jump to content

User:Enterprisey/diff-permalink.js: Difference between revisions

From Wikipedia, the free encyclopedia
Content deleted Content added
new script
 
remove pointless outer wrapper
(15 intermediate revisions by the same user not shown)
Line 1: Line 1:
// <nowiki>
// <nowiki>
$( function () {
$.when( $.ready, mw.loader.using( [ "mediawiki.util" ] ) ).then( function () {
var suffix = mw.config.get( "wgDiffNewId" );
var suffix = mw.config.get( "wgDiffNewId" );
var page;
if( suffix ) {
if( suffix ) {
if( document.getElementsByClassName( "diff-multi" ).length )
if( document.getElementsByClassName( "diff-multi" ).length ||
mw.config.get("wgPageName") === "Special:ComparePages" ) {
suffix = mw.config.get( "wgDiffOldId" ) + "/" + suffix;
suffix = mw.config.get( "wgDiffOldId" ) + "/" + suffix;
}
var diffEl = $( "<input>" ).val( "Special:Diff/" + suffix )
page = "Special:Diff/" + suffix;
.click( function () { this.select(); document.execCommand( "copy" ); } );
} else {
diffEl.attr( "size", diffEl.val().length ); // resize to diff length
$( "#bodyContent" ).prepend( diffEl )
var oldidMatch = mw.util.getParamValue( "oldid" );
.prepend( "Permalink to this diff: " );
if( oldidMatch ) {
page = "Special:Permalink/" + oldidMatch;
} else return; // nothing to do here
}

var permalinkEl = $( "<div>" ).append(
"Permalink to this " + ( suffix ? "diff" : "oldid" ) + ": ",
$( "<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" );
} ) );
$( "#diff-permalink-link" ).attr( "size", page.length ) // resize to diff length
if( suffix ) {
$( "#bodyContent" ).prepend( permalinkEl );
} else {
$( "#contentSub" ).after( permalinkEl );
}
}
} );
} );

Revision as of 09:37, 6 December 2020

// <nowiki>
$.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(
        "Permalink to this " + ( suffix ? "diff" : "oldid" ) + ": ",
        $( "<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" );
            } ) );
    $( "#diff-permalink-link" ).attr( "size", page.length ) // resize to diff length
    if( suffix ) {
        $( "#bodyContent" ).prepend( permalinkEl );
    } else {
        $( "#contentSub" ).after( permalinkEl );
    }
} );
// </nowiki>