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

Content deleted Content added
fix
test
Line 1:
function teahouseTalkbackLink()
{
if ($("#mw-content-text").length > 0) {
{
var $nodeList = $('a[title^="User talk:"]'), pdne = ' (page does not exist)';
if(var $nodeList != $('a[title^="User nulltalk:"]') {,
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]);
var newLinkString = "<span class='reply-link-wrapper'>|";
$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>');
var newLinkId = $link[0].title.replace(pdne, "") ;
$newLink.click(function(e) {
$($link).after($(newLinkString += '<a href=' + (($link[0].href).replace("User_talk:", "Special:Contributions/")) + ' style="font-size:x-small; display:inline-block;">C</a>|'));
$newLinknewLinkString += $('<a href="#' + $link[0].title.replace(pdne, "")newLinkId + '" style="font-size:x-small; display:inline-block;" title="Send a talkback!" noPopup=1 id="TBsubmit' + i + '">TB</a>|</span>');
$($link).after("<!--1-->|"newLinkString);
$newLink("#" + newLinkId).click(function (e) {
{
talkbackSubmit($(this).attr('href').substr(1), this.id)
});
$($link).after("<!--1-->|");
$($link).after($newLink);
$($link).after("<!--2-->|");
$($link).after($('<a href='+(($link[0].href).replace("User_talk:", "Special:Contributions/"))+' style="font-size:x-small; display:inline-block;">C</a>'));
$($link).after("<!--3-->|");
}
}
}
}
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|";
if (questionTitle === null) {
{
return;
}
else if (questionTitle === "") {
{
sectionTitle += "ts=~~" + "~~}}";
}
else {
{
sectionTitle += questionTitle + "|ts=~~" + "~~}}";
}
var data = {
{
format : 'json',
action format: 'editjson',
minor action: false'edit',
title minor: pagefalse,
text title: sectionTitlepage,
text: sectionTitle,
section : 'new',
summarysection: 'new',
summary: "Teahouse talkback: you've got messages!",
token : mw.user.tokens.get('editToken')
};
$.ajax({
{
url : mw.util.wikiScript('api'),
type : 'POST',
dataType type: 'jsonPOST',
data dataType: data'json',
success data: function(data) {,
success: function (data)
{
if (data && data.edit && data.edit.result && data.edit.result === 'Success') {
{
//window.___location = mw.util.getUrl(page);
alert("Talkback posted!");
} else {
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.');
}
});
}
if (mw.config.get('wgPageName') === "Wikipedia:Teahouse")
{
teahouseTalkbackLink();
}