Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
//<pre>
/* This is the iglooCSD Module, made by Kangaroopower */
/* To Do:
	- savelog page is defined through igloosettings.logpage which I don't have control of- ask to integrate
	- Add way for savelog to be turned off
*/
function iglooCSD () {
		// iglooCSD
		// timer var
		this.timer = null;
 
		this.startInterface = function() {
			if (document.getElementById('igloo-buttons-csd') == null) return false;
 
			this.csdTagger = new wa_window ( document.getElementById ( 'igloo-buttons-csd' ) );
			this.csdTagger.win_top = 71;
			this.csdTagger.win_left = -100;
			this.csdTagger.win_width = 170;
			this.csdTagger.win_height= 80;
			this.csdTagger.win_alpha = 0;
			this.csdTagger.win_cursor = 'pointer';
			this.csdTagger.win_disp = 'none';
			this.csdTagger.applyAll ();
 
			this.csdDisplay = new wa_window ( document.getElementById ( 'igloo-buttons-csd' ) );
			this.csdDisplay.win_top = 77;
			this.csdDisplay.win_left = -100;
			this.csdDisplay.win_width = 170;
			this.csdDisplay.win_bg = '#d0d0d0';
			this.csdDisplay.win_bd = '#000000';
			this.csdDisplay.win_bd_wd = 1;
			this.csdDisplay.win_padding = 2;
			this.csdDisplay.win_fontsize = 10;
			this.csdDisplay.win_cursor = 'pointer';
			this.csdDisplay.win_disp = 'none';
			this.csdDisplay.win_content = '<div id="igloocsdTagger-note" style="width: 100%;">loading csd tags - wait...</div><ul style="display: none; width: 100%; height: 100%; margin: 0px; padding: 0px; overflow-x: hidden; overflow-y: auto;" id="igloocsdTagger-cont"></ul>';
			this.csdDisplay.applyAll ();
 
			wa_attach ( document.getElementById ( 'igloo-buttons-csd' ), 'mouseenter', igloo.iglooCSD.mouseOver );
			wa_attach ( document.getElementById ( 'igloo-buttons-csd' ), 'mouseleave', igloo.iglooCSD.mouseOut );
		};
 
		this.mouseOver = function () {
			if ( igloo.iglooDiff.viewingDiff === true ) {
				if ( igloo.iglooCSD.timer ) { clearTimeout ( igloo.iglooCSD.timer ); igloo.iglooCSD.timer = false; } else {
					igloo.iglooCSD.csdDisplay.show(); 
					igloo.iglooCSD.csdTagger.show();
					igloo.iglooCSD.csdList ();
				}
			}
		};

		this.mouseOut = function () {
			// Keeps same timeout as history
			igloo.iglooCSD.timer = setTimeout(function() { igloo.iglooCSD.csdDisplay.hide(); igloo.iglooCSD.csdTagger.hide(); igloo.iglooCSD.timer = false; }, iglooSettings.histWinTimeout * 1000);
		};

		this.csdLink = function (linktype, linkreason) { 
			 return '<li id="igloocsdlink" onclick="igloo.iglooCSD.docsdAction(\'' + linktype + ','+ igloo.iglooDiff.currentDiff [0] +'\');" onmouseover="this.style.backgroundColor = "#dddddd";" onmouseout="this.style.backgroundColor = "#ffffff";" style="cursor: pointer; width: 186px; padding: 2px; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: rgb(0, 0, 0); list-style-type: none; list-style-image: none; background-color: rgb(255, 255, 255); ">'+ linktype.toUpperCase() +'- '+ linkreason +'</li>';
		};

		this.csdList = function () {
			var pageCSD = '',
				reasons = {
				"g1": "Patent Nonsense",
				"g2": "Test Page",
				"g3": "Vandalism",
				"g4": "Recreation of Deleted Content",
				"g5": "Created by banned user",
				"g6": "Maintenence",
				"g7": "Blanked or requested by creator",
				"g10": "Attack Page",
				"g11": "Advertising",
				"g12": "Copyvio",
				"a1": "No context",
				"a2": "Wrong Project",
				"a3": "No Content",
				"a5": "Transwikied Article",
				"a7": "Importance not asserted",
				"a9": "Song/Music Article Lacking Artist's article",
				"r3": "Implausible typos in redirect"
			};
			for(var i in reasons) {
				pageCSD += igloo.iglooCSD.csdLink(i, reasons[i])
			}

			// lists all csd templates- for article namespace only
			$('#igloocsdTagger-cont').css({display:'block'});
			$('#igloocsdTagger-note').({display:'none')};
								
			pageCSD += '<li style="width: 100%; list-style-type: none; list-style-image: none; text-align: center;" onclick="igloo.iglooActions.sendLinkToParent(\'' + mw.util.wikiScript('index') + '?title=WP:CSD' + '\');">- Learn More -</li>';
			$('#igloocsdTagger-cont').html(pageCSD);
		};
		this.docsdAction = function (page, csdtype) {
			if(iglooSettings.mesysop === true) {
				var csdsummary = csdtype+': Deleting page according to CSD criteria ([[User:Ale_jrb/Scripts/igloo|GLOO]])',
				deletecsdPage = new wa_mediawikiApi ();
				deletecsdPage.deletePage( csdPage, csdsummary );
				deletecsdPage.onCompleteAction = function () { igloo.iglooStatus.addStatus( 'Successfully deleted <strong>' + page + '</strong>!' ); };
			} else {
				var csdmessage = '{{subst:Db-'+csdtype+'}}',
					csdsummary = 'Tagging page for CSD ([[User:Ale_jrb/Scripts/igloo|GLOO]])';
				$.post(mw.util.wikiScript('api') +'?action=edit&title='+page+'&summary='+csdsummary+'&prependtext='+csdmessage+'&token'+ mw.user.tokens.values.editToken, function () {
					igloo.iglooStatus.addStatus( 'Successfully issued a csd tag on <strong>' + page + '</strong>!' );
					this.notifyUser(page, csdtype);
				});
			}
		};

		this.notifyUser = function (page, csdtype) {
			$.getJSON(mw.util.wikiScript('api') + '?action=query&prop=revisions&indexpageids=1&titles='+page+'&rvlimit=1&rvprop=user&rvdir=newer&format=json', function (data) {
				var csduser = data.query.pages[data.query.pageids[0]].revisions[0].user,
					csdmessage = '== CSD Tag on '+ page +' == {{subst:Db-notice|target='+ page +'|text= Hello. This page has been tagged for speedy deletion under the '+ csdtype+' criteria.|after explaining position = Best, --~~~~ }}',
					csdsummary = 'Notifying '+ csduser +' about csd tag on '+page+' ([[User:Ale_jrb/Scripts/igloo|GLOO]])';
				$.post(mw.util.wikiScript('api') +'?action=edit&title=User_Talk:'+csduser+'&summary='+csdsummary+'&appendtext='+usercsdmessage+'&format=json&token'+ mw.user.tokens.values.editToken, function () {
						igloo.iglooStatus.addStatus( 'Successfully notified the user about the csd tag on <strong>' + thisRevert.revertPage + '</strong>!')
						this.saveLog(page, csdtype, csduser);
				});
			});
		};

		this.saveLog = function(page, csdtype, csduser) {
			/* Credit for pretty much the entire concept of this goes to Twinkle */
			/* Converted to use waLib and to work for igloo by Kangaroopower */
			$.getJSON(mw.util.wikiScript('api') +'?action=query&indexpageids=1&titles='+ page +'&format=json', function (data) {
				var text = '';
				if (data.query.pageids[0] === "-1") text += "This is a log of all [[WP:CSD|speedy deletion]] nominations made by this user using [[WP:GLOO|Igloo]]'s CSD module. If you no longer wish to keep this log, you can turn it off in igloo settings and request it deleted under CSD U1.";
				var date = new Date(),
					headerRe = new RegExp("^==+\\s*" + date.getUTCMonthName() + "\\s+" + date.getUTCFullYear() + "\\s*==+", "m");
				if (!headerRe.exec(text)) text += "\n\n=== " + date.getUTCMonthName() + " " + date.getUTCFullYear() + " ===";
				text += "\n# [[:" + page + "]]: [[WP:CSD#" + csdtype.toUpperCase() + "|CSD " + csdtype.toUpperCase() + "]] ({{tl|db-" + csdtype + "}}); notified {{user|" + csduser + "}}";
				var csdlogsummary = "Logging speedy deletion nomination of [["+page+"]]. ([[User:Ale_jrb/Scripts/igloo|GLOO]])"
				$.post(mw.util.wikiScript('api') +'?action=edit&title='+iglooSettings.logpage+'&summary='+csdlogsummary+'&appendtext='+usercsdmessage+'&format=json&token='+ mw.user.tokens.values.editToken, igloo.iglooStatus.addStatus( 'Successfully log csd tagging on <strong>' + thisRevert.revertPage + '</strong>!'));	
			});
		};
}
//</pre>