User:Tollens/longCommenter.js
Appearance
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:Tollens/longCommenter. |
if (sessionStorage.getItem("justAddedLongComment") === "true") {
mw.notify("Long comment tag added successfully", { type: "success" });
sessionStorage.removeItem("justAddedLongComment");
}
$.when(mw.loader.using(["mediawiki.util"]), $.ready).done(function () {
if (mw.config.get("wgNamespaceNumber") !== 0) console.warn("Not in mainspace, exiting");
const api = new mw.Api();
const currentPage = mw.config.get("wgPageName");
let button = mw.util.addPortletLink(
"p-cactions",
"#",
"Add long comment tag",
"ca-add-longcomment",
"Add long comment tag to this page"
);
if (button) {
button.addEventListener("click", async function () {
const length = Object.values(
(
await api.post({
action: "query",
prop: "revisions",
titles: currentPage,
rvprop: "size"
})
).query.pages
)[0].revisions[0].size;
if (length >= 256) {
mw.notify(`Page too long (${length} bytes), will not tag`, { type: "warn" });
return;
}
await api.postWithToken("csrf", {
action: "edit",
title: currentPage,
summary: "Adding long comment tag to prevent legitimately short page from listing at [[Special:ShortPages]] (via [[User:Tollens/longCommenter.js|script]])",
appendtext: "\n{{Short pages monitor}}<!-- This long comment was added to the page to prevent it from being listed on Special:Shortpages. It and the accompanying monitoring template were generated via Template:Long comment. Please do not remove the monitoring template without removing this comment as well.-->"
});
sessionStorage.setItem("justAddedLongComment", "true");
window.location.reload();
});
}
});