-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathredirect.js
36 lines (26 loc) · 1.38 KB
/
redirect.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
var redirectButton = document.createElement('button');
redirectButton.id = "redirect-button";
redirectButton.innerHTML = "Configure on dmu.events";
redirectButton.className = "btn btn-primary btn-redirect";
var eventDropdown = document.getElementsByName("form[args][lgl_event_id]")[0];
redirectButton.addEventListener("click", function () {
// Get the URL that contains the form ID
const dataUrl = eventDropdown.getAttribute("data-url");
// Extract the form ID from the URL
const formId = dataUrl.slice(dataUrl.indexOf("forms/") + 6, dataUrl.indexOf("/update"));
// Base for the redirect URL
const redirectBase = "https://dmu.events/portal";
// Event name is extracted from the dropdown selected option's text
const eventName = eventDropdown.options[eventDropdown.selectedIndex].text;
// Final URL to redirect to
const finalUrl = `${redirectBase}?link=https://secure.lglforms.com/form_engine/s/${formId}&name=${eventName}`;
// Redirect to final URL
location.href = finalUrl;
});
// Text underneath the dropdown
var textAfterDropdown = document.getElementsByClassName("lgld-input-sublabel")[0];
// Inserting the button after the explanatory text under the dropdown
insertAfter(redirectButton, textAfterDropdown);
function insertAfter(newNode, referenceNode) {
referenceNode.parentNode.insertBefore(newNode, referenceNode.nextSibling);
}