blob: 8081428fe4c2b26ef82980647f1ac35785e88042 (
plain)
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
|
// Get the routeprefix by finding the '/' after the ID
let url = window.location.pathname
let end = url.indexOf("/", "/server/".length +1)
let routePrefix = url.substring(0, end)
console.log("routePrefix:", routePrefix)
let dels:NodeListOf<HTMLFormElement> = document.querySelectorAll("form[action=\"/idea/delete/\"]");
for (let el of dels) {
el.onsubmit = function(e) {
e.preventDefault();
if (confirm("are you sure?") === true) {
el.submit();
}
};
}
let eels:NodeListOf<HTMLButtonElement> = document.querySelectorAll("button.edit");
for (let el of eels) {
el.onclick = function() {
let id = el.getAttribute("idea-id");
location.href = routePrefix + "/idea/edit?id=" + id;
}
}
let link = document.getElementById("link");
if (link !== null) {
link.addEventListener("click", function() {
navigator.clipboard.writeText(window.location.href)
let old_text: string;
if (link !== null) {
old_text = link.innerHTML;
link.innerHTML = "(copied)";
link.classList.remove("copied");
}
setTimeout(function() {
if (link !== null) {
link.innerHTML = old_text;
link.classList.add("copied");
}
}, 1000);
});
}
|