User:Qwerfjkl/scripts/talkback.js

// 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 += 'C|'; newLinkString += 'TB'; // 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 = "\n== Talkback: you've got messages! ==\n" + sectionTitle; var requestData = { summary: "Talkback: you've got messages! (via 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 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