generated from TCOTC/siyuan-ttf-HarmonyOS_Sans_SC-and-Twemoji
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
50 lines (42 loc) · 1.82 KB
/
index.js
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
// module.exports = class PluginLXGWTwemoji extends require('siyuan').Plugin {};
module.exports = class PluginLXGWTwemoji extends require('siyuan').Plugin {
onload() {
console.log("siyuan-ttf-LXGWWenKaiGB-and-Twemoji: loaded");
// 创建 style 元素
const styleElement = document.createElement('style');
styleElement.id = 'snippetCSS-LXGWTwemoji'; // id 以 snippet 开头的 style 会被添加到导出 PDF 中 https://github.com/siyuan-note/siyuan/commit/4318aa446369eaf4ea85982ba4919b5d47340552
// 插入到 head 中
document.head.appendChild(styleElement);
// 获取 CSS 文件内容
fetch('../plugins/siyuan-ttf-LXGWWenKaiGB-and-Twemoji/style.css')
.then(response => {
if (!response.ok) {
throw new Error('siyuan-ttf-LXGWWenKaiGB-and-Twemoji: Failed to load CSS file');
}
return response.text();
})
.then(cssText => {
// 将 CSS 文本插入到 style 元素中
styleElement.textContent = cssText;
})
.catch(error => {
console.error('siyuan-ttf-LXGWWenKaiGB-and-Twemoji: Error loading CSS:', error);
});
}
onunload() {
// 移除 style 元素
const styleElement = document.getElementById('snippetCSS-LXGWTwemoji');
if (styleElement) {
styleElement.remove();
}
console.log("siyuan-ttf-LXGWWenKaiGB-and-Twemoji: unloaded");
}
uninstall() {
// 在卸载时也移除 style 元素
const styleElement = document.getElementById('snippetCSS-LXGWTwemoji');
if (styleElement) {
styleElement.remove();
}
console.log("siyuan-ttf-LXGWWenKaiGB-and-Twemoji: uninstall");
}
}