2
2
const tex = ref (' ' );
3
3
const message = ref <null | { content: string , type: ' success' | ' error' }>(null );
4
4
5
- function onMigrate() {
5
+ function migrate() {
6
+ // 1. Migrate the TeX
6
7
try {
7
8
const migrated = safeMigrateTex (tex .value );
8
9
if (migrated === tex .value ) {
@@ -13,16 +14,40 @@ function onMigrate() {
13
14
message .value = { content: ' Migrated successfully' , type: ' success' };
14
15
} catch (error : any ) {
15
16
message .value = { content: error ?.message ?? ' Unknown error' , type: ' error' };
17
+ return ;
18
+ }
19
+
20
+ // 2. Copy the migrated TeX to the clipboard
21
+ try {
22
+ navigator .clipboard .writeText (tex .value );
23
+ } catch (error : any ) {
24
+ message .value = { content: error ?.message ?? ' Unknown error when copying to clipboard' , type: ' error' };
25
+ return ;
26
+ }
27
+
28
+ // 3. Notify the parent window
29
+ if (window .parent !== window ) {
30
+ window .parent .postMessage ({ type: ' migrated' , tex: tex .value }, ' *' );
16
31
}
17
32
}
33
+
34
+ // On mount, get the hash from the URL and set it to the textarea
35
+ onMounted (() => {
36
+ const hash = window .location .hash .slice (1 );
37
+ if (hash ) {
38
+ tex .value = decodeURIComponent (hash );
39
+ migrate ();
40
+ }
41
+ });
42
+
18
43
</script >
19
44
20
45
<template >
21
46
<div class =" container" >
22
47
<textarea v-model =" tex" ></textarea >
23
48
<p v-if =" message" :class =" 'message message-' + message.type" >{{ message.content }}</p >
24
49
<div class =" actions" >
25
- <button @click =" onMigrate " >Migrate TeX</button >
50
+ <button @click =" migrate " >Migrate TeX</button >
26
51
</div >
27
52
</div >
28
53
</template >
@@ -89,4 +114,4 @@ button {
89
114
background-color : #f5f5f5 ;
90
115
cursor : pointer ;
91
116
}
92
- </style >
117
+ </style >
0 commit comments