jointrashposs/components/g/AiChan.vue

59 lines
1.4 KiB
Vue
Raw Normal View History

2023-07-12 15:50:26 +02:00
<template>
<iframe v-if="isEnabledAiChanMode" @load="initAiChan()" ref="live2d" src="https://misskey-dev.github.io/mascot-web/?scale=2&y=1.4"></iframe>
</template>
<script setup lang="ts">
const live2d = ref<HTMLIFrameElement>();
const isEnabledAiChanMode = ref<boolean>(false);
if (process.client) {
isEnabledAiChanMode.value = ((localStorage.getItem('miHub_aichan_mode') ?? '') == 'true');
// migration
2023-12-22 12:07:58 +01:00
if (!localStorage.getItem('miHub_aichan_mode')) {
2023-07-12 15:50:26 +02:00
isEnabledAiChanMode.value = ((localStorage.getItem('aimode') ?? '') == 'true');
}
}
function initAiChan() {
2023-11-12 08:13:10 +01:00
if (!live2d.value) return;
2023-07-12 15:50:26 +02:00
const iframeRect = live2d.value.getBoundingClientRect();
window.addEventListener('mousemove', ev => {
2023-11-12 08:13:10 +01:00
if (!live2d.value) return;
live2d.value.contentWindow?.postMessage({
2023-07-12 15:50:26 +02:00
type: 'moveCursor',
body: {
x: ev.clientX - iframeRect.left,
y: ev.clientY - iframeRect.top,
},
}, '*');
}, { passive: true });
window.addEventListener('touchmove', ev => {
2023-11-12 08:13:10 +01:00
if (!live2d.value) return;
live2d.value.contentWindow?.postMessage({
2023-07-12 15:50:26 +02:00
type: 'moveCursor',
body: {
x: ev.touches[0].clientX - iframeRect.left,
y: ev.touches[0].clientY - iframeRect.top,
},
}, '*');
}, { passive: true });
}
</script>
<style scoped>
iframe {
position: fixed;
bottom: 0;
right: 0;
width: 300px;
height: 600px;
border: none;
pointer-events: none;
background: transparent;
color-scheme: light dark;
2023-07-12 15:50:26 +02:00
}
</style>