User:Enterprisey/parsoid-round-trip.js

$( function {    if( mw.config.get( "wgPageName" ) === "Special:BlankPage/Parsoid_round_trip" ) {        mw.loader.load( [ "mediawiki.diff.styles" ] );        mw.loader.addStyleTag( "#go:not(:disabled) { cursor: pointer; }" );        $( "#firstHeading" ).text( "Parsoid round trip" );        var userAgent = "parsoid-round-trip.js (https://en.wikipedia.org/wiki/User:Enterprisey/parsoid-round-trip)";        $( "#mw-content-text" ).empty.append( " Wikitext: ", $( " ", { id: "wikitext", height: "6em" } ), $( " ", { id: "go" } ) .css( { padding: "0.5em", margin: "0.5em 0" } ) .text( "Round-trip from wikitext to HTML and back" ) .click( function {                    $( "#go" ).prop( "disabled", true );                    var originalWikitext = $( "#wikitext" ).val;                    $.post( { url: "https://en.wikipedia.org/api/rest_v1/transform/wikitext/to/html", data: { wikitext: originalWikitext, body_only: true }, headers: { "User-Agent": userAgent } } ).then( function ( html ) { $.post( {                           url: "https://en.wikipedia.org/api/rest_v1/transform/html/to/wikitext",                            data: { html: html },                            headers: { "User-Agent": userAgent }                        } ).then( function ( wikitext ) {                            $( "#result" ).text( wikitext );                            $.get( { url: "https://en.wikipedia.org/w/api.php?action=compare&prop=diff&format=json&formatversion=2&fromslots=main&fromcontentmodel-main=wikitext&fromtext-main=" + encodeURIComponent( originalWikitext ) + "&toslots=main&tocontentmodel-main=wikitext&totext-main=" + encodeURIComponent( wikitext ), headers: { "User-Agent": userAgent } } ).then( function ( data ) { $( "#go" ).prop( "disabled", false ); var diffHtml = data.compare.body; if( diffHtml ) { $( "#diff" ).empty.append( $( " ", { "class": "diff" } ).append( '  ', diffHtml ) ); } else { $( "#diff" ).empty.text( "(no difference)" ); }                           }, function  { $( "#go" ).prop( "disabled", false ); } );                        }, function  { $( "#go" ).prop( "disabled", false ); } ); }, function { $( "#go" ).prop( "disabled", false ); } );                } ), $( " ", { id: "result" } ).css( {               padding: "0.5em",                border: "thin dashed gray",                "font-family": "monospace",                "white-space": "pre",                overflow: "auto"            } ), $( " ", { id: "diff" } ) );   } } );