IPA Pronunciation Linker

Automatically link IPA pronunciations to a tool to pronounce them

Bu betiği kurabilmeniz için Tampermonkey, Greasemonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği yüklemek için Tampermonkey gibi bir uzantı yüklemeniz gerekir.

Bu betiği kurabilmeniz için Tampermonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Userscripts gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği indirebilmeniz için ayrıca Tampermonkey gibi bir eklenti kurmanız gerekmektedir.

Bu komut dosyasını yüklemek için bir kullanıcı komut dosyası yöneticisi uzantısı yüklemeniz gerekecek.

(Zaten bir kullanıcı komut dosyası yöneticim var, kurmama izin verin!)

Bu stili yüklemek için Stylus gibi bir uzantı yüklemeniz gerekir.

Bu stili yüklemek için Stylus gibi bir uzantı kurmanız gerekir.

Bu stili yükleyebilmek için Stylus gibi bir uzantı yüklemeniz gerekir.

Bu stili yüklemek için bir kullanıcı stili yöneticisi uzantısı yüklemeniz gerekir.

Bu stili yüklemek için bir kullanıcı stili yöneticisi uzantısı kurmanız gerekir.

Bu stili yükleyebilmek için bir kullanıcı stili yöneticisi uzantısı yüklemeniz gerekir.

(Zateb bir user-style yöneticim var, yükleyeyim!)

// ==UserScript==
// @name         IPA Pronunciation Linker
// @description  Automatically link IPA pronunciations to a tool to pronounce them
// @author       Matthew Miner
// @version      1.0
// @namespace    https://matthewminer.name
// @copyright    2022, Matthew Miner (https://matthewminer.name)
// @license      MIT
// @homepageURL  https://github.com/mminer237/ipa-pronunciation-linker/
// @supportURL   https://github.com/mminer237/ipa-pronunciation-linker/issues
// @match        https://*.wiktionary.org/wiki/*
// @match        https://*.wikipedia.org/wiki/*
// @grant        none
// ==/UserScript==

(() => {
	"use strict";

	document.querySelectorAll("span.IPA").forEach(span => {
		/* Parse the IPA pronunciation */
		let text = span.textContent.match(/[\/\[](?<text>.+)[\/\]]/)?.groups.text;

		/* Select voice */
		const voice = 'Joey';

		if (text) {
			/* Replace non-standard IPA characters */
			text = text.normalize('NFD');
			text = text.replace(/a[\u0300-\u0307\u0309-\u031c\u031f-\u036f]/gu, 'a');
			text = text.replace(/e[\u0300-\u031c\u031f-\u036f]/gu, 'e');
			text = text.replace(/i[\u0300-\u031c\u031f-\u036f]/gu, 'i');
			text = text.replace(/o[\u0300-\u031c\u031f-\u036f]/gu, 'o');
			text = text.replace(/u[\u0300-\u031c\u031f-\u036f]/gu, 'u');

			/* Insert link */
			span.innerHTML = `<a href="http://ipa-reader.xyz/?text=${text}&voice=${voice}" target="_blank">${span.innerText}</a>`;
		}
	});
})();