User:Trijnstel/common.js
Appearance
Note: After publishing, you may have to bypass your browser's cache to see the changes.
- Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
- Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
- Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5.
/**
* StewardScript extends the user interface for Wikimedia stewards' convenience.
* @see https://meta.wikimedia.org/wiki/StewardScript
* @update-token [[File:pathoschild/stewardscript.js]]
*/
mw.loader.load('//tools-static.wmflabs.org/meta/scripts/pathoschild.stewardscript.js');
//https://en.wikipedia.org/wiki/User:Σ/Testing_facility/Archiver.js
// Translated by: [[User:Zaher.Kadour/Archiver.js]]
$(document).ready(function() {
if (mw.config.get("wgNamespaceNumber") == -1)
// is a special page
return;
$("head").append("<style>a.arkylink { font-weight:bold } .arkyhighlight { background-color:#D9E9FF }</style>");
var validSections = new Object();
var fromTos = new Object();
var wikiText = "";
var revStamp;
var startArchiveButton = mw.util.addPortletLink("p-cactions", "#", "archiving", "pt-oeca", "Start/End the Archive Wizard", null, null);
var overlay = $(document.createElement("button"));
$(startArchiveButton).click(function(e) {
$(".arkylink").click();
$(".arky").toggle();
$("#archivebutton").toggle();
});
overlay.html("archiving all sections")
.attr("id", 'archivebutton')
.css("position", 'fixed')
.css("bottom", 0)
.css("height", '44px')
.css("width", '100%')
.css("font-size", '200%');
$(document.body).append(overlay);
overlay.toggle();
overlay.click(function(e) {
var numOfThreads, archiveTarget;
var sections, archiveThis;
var cutOffset, revisedPage;
function cut(s, start, end) {
return s.substr(0, start) + s.substring(end);
}
cutOffset = numOfThreads = 0;
revisedPage = wikiText;
sections = $("a.arkylink").map(function() {
return $(this).attr("data-section");
});
if (!(numOfThreads = sections.length))
return alert("No section selected, Cancel");
archiveTarget = prompt("archiving" + numOfThreads + "Sections: What is the title of the archive page?", mw.config.get("wgPageName"));
if (!archiveTarget || archiveTarget == mw.config.get("wgPageName"))
return alert("No selected archive page, Cancel");
sections.each(function(i, n) {
revisedPage = cut(
revisedPage,
fromTos[n][0] - cutOffset,
fromTos[n][1] - cutOffset
);
cutOffset += fromTos[n][1] - fromTos[n][0];
});
archiveThis = sections.map(function() {
return wikiText.substring(fromTos[this][0], fromTos[this][1]);
}).toArray().join("");
console.log("archive this:" + archiveThis);
console.log("revised page:" + revisedPage);
if (1) new mw.Api().postWithToken("csrf", {action: 'edit', title: mw.config.get("wgPageName"), text: revisedPage, summary: "archiving " + numOfThreads + " sections to [[" + archiveTarget + "]]", basetimestamp: revStamp, starttimestamp: revStamp})
.done(function(res1) {
alert("section successfully moved");
console.log(res1);
new mw.Api().postWithToken("csrf", {action: 'edit', title: archiveTarget, appendtext: "\n" + archiveThis, summary: "archiving from [[" + mw.config.get("wgPageName") + "]]"})
.done(function(res2) {
alert("Sections have been added to the archive page successfully");
})
.fail(function(res2) {
alert("Failed to add the sections to the archive page. Manual checking is required");
})
.always(function(res2) {
console.log(res2);
window.location.reload();
});
})
.fail(function(res1) {
alert("Failed to add the sections to the archive page. Canecel the archiving process.");
console.log(res1);
window.location.reload();
});
});
new mw.Api().get({action: 'parse', page: mw.config.get("wgPageName")}).done(function(dataShit) {
new mw.Api().get({action: 'query', pageids: mw.config.get("wgArticleId"), prop: ['revisions'], rvprop: ['content', 'timestamp']}).done(function(shit) {
var rv;
rv = shit.query.pages[mw.config.get("wgArticleId")].revisions[0];
wikiText = rv["*"];
revStamp = rv['timestamp'];
});
$(dataShit.parse.sections)
.filter(function(i, s) { return s.index == parseInt(s.index) })
.each(function(i, s) { validSections[s.index] = s });
for (var i in validSections) {
i = parseInt(i);
fromTos[i] = [
validSections[i].byteoffset,
validSections.hasOwnProperty(i+1)?validSections[i+1].byteoffset:Infinity
];
}
$("#mw-content-text").find(":header").find("span.mw-headline").each(function(i, title) {
var header, editSection, sectionNumber;
header = $(this).parent();
editSection = header.find(".mw-editsection"); // 1st child
sectionNumber = header.find(".mw-editsection a:first");
if (sectionNumber[0]) {
sectionNumber = sectionNumber.attr("href").match(/§ion=(\d+)/);
if (sectionNumber)
sectionNumber = sectionNumber[1];
} else // eg <h2>not a real section</h2>
sectionNumber = undefined;
if (validSections.hasOwnProperty(sectionNumber))
editSection[0].innerHTML += " <span class=arky style=display:none><span class=mw-editsection-bracket>[</span><a data-section=" + sectionNumber + " " + "onclick=$(this).closest(':header').toggleClass('arkyhighlight');$(this).toggleClass('arkylink');>أرشف</a><span class=mw-editsection-bracket>]</span></span>";
});
});
});
mw.loader.load('//meta.wikimedia.org/w/index.php?title=User:ASammour/test.js&action=raw&ctype=text/javascript');
mw.loader.load('https://meta.wikimedia.org/w/index.php?title=User:DannyS712/SRG.js&oldid=20260849&action=raw&ctype=text/javascript');