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

Content deleted Content added
test
rm span
 
(13 intermediate revisions by the same user not shown)
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:"]') {,
pdne = ' (page does not exist)';
if ($nodeList !== null)
{
var i;
for( (i = 0; i < $nodeList.length; i++) {
{
var $link = $($nodeList[i]);
var newLinkString = "|";
$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 redlink = false;
$newLink.click(function(e) {
var newLinkHref = $link[0].title
talkbackSubmit($(this).attr('href').substr(1), this.id)
if(newLinkHref.includes(pdne))
});
{
$($link).after($newLink);
redlink = true;
$($link).after($('<a href='+(($link[0].href).replace("User_talk:", "Special:Contributions/"))+' style="font-size:x-small; display:inline-block;">C</a>'));
newLinkHref = newLinkHref.replace(pdne, "");
$($link).after("|");
}
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);
}
}
$('a[title="Send a talkback!"]').tipsy({html: true}).before("<span class='reply-link-wrapper'>|").after("|</span>");
}
}
function talkbackSubmit(page, idevent)
{
var page = event.data.page;
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|";
var redlink = event.data.redlink;
if (questionTitle === null) {
var questionTitle = prompt("Please enter the title of the question you're replying to (or just leave it blank):", ""),
$("#"+id).attr("title", 'You canceled the talkback!').tipsy("show");
sectionTitle = "{{Wikipedia:Teahouse/Teahouse talkback|WP:Teahouse|";
return;
if (questionTitle === null)
{
return;
}
else if (questionTitle === "") {
{
sectionTitle += "ts=~~" + "~~}}";
}
else {
{
sectionTitle += questionTitle + "|ts=~~" + "~~}}";
}
if(redlink)
var data = {
{
format : 'json',
sectionTitle = "== Teahouse talkback: you've got messages! ==\n" + sectionTitle;
action : 'edit',
var requestData =
minor : false,
{
title : page,
summary: "Teahouse talkback: you've got messages!"
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) {
if(data && data.edit && data.edit.result && data.edit.result === 'Success') {
//window.___location = mw.util.getUrl(page);
alert("Talkback posted!");
} else {
$("#"+id).attr("title", 'There was an error requesting the page edit. Code: ' + data.error.code + '": ' + data.error.info).tipsy("show");
}
},
error : function() {
$("#"+id).attr("title", 'There was an error using AJAX to edit the page.').tipsy("show");
}
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();
});
}
if(mw.config.get('wgPageName') === "Wikipedia:Teahouse") {
mw.loader.using( 'jquery.tipsy', function () { $(teahouseTalkbackLink); } );}