User:Padenton/DelsortMenu.js

// // Script:        DelsortMenu.js // Version:        1.0.0 // Author:        Padenton // Documentation: User:Padenton/DelsortMenu // GitHub: // Prerequisites: MediaWiki version 1.8 or higher //                jStorage via ResourceLoader //                Any modern broswer or IE8+ //				  Vector css // // Text available under the Creative Commons Attribution-ShareAlike License (CC BY-SA 3.0) //

// Modifications to add delsort by User:Padenton. Functions adapted from WP:FWDS function defineLink(category) { mw.util.addPortletLink('p-delsort', 'javascript:doDelsort("' + category + '")', category, '', 'delsort XfD into ' + category + '.'); }

function delsortIt { x = prompt("Category: "); if (x != null) { //TODO: Add check to make sure valid category doDelsort(x); }		else { alert('Delsort cancelled!'); }	}

function doDelsort(cat) { var url = "//en.wikipedia.org/w/api.php?action=tokens&format=json&type=edit"; var xhr = new XMLHttpRequest; xhr.open("GET", url); //Code now working, was set to async xhr.send; xhr.onreadystatechange = function { if (xhr.readyState == 4 && xhr.status == 200) { var resp = JSON.parse(xhr.responseText); console.log("Token first: ", resp.tokens.edittoken); $.each(resp, function(i, v) {						console.log(i, "=", v);					}); var etoken = resp.tokens.edittoken; console.log("The token is: ", etoken); if (cat != null) { var editData = { action: "edit", format: "json", summary: "Listing at WP:DELSORT under " + cat + " (FWDS)", token: etoken, title: mw.config.get('wgPageName'), appendtext: "\{\{subst:Delsort|" + cat + "|\~\~\~\~\}\}" };						$.each(editData, function(i, v) {							console.log(i, "=", v);						}); $.post('//en.wikipedia.org/w/api.php', editData, function(data) {							jQuery.each(data, function(index, value) { console.log("index", index, "value", value); });						});						// Add to the Delsort page //First, get the content $.post('//en.wikipedia.org/w/api.php', {							action: 'query',							format: 'json',							prop: 'revisions',							rvprop: 'content',							rvlimit: '1',							titles: 'Wikipedia:WikiProject Deletion sorting/' + cat						}, function(data) {							$.each(data.query.pages, function(i, v) { window.editContent = v.revisions[0]['*'].replace('directly below this line -->', 'directly below this line -->\n\{\{' + mw.config.get('wgPageName') + '\}\}'); });							var editData = {								action: "edit",								format: "json",								token: etoken,								summary: "Listing " + mw.config.get('wgPageName') + " (FWDS)",								title: 'Wikipedia:WikiProject Deletion sorting/' + cat,								text: window.editContent							};							$.each(editData, function(i, v) { console.log(i, "=", v); });							$.post('//en.wikipedia.org/w/api.php', editData, function(data) { jQuery.each(data, function(index, value) {									console.log("index", index, "value", value);								}); });							alert('Delsort complete.');						}); }				}			}		}		//end functions adapted from WP:FWDS //begin functions adapted from User:MusikAnimal/MoreMenu

(function {	var api = new mw.Api,		namespaceNumber = mw.config.get('wgNamespaceNumber'),		canonicalSpecialPageName = mw.config.get('wgCanonicalSpecialPageName'),		isPageProtected = (!!mw.config.get('wgRestrictionEdit') && mw.config.get('wgRestrictionEdit').length) || (!!mw.config.get('wgRestrictionCreate') && mw.config.get('wgRestrictionCreate').length),		serverName = mw.config.get('wgServerName'),		siteName = mw.config.get('wgSiteName'),		userGroups = mw.config.get('wgUserGroups'),		contentLanguage = mw.config.get('wgContentLanguage'),		noticeProject = mw.config.get('wgNoticeProject'),		articleId = mw.config.get('wgArticleId'),		mwDBname = mw.config.get('wgDBname'),		pageName = mw.config.get('wgPageName'),		userName = mw.config.get('wgRelevantUserName'),		isUserSpace, metaUserGroups, userPermissions, currentDate = new Date;	var escapedPageName = encodeURIComponent(pageName.replace(/[!'*]/g, escape)), escapedUserName = encodeURIComponent(userName).replace(/[!'*]/g, escape); $('#ca-protect,#ca-unprotect,#ca-delete,#ca-undelete').remove; var delsortMenuList = { 'Delsort': { 'Manual Entry': { url: "#\" onclick=\"delsortIt" },			'Africa': { 'Africa': { url: "#\" onclick=\"doDelsort('Africa')" },				'Egypt': { url: "#\" onclick=\"doDelsort('Egypt')" },				'Ethiopia': { url: "#\" onclick=\"doDelsort('Ethiopia')" },				'Kenya': { url: "#\" onclick=\"doDelsort('Kenya')" },				'Mauritius': { url: "#\" onclick=\"doDelsort('Mauritius')" },				'Morocco': { url: "#\" onclick=\"doDelsort('Morocco')" },				'Nigeria': { url: "#\" onclick=\"doDelsort('Nigeria')" },				'Somalia': { url: "#\" onclick=\"doDelsort('Somalia')" },				'South Africa': { url: "#\" onclick=\"doDelsort('South Africa')" },				'Zimbabwe': { url: "#\" onclick=\"doDelsort('Zimbabwe')" }			},			'Asia': { 'Asia': { url: "#\" onclick=\"doDelsort('Asia')" },				'Afghanistan': { url: "#\" onclick=\"doDelsort('Afghanistan')" },				'Bangladesh': { url: "#\" onclick=\"doDelsort('Bangladesh')" },				'Bahrain': { url: "#\" onclick=\"doDelsort('Bahrain')" },				'Brunei': { url: "#\" onclick=\"doDelsort('Brunei')" },				'Cambodia': { url: "#\" onclick=\"doDelsort('Cambodia')" },				'China': { url: "#\" onclick=\"doDelsort('China')" },				'Hong Kong': { url: "#\" onclick=\"doDelsort('Hong Kong')" },				'India': { url: "#\" onclick=\"doDelsort('India')" },				'Indonesia': { url: "#\" onclick=\"doDelsort('Indonesia')" },				'Japan': { url: "#\" onclick=\"doDelsort('Japan')" },				'Korea': { url: "#\" onclick=\"doDelsort('Korea')" },				'Malaysia': { url: "#\" onclick=\"doDelsort('Malaysia')" },				'Maldives': { url: "#\" onclick=\"doDelsort('Maldives')" },				'Mongolia': { url: "#\" onclick=\"doDelsort('Mongolia')" },				'Nepal': { url: "#\" onclick=\"doDelsort('Nepal')" },				'Pakistan': { url: "#\" onclick=\"doDelsort('Pakistan')" },				'Philippines': { url: "#\" onclick=\"doDelsort('Philippines')" },				'Singapore': { url: "#\" onclick=\"doDelsort('Singapore')" },				'Sri Lanka': { url: "#\" onclick=\"doDelsort('Sri Lanka')" },				'Taiwan': { url: "#\" onclick=\"doDelsort('Taiwan')" },				'Thailand': { url: "#\" onclick=\"doDelsort('Thailand')" },				'Vietnam': { url: "#\" onclick=\"doDelsort('Vietnam')" }			},			'Central Asia': { 'Central Asia': { url: "#\" onclick=\"doDelsort('Central Asia')" },				'Kazakhstan': { url: "#\" onclick=\"doDelsort('Kazakhstan')" },				'Kyrgyzstan': { url: "#\" onclick=\"doDelsort('Kyrgyzstan')" },				'Tajikistan': { url: "#\" onclick=\"doDelsort('Tajikistan')" },				'Turkmenistan': { url: "#\" onclick=\"doDelsort('Turkmenistan')" },				'Uzbekistan': { url: "#\" onclick=\"doDelsort('Uzbekistan')" }			},			'Middle East': { 'Middle East': { url: "#\" onclick=\"doDelsort('Middle East')" },				'Iran': { url: "#\" onclick=\"doDelsort('Iran')" },				'Iraq': { url: "#\" onclick=\"doDelsort('Iraq')" },				'Israel': { url: "#\" onclick=\"doDelsort('Israel')" },				'Lebanon': { url: "#\" onclick=\"doDelsort('Lebanon')" },				'Palestine': { url: "#\" onclick=\"doDelsort('Palestine')" },				'Saudi Arabia': { url: "#\" onclick=\"doDelsort('Saudi Arabia')" },				'Syria': { url: "#\" onclick=\"doDelsort('Syria')" },				'United Arab Emirates': { url: "#\" onclick=\"doDelsort('United Arab Emirates')" }			},			'Europe': { 'Europe': { url: "#\" onclick=\"doDelsort('Europe')" },				'Albania': { url: "#\" onclick=\"doDelsort('Albania')" },				'Armenia': { url: "#\" onclick=\"doDelsort('Armenia')" },				'Austria': { url: "#\" onclick=\"doDelsort('Austria')" },				'Azerbaijan': { url: "#\" onclick=\"doDelsort('Azerbaijan')" },				'Belarus': { url: "#\" onclick=\"doDelsort('Belarus')" },				'Belgium': { url: "#\" onclick=\"doDelsort('Belgium')" },				'Bosnia and Herzegovina': { url: "#\" onclick=\"doDelsort('Bosnia and Herzegovina')" },				'Bulgaria': { url: "#\" onclick=\"doDelsort('Bulgaria')" },				'Croatia': { url: "#\" onclick=\"doDelsort('Croatia')" },				'Cyprus': { url: "#\" onclick=\"doDelsort('Cyprus')" },				'Czech Republic': { url: "#\" onclick=\"doDelsort('Czech Republic')" },				'Denmark': { url: "#\" onclick=\"doDelsort('Denmark')" },				'Estonia': { url: "#\" onclick=\"doDelsort('Estonia')" },				'Finland': { url: "#\" onclick=\"doDelsort('Finland')" },				'France': { url: "#\" onclick=\"doDelsort('France')" },				'Georgia (country)': { url: "#\" onclick=\"doDelsort('Georgia (country)')" },				'Germany': { url: "#\" onclick=\"doDelsort('Germany')" },				'Greece': { url: "#\" onclick=\"doDelsort('Greece')" },				'Hungary': { url: "#\" onclick=\"doDelsort('Hungary')" },				'Iceland': { url: "#\" onclick=\"doDelsort('Iceland')" },				'Ireland': { url: "#\" onclick=\"doDelsort('Ireland')" },				'Italy': { url: "#\" onclick=\"doDelsort('Italy')" },				'Jersey': { url: "#\" onclick=\"doDelsort('Jersey')" },				'Kosovo': { url: "#\" onclick=\"doDelsort('Kosovo')" },				'Latvia': { url: "#\" onclick=\"doDelsort('Latvia')" },				'Lithuania': { url: "#\" onclick=\"doDelsort('Lithuania')" },				'Luxembourg': { url: "#\" onclick=\"doDelsort('Luxembourg')" },				'Macedonia': { url: "#\" onclick=\"doDelsort('Macedonia')" },				'Moldova': { url: "#\" onclick=\"doDelsort('Moldova')" },				'Montenegro': { url: "#\" onclick=\"doDelsort('Montenegro')" },				'Netherlands': { url: "#\" onclick=\"doDelsort('Netherlands')" },				'Norway': { url: "#\" onclick=\"doDelsort('Norway')" },				'Poland': { url: "#\" onclick=\"doDelsort('Poland')" },				'Portugal': { url: "#\" onclick=\"doDelsort('Portugal')" },				'Romania': { url: "#\" onclick=\"doDelsort('Romania')" },				'Russia': { url: "#\" onclick=\"doDelsort('Russia')" },				'Serbia': { url: "#\" onclick=\"doDelsort('Serbia')" },				'Slovakia': { url: "#\" onclick=\"doDelsort('Slovakia')" },				'Slovenia': { url: "#\" onclick=\"doDelsort('Slovenia')" },				'Spain': { url: "#\" onclick=\"doDelsort('Spain')" },				'Sweden': { url: "#\" onclick=\"doDelsort('Sweden')" },				'Switzerland': { url: "#\" onclick=\"doDelsort('Switzerland')" },				'Turkey': { url: "#\" onclick=\"doDelsort('Turkey')" },				'Ukraine': { url: "#\" onclick=\"doDelsort('Ukraine')" },				'Yugoslavia': { url: "#\" onclick=\"doDelsort('Yugoslavia')" }			},			'United Kingdom': { 'United Kingdom': { url: "#\" onclick=\"doDelsort('United Kingdom')" },				'England': { url: "#\" onclick=\"doDelsort('England')" },				'Northern Ireland': { url: "#\" onclick=\"doDelsort('Northern Ireland')" },				'Scotland': { url: "#\" onclick=\"doDelsort('Scotland')" },				'Wales': { url: "#\" onclick=\"doDelsort('Wales')" }			},			'Oceania': { 'Oceania': { action: "#\" onclick=\"doDelsort('Oceania')" },				'Antarctica': { url: "#\" onclick=\"doDelsort('Antarctica')" },				'Australia': { url: "#\" onclick=\"doDelsort('Australia')" },				'New Zealand': { url: "#\" onclick=\"doDelsort('New Zealand')" }			},			'Canada': { 'Canada': { url: "#\" onclick=\"doDelsort('Canada')" },				'British Columbia': { url: "#\" onclick=\"doDelsort('British Columbia')" },				'Manitoba': { url: "#\" onclick=\"doDelsort('Manitoba')" },				'Nova Scotia': { url: "#\" onclick=\"doDelsort('Nova Scotia')" },				'Ontario': { url: "#\" onclick=\"doDelsort('Ontario')" },				'Quebec': { url: "#\" onclick=\"doDelsort('Quebec')" }			},			'United States A-M': { 'United States of America': { url: "#\" onclick=\"doDelsort('United States of America')" },				'Alabama': { url: "#\" onclick=\"doDelsort('Alabama')" },				'Alaska': { url: "#\" onclick=\"doDelsort('Alaska')" },				'Arkansas': { url: "#\" onclick=\"doDelsort('Arkansas')" },				'Arizona': { url: "#\" onclick=\"doDelsort('Arizona')" },				'California': { url: "#\" onclick=\"doDelsort('California')" },				'Colorado': { url: "#\" onclick=\"doDelsort('Colorado')" },				'Connecticut': { url: "#\" onclick=\"doDelsort('Connecticut')" },				'Delaware': { url: "#\" onclick=\"doDelsort('Delaware')" },				'Florida': { url: "#\" onclick=\"doDelsort('Florida')" },				'Georgia (U.S. state)': { url: "#\" onclick=\"doDelsort('Georgia (U.S. state)')" },				'Hawaii': { url: "#\" onclick=\"doDelsort('Hawaii')" },				'Idaho': { url: "#\" onclick=\"doDelsort('Idaho')" },				'Illinois': { url: "#\" onclick=\"doDelsort('Illinois')" },				'Indiana': { url: "#\" onclick=\"doDelsort('Indiana')" },				'Iowa': { url: "#\" onclick=\"doDelsort('Iowa')" },				'Kansas': { url: "#\" onclick=\"doDelsort('Kansas')" },				'Kentucky': { url: "#\" onclick=\"doDelsort('Kentucky')" },				'Louisiana': { url: "#\" onclick=\"doDelsort('Louisiana')" },				'Maine': { url: "#\" onclick=\"doDelsort('Maine')" },				'Maryland': { url: "#\" onclick=\"doDelsort('Maryland')" },				'Massachusetts': { url: "#\" onclick=\"doDelsort('Massachusetts')" },				'Michigan': { url: "#\" onclick=\"doDelsort('Michigan')" },				'Minnesota': { url: "#\" onclick=\"doDelsort('Minnesota')" },				'Mississippi': { url: "#\" onclick=\"doDelsort('Mississippi')" },				'Missouri': { url: "#\" onclick=\"doDelsort('Missouri')" },				'Montana': { url: "#\" onclick=\"doDelsort('Montana')" }			},			'United States N-Z': { 'United States of America': { url: "#\" onclick=\"doDelsort('United States of America')" },				'Nebraska': { url: "#\" onclick=\"doDelsort('Nebraska')" },				'Nevada': { url: "#\" onclick=\"doDelsort('Nevada')" },				'New Hampshire': { url: "#\" onclick=\"doDelsort('New Hampshire')" },				'New Jersey': { url: "#\" onclick=\"doDelsort('New Jersey')" },				'New Mexico': { url: "#\" onclick=\"doDelsort('New Mexico')" },				'New York': { url: "#\" onclick=\"doDelsort('New York')" },				'North Carolina': { url: "#\" onclick=\"doDelsort('North Carolina')" },				'North Dakota': { url: "#\" onclick=\"doDelsort('North Dakota')" },				'Ohio': { url: "#\" onclick=\"doDelsort('Ohio')" },				'Oklahoma': { url: "#\" onclick=\"doDelsort('Oklahoma')" },				'Oregon': { url: "#\" onclick=\"doDelsort('Oregon')" },				'Pennsylvania': { url: "#\" onclick=\"doDelsort('Pennsylvania')" },				'Rhode Island': { url: "#\" onclick=\"doDelsort('Rhode Island')" },				'South Carolina': { url: "#\" onclick=\"doDelsort('South Carolina')" },				'South Dakota': { url: "#\" onclick=\"doDelsort('South Dakota')" },				'Tennessee': { url: "#\" onclick=\"doDelsort('Tennessee')" },				'Texas': { url: "#\" onclick=\"doDelsort('Texas')" },				'Utah': { url: "#\" onclick=\"doDelsort('Utah')" },				'Vermont': { url: "#\" onclick=\"doDelsort('Vermont')" },				'Virginia': { url: "#\" onclick=\"doDelsort('Virginia')" },				'Washington': { url: "#\" onclick=\"doDelsort('Washington')" },				'Washington, D.C.': { url: "#\" onclick=\"doDelsort('Washington, D.C.')" },				'West Virginia': { url: "#\" onclick=\"doDelsort('West Virginia')" },				'Wisconsin': { url: "#\" onclick=\"doDelsort('Wisconsin')" },				'Wyoming': { url: "#\" onclick=\"doDelsort('Wyoming')" }			},			'Latin America': { 'Latin America': { url: "#\" onclick=\"doDelsort('Latin America')" },				'Caribbean': { url: "#\" onclick=\"doDelsort('Caribbean')" },				'South America': { url: "#\" onclick=\"doDelsort('South America')" },				'Argentina': { url: "#\" onclick=\"doDelsort('Argentina')" },				'Barbados': { url: "#\" onclick=\"doDelsort('Barbados')" },				'Belize': { url: "#\" onclick=\"doDelsort('Belize')" },				'Bolivia': { url: "#\" onclick=\"doDelsort('Bolivia')" },				'Brazil': { url: "#\" onclick=\"doDelsort('Brazil')" },				'Chile': { url: "#\" onclick=\"doDelsort('Chile')" },				'Colombia': { url: "#\" onclick=\"doDelsort('Colombia')" },				'Cuba': { url: "#\" onclick=\"doDelsort('Cuba')" },				'Ecuador': { url: "#\" onclick=\"doDelsort('Ecuador')" },				'El Salvador': { url: "#\" onclick=\"doDelsort('El Salvador')" },				'Guatemala': { url: "#\" onclick=\"doDelsort('Guatemala')" },				'Haiti': { url: "#\" onclick=\"doDelsort('Haiti')" },				'Mexico': { url: "#\" onclick=\"doDelsort('Mexico')" },				'Panama': { url: "#\" onclick=\"doDelsort('Panama')" },				'Paraguay': { url: "#\" onclick=\"doDelsort('Paraguay')" },				'Peru': { url: "#\" onclick=\"doDelsort('Peru')" },				'Puerto Rico': { url: "#\" onclick=\"doDelsort('Puerto Rico')" },				'Trinidad and Tobago': { url: "#\" onclick=\"doDelsort('Trinidad and Tobago')" },				'Uruguay': { url: "#\" onclick=\"doDelsort('Uruguay')" },				'Venezuela': { url: "#\" onclick=\"doDelsort('Venezuela')" }			},			'Arts': { 'Arts': { url: "#\" onclick=\"doDelsort('Arts')" },				'Food and drink': { url: "#\" onclick=\"doDelsort('Food and drink')" },				'Wine': { url: "#\" onclick=\"doDelsort('Wine')" },				'Language': { url: "#\" onclick=\"doDelsort('Language')" },				'Literature': { url: "#\" onclick=\"doDelsort('Literature')" },				'Poetry': { url: "#\" onclick=\"doDelsort('Poetry')" },				'Albums and songs': { url: "#\" onclick=\"doDelsort('Albums and songs')" },				'Television': { url: "#\" onclick=\"doDelsort('Television')" },				'Music': { url: "#\" onclick=\"doDelsort('Music')" },				'Film': { url: "#\" onclick=\"doDelsort('Film')" },				'Radio': { url: "#\" onclick=\"doDelsort('Radio')" },				'Video Games': { url: "#\" onclick=\"doDelsort('Video Games')" },				'Visual arts': { url: "#\" onclick=\"doDelsort('Visual arts')" },				'Architecture': { url: "#\" onclick=\"doDelsort('Architecture')" },				'Fashion': { url: "#\" onclick=\"doDelsort('Fashion')" },				'Photography': { url: "#\" onclick=\"doDelsort('Photography')" },				'Comics and animation': { url: "#\" onclick=\"doDelsort('Comics and animation')" },				'Anime and manga': { url: "#\" onclick=\"doDelsort('Anime and manga')" },				'Webcomics': { url: "#\" onclick=\"doDelsort('Webcomics')" },				'Fictional elements': { url: "#\" onclick=\"doDelsort('Fictional elements')" },				'Science fiction': { url: "#\" onclick=\"doDelsort('Science fiction')" }			},			'Topical': { 'Advertising': { url: "#\" onclick=\"doDelsort('Advertising')" },				'Aviation': { url: "#\" onclick=\"doDelsort('Aviation')" },				'Bibliographies': { url: "#\" onclick=\"doDelsort('Bibliographies')" },				'Bilateral relations': { url: "#\" onclick=\"doDelsort('Bilateral relations')" },				'Business': { url: "#\" onclick=\"doDelsort('Business')" },				'Conservatism': { url: "#\" onclick=\"doDelsort('Conservatism')" },				'Conspiracy theories': { url: "#\" onclick=\"doDelsort('Conspiracy theories')" },				'Crime': { url: "#\" onclick=\"doDelsort('Crime')" },				'Education': { url: "#\" onclick=\"doDelsort('Education')" },				'Environment': { url: "#\" onclick=\"doDelsort('Environment')" },				'Ethnic groups': { url: "#\" onclick=\"doDelsort('Ethnic groups')" },				'Events': { url: "#\" onclick=\"doDelsort('Events')" },				'Firearms': { url: "#\" onclick=\"doDelsort('Firearms')" },				'Games': { url: "#\" onclick=\"doDelsort('Games')" },				'Health and fitness': { url: "#\" onclick=\"doDelsort('Health and fitness')" },				'History': { url: "#\" onclick=\"doDelsort('History')" },				'Law': { url: "#\" onclick=\"doDelsort('Law')" },				'Language': { url: "#\" onclick=\"doDelsort('Language')" },				'Logic': { url: "#\" onclick=\"doDelsort('Logic')" },				'Magic': { url: "#\" onclick=\"doDelsort('Magic')" },				'Management': { url: "#\" onclick=\"doDelsort('Management')" },				'Medicine': { url: "#\" onclick=\"doDelsort('Medicine')" },				'Military': { url: "#\" onclick=\"doDelsort('Military')" },				'News media': { url: "#\" onclick=\"doDelsort('News media')" },				'Organisms': { url: "#\" onclick=\"doDelsort('Organisms')" },				'Organizations': { url: "#\" onclick=\"doDelsort('Organizations')" },				'Paranormal': { url: "#\" onclick=\"doDelsort('Paranormal')" },				'Philosophy': { url: "#\" onclick=\"doDelsort('Philosophy')" },				'Piracy': { url: "#\" onclick=\"doDelsort('Piracy')" },				'Politics': { url: "#\" onclick=\"doDelsort('Politics')" },				'Popular culture': { url: "#\" onclick=\"doDelsort('Popular culture')" },				'Sexuality and gender': { url: "#\" onclick=\"doDelsort('Sexuality and gender')" },				'Terrorism': { url: "#\" onclick=\"doDelsort('Terrorism')" },				'Transportation': { url: "#\" onclick=\"doDelsort('Transportation')" }			},			'Science': { 'Science': { url: "#\" onclick=\"doDelsort('Science')" },				'Behavioural science': { url: "#\" onclick=\"doDelsort('Behavioural science')" },				'Social science': { url: "#\" onclick=\"doDelsort('Social science')" }				},			'Religion': { 'Religion': { url: "#\" onclick=\"doDelsort('Religion')" },				'Atheism': { url: "#\" onclick=\"doDelsort('Atheism')" },				'Bible': { url: "#\" onclick=\"doDelsort('Bible')" },				'Buddhism': { url: "#\" onclick=\"doDelsort('Buddhism')" },				'Christianity': { url: "#\" onclick=\"doDelsort('Christianity')" },				'Islam': { url: "#\" onclick=\"doDelsort('Islam')" },				'Judaism': { url: "#\" onclick=\"doDelsort('Judaism')" },				'Hinduism': { url: "#\" onclick=\"doDelsort('Hinduism')" },				'Paganism': { url: "#\" onclick=\"doDelsort('Paganism')" },				'Sikhism': { url: "#\" onclick=\"doDelsort('Sikhism')" },				'Spirituality': { url: "#\" onclick=\"doDelsort('Spirituality')" }			},			'Technology': { 'Technology': { url: "#\" onclick=\"doDelsort('Technology')" },				'Computing': { url: "#\" onclick=\"doDelsort('Computing')" },				'Internet': { url: "#\" onclick=\"doDelsort('Internet')" },				'Software': { url: "#\" onclick=\"doDelsort('Software')" },				'Websites': { url: "#\" onclick=\"doDelsort('Websites')" }			},			'Sports': { 'Sports': { url: "#\" onclick=\"doDelsort('Sports')" },				'American football': { url: "#\" onclick=\"doDelsort('American football')" },				'Baseball': { url: "#\" onclick=\"doDelsort('Baseball')" },				'Basketball': { url: "#\" onclick=\"doDelsort('Basketball')" },				'Bodybuilding': { url: "#\" onclick=\"doDelsort('Bodybuilding')" },				'Cricket': { url: "#\" onclick=\"doDelsort('Cricket')" },				'Cycling': { url: "#\" onclick=\"doDelsort('Cycling')" },				'Football': { url: "#\" onclick=\"doDelsort('Football')" },				'Golf': { url: "#\" onclick=\"doDelsort('Golf')" },				'Ice hockey': { url: "#\" onclick=\"doDelsort('Ice hockey')" },				'Rugby union': { url: "#\" onclick=\"doDelsort('Rugby union')" },				'Softball': { url: "#\" onclick=\"doDelsort('Softball')" },				'Martial arts': { url: "#\" onclick=\"doDelsort('Martial arts')" },				'Wrestling': { url: "#\" onclick=\"doDelsort('Wrestling')" },			},			'People': { 'People': { url: "#\" onclick=\"doDelsort('People')" },				'Academics and educators': { url: "#\" onclick=\"doDelsort('Academics and educators')" },				'Actors and filmmakers': { url: "#\" onclick=\"doDelsort('Actors and filmmakers')" },				'Authors': { url: "#\" onclick=\"doDelsort('Authors')" },				'Bands and musicians': { url: "#\" onclick=\"doDelsort('Bands and musicians')" },				'Businesspeople': { url: "#\" onclick=\"doDelsort('Businesspeople')" },				'Politicians': { url: "#\" onclick=\"doDelsort('Politicians')" },				'Sportspeople': { url: "#\" onclick=\"doDelsort('Sportspeople')" },				'Lists of people': { url: "#\" onclick=\"doDelsort('Lists of people')" }			},			'Places': { 'Shopping malls': { url: "#\" onclick=\"doDelsort('Shopping malls')" },				'Museums and libraries': { url: "#\" onclick=\"doDelsort('Museums and libraries')" },				'Schools': { url: "#\" onclick=\"doDelsort('Schools')" }			},			'Other': { 'Disambiguations': { url: "#\" onclick=\"doDelsort('Disambiguations')" },				'Lists': { url: "#\" onclick=\"doDelsort('Lists')" },				'Islands': { url: "#\" onclick=\"doDelsort('Islands')" }			}		}	};	var dependencies = []; if (!$.jStorage) dependencies.push('jquery.jStorage'); if (!Object.keys) dependencies.push('es5-shim'); // initialize script mw.loader.using(dependencies, function {		var menus = [];		if (wgPageName.indexOf('Wikipedia:Articles_for_deletion/') != -1 && wgPageName.indexOf('Wikipedia:Articles_for_deletion/Log/201') == -1) {			menus.push(delsortMenuList);			init(menus, function(data) { completePageLinks; });		}	});	// custom callback functions for these menus function completePageLinks { $('#c2-page-xfds').hide; if (mwDBname === 'enwiki') { apiGet({				titles: 'Wikipedia:Articles for deletion/' + pageName + '|Wikipedia:Miscellany for deletion/' + pageName,				prop: 'info'			}).done(function(data) {				for (var i in data.query.pages) {					if (i > -1) {						if (data.query.pages[i].title.split('/')[0] === 'Wikipedia:Miscellany for deletion') {							$('#c2-page-xfds').show.find('a').text('MfDs').prop('href', mw.util.getUrl('Special:PrefixIndex/Wikipedia:Miscellany_for_deletion/' + pageName));						}						else if (data.query.pages[i].title.split('/')[0] === 'Wikipedia:Articles for deletion') {							$('#c2-page-xfds').show.find('a').text('AfDs').prop('href', mw.util.getUrl('Special:PrefixIndex/Wikipedia:Articles_for_deletion/' + pageName));						}						break;					}				}			}); if (mw.user.options.get('gadget-edittop') === '1') { $('#c2-page-edit_intro').remove; }		}		if (mwDBname !== 'commonswiki') { $('#ca-move').hide; }		$('#p-views ul').on('beforeTabCollapse', function {			if ($('#ca-history').hasClass('collapsible')) {				$('#p-page2').find('ul').append($('#ca-history').detach);			}		}); }

// everything below is internal functions – should not need to be modified for any customization function addListeners { $('.c2-hover-menu').each(function {			$(this).hover(function { $el = $(this).find('.submenu'); $el.css({					left: $(this).outerWidth,					top: '-1px',					'border-top-width': 1				}); $el.show; }, function { $(this).find('.submenu').hide; });		});	}

function apiGet(params) { return api.get($.extend(params, { action: 'query' }));	}

function canAddRemoveGroups(groups, permissions) { if (permissions && permissions.indexOf('userrights') >= 0) return true; var ret = false; for (var i = 0; i < groups.length; i++) { if (metaUserGroups[groups[i]].addRemoveGroups) { ret = true; break; }			}			return ret; }		// scope is an array, returns true if all elements in 'array' exist in scope function containsArray(array, index, last) { if (!index) { index = 0; last = 0; this.sort; array.sort; }		return index === array.length || (last = this.indexOf(array[index], last)) > -1 && containsArray.call(this, array, ++index, ++last); }

function generateMenuContent(tabName, menuList, userData, userPermissions) { var html = ''; $.each(menuList, function(name, action) {			if (action) {				var newHtml = '';				if (!action.url) {					newHtml += '' + '' + name + '&hellip;' + ' ';					$.each(action, function(k, v) { newHtml += linkHtml(tabName, k, v, name, userData, userPermissions); });					newHtml += ' ';					if ($(newHtml).last.find('.submenu li').length === 0) {						newHtml = '';					}				}				else {					newHtml += linkHtml(tabName, name, action, null, userData, userPermissions);				}				html += newHtml;			}		}); return html; }

function hasConditional(permitted, given) { permitted = $.makeArray(permitted); given = $.makeArray(given); if (!permitted.length) { return true; }		else if (!given.length) { return false; }		else { var valid = false; for (var i = 0; i < given.length; i++) { if ($.inArray(given[i], permitted) >= 0) { valid = true; break; }			}			return valid; }	}

function linkId(tabName, name, parent) { return 'c2-' + sanitize(tabName.toLowerCase) + '-' + (parent ? sanitize(parent) + '-' : '') + sanitize(name); }

function linkHtml(tabName, name, action, parent, userData, userPermissions) { var validations = /* namespace         */ (hasConditional(action.namespaceRestrict, namespaceNumber) || !hasConditional(action.namespaceExclude, namespaceNumber)) && /* existence         */ ((action.pageExists && articleId > 0) || (!action.pageExists)) && /* deleted           */ (action.pageDeleted ? articleId === 0 && mw.config.get('wgIsArticle') === false : true) && /* protected         */ (action.isProtected ? isPageProtected : true) && /* database          */ hasConditional(action.databaseRestrict, mwDBname) && /* notice project    */ hasConditional(action.noticeProjectRestrict, noticeProject) && /* user's user groups */ hasConditional(action.userGroups, userGroups) && /* user's permissions */ hasConditional(action.userPermissions, userPermissions) && /* can change groups */ (action.userAddRemoveGroups ? canAddRemoveGroups(userGroups, userPermissions) : true); if (isUserSpace) { // FIXME: find something better than userData.invalid === '' for checking if IP			validations &= /* their user groups */ hasConditional(action.groups, userData.groups) && /* their permissions */ hasConditional(action.permissions, userData.rights) && /* they're blocked   */ (action.blocked !== undefined ? !!userData.blockid === action.blocked : true) && /* can change groups */ (action.addRemoveGroups ? canAddRemoveGroups(userData.groups, userData.rights) : true) && /* IP                */ (action.ipOnly ? userData.invalid === '' : true); }		if (!!validations) { return '' + name + ''; }		else { return ''; }	}

function sanitize(name) { return name.toLowerCase.replace(/ /g, '_'); }

function init(menus, fn) { var promises = new Array(3), cacheDate = $.jStorage.get('mmCacheDate'), expired = cacheDate < currentDate; if (isUserSpace) { promises[0] = apiGet({				list: 'users|blocks',				ususers: userName,				bkusers: userName,				usprop: 'blockinfo|groups|rights',				bkprop: 'id'			}); }		if (expired || !(userPermissions = $.jStorage.get('mmUserRights'))) { promises[1] = mw.user.getRights; }		if (expired || !(metaUserGroups = $.jStorage.get('mmMetaUserGroups'))) { promises[2] = apiGet({				meta: 'siteinfo',				siprop: 'usergroups'			}); }		$.when.apply(this, promises).done(function(data, userRightsData, metaData) {			var userData;			if (data) {				userData = data[0].query.users[0];				if (!userData) {					// FIXME: add functionality to only show menu based on custom function;					//   temporary fix so that script doesn't break on pages of users that don't exist					isUserSpace = false;					for (var j = 0; j < menus.length; j++) {						if (!!menus[j].User) menus.splice(j, 1);					}				}				else if (userData.invalid === '') {					userData.groups = [];					userData.rights = [];					if (data[0].query.blocks.length) {						userData.blockid = data[0].query.blocks[0].id;					}				}			}			if (userRightsData) {				userPermissions = $.jStorage.set('mmUserRights', userRightsData);			}			if (metaData) {				metaUserGroups = {};				$.each(metaData[0].query.usergroups, function(i, el) { metaUserGroups[el.name] = { permissions: el.rights, addRemoveGroups: !!el.add || !!el.remove };				});				$.jStorage.set('mmMetaUserGroups', metaUserGroups);			}			if (expired) {				var newDate = new Date;				$.jStorage.set('mmCacheDate', newDate.setDate(newDate.getDate + 7));			}			for (var i = 0; i < menus.length; i++) {				var tabName = Object.keys(menus[i])[0];				var html = '' + ' ' + ' ' + tabName + ' ' + '' + ' ' + ' ';				html += generateMenuContent(tabName, menus[i][tabName], userData, userPermissions);				html += ' ';				if ($('#p-cactions')[0]) {					$(html).insertAfter($('#p-cactions'));				}				else {					$(html).insertAfter($('#p-views'));				}				addListeners;			}			if (typeof fn === 'function') fn(data, userPermissions);		}); } }); //