Last active
May 17, 2020 11:32
-
-
Save nacika-ins/580b2d2508a4cee6a1a1c6f0e1b54174 to your computer and use it in GitHub Desktop.
マストドン音声読み上げ v3対応 (MITライセンス)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function () { | |
const synth = window.speechSynthesis; | |
const home = document.querySelector('.item-list[role="feed"]') | |
const observer = new MutationObserver(function(mutations) { | |
mutations.forEach(function(mutation) { | |
const name = (mutation.addedNodes[0].querySelector(".display-name strong").textContent || "") | |
.replace(/@/g, "アットマーク") | |
; | |
const text = (mutation.addedNodes[0].querySelector("p").textContent || "") | |
.replace(/https?:\/\/[\w/:%#\$&\?\(\)~\.=\+\-]+/g, "") | |
.replace(/@/g, "アットマーク") | |
.replace(/([^a-z^A-Z])ltl([^a-z^A-Z]?)/ig, "$1。ローカルタイムライン。$2") | |
.replace(/([^a-z^A-Z])ftl([^a-z^A-Z]?)/ig, "$1。連合タイムライン。$2") | |
.replace(/([^a-z^A-Z])pawoo([^a-z^A-Z]?)/ig, "$1。ぱうー。$2") | |
.replace(/ /g, "。。。") | |
.replace(/ww.+/g, "。だいぞうきば。") | |
.replace(/ww/g, "。きば生える。") | |
.replace(/([^a-z^A-Z])w([^a-z^A-Z]?)/g, "$1。きば。$2") | |
.replace(/ww.+/g, "。だいぞうきば。") | |
.replace(/ww/g, "。きば生える。") | |
.replace(/([^a-z^A-Z])w([^a-z^A-Z]?)/g, "$1。きば。$2") | |
.replace(/jj.+/g, "。だいぞうきば。") | |
.replace(/jj/g, "。きば生える。") | |
.replace(/([^a-z^A-Z])j([^a-z^A-Z]?)/g, "$1。きば。$2") | |
.replace(/jj.+/g, "。だいぞうきば。") | |
.replace(/jj/g, "。きば生える。") | |
.replace(/([^a-z^A-Z])j([^a-z^A-Z]?)/g, "$1。きば。$2") | |
.replace(/([^a-z^A-Z])JK([^a-z^A-Z]?)/g, "$1。常識に考えて。$2") | |
.replace(/→/g, "は、") | |
; | |
const output = name+"。。。"+text; | |
console.log(output); | |
const ssu = new SpeechSynthesisUtterance(output); | |
ssu.rate = 1.2; | |
ssu.lang = "ja-JP"; | |
const voices = synth.getVoices().filter( voice => voice.lang == "ja-JP" ); | |
const voiceNumber = Math.round(Math.random() * voices.length); | |
ssu.voice = voices[voiceNumber]; | |
synth.speak(ssu); | |
}); | |
}); | |
const config = { attributes: true, childList: true, characterData: true }; | |
observer.observe(home, config); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
http://closure-compiler.appspot.com/home