User:Terasail/Edit Request Tool.js: Difference between revisions

Content deleted Content added
m Change indentation
Account for Template:Sudo
 
(3 intermediate revisions by the same user not shown)
Line 4:
*/
var dataERT;
var userSignauteERT = "";
var editRequestBoxes = $('.editrequest');
var editRequests = [];
Line 23 ⟶ 24:
$.getJSON("https://en.wikipedia.org/w/index.php?title=User:Terasail/Edit_Request_Tool.json&action=raw&ctype=text/json", function (newData) {
dataERT = newData;
});
ApiGetERT({
action: "parse",
title: mw.config.get("wgPageName"),
text: "~~~~",
pst: "true",
disablelimitreport: "true",
disableeditsection: "true",
preview: "true"
}).then(function(data){
userSignauteERT = data.parse.text["*"].replaceAll(/([^]+(?=<p>)<p>|<\/div>)/g, " ");
});
});
Line 69 ⟶ 81:
let boxType = editRequest.dataset.origlevel;
boxType = boxType.replace("full", "fully");
$('<table style="border:1px solid #A2A9B1; border-radius:2px; padding:10px 16px 0; margin:auto; max-width:55em; width:100%; clear:both;"><tr><td style="color:#808080"><div style="font-style:italic; margin-left:1em;">There are currently ' + watchStatus[0] + ' users watching this page (' + watchStatus[1] + ' have viewed recent edits).</div><div>Quick options:</div></td></tr><tr style="display: flex; justify-content: center;"><td class="response-quick"></td></tr><tr><td style="color:#808080">Custom response:</td></tr><tr style="text-align:center;"><td class="response-custom"></td></tr><tr style="background:#F6F6F6;"><td class="response-preview" style="display:none;"><div style="color:#808080">Preview:</div><div></div></td></tr><tr style="display: flex; justify-content: right;"><td class="response-controls"></td></tr></table>').insertAfter(editRequest);
let responseBox = editRequest.nextElementSibling;
let responseQuick = $(responseBox).find('.response-quick')[0];
Line 290 ⟶ 302:
function previewERT(inputText, replyOption, tableRow, template) {
var restTransform = "https://en.wikipedia.org/api/rest_v1/transform/wikitext/to/html/" + encodeURIComponent(mw.config.get('wgPageName'));
let preview = ""inputText.value;
let newText = inputText.value;
if (typeof (inputText) == 'string') {
newText = inputText;
}
template = dataERT.protections[template][1];
if (typeof (replyOption) != "undefined") {
preview += "{{" + template + replyOption[0] + "}} " + preview;
}
if (newText != "" && typeof (newText) != "undefined") {
preview += newText + " ";
}
if (preview != "") {
let nickname = " " + mw.user.options.values.nickname;
if (nickname == " ") {//Create default signature if no nickname
nickname = mw.user.getName();
nickname = " [[User:" + nickname + "|" + nickname + "]] ([[User talk:" + nickname + "|talk]])";
}
let dateObj = new Date();
let dateNow = dateObj.toLocaleDateString('en-GB', {
timeZone: 'UTC',
year: 'numeric',
month: 'long',
day: 'numeric'
});
let timeNow = dateObj.toLocaleTimeString('en-GB', {timeZone: 'UTC', hour: '2-digit', minute: '2-digit'});
preview += nickname + " " + timeNow + ", " + dateNow + " (UTC)";
preview = preview.replaceAll(/{{subst:/gi, "{{");
$.post(restTransform, 'wikitext=' + encodeURIComponent(preview) + '&body_only=true',
Line 322 ⟶ 313:
if (inputText.value != "" || typeof (replyOption) != "undefined") {//Stops preview appearing with empty input box
tableRow.style = "padding:8px 1em 2px;";
tableRow.children[1].innerHTML = html.replace("</p>", userSignauteERT);
}
}
Line 356 ⟶ 347:
//Set preview for output
if (responseOption[0] != "") {//Don't preview a non-response
let tempValue = {value:responseText};
previewERT(responseTexttempValue, responseOption, requestBox[2], requestType);
}
//Find header
Line 375 ⟶ 367:
sectionIndex = parseInt(tempElement.parentElement.dataset.mwSectionId);
} else {
header =if (tempElement.getElementsByClassName("mw-headline")[0].id;length > 0) { //Vector 2022
header = tempElement.getElementsByClassName("mw-headline")[0].id;
} else { //Vector Legacy
header = $(tempElement).find("h1,h2,h3,h4,h5,h6")[0].id;
}
for (let i = 0; i < sections.length; i++) {
if (sections[i].anchor == header) {
Line 405 ⟶ 401:
editTemplate += "|answered=no";
}
wikitext = wikitext.replace(/{{ *([SETFI]PER|Edit([ -]?[A-Z]+[ -]?|[- ])Protected|Sudo)\s*[^}}]*/i, editTemplate);
if (responseOption[1] != "Close") {
wikitext = wikitext.trim() + "\n:";
Line 449 ⟶ 445:
apiParams.watchlistexpiry = watchValue;
}
let reloadURL = "/w/index.php?title=" + encodeURI(mw.config.get("wgPageName")) + "&type=revision&diff=cur&oldid=prev";
new mw.Api().postWithEditToken(apiParams).done(function () {
let reloadURL window.___location = "/w/index.php?title=" + encodeURI(mw.config.get("wgPageName")) + "&type=revision&diff=cur&oldid=prev";
window.___location = reloadURL;
});
}