Created
April 20, 2019 17:23
-
-
Save yuta0801/269e3698219bef89c8ae22cea34f799d to your computer and use it in GitHub Desktop.
e-typingのお題をクリップボードにコピーするコード
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
const cp = copy | |
const observe = (target, callback) => { | |
const observer = new MutationObserver(records => { | |
records.forEach(record => { | |
if (!record.addedNodes[0]) return | |
callback(record, () => observer.disconnect()) | |
}) | |
}) | |
observer.observe(target, { childList: true }) | |
} | |
observe(document.getElementById('example_container'), (record, disconnect) => { | |
if (record.addedNodes[0].id !== 'kanaText') return | |
disconnect() | |
const el = record.addedNodes[0].children[0] | |
cp(el.children[1].textContent) | |
observe(el, record => { | |
if (record.addedNodes[0].classList.length) return | |
cp(record.addedNodes[0].textContent) | |
}) | |
}) | |
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
const cp=copy,observe=(e,d)=>{const t=new MutationObserver(e=>{e.forEach(e=>{e.addedNodes[0]&&d(e,()=>t.disconnect())})});t.observe(e,{childList:!0})};observe(document.getElementById("example_container"),(e,d)=>{if("kanaText"!==e.addedNodes[0].id)return;d();const t=e.addedNodes[0].children[0];cp(t.children[1].textContent),observe(t,e=>{e.addedNodes[0].classList.length||cp(e.addedNodes[0].textContent)})}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment