Created
July 9, 2023 10:26
-
-
Save hogashi/0baac922b1dce89246d10c4bacb5a5cb to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// ==UserScript== | |
// @name misskey-nya2na | |
// @namespace misskey-nya2na | |
// @version 0.1 | |
// @description replace misskey notes にゃ to ruby-ed な(にゃ) | |
// @author hogashi | |
// @match https://misskey.io/ | |
// @grant none | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
const onLoad = () => { | |
const targetNode = document.querySelector('[data-sticky-container-header-height] div:has(> div > article)'); | |
const onMutate = () => { | |
targetNode.querySelectorAll('article span:not(:has(.nya2na))').forEach(span => { | |
span.innerHTML = span.innerHTML.replace(/にゃ/g, '<ruby class="nya2na">な<rp>(</rp><rt>にゃ</rt><rp>)</rp></ruby>'); | |
}); | |
}; | |
const observer = new MutationObserver(onMutate); | |
// Start observing the target node for configured mutations | |
observer.observe(targetNode, { childList: true }); | |
onMutate(); | |
}; | |
window.addEventListener('load', () => { | |
console.log('nya2na: window loaded'); | |
setTimeout(() => { | |
console.log('nya2na: onLoad'); | |
onLoad(); | |
}, 5000); | |
}); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment