Jump to content

User:Topher385/common.js

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Topher385 (talk | contribs) at 16:33, 4 August 2012 (added 3 scripts). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
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.
importScript('User:Tim_Song/afchelper4.js')
importScript('MediaWiki:Gadget-HotCat.js')
importScript("User:Writ Keeper/Scripts/teahouseTalkback.js");
function teahouseTalkbackLink() { 	if($("#mw-content-text").length > 0) { 		var $nodeList = $('a[title^="User talk:"]'), pdne = ' (page does not exist)'; 		if($nodeList !== null) { 			var i; 			for( i = 0; i < $nodeList.length; i++) { 				var $link = $($nodeList[i]); 					$newLink = $('<a href="#' + $link[0].title.replace(pdne, "") + '" style="font-size:x-small; display:inline-block;" title="Send a talkback!" noPopup=1 id="TBsubmit' + i + '">TB</a>'); 				$newLink.click(function(e) { 					talkbackSubmit($(this).attr('href').substr(1), this.id) 				}); 				$($link).after($newLink); 			} 		} 	$('a[title="Send a talkback!"]').tipsy({html: true}).before("|").after("|"); 	} } function talkbackSubmit(page, id) { 	var questionTitle = prompt("Please enter the title of the question you're replying to (or just leave it blank):", ""), sectionTitle = "{{Wikipedia:Teahouse/Teahouse talkback|WP:Teahouse/Questions|"; 	if (questionTitle === null) { 		 $("#"+id).attr("title", 'You canceled the talkback!').tipsy("show"); 		 return; 	} 	else if (questionTitle === "") { 		sectionTitle += "ts=~~" + "~~}}"; 	} 	else { 		sectionTitle += questionTitle + "|ts=~~" + "~~}}"; 	} 	var data = { 		format : 'json', 		action : 'edit', 		minor : false, 		title : page, 		text : sectionTitle, 		section : 'new', 		summary : "Teahouse talkback: you've got messages!", 		token : mw.user.tokens.get('editToken') 	}; 	$.ajax({ 		url : mw.util.wikiScript('api'), 		type : 'POST', 		dataType : 'json', 		data : data, 		success : function(data) { 			if(data && data.edit && data.edit.result && data.edit.result === 'Success') { 				window.location = mw.util.wikiGetlink(page); 			} else { 				$("#"+id).attr("title", 'There was an error requesting the page edit. Code: ' + data.error.code + '": ' + data.error.info).tipsy("show"); 			} 		}, 		error : function() { 			$("#"+id).attr("title", 'There was an error using AJAX to edit the page.').tipsy("show"); 		} 	}); } if(mw.config.get('wgPageName') === "Wikipedia:Teahouse/Questions") { 	mw.loader.using( 'jquery.tipsy', function () { $(teahouseTalkbackLink); } );}
/* 	This script adds entries for posting Teahouse talkbacks and invites into the page action menu (and adds the page action menu itself, if it's not present)  */   //standard onloadhook addOnloadHook(teahouseMenu);   //add menu if it's not there; populate it with new buttons  function teahouseMenu() { 	if(wgCanonicalNamespace == "User" || wgCanonicalNamespace == "User_talk")//Only if we're on a user or user talk page 	{ 		var inviteLink = mw.util.addPortletLink("p-cactions", "#", "THInvite", "th-invite", "Add a Teahouse invite template", null, "#ca-move"); 		var afcLink = mw.util.addPortletLink("p-cactions", "#", "THInvite (AfC)", "th-afc", "Add a Teahouse invite template", null, "#ca-move"); 		var talkbackLink = mw.util.addPortletLink("p-cactions", "#", "THTalkback", "th-talkback", "Add a Teahouse talkback template", null, "#ca-move"); 		$(inviteLink).click(postTHInvite); 		$(afcLink).click(postTHafc); 		$(talkbackLink).click(postTHTalkback); 	} }   function populateListEntry(listEntry) { 	var form = document.createElement("form"); 	var slashLocation = wgTitle.indexOf("/"); 	form.style.display = "inline-block"; 	form.method = "POST"; 	if(slashLocation > 0) 	{ 		form.action = "http://en.wikipedia.org/wiki/User_talk:" + wgTitle.substring(0, wgTitle.indexOf("/")) + "?action=submit&section=new"; 	} 	else 	{ 		form.action = "http://en.wikipedia.org/wiki/User_talk:" + wgTitle + "?action=submit&section=new"; 	} 	listEntry.appendChild(form); 	return form; }   function postTHInvite() {	    invitationBody = "{{su" + "bst:#ife" + "xist: User:" + wgUserName + "/Teahouse invite | {{su"+"bst:User:" + wgUserName + "/Teahouse invite}} | {{Wikipedia:Teahouse/Invitation|sign=~~"+"~~}} }}";      //If you want to change what the invitation section is titled, edit the words below within the doublequote (but don't take out the doublequote!)    invitationSectionTitle = "Welcome to Wikipedia: check out the Teahouse!"   	var timestamp = getMWTimestamp();   	var linkArray = document.getElementById("mw-content-text").getElementsByTagName("a"); 	var i; 	for(i = 0; i < linkArray.length; i++) 	{ 		if(linkArray[i].href.search("Wikipedia:Teahouse") > -1) 		{ 			if(confirm("Someone may have already invited this person to the Teahouse!\n\nAre you sure you want to continue?")) 			{ 				break; 			} 			else return; 		} 	} 	$.post(getSubmitURL(true), {wpTextbox1 : invitationBody, wpSection : "new", wpEditToken : mw.user.tokens.get('editToken'), wpStarttime : timestamp, wpEdittime : timestamp, wpSummary : invitationSectionTitle}, function(){ alert("Invitation posted!"); window.location = getSubmitURL(false);}); }   function postTHafc() {	    invitationBody = "{{su" + "bst:#ife" + "xist: User:" + wgUserName + "/Teahouse AfC invite | {{su"+"bst:User:" + wgUserName + "/Teahouse AfC invite}} | {{Wikipedia:Teahouse/AfC Invitation|sign=~~"+"~~}} }}";      //If you want to change what the invitation section is titled, edit the words below within the doublequote (but don't take out the doublequote!)    invitationSectionTitle = "Welcome to Wikipedia! Need a hand?"   	var timestamp = getMWTimestamp();   	var linkArray = document.getElementById("mw-content-text").getElementsByTagName("a"); 	var i; 	for(i = 0; i < linkArray.length; i++) 	{ 		if(linkArray[i].href.search("Wikipedia:Teahouse") > -1) 		{ 			if(confirm("Someone may have already invited this person to the Teahouse!\n\nAre you sure you want to continue?")) 			{ 				break; 			} 			else return; 		} 	} 	$.post(getSubmitURL(true), {wpTextbox1 : invitationBody, wpSection : "new", wpEditToken : mw.user.tokens.get('editToken'), wpStarttime : timestamp, wpEdittime : timestamp, wpSummary : invitationSectionTitle}, function(){ alert("Invitation posted!"); window.location = getSubmitURL(false);}); }   function postTHTalkback() { 	var questionTitle = prompt("Please enter the title of the question you're replying to (or just leave it blank):",""); 	var sectionTitle = "{{Wikipedia:Teahouse/Teahouse talkback|WP:Teahouse/Questions|"; 	if(questionTitle == null) 	{ 		return; 	} 	else if(questionTitle == "") 	{ 		sectionTitle +=	"ts=~~"+"~~}}"; 	} 	else 	{ 		sectionTitle += questionTitle +"|ts=~~"+"~~}}"; 	} 	var timestamp = getMWTimestamp(); 	$.post(getSubmitURL(true), {wpTextbox1 : "{{Wikipedia:Teahouse/Teahouse talkback|WP:Teahouse/Questions|"+ questionTitle +"|ts=~~"+"~~}}", wpSection : "new", wpEditToken : mw.user.tokens.get('editToken'), wpStarttime : timestamp, wpEdittime : timestamp, wpSummary : "Teahouse talkback: you\'ve got messages!"}, function(){ alert("Talkback posted!"); window.location = getSubmitURL(false);}); 	 }   function getMWTimestamp() { 	var date = new Date(); 	var month = "" + (date.getUTCMonth() + 1); 	var day = "" + date.getUTCDate(); 	var hours = "" + date.getUTCHours(); 	var minutes = "" + date.getUTCMinutes(); 	var seconds = "" + date.getUTCSeconds();   	if(month.length != 2) 	{ 		month = "0" + month; 	} 	if(day.length != 2) 	{ 		day = "0" + day; 	} 	if(hours.length != 2) 	{ 		hours = "0" + hours; 	} 	if(minutes.length != 2) 	{ 		minutes = "0" + minutes; 	} 	if(seconds.length != 2) 	{ 		seconds = "0" + seconds; 	} 	return "" + date.getUTCFullYear() + month + day + hours + minutes + seconds; } function getSubmitURL(moreArgs) { 	var submitURL = wgServer + "/wiki/User talk:";   	if(wgTitle.indexOf("/") > 0) 	{ 		submitURL += wgTitle.substring(0, wgTitle.indexOf("/")); 	} 	else 	{ 		submitURL += wgTitle; 	} 	if(moreArgs) 	{ 		submitURL += "?action=submit&section=new"; 	} 	return submitURL; }