User:Ricky81682/common.js

/* User:Σ/Testing facility/Archiver */ importScript( 'User:Σ/Testing facility/Archiver.js' ); // Backlink: User:Σ/Testing facility/Archiver

importScript('User:Mr. Stradivarius/gadgets/Draftify.js'); // Linkback: User:Mr. Stradivarius/gadgets/Draftify.js

// ( function ( $, mw ) {   mw.loader.load( "jquery.chosen" );    mw.loader.load( "mediawiki.ui.input", "text/css" );    if ( mw.config.get( "wgNamespaceNumber" ) !== 118 ) return;    const WIKIPROJECT_LIST = "User:Theo's Little Bot/afchwikiproject.js";    var portletLink = mw.util.addPortletLink('p-cactions', '#', 'Sort (draft)', 'pt-draftsort', 'Manage WikiProject tags');    $( portletLink ).click( function ( e ) { e.preventDefault; // If it's already there, don't duplicate if ( $( "#draft-sorter" ).length ) return; // Construct the form var form = $( " " ) .append( $( " " )               .text( "Loading form..." )               .css( "color", "gray" ) ); $.getJSON( mw.config.get( 'wgServer' ) + "/w/index.php?title=" +                  WIKIPROJECT_LIST + "&action=raw&ctype=text/javascript", null, function ( data ) {            var select = $( " " )                .attr( "id", "draft-sorter-form" )                .attr( "multiple", "multiple" );            $.each( data, function ( name, template ) { select.append( $( " " )           	    .attr( "value", template )            	    .text( name ) ); } );           form.hide;            form.empty;            form.append( $( " " ) .text( "Tag WikiProjects: " ) .css( {               	"font-size": "115%",                	"font-weight": "bold"                } ) );            form.append( select );            form.append( $( " " ) .text( "Submit" ) .addClass( "mw-ui-button" ) .addClass( "mw-ui-constructive" ) .addClass( "mw-ui-big" ) .css( "margin-left", "0.25em" ) .click( submit ) );           form.append( $( " " ) .addClass( "mw-ui-button mw-ui-destructive mw-ui-quiet" ) .text( "Cancel" ) .click( function ( e ) {                               $( "#draft-sorter" ).remove;                        } ) );            form.show;            $( select ).chosen( { "placeholder_text_multiple": "Select some WikiProjects" } );       } );        // Insert the form into the "ombox" we're putting on the page $( " " )           .insertAfter( "#jump-to-nav" ) .attr( "id", "draft-sorter" ) .addClass( "ombox" ) .append( $( " " )               .append( $( " " ) .append( $( " " )                       .addClass( "mbox-image" )                        .append( $( " " ) .css( "padding", "5px" ) .attr( {                           	"src": "https://upload.wikimedia.org/wikipedia/commons/f/f9/Curation_tool_tag_icon.svg",                            	"alt": "Tag icon",                            	"width": "75",                            	"height": "75"                            } ) ) ) .append( $( " " )                       .addClass( "mbox-text" )                        .append( form ) ) ) ); // The submission function var submit = function { var newTags = $( "#draft-sorter-form").val; console.log( newTags ); $( "#draft-sorter tbody tr td.mbox-text" ).empty; var statusList = $( "" ) .appendTo( "#draft-sorter tbody tr td.mbox-text" ) .append( $( "" ).text( "Saving " + newTags.length + " new tags." ) );       	var showStatus = function ( status ) { return $( "" ) .text( status ) .appendTo( statusList ); };       	var newText = ""; newTags.forEach( function ( element ) {       		newText += "";        	} ); $.ajax( {               url: mw.util.wikiScript( 'api' ),                type: 'POST',                dataType: 'json',                data: {                    format: 'json',                    action: 'edit',                    title: "Draft talk:" + mw.config.get( 'wgTitle' ),                    summary: "Tagging drafts (draft-sorter.js)",                    token: mw.user.tokens.get( 'editToken' ),                    prependtext: newText                }        	} ).done( function ( data ) {        		if ( data && data.edit && data.edit.result && data.edit.result === "Success" ) {        			showStatus( "Edit saved successfully! (" ) .append( $( "" )                           .text( "reload" )                            .attr( "href", "#" )                            .click( function  { document.location.reload( true ); } ) ) .append( ")" );       		} else {        			showStatus( "Couldn't save due to error: " + JSON.stringify( data ) );        		}        	} ).fail( function ( error ) {        		showStatus( "Couldn't save due to error: " + JSON.stringify( error ) );        	} ); };   } ); }( jQuery, mediaWiki ) ); //