User:HelloAnnyong/sockblock.js

// /** * Sockblock script * Just a little script I put together. When you're on a user talk page, it adds two links to the Toolbox on the left, one for master and one for sock. * Clicking on them just copies the appropriate options into the edit box, making life a little easier. * * last updated 2011.09.05 */

function isUserTalkPage {	return (mw.config.get('wgPageName').match(/User_talk:/)		&& (mw.config.get('wgAction')=='edit' || mw.config.get('wgAction')=='submit')); }

function isUserPage {	return (mw.config.get('wgPageName').match(/User:/) && (mw.config.get('wgAction')=='edit' || mw.config.get('wgAction')=='submit')); }

function addSockBlock(isMaster) {	if(isMaster === undefined) isMaster = false; if(isUserTalkPage) {		var editform = document.editform; var textbox = editform.wpTextbox1; var toAdd = (textbox.value.trim != "" ? "\n" : ''); if(mw.util.getParamValue("section")=="new") {			editform.wpSummary.value = "Blocked"; }		else {			toAdd += "== Blocked ==\n"; }

toAdd += ""; textbox.value += toAdd; } }

function addSockTag(isMaster, isConfirm) {	if(isUserPage) {		var editform = document.editform; var textbox = editform.wpTextbox1; var toAdd = ''; if(isMaster) {			toAdd += "{" + "{sockpuppeteer|blocked"; editform.wpSummary.value = "Suspected sockpuppeteer"; if(isConfirm) { toAdd += "|checked=yes"; editform.wpSummary.value = "Confirmed sockpuppeteer"; }			toAdd += "}}"; }		else {			var masterName = prompt("Enter the master's name:",""); if(masterName) { editform.wpSummary.value = (isConfirm ? 'Confirmed' : 'Suspected')+" sock of "+masterName; toAdd += "{" + "{sock|"+masterName+"|"; toAdd += (isConfirm ? 'confirmed' : 'blocked'); toAdd += "}}"; }		}		if(toAdd != '') { textbox.value = toAdd; if(editform.wpWatchthis.checked || editform.wpWatchthis.checked == 'checked') { editform.wpWatchthis.checked = ''; }		}	} }

$.when( mw.loader.using( 'mediawiki.util' ), $.ready ).done(function {	if(isUserTalkPage)	{		mw.util.addPortletLink('p-tb', 'javascript:addSockBlock(true)', 'SockBlock - master', 't-sockblockmaster', 'SockBlock - master', , );		mw.util.addPortletLink('p-tb', 'javascript:addSockBlock(false)', 'SockBlock - sock', 't-sockblocksock', 'SockBlock - sock', , );	}	if(isUserPage)	{		mw.util.addPortletLink('p-tb', 'javascript:addSockTag(true, true)', 'SockMaster - confirmed master', 't-sockmasterconfirm', 'SockMaster - confirmed master', , );		mw.util.addPortletLink('p-tb', 'javascript:addSockTag(true, false)', 'SockMaster - suspected master', 't-sockmasterblock', 'SockMaster - suspected master', , );		mw.util.addPortletLink('p-tb', 'javascript:addSockTag(false, true)', 'SockTag - confirmed sock', 't-socktagconfirm', 'SockTag - confirmed sock', , );		mw.util.addPortletLink('p-tb', 'javascript:addSockTag(false, false)', 'SockTag - suspected sock', 't-socktagblock', 'SockTag - suspected sock', , ); }

}); //