MediaWiki:Common.js

From Ragnarok Plus Wiki
Revision as of 07:31, 26 September 2025 by Admin (talk | contribs) (Created page with "Any JavaScript here will be loaded for all users on every page load.: // Function to copy text to clipboard function copyToClipboard(text) { if (navigator.clipboard && navigator.clipboard.writeText) { // Use modern clipboard API navigator.clipboard.writeText(text).then( () => mw.notify("Copied: " + text), // notification on success (err) => mw.notify("Copy failed: " + err) // notification on error ); } e...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

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.
/* Any JavaScript here will be loaded for all users on every page load. */

// Function to copy text to clipboard
function copyToClipboard(text) {
    if (navigator.clipboard && navigator.clipboard.writeText) {
        // Use modern clipboard API
        navigator.clipboard.writeText(text).then(
            () => mw.notify("Copied: " + text),       // notification on success
            (err) => mw.notify("Copy failed: " + err) // notification on error
        );
    } else {
        // Fallback for older browsers
        const textarea = document.createElement("textarea");
        textarea.value = text;
        document.body.appendChild(textarea);
        textarea.select();
        document.execCommand("copy");
        document.body.removeChild(textarea);
        mw.notify("Copied: " + text);
    }
}

// Click event handler for elements with class .copyword
$(document).on("click", ".copyword", function () {
    // Copy data-copy attribute if exists, otherwise copy visible text
    const text = $(this).data("copy") || $(this).text();
    copyToClipboard(text);
});