User:Gryllida/js/wab-sub.js

mw.loader.using(['mediawiki.api', 'oojs-ui'], function {	$options = $(' Article status: (select drafts to help copyedit new submissions!)  ');	$s_status = $(' ');	$s_status.append($(' '));	$s_status.append(" New published ");	$s_status.append($(' '));	$s_status.append(" New drafts ");	$options.append($s_status);	$s_dtype = $(' Delivery type: ');	$s_dtype.append($(' '));	$s_dtype.append(" Email (uses Special:EmailUser) ");	$s_dtype.append($(' '));	$s_dtype.append(" My personal talk page ");	$options.append($s_dtype); var buttonP = new OO.ui.ButtonWidget( {		label: 'Save and select topics',		flags: 'progressive'	} ); buttonP.$element.click(function(e){		// content		cats = '';		$('#mw-normal-catlinks > ul > li > a').each(function(e){ var cat = $(this).attr('title').replace('Category:', ''); if(cat== 'Published' || cat=='Developing' || cat=='Disputed'){return true;} if(cat.indexOf(',') > 0){return true;} cats += '*' + $(this).attr('title').replace('Category:', '') + '\r\n'; });		cats += 'Cat' + 'egory:Gryllida' + '/WAB/Pending';		status = $('input[name=wab-status]:checked').val;		delivery = $('input[name=wab-delivery]:checked').val;		titlePostFix = '/wab/' + status + '/' + delivery,		api = new mw.Api;		var titleEdit = 'User:' + wgUserName + titlePostFix + '/preload';		api.postWithToken('edit',{ action: 'edit', title: titleEdit, text: cats, summary: 'created my delivery list (assisted)' }).done(function (data){ console.log(data); titleEdit = 'User talk: ' + wgUserName + titlePostFix; api.postWithToken('edit',{				action: 'edit',				title: titleEdit,				text: '0',				summary: 'created my delivery list (assisted)'			}).done(function (data){				console.log(data);				url = 'http://en.wikinews.org/wiki/User:' + wgUserName + titlePostFix;				url += '?action=edit';				url += '&preload=User:' + wgUserName + titlePostFix + '/preload';				url += '&editintro=User:Gryllida/wab/editintro';				window.location.href = url;			}); }).fail( function( code, result ) { console.log(result); });

});	$options.append(buttonP.$element);

var popupButton = new OO.ui.PopupButtonWidget( { 		label: 'Subscribe', 		id: 'wab-sub-button',		icon: 'articles', 		popup: {			$content: $options,			padded: true,			align: 'forwards'		}	} ); $('#catlinks').append(popupButton.$element );

});