Jump to content

User:ClaudineChionh/Scripts/scriptSandbox.js

From Wikipedia, the free encyclopedia
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
// copyPageToClipboard
// Copy the page content to the system clipboard.

function copyPageToClipboard() {
    try {
        var textbox = $("#wpTextbox1").val();
        navigator.clipboard.writeText(textbox).then(function () {
            console.log("Copied content to system clipboard");
        });
    } catch (error) {
        console.log(error);
    }
}

$(document).ready(function () {
    // Add the portlet link to copy to clipboard.
    if ($("#wpTextbox1").val() != undefined) {
        var copyLink = mw.util.addPortletLink("p-cactions", "#", "Copy page", "ca-copypage", "Copy page to clipboard");
        $(copyLink).click(function (event) {
            copyPageToClipboard();
        })
    }
});