Yiɣi chaŋ yɛligu maŋamaŋa puuni

Ŋun su:Masssly/copy-DagChar.js

Diyila Dagbani Wikipedia

A yi zaŋ pa pɔhim zuɣu naai shee a bypaasi a browser tobu neema maa n nya raɣibu nima.

// 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, put the following line on your common.js User subpage: importScript('User:Masssly/copy-DagChar.js');
// 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 = [
  { text: 'ɛ', capitalizedText: 'Ɛ' },
  { text: 'ɣ', capitalizedText: 'Ɣ' },
  { text: 'ŋ', capitalizedText: 'Ŋ' },
  { text: 'ɔ', capitalizedText: 'Ɔ' },
  { text: 'ʒ', capitalizedText: 'Ʒ' },
  { text: 'ch', capitalizedText: 'Ch' },
  { text: 'gb', capitalizedText: 'Gb' },
  { text: 'kp', capitalizedText: 'Kp' },
  { text: 'ŋm', capitalizedText: 'Ŋm' },
  { text: 'sh', capitalizedText: 'Sh' },
  { text: 'ny', capitalizedText: 'Ny' },
];

let isCapitalized = false;

mw.loader.using('oojs-ui-core').done(() => {
  const container = $('<div>').attr('id', 'dag-char-buttons').css({
    position: 'fixed',
    right: '10px',
    bottom: '10px',
    zIndex: '1000'
  }).appendTo('.mw-indicators');

  const capsButton = $('<button>').addClass('oo-ui-buttonElement oo-ui-widget oo-ui-widget-enabled oo-ui-buttonWidget oo-ui-buttonWidget-framed').appendTo(container);

  updateCapsButtonText();

  capsButton.click(() => {
    isCapitalized = !isCapitalized;
    updateCapsButtonText();
    chars.forEach((char, index) => $(`#dag-char-button-${index}`).text(isCapitalized ? char.capitalizedText : char.text));
  });

  chars.forEach((char, index) => {
    $('<button>').attr('id', `dag-char-button-${index}`).addClass('oo-ui-buttonElement oo-ui-widget oo-ui-widget-enabled oo-ui-buttonWidget oo-ui-buttonWidget-framed').text(char.text).click(() => {
      navigator.clipboard.writeText(isCapitalized ? char.capitalizedText : char.text).then(
        () => {
          const popup = $('<div>').addClass('copy-popup').text('Copied!').css({
            width: '80px',
            position: 'fixed',
            bottom: '10px',
            right: '10px',
            textAlign: 'center',
            backgroundColor: 'rgba(0, 0, 0, 0.7)',
            color: '#fff',
            padding: '10px',
            borderRadius: '5px',
            zIndex: '1001'
          }).appendTo('body');
          popup.fadeIn(1000).fadeOut(1000, () => popup.remove());
        },
        () => {
          const popup = $('<div>').addClass('copy-popup').text('Copy failed').css({
            width: '80px',
            position: 'fixed',
            bottom: '10px',
            right: '10px',
            textAlign: 'center',
            backgroundColor: 'rgba(0, 0, 0, 0.7)',
            color: '#fff',
            padding: '10px',
            borderRadius: '5px',
            zIndex: '1001'
          }).appendTo('body');
          popup.fadeIn(1000).fadeOut(1000, () => popup.remove());
        }
      );
    }).appendTo(container);
  });

  function updateCapsButtonText() {
    capsButton.text(`Caps: ${isCapitalized ? 'On' : 'Off'}`);
  }
});