User:Danski454/wikiproject status.js

// $.when(	window.Morebits || mw.loader.getScript('https://en.wikipedia.org/w/index.php?title=MediaWiki:Gadget-morebits.js&action=raw&ctype=text/javascript'),	$.ready,	importStylesheet( 'MediaWiki:Gadget-morebits.css' ) ).then(function{	if (!mw.config.get('wgPageName').startsWith('Wikipedia:WikiProject_')) {		return;//not a WikiProject	}	var interfaceWindow, form;	function doEdit{	}	function display(wikitext){		var data = wikitext.match(/{{\s*(wiki)?project( status| header)?\s*(\|\s*(1\s*=\s*)?([^|=}]*\w)\s*)?(\|[^}]*)?}}/i) || [];		var statuses = [{value:'active', label:'active'},						{value:'semi-active', label:'semi-active'},						{value:'draft', label:'draft'},						{value:'inactive', label:'inactive'},						{value:'defunct', label:'defunct'}];		var parameters = {};		switch ((data[5] || '').toLowerCase) {			case 'semi':			case 'semi-active':				statuses[1].selected = true;				break; case 'draft': statuses[2].selected = true; break; case 'inactive': statuses[3].selected = true; break; case 'defunct': statuses[4].selected = true; break; default: statuses[0].selected = true; }		var paramlist = (data[6] || '').split('|'); for (var i = 0; i < paramlist.length; i++) { var match = paramlist[i].match(/\s*([^=]*[^=\s])\s*=\s*(.*\S)\s*/s); if (match) { parameters[match[1]] = match[2]; }		}		var shortcuts = []; if (parameters.sc && !parameters.sc1) { shortcuts.push(parameters.sc); }		for (i = 1; i <= 5; i++) { if (parameters['sc' + i.toString]) { shortcuts.push(parameters['sc' + i.toString]); }		}		var nocat = [{value:'true', label:'Off'}, {value:'', label: 'Default'}, {value:'false', label:'Force'}]; switch ((parameters.nocat || '').toLowerCase){ case '1': case 'y': case 'yes': case 'true': nocat[0].selected = true; break; case '0': case 'n': case 'no': case 'false': nocat[2].selected = true; break; default: nocat[1].selected = true; }		var projectType = [{value:, label:}, {value:'topic', label: 'Topic'}, {value:'process', label:'Process'}]; var topic = parameters.topic || parameters.process || ''; switch ((parameters['project-type'] || '').toLowerCase){ case 'topic': projectType[1].selected = true; break; case 'process': projectType[2].selected = true; topic = parameters.process || topic; break; default: projectType[0].selected = true; }		interfaceWindow = new Morebits.simpleWindow(			Math.min(900, Math.floor(window.innerWidth*0.8)),			Math.floor(window.innerHeight*0.9)		); interfaceWindow.setTitle( 'WikiProject status' ); interfaceWindow.addFooterLink('script documentation', 'User:Danski454/wikiproject status'); interfaceWindow.addFooterLink('template documentation', 'Template:WikiProject status'); form = new Morebits.quickForm(doEdit); form.append({			type: 'select',			label: 'Status',			name: 'status',			list: statuses		}); form.append({			type: 'input',			label: 'Date ',			name: 'date',			value: parameters.date || ''		}); form.append({			type: 'input',			label: 'Portal ',			name: 'portal',			value: parameters.portal || ''		}); form.append({			type: 'input',			label: 'Merged to ',			name: 'mergedto',			value: parameters.mergedto || ''		}); form.append({			type: 'input',			label: 'Type ',			name: 'type',			value: parameters.type || ''		}); form.append({			type: 'input',			label: 'Parent ',			name: 'parent',			value: parameters.parent || ''		}); form.append({			type: 'select',			label: 'Categorisation ',			name: 'nocat',			list: nocat		}); form.append({			type: 'textarea',			label: 'Note',			name: 'note',			value: parameters.note || ''		}); form.append({			type: 'dyninput',			label: 'Shortcuts',			name: 'shortcuts',			sublabel: 'Shortcut ',			id: 'wpshortcuts',			min: 0,			max: 5		}); var TFfield = form.append({			type: 'field',			label: 'Task force'		}); TFfield.append({			type: 'checkbox',			list:[{			label: 'Is task force ',			name: 'taskforce',			checked: !!parameters.taskforce		}]}); TFfield.append({			type: 'select',			label: 'Project type',			name: 'project-type',			list: projectType		}); TFfield.append({			type: 'input',			label: 'Topic/process ',			name: 'topic',			value: topic		}); var stylefield = form.append({			type: 'field',			label: 'Style'		}); stylefield.append({			type: 'input',			label: 'Margin ',			name: 'margin',			value: parameters.margin || ''		}); stylefield.append({			type: 'input',			label: 'Style ',			name: 'style',			value: parameters.style || ''		}); stylefield.append({			type: 'input',			label: 'Image ',			name: 'image',			value: parameters.image || ''		}); stylefield.append({			type: 'checkbox',			list:[{			label: 'Hide ',			name: 'hide',			checked: !!parameters.hide		}]}); stylefield.append({			type: 'checkbox',			list:[{			label: 'Use British English ',			name: 'en-gb',			checked: !!parameters['en-gb']		}]}); var result = form.render; interfaceWindow.setContent(result); interfaceWindow.display; if (shortcuts.length) { $('#wpshortcuts div').first.find('input').first.val(shortcuts[0]); }		for (i = 1; i < shortcuts.length; i++) { $('#wpshortcuts span').last.find('input').click; $('#wpshortcuts div').last.find('input').first.val(shortcuts[i]); }	}	function load{ $.getJSON(			mw.util.wikiScript('api'),			{				format: 'json',				action: 'query',				prop: 'revisions',				rvprop: 'content',				rvlimit: 1,				titles: mw.config.get('wgPageName')			}		) .done(function ( data ) {				var page, wikitext;				//try {					for ( page in data.query.pages ) {						wikitext = data.query.pages[page].revisions[0]['*'];						display( wikitext );					}				/*} catch ( e ) {					console.error('Failed to get page contents');				}*/			}) .fail( function{console.error('Failed to get page contents');} ); }	var portletLink = mw.util.addPortletLink('p-cactions', '#', 'WikiProject status', 'ca-wp-status', 'Edit the WikiProject status banner', ''); $(portletLink).click(load); /{{\s*(wiki)?project( status| header)?\s*(\|\s*(1\s*=\s*)?([^|=}]*\w)\s*)?(\|[^}]*)?}}/i; }); //