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

Content deleted Content added
bugfix
rm span
 
(29 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";
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++;
}
else if(link.href.substring(42,52) == "User_talk:" && link.href.lastIndexOf("/") == 25)
{
var newLink = document.createElement("form");
newLink.style.display = "inline-block";
newLink.method = "post";
newLink.action = link.href.substring(0, link.href.search("&"))+ "&action=submit&section=new";
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 page = event.data.page;
submitForm = document.getElementById("TBSubmit" + i);
var timestampredlink = getMWTimestamp()event.data.redlink;
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)
if (questionTitle === null)
{
return;
}
else if (questionTitle === "")
{
sectionTitle += "ts=~~" + "~~}}";
}
else
{
sectionTitle += questionTitle + "|ts=~~" + "~~}}";
}
if(redlink)
submitForm.innerHTML = '<input type="hidden" name="wpTextbox1" value="+sectionTitle+">\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="' + timestamp + '">\n<input type="hidden" name="wpEdittime" value="' + timestamp + '">\n<input type="hidden" name="wpSummary" value="Teahouse talkback: you\'ve got messages!">';
submitForm.submit();
}
 
function addAfter(newNode, oldNode)
{
if(oldNode.nextSibling != null)
{
sectionTitle = "== Teahouse talkback: you've got messages! ==\n" + sectionTitle;
oldNode.parentNode.insertBefore(newNode, oldNode.nextSibling);
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 =
oldNode.parentNode.appendChild(newNode);
{
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")
 
function getMWTimestamp()
{
mw.loader.using("mediawiki.api", function()
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)
{
teahouseTalkbackLink();
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;
}