User:Eraloiz/common.js

/* Adds a (copy unsigned) button on diff pages */ $(function {	const currentRevisionId = mw.config.get("wgDiffNewId");

if (!currentRevisionId) return;

new mw.Api.get({		action: "query",		prop: "revisions",		revids: currentRevisionId,		rvprop: "user|timestamp",		formatversion: 2	}).done(function(data) {		const page = data.query.pages[0];		const revision = page.revisions[0];

const user = revision.user; const date = new Date(revision.timestamp); const timestamp = padTime(date.getUTCHours) + ":"			+ padTime(date.getUTCMinutes) + ", "			+ date.getUTCDate + " "			+ date.toLocaleDateString("en-us", { month: "long", timeZone: "UTC" }) + " "			+ date.getUTCFullYear; const textToCopy = "";

var copyUnsignedA = document.createElement("a"); copyUnsignedA.href = "javascript:void(0);"; copyUnsignedA.textContent = "copy unsigned"; $(copyUnsignedA).click(function {			navigator.clipboard.writeText(textToCopy);		});

var copyUnsignedSpan = document.createElement("span"); copyUnsignedSpan.classList.add("copy-unsigned"); copyUnsignedSpan.append("(");		copyUnsignedSpan.append(copyUnsignedA);		copyUnsignedSpan.append(")"); const diffTopOptions = document.querySelector(".diff .diff-ntitle strong"); diffTopOptions.append(" "); diffTopOptions.append(copyUnsignedSpan); }); });

function padTime(time) { return (time + "").padStart(2, "0"); }