add: code hide button

This commit is contained in:
moris 2024-12-08 00:15:11 +09:00
parent 43c3eb92e0
commit e5e8123d51

View File

@ -1,6 +1,8 @@
<script>
export let mdtext;
import { onMount } from "svelte";
import { remark } from 'remark'
import remarkgfm from 'remark-gfm'
import remarkBreaks from "remark-breaks"
@ -28,6 +30,27 @@
.use(rehypeStringify, {allowDangerousHtml: true})
.processSync(mdtext)
onMount(()=>{
let toggleHide = function(e){
let iframes = document.getElementsByTagName('iframe')
for ( let i = 0; i < iframes.length; i++ ){
try{
console.log(iframes[i].contentWindow.name)
if (e.origin === window.origin && iframes[i].contentWindow.name == e.data.id){
iframes[i].classList.toggle('hide')
}
}catch(e){
console.log(e)
}
}
}
window.addEventListener('message', toggleHide)
return ()=>{window.removeEventListener('message', toggleHide)}
})
</script>
<div class='markdown'>