User:Writ Keeper/Scripts/teahouseTalkbackLink.js: Difference between revisions

Content deleted Content added
bugfix
rm span
 
(42 intermediate revisions by 3 users not shown)
Line 1:
addOnloadHook(teahouseTalkbackLink);
 
function teahouseTalkbackLink()
{
if ($("#mw-content-text").length > 0)
if(wgPageName == "Wikipedia:Teahouse/Questions")
{
var $nodeList = $('a[title^="User talk:"]'),
var contentBody = document.getElementById("mw-content-text");
pdne = ' (page does not exist)';
if(contentBody != null)
if ($nodeList !== null)
{
var i;
var nodeList = contentBody.getElementsByTagName("a");
for (i = 0; i < $nodeList.length; i++)
if(nodeList != null)
{
var $link = $($nodeList[i]);
var newLinkString = "|";
for(i = 0; i < nodeList.length; i++)
var redlink = false;
var newLinkHref = $link[0].title
if(newLinkHref.includes(pdne))
{
var linkredlink = nodeList[i]true;
newLinkHref = newLinkHref.replace(pdne, "");
if(link.href.substring(28,39) == "/User_talk:" && link.href.lastIndexOf("/") == 28)
{
var newLink = document.createElement("form");
newLink.style.display = "inline-block";
newLink.method = "post";
newLink.action = link.href + "?action=submit&section=new&preloadTitle=Teahouse%20Talkback";
newLink.id = "TBSubmit" + i;
newLink.innerHTML = '|<a href="#" onclick="talkbackSubmit(' + i + '); return;" style="font-size:x-small;" title="Send a talkback!">TB</a>|';
addAfter(newLink, link);
i++;
}
}
var newLinkId = "TBsubmit" + i;
newLinkString += '<a href=' + (($link[0].href).replace("User_talk:", "Special:Contributions/")) + ' style="font-size:x-small; display:inline-block;">C</a>|'
newLinkString += '<a style="font-size:x-small; display:inline-block;" title="Send a talkback!" noPopup=1 id="' + newLinkId + '">TB</a>|';
$($link).after(newLinkString)
$("#" + newLinkId).click({"page":newLinkHref, "redlink":redlink}, talkbackSubmit);
}
}
}
}
function talkbackSubmit(event)
 
function talkbackSubmit(i)
{
var datepage = new Date()event.data.page;
var redlink = event.data.redlink;
submitForm = document.getElementById("TBSubmit" + i);
var questionTitle = prompt("Please enter the title of the question you're replying to (or just leave it blank):", ""),
submitForm.innerHTML = '<input type="hidden" name="wpTextbox1" value="{{Wikipedia:Teahouse/Teahouse talkback|WP:Teahouse/Questions|ts=[[User:Writ Keeper|Writ Keeper]] [[User Talk: Writ Keeper|&#9863;]][[Special:Contributions/Writ_Keeper|&#9812;]] 17:36, 20 March 2012 (UTC)}}">\n<input type="hidden" name="wpSection" value="new">\n<input type="hidden" name="wpEditToken" value="' + mw.user.tokens.get( 'editToken' ) + '">\n<input type="hidden" name="wpStarttime" value="' + date.getYear() + (date.getMonth() + 1) + date.getDate() + date.getHours() + date.getMinutes() + date.getSeconds() + '">\n<input type="hidden" name="wpEdittime" value="' + date.getYear() + (date.getMonth() + 1) + date.getDate() + date.getHours() + date.getMinutes() + date.getSeconds() + '">\n<input type="hidden" name="wpSummary" value="Teahouse talkback: you\'ve got messages!">';
sectionTitle = "{{Wikipedia:Teahouse/Teahouse talkback|WP:Teahouse|";
submitForm.submit();
}
if (questionTitle === null)
 
function addAfter(newNode, oldNode)
{
if(oldNode.nextSibling != null)
{
return;
oldNode.parentNode.insertBefore(newNode, oldNode.nextSibling);
}
else if (questionTitle === "")
{
sectionTitle += "ts=~~" + "~~}}";
}
else
{
sectionTitle += questionTitle + "|ts=~~" + "~~}}";
oldNode.parentNode.appendChild(newNode);
}
if(redlink)
{
sectionTitle = "== Teahouse talkback: you've got messages! ==\n" + sectionTitle;
var requestData =
{
summary: "Teahouse talkback: you've got messages!"
}
new mw.Api().create(page, requestData, sectionTitle).done(function(data)
{
if (data && data.result && data.result === 'Success')
{
alert("Talkback posted!");
}
else
{
alert('There was an error requesting the page create. Code: ' + data);
}
}).fail(function(data) {
alert('There was an error using AJAX to create the page. Error: ' + data);
});
}
else
{
var requestData =
{
minor: false,
text: sectionTitle,
section: 'new',
summary: "Teahouse talkback: you've got messages!"
};
new mw.Api().edit(page, function() {
return requestData;
}).done(function(data) {
if (data && data.result && data.result === 'Success')
{
alert("Talkback posted!");
}
else
{
alert('There was an error requesting the page edit. Code: ' + data);
}
}).fail(function(data) {
alert('There was an error using AJAX to edit the page. Error: ' + data);
});
}
}
if (mw.config.get('wgPageName') === "Wikipedia:Teahouse")
{
mw.loader.using("mediawiki.api", function()
{
teahouseTalkbackLink();
});
}