Jump to content

User:Masssly/copy-DagChar.js

From Meta, a Wikimedia project coordination wiki

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.
// This script enables you to copy and paste Dagbani language special characters and digraphs: ɛ, ɣ, ŋ, ɔ, ʒ and ch, gb, kp, ŋm, sh ny.
// To enable this script, add it to your global.js page.
// To fork this tool for your language, simply change the characters in the chars array.
// Code inspired by [[User:Abbe98/copy-qid.js]]

const chars = ['ɛ', 'ɣ', 'ŋ', 'ɔ', 'ʒ', 'ch', 'gb', 'kp', 'ŋm', 'sh', 'ny'];

mw.loader.using(['oojs-ui-core']).done(() => {
    const container = $('<div id="dag-char-buttons" style="position:fixed;right:10px;bottom:10px;z-index:1000;"></div>').appendTo('body');
    chars.forEach(c => {
        const copy = () => navigator.clipboard.writeText(c).then(
            () => $('<div>', { class: 'copy-popup', text: 'Copied!', css: { position: 'fixed', bottom: '20px', right: '10px', width: 80 } }).appendTo('body').fadeIn(1000).fadeOut(1000, () => $(this).remove()),
            () => $('<div>', { class: 'copy-popup', text: 'Copy failed', css: { position: 'fixed', bottom: '20px', right: '10px', width: 80 } }).appendTo('body').fadeIn(1000).fadeOut(1000, () => $(this).remove())
        );
        const button = $('<button>', { class: 'oo-ui-buttonElement oo-ui-widget oo-ui-widget-enabled oo-ui-buttonWidget oo-ui-buttonWidget-framed', text: `Copy ${c}` }).appendTo(container).click(copy);
    });
});