-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.tsx
87 lines (77 loc) · 2.22 KB
/
index.tsx
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
import definePlugin, { OptionType } from "@utils/types";
import { definePluginSettings } from "@api/Settings";
let settings = definePluginSettings({
font: {
type: OptionType.SELECT,
description: "Which font to use for Manchu text",
options: [
{
label: "Default system font",
value: "default",
default: true,
},
{
label: "Noto Sans Mongolian",
value: "noto",
},
],
onChange: () => updateStyles()
},
size: {
type: OptionType.SLIDER,
description: "Font size in pt",
markers: [14, 16, 18, 20, 24, 32, 40],
default: 16,
stickToMarkers: true,
onChange: () => updateStyles()
}
});
let styles: HTMLStyleElement;
const updateStyles = () => {
const size = Vencord.Settings.plugins.ManchuRenderer.size;
const font = Vencord.Settings.plugins.ManchuRenderer.font === "noto" ? "@import url('https://fonts.googleapis.com/css2?family=Noto+Sans+Mongolian&display=swap');" : "";
styles.textContent = `
${font}
div:lang(mnc) {
font-family: "Noto Sans Mongolian";
writing-mode: vertical-lr;
font-size: ${size}pt;
}`
};
function isManchu(s: string) {
return s.match(/^((\p{Script=Mongolian}|\W)+)$/gu);
}
export default definePlugin({
name: "ManchuRenderer",
authors: [{
id: 328701311736479755n,
name: "azazo",
}],
description: "Renders Manchu text vertically.",
settings,
patches: [
{
find: ".VOICE_HANGOUT_INVITE?",
replacement: {
match: /(contentRef:\i}=(\i).+?)\(0,(.+]}\)]}\))/,
replace: "$1 $self.modify($2, (0, $3)"
}
}
],
modify(e, c) {
if (isManchu(e.message.content)) {
// console.log(e.message.content);
// console.log(c.props.children);
return <div lang="mnc">{c}</div>
} else {
return c;
}
},
start: () => {
styles = document.createElement("style");
styles.id = "ManchuText";
document.head.appendChild(styles);
updateStyles();
},
stop: () => styles.remove()
});