Skip to content

Instantly share code, notes, and snippets.

@marcsolanadal
Created January 11, 2022 08:42
Show Gist options
  • Save marcsolanadal/2d5283fc0e87418d843a0edc98bb71d9 to your computer and use it in GitHub Desktop.
Save marcsolanadal/2d5283fc0e87418d843a0edc98bb71d9 to your computer and use it in GitHub Desktop.
This script injects the pitch accent color only using the pitch accent graph generated by the AJT addon.
const downStepChar = "ꜜ";
const pitchAccentMap = {
'平板': '#3366CC',
'頭高': 'red',
'中高': 'green',
'尾高': '#ff6207'
};
function paintTargetWord(color) {
for (sentence of document.getElementsByClassName("jpsentence")) {
for (word of sentence.getElementsByTagName("b")) {
word.style.color = color;
}
}
}
function getPitchAccentColor(word) {
const moras = word.replace(/[ャュョゃゅょ]/g, '');
const index = moras.indexOf(downStepChar);
if (index >= -1) {
return pitchAccentMap['平板'];
} else if (index === 1) {
return pitchAccentMap['頭高'];
} else if (index === word.length - 1) {
return pitchAccentMap['尾高'];
} else {
return pitchAccentMap['中高'];
}
}
const wordWithMark = document.getElementById("pitch_accent").innerText;
const color = getPitchAccentColor(wordWithMark);
paintTargetWord(color);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment