mw.loader.using(, function() {
if (mw.config.get("wgCanonicalSpecialPageName") !== "ExpandTemplates")
return;
new OO.ui.ButtonWidget({
label: "Copy URL",
href: "#",
})
.on("click", function() {
const form = $(".mw-htmlform").get(0);
const url = new URL(mw.util.getUrl("Special:ExpandTemplates"), location);
.forEach(
param => url.searchParams.set(param, form.elements.value)
);
[
"wpRemoveComments",
"wpRemoveNowiki",
"wpGenerateXml",
"wpGenerateRawHtml"
].forEach(
param => url.searchParams.set(
param,
Number(OO.ui.infuse($(``).parent()).isSelected())
)
);
try {
navigator.clipboard.writeText(url)
.then(() => mw.notify("Link copied to clipboard"))
.catch(err => {
console.warn(err);
copyFallback(url);
});
} catch (err) {
console.warn(err);
copyFallback(url);
}
})
.$element.appendTo(".mw-htmlform-submit-buttons");
function copyFallback(text) {
const input = $("<input>", {
value: text,
type: "text",
style: "position: fixed; top: -100em;"
})
.appendTo("body").select();
document.execCommand("copy");
input.remove();
mw.notify(
"Warning: Falling back to old method of clipboard access. Copying to clipboard may have failed.", {
type: "warn"
}
);
}
});