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

Content deleted Content added
test
rm span
 
(7 intermediate revisions by the same user not shown)
Line 11:
{
var $link = $($nodeList[i]);
var newLinkString = "<span class='reply-link-wrapper'>|";
var newLinkIdredlink = $link[0].title.replace(pdne, "") false;
var newLinkHref = $link[0].title
if(newLinkHref.includes(pdne))
{
redlink = true;
newLinkHref = newLinkHref.replace(pdne, "");
}
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 href="#' + newLinkId + '" style="font-size:x-small; display:inline-block;" title="Send a talkback!" noPopup=1 id="TBsubmit' + inewLinkId + '">TB</a>|</span>');
$($link).after(newLinkString)
$("#" + newLinkId).click(function{"page":newLinkHref, (e"redlink":redlink}, talkbackSubmit);
{
talkbackSubmit($(this).attr('href').substr(1), this.id)
});
}
}
}
}
function talkbackSubmit(page, idevent)
{
var page = event.data.page;
var redlink = event.data.redlink;
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|";
{
if (questionTitle === null)
{
Line 40 ⟶ 47:
sectionTitle += questionTitle + "|ts=~~" + "~~}}";
}
if(redlink)
var data =
{
summary:sectionTitle = "== Teahouse talkback: you've got messages! ==\n", + sectionTitle;
format: 'json',
var requestData =
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)
{
summary: "Teahouse talkback: you've got messages!"
if (data && data.edit && data.edit.result && data.edit.result === 'Success')
{
//window.___location = mw.util.getUrl(page);
alert("Talkback posted!");
}
else
{
alert('There was an error requesting the page edit. Code: ' + data.error.code + '": ' + data.error.info);
}
},
error: function ()
{
alert('There was an error using AJAX to edit the page.');
}
new mw.Api().create(page, requestData, sectionTitle).done(function(data)
});
{
if (data && data.edit && data.edit.result && data.edit.result === 'Success')
{
alert("Talkback posted!");
}
else
{
alert('There was an error requesting the page create. Code: ' + data);
});
success: }).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;
error: }).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.error.code + '": ' + data.error.info);
}
}).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();
{
teahouseTalkbackLink();
});
}