User:Qwerfjkl/scripts/talkback.js
Appearance
< User:Qwerfjkl | scripts
Code that you insert on this page could contain malicious content capable of compromising your account. If you import a script from another page with "importScript", "mw.loader.load", "iusc", or "lusc", take note that this causes you to dynamically load a remote script, which could be changed by others. Editors are responsible for all edits and actions they perform, including by scripts. User scripts are not centrally supported and may malfunction or become inoperable due to software changes. A guide to help you find broken scripts is available. If you are unsure whether code you are adding to this page is safe, you can ask at the appropriate village pump. This code will be executed when previewing this page. |
This user script seems to have a documentation page at User:Qwerfjkl/scripts/talkback. |
// 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*='\/'])"),
pdne = ' (page does not exist)';
if ($nodeList !== null) {
var i;
for (i = 0; i < $nodeList.length; i++) {
var $link = $($nodeList[i]);
var newLinkString = "|";
var redlink = 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 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
$($link).after(newLinkString);
$("#" + newLinkId).click({
"page": newLinkHref,
"redlink": redlink
}, function (event) {
event.preventDefault(); // prevent href being followed
talkbackSubmit(event)
});
}
}
}
}
function talkbackSubmit(event) {
var page = event.data.page;
var redlink = event.data.redlink;
var questionTitle = prompt("Please enter the title of the section 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 === "") {
sectionTitle += "ts=~~" + "~~" + "~}}\n~~" + "~";
} else {
sectionTitle += questionTitle + "|ts=~~" + "~~" + "~}}\n~~" + "~";
}
if (redlink) {
sectionTitle = "{{Talk header}}\n== Talkback: you've got messages! ==\n" + sectionTitle;
var requestData = {
summary: "Talkback: you've got messages! (via [[User:Qwerfjkl/scripts/talkback|script]])"
};
new mw.Api().create(page, requestData, sectionTitle).done(function(data) {
if (data && data.result && data.result === 'Success') {
mw.notify("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 requestData2 = {
minor: false,
appendtext: "\n== Talkback: you've got messages! ==\n" + sectionTitle,
//section: 'new',
summary: "Talkback: you've got messages! (via [[User:Qwerfjkl/scripts/talkback|script]])"
};
new mw.Api().edit(page, function() {
return requestData2;
}).done(function(data) {
if (data && data.result && data.result === 'Success') {
mw.notify("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);
});
}
}
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]]