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

Content deleted Content added
hopefully final bugfix
rm span
 
(32 intermediate revisions by 3 users not shown)
Line 1:
addOnloadHook(teahouseTalkbackLink);
 
function teahouseTalkbackLink()
{
if ($("#mw-content-text").length > 0)
if(wgPageName == "User:Writ_Keeper/sandbox")
{
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 redlink = event.data.redlink;
var timestamp = getMWTimestamp();
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='+'~~'+'~~'+'}}">\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!">';
sectionTitle = "{{Wikipedia:Teahouse/Teahouse talkback|WP:Teahouse|";
submitForm.submit();
}
 
function addAfter(newNode, oldNode)
{
if(oldNode.nextSibling != null)
{
oldNode.parentNode.insertBefore(newNode, oldNode.nextSibling);
}
else
{
oldNode.parentNode.appendChild(newNode);
}
}
 
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.lengthquestionTitle !=== 2null)
{
return;
month = "0" + month;
}
else if (day.lengthquestionTitle !=== 2"")
{
daysectionTitle += "0ts=~~" + day"~~}}";
}
else
if(hours.length != 2)
{
hourssectionTitle += questionTitle + "0|ts=~~" + hours"~~}}";
}
if(minutes.length != 2redlink)
{
sectionTitle = "== Teahouse talkback: you've got messages! ==\n" + sectionTitle;
minutes = "0" + minutes;
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
if(seconds.length != 2)
{
var requestData =
seconds = "0" + seconds;
{
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);
});
}
}
return "" + date.getUTCFullYear() + month + day + hours + minutes + seconds;
if (mw.config.get('wgPageName') === "Wikipedia:Teahouse")
{
mw.loader.using("mediawiki.api", function()
{
teahouseTalkbackLink();
});
}