-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.vue
117 lines (103 loc) · 2.33 KB
/
app.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
<script setup lang="ts">
const tex = ref('');
const message = ref<null | { content: string, type: 'success' | 'error' }>(null);
function migrate() {
// 1. Migrate the TeX
try {
const migrated = safeMigrateTex(tex.value);
if (migrated !== tex.value) {
tex.value = migrated;
message.value = { content: 'Migrated successfully', type: 'success' };
} else {
message.value = { content: 'No need to migrate', type: 'success' };
}
} catch (error: any) {
message.value = { content: error?.message ?? 'Unknown error', type: 'error' };
return;
}
// 2. Copy the migrated TeX to the clipboard
try {
navigator.clipboard.writeText(tex.value);
} catch (error: any) {
message.value = { content: error?.message ?? 'Unknown error when copying to clipboard', type: 'error' };
return;
}
// 3. Notify the parent window
if (window.parent !== window) {
window.parent.postMessage({ type: 'migrated', tex: tex.value }, '*');
}
}
// On mount, get the hash from the URL and set it to the textarea
onMounted(() => {
const hash = window.location.hash.slice(1);
if (hash) {
tex.value = decodeURIComponent(hash);
migrate();
}
});
</script>
<template>
<div class="container">
<textarea v-model="tex"></textarea>
<p v-if="message" :class="'message message-' + message.type">{{ message.content }}</p>
<div class="actions">
<button @click="migrate">Migrate TeX</button>
</div>
</div>
</template>
<style>
body {
padding: 0;
margin: 0;
width: 100vw;
height: 100vh;
}
body > div {
width: 100%;
height: 100%;
}
</style>
<style scoped>
.container {
width: 100%;
height: 100%;
display: flex;
flex-direction: column;
}
textarea {
flex-grow: 1;
font-size: 20px;
padding: 20px;
font-family: 'Monospace', monospace;
box-sizing: border-box;
border: none;
outline: none;
resize: none;
background-color: #f5f5f5;
}
.message {
text-align: center;
font-family: 'Monospace', monospace;
}
.message .message-success {
color: #4caf50;
}
.message .message-error {
color: #f44336;
}
.actions {
display: flex;
justify-content: center;
}
button {
margin: 10px;
padding: 10px;
font-size: 20px;
font-family: 'Noto Sans JP', sans-serif;
border: none;
outline: none;
border-radius: 5px;
background-color: #f5f5f5;
cursor: pointer;
}
</style>