User:Qwerfjkl/scripts/talkback.js: Difference between revisions

Content deleted Content added
Test
remove titles with / [Factotum]
 
(22 intermediate revisions by the same user not shown)
Line 1:
// Forked from [[User:Writ Keeper/Scripts/TeahouseTalkbackLink.js]]
function talkbackLink() {
if ($("#mw-content-text").length > 0) {
{
var $nodeList = $('a[title^="User talk:"]').filter("a:not([title*='\/'])"),
if ($("#mw-content-text").length > 0)
pdne = ' (page does not exist)';
{
var if ($nodeList != $('a[title^="User talk:"]'null), {
var i;
pdne = ' (page does not exist)';
for (i = 0; i < $nodeList.length; i++) {
if ($nodeList !== null)
var $link = $($nodeList[i]);
{
var newLinkString = "|";
var i;
var redlink = false;
for (i = 0; i < $nodeList.length; i++)
var newLinkHref = $link[0].title;
{
if (newLinkHref.includes(pdne)) {
var $link = $($nodeList[i]);
redlink = true;
var newLinkString = "|";
newLinkHref = newLinkHref.replace(pdne, "");
var redlink = false;
}
var newLinkHref = $link[0].title;
var newLinkId = "TBsubmit" + i;
if(newLinkHref.includes(pdne))
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 + '" href= "'+($link[0].href)+'">TB</a>'; // add href so there is a link to the userpage just before the timestamp
redlink = true;
$($link).after(newLinkString);
newLinkHref = newLinkHref.replace(pdne, "");
$("#" + newLinkId).click({
}
"page": newLinkHref,
var newLinkId = "TBsubmit" + i;
"redlink": redlink
newLinkString += '<a href=' + (($link[0].href).replace("User_talk:", "Special:Contributions/")) + ' style="font-size:x-small; display:inline-block;">C</a>|';
}, function (event) {
newLinkString += '<a style="font-size:x-small; display:inline-block;" title="Send a talkback!" noPopup=1 id="' + newLinkId + '">TB</a>';
event.preventDefault(); // prevent href being followed
$($link).after(newLinkString);
$("#" + newLinkId).click({"page":newLinkHref, "redlink":redlink}, talkbackSubmit(event);
});
}
}
}
}
}
}
}
 
function talkbackSubmit(event)
function talkbackSubmit(event) {
{
var page = event.data.page;
var redlink = event.data.redlink;
var questionTitle = prompt("Please enter the title of the questionsection you're replying to (or just leave it blank):", "").trim().replace(/^(Wikipedia|User|Template|Draft|Help|Module|MediaWiki).+?#/, ''),
sectionTitle = "{{Talkback|" + mw.config.get('wgPageName').replace(/_/g, ' ') + "|";
 
if (questionTitle === null) {
return;
{
} else if (questionTitle === "") {
return;
sectionTitle += "ts=~~" + "~~" + "~}}\n~~" + "~";
}
} else {
else if (questionTitle === "")
sectionTitle += questionTitle + "|ts=~~" + "~~" + "~}}\n~~" + "~";
{
}
sectionTitle += "ts=~~" + "~~" + "~}}\n~~" + "~";
if (redlink) {
}
sectionTitle = "{{Talk header}}\n== Talkback: you've got messages! ==\n" + sectionTitle;
else
var requestData = {
{
summary: "Talkback: you've got messages! (via [[User:Qwerfjkl/scripts/talkback|script]])"
sectionTitle += questionTitle + "|ts=~~" + "~~" + "~}}\n~~" + "~";
};
}
new mw.Api().create(page, requestData, sectionTitle).done(function(data) {
if(redlink)
 
{
if (data && data.result && data.result === 'Success') {
sectionTitle = "== Talkback: you've got messages! ==\n" + sectionTitle;
mw.notify("Talkback posted!");
var requestData =
} else {
{
alert('There was an error requesting the page create. Code: ' + data);
summary: "Talkback: you've got messages! (via [[User:Qwerfjkl/scripts/talkback|script]])"
}
};
new mw.Api().create(page, requestData, sectionTitle }).donefail(function(data) {
alert('There was an error using AJAX to create the page. Error: ' + data);
{
});
} else {
if (data && data.result && data.result === 'Success')
var requestData2 = {
{
minor: false,
alert("Talkback posted!");
appendtext: "\n== Talkback: you've got messages! ==\n" + sectionTitle,
}
//section: 'new',
else
summary: "Talkback: you've got messages! (via [[User:Qwerfjkl/scripts/talkback|script]])"
{
};
alert('There was an error requesting the page create. Code: ' + data);
new mw.Api().edit(page, function() {
}
return requestData2;
}).fail(function(data) {
}).done(function(data) {
alert('There was an error using AJAX to create the page. Error: ' + data);
 
});
if (data && data.result && data.result === 'Success') {
}
mw.notify("Talkback posted!");
else
} else {
{
alert('There was an error requesting the page edit. Code: ' + data);
var requestData =
}
{
}).fail(function(data) {
minor: false,
alert('There was an error using AJAX to edit the page. Error: ' + data);
text: sectionTitle,
});
section: 'new',
}
summary: "Talkback: you've got messages! (via [[User:Qwerfjkl/scripts/talkback|script]])"
};
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 (1 === 1)
{
mw.loader.using("mediawiki.api", function()
{
talkbackLink();
});
}
 
mw.loader.using("mediawiki.api", function() {
talkbackLink();
});
 
mw.loader.load('/w/index.php?title=User:Qwerfjkl/scripts/sectionLink.js&action=raw&ctype=text/javascript'); // Backlink: [[User:Qwerfjkl/scripts/sectionLink.js]]