-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmatrix-link-to-useful-text.html
87 lines (74 loc) · 1.94 KB
/
matrix-link-to-useful-text.html
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
<!DOCTYPE html>
<html>
<head>
<title>Matrix Link to Useful Text</title>
<style>
input,
textarea,
button {
width: 700px;
font-size: 1.5em;
}
textarea {
height: 150px;
}
#error-text {
color: red;
}
</style>
</head>
<body>
<p>
<input id="permalink-input" type="text" placeholder="enter your matrix.to permalink here" />
</p>
<p id="error-text">
</p>
<p>
<textarea id="useful-text" onclick="this.select()" readonly></textarea>
</p>
<p>
<button id="copy-button" disabled>Copy</button>
</p>
<p>
<a href="https://github.com/sumnerevans/nevarro.space">Source Code</a>
</p>
<script>
const permalinkInput = document.getElementById("permalink-input");
const errorText = document.getElementById("error-text");
const usefulText = document.getElementById("useful-text");
const copyButton = document.getElementById("copy-button");
const getInfo = (permalink) => {
const match = permalink.match(/^https?:\/\/matrix.to\/#\/(!.*)\/(\$.*?)(?:\?.*)?$/);
if (!match) return null;
return {
roomID: match[1],
eventID: match[2],
};
};
const copy = () => {
usefulText.select();
document.execCommand("copy");
};
const updateInfo = () => {
const info = getInfo(permalinkInput.value);
if (info) {
errorText.innerHTML = "";
usefulText.innerHTML = `Room ID: ${info.roomID}\nEvent ID: ${info.eventID}`;
copyButton.disabled = false;
} else {
errorText.innerHTML = "Invalid matrix.to link";
copyButton.disabled = true;
}
return info != null;
};
permalinkInput.addEventListener("input", updateInfo);
permalinkInput.addEventListener("keyup", (e) => {
if (e.key === "Enter" || e.keyCode === 13) {
copy();
}
});
copyButton.addEventListener("click", copy);
permalinkInput.focus();
</script>
</body>
</html>