lookyloo/website/web/static/capture.js

195 lines
8.7 KiB
JavaScript
Raw Normal View History

// scripts for the submission type
2024-05-13 09:29:48 +02:00
2024-05-13 09:45:57 +02:00
document.getElementById('nav-url-tab').addEventListener('click', function (e) {
2024-05-13 09:29:48 +02:00
// switch to tab for capture of URL(s)
// default: single capture field
document.getElementById("singleCaptureField").required = true;
document.getElementById("singleCaptureField").classList.remove("d-none");
// hide multiple captures field
document.getElementById('multipleCaptures').checked = false;
document.getElementById("multipleCapturesField").required = false;
document.getElementById("multipleCapturesField").classList.add("d-none");
document.getElementById("document").required = false;
});
2024-05-13 09:45:57 +02:00
document.getElementById('nav-doc-tab').addEventListener('click', function (e) {
2024-05-13 09:29:48 +02:00
// switch to tab for capture of document
document.getElementById("document").required = true;
document.getElementById("multipleCapturesField").required = false;
document.getElementById("singleCaptureField").required = false;
});
2024-05-13 09:45:57 +02:00
document.getElementById('multipleCaptures').addEventListener('click', function (e) {
2024-05-13 09:29:48 +02:00
// switch input-fields between multiple and single capture
if (document.getElementById('multipleCaptures').checked === true) {
// enable multiple captures
document.getElementById('singleCaptureField').value = '';
document.getElementById("singleCaptureField").classList.add("d-none");
document.getElementById("singleCaptureField").required = false;
document.getElementById("multipleCapturesField").classList.remove("d-none");
document.getElementById("multipleCapturesField").required = true;
} else {
// disable multiple captures
document.getElementById('multipleCapturesField').value = '';
document.getElementById("multipleCapturesField").classList.add("d-none");
document.getElementById("multipleCapturesField").required = false;
document.getElementById("singleCaptureField").classList.remove("d-none");
document.getElementById("singleCaptureField").required = true;
}
});
// scripts for browser configuration of the capture
2024-05-13 09:45:57 +02:00
document.getElementById("os").addEventListener("change", function () {
2024-05-13 09:29:48 +02:00
let osSelect = document.getElementById("os");
2024-05-14 09:23:09 +02:00
let os_name = osSelect.options[osSelect.selectedIndex].value.replace(/(:|\.|\[|\]|,|=|\\)/g, "\\$1").replace(/ /g, "_");
let first_browser_name = document.querySelector(`[id='${os_name}'] select option:first-child`).value.replace(/(:|\.|\[|\]|,|=|\\)/g, "\\$1").replace(/ /g, "_");
// Hide and disable everything
2024-05-13 09:45:57 +02:00
document.querySelectorAll("#os option").forEach(function (option) {
option.removeAttribute('selected');
});
2024-05-13 09:45:57 +02:00
document.querySelectorAll(".style-sub-1").forEach(function (element) {
element.style.display = 'none';
});
document.querySelectorAll(".style-sub-1 > label > span > select").forEach(function (select) {
select.disabled = true;
2024-05-13 09:45:57 +02:00
select.querySelectorAll('option').forEach(function (option) {
option.removeAttribute('selected');
});
});
2024-05-13 09:45:57 +02:00
document.querySelectorAll(".style-sub-2").forEach(function (element) {
element.style.display = 'none';
});
document.querySelectorAll(".style-sub-2 > label > span > select").forEach(function (select) {
select.disabled = true;
2024-05-13 09:45:57 +02:00
select.querySelectorAll('option').forEach(function (option) {
option.removeAttribute('selected');
});
});
// Re-enable and show what makes sense
document.querySelector(`[id='${os_name}']`).style.display = 'block';
document.querySelectorAll(`[id='${os_name}'] > label > span > select`).forEach(function (select) {
select.disabled = false;
select.querySelector('option:first-child').selected = true;
});
document.querySelector(`[id='${os_name}_${first_browser_name}']`).style.display = 'block';
document.querySelectorAll(`[id='${os_name}_${first_browser_name}'] > label > span > select`).forEach(function (select) {
select.disabled = false;
select.querySelector('option:first-child').selected = true;
});
});
document.querySelectorAll('select[name="browser"]').forEach( function(element)
{
element.addEventListener('change', function (e) {
let browser_name = element.options[element.selectedIndex].value.replace(/(:|\.|\[|\]|,|=|\\)/g, "\\$1").replace(/ /g, "_");
let osSelect = document.getElementById("os");
let os_name = osSelect.options[osSelect.selectedIndex].value.replace(/(:|\.|\[|\]|,|=|\\)/g, "\\$1").replace(/ /g, "_");
// Hide and disable every useragent
document.querySelectorAll(".style-sub-2").forEach(function (element) {
element.style.display = 'none';
});
document.querySelectorAll(".style-sub-2 > label > span > select").forEach(function (select) {
select.disabled = true;
select.querySelectorAll('option').forEach(function (option) {
option.removeAttribute('selected');
});
});
// Show only the correct user-agent
document.querySelector(`[id='${os_name}_${browser_name}']`).style.display = 'block';
document.querySelectorAll(`[id='${os_name}_${browser_name}'] > label > span > select`).forEach(function (select) {
select.disabled = false;
select.querySelector('option:first-child').selected = true;
});
});
});
2024-05-13 09:45:57 +02:00
document.getElementById('personal_ua_select').addEventListener('click', function (e) {
2024-05-13 09:29:48 +02:00
//disable select fields when personal useragent (ua) selected etc...
document.getElementById('personal_ua').disabled = false;
document.getElementById('freetext_ua').disabled = true;
disablePredefinedUA();
});
2024-05-13 09:29:48 +02:00
2024-05-13 09:45:57 +02:00
document.getElementById('predefined_ua_select').addEventListener('click', function (e) {
2024-05-13 09:29:48 +02:00
document.getElementById('os-type').value = 'desktop';
document.getElementById('os-type').dispatchEvent(new Event('change'));
document.getElementById('freetext_ua').disabled = true;
document.getElementById('personal_ua').disabled = true;
// Enable predefinded user-agent
let os_type = document.getElementById('os-type');
os_type.value = 'desktop';
os_type.dispatchEvent(new Event('change'))
});
2024-05-13 09:45:57 +02:00
document.getElementById('freetext_ua_select').addEventListener('click', function (e) {
2024-05-13 09:29:48 +02:00
// Enable freetext user-agent
document.getElementById('freetext_ua').disabled = false;
document.getElementById('personal_ua').disabled = true;
disablePredefinedUA()
2024-05-13 09:29:48 +02:00
})
2024-05-13 09:45:57 +02:00
const disablePredefinedUA = function () {
2024-05-13 09:29:48 +02:00
document.getElementById('os-type').disabled = true;
document.getElementById('device-name-mobile').disabled = true;
document.getElementById('os').disabled = true;
2024-05-13 09:45:57 +02:00
document.querySelectorAll('select[name="browser"]').forEach(function (element) {
element.disabled = true;
});
document.querySelectorAll('select[name="user_agent"]').forEach(function (element) {
element.disabled = true;
});
};
2024-05-13 09:45:57 +02:00
document.getElementById('os-type').addEventListener('change', function () {
2024-05-13 09:29:48 +02:00
document.getElementById('os-type').disabled = false;
2024-05-13 09:45:57 +02:00
if (this.value === "mobile") {
2024-05-13 09:29:48 +02:00
document.getElementById("mobiles-list").style.display = 'block';
document.getElementById('device-name-mobile').disabled = false;
2024-05-13 09:29:48 +02:00
document.getElementById("desktops-list").style.display = 'none';
document.getElementById('os').disabled = true;
2024-05-13 09:45:57 +02:00
document.querySelectorAll('select[name="browser"]').forEach(function (element) {
2024-05-13 09:29:48 +02:00
element.disabled = true;
});
2024-05-13 09:45:57 +02:00
document.querySelectorAll('select[name="user_agent"]').forEach(function (element) {
2024-05-13 09:29:48 +02:00
element.disabled = true;
});
} else { // os-type is desktop
document.getElementById("desktops-list").style.display = 'block';
document.getElementById('os').disabled = false;
2024-05-13 09:45:57 +02:00
document.querySelectorAll('select[name="browser"]:not([hidden])').forEach(function (element) {
2024-05-13 09:29:48 +02:00
element.disabled = false;
});
2024-05-13 09:45:57 +02:00
document.querySelectorAll('select[name="user_agent"]:not([hidden])').forEach(function (element) {
2024-05-13 09:29:48 +02:00
element.disabled = false;
});
document.getElementById("mobiles-list").style.display = 'none';
document.getElementById('device-name-mobile').disabled = true;
}
});
2024-05-13 09:45:57 +02:00
// admin-only report-form
let report_form = document.getElementById("auto-report");
if (report_form) { // admin is logged in
report_form.addEventListener('change', function() {
let show_form = document.getElementById("auto-report").checked;
if(show_form) {
document.getElementById("collapseMailConfiguration").style.display = "block";
} else {
document.getElementById("collapseMailConfiguration").style.display = "none";
}
});
2024-05-13 09:45:57 +02:00
}
2024-05-13 09:45:57 +02:00