CSP and other stuff

This commit is contained in:
CenTdemeern1 2025-02-03 01:01:53 +01:00
parent c7ea3326cb
commit cc15a4b29f
3 changed files with 21 additions and 23 deletions

View file

@ -6,13 +6,11 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>FeDirect</title> <title>FeDirect</title>
<link rel="stylesheet" href="/static/main.css"> <link rel="stylesheet" href="/static/main.css">
<meta http-equiv="Content-Security-Policy" content="default-src 'self'; img-src *;">
</head> </head>
<body> <body>
<script type="module"> <script type="module" src="/static/crossroad.mjs"></script>
Object.assign(globalThis, await import("/static/crossroad.mjs"));
getMainDialog().show(); // Don't show until the page is ready
</script>
<div class="flex-vcenter"> <div class="flex-vcenter">
<dialog id="mainDialog" class="half-width half-height"> <dialog id="mainDialog" class="half-width half-height">
<header class="separator-bottom margin-large-bottom"> <header class="separator-bottom margin-large-bottom">
@ -31,7 +29,7 @@
<p id="no-instance">You currently don't have any instances. You should add one!</p> <p id="no-instance">You currently don't have any instances. You should add one!</p>
<form id="instanceSelectForm" class="align-start wfit-content"></form> <form id="instanceSelectForm" class="align-start wfit-content"></form>
<br> <br>
<button onclick="showAddInstanceDialog()">Add an instance</button> <button id="showAddInstanceDialog">Add an instance</button>
</center> </center>
</div> </div>
<div class="half-width align-self-start"> <div class="half-width align-self-start">

View file

@ -5,11 +5,16 @@ import storageManager from "./storage_manager.mjs";
const radioButtonName = "instanceSelect"; const radioButtonName = "instanceSelect";
const mainDialog = findDialogOrFail(document.body, "#mainDialog");
const showAddInstanceDialogButton = findButtonOrFail(document.body, "#showAddInstanceDialog");
const detailsDialog = findDialogOrFail(document.body, "#instanceDetails"); const detailsDialog = findDialogOrFail(document.body, "#instanceDetails");
const addDialog = findDialogOrFail(document.body, "#addInstance"); const addDialog = findDialogOrFail(document.body, "#addInstance");
const instanceSelectForm = findFormOrFail(document.body, "#instanceSelectForm"); const instanceSelectForm = findFormOrFail(document.body, "#instanceSelectForm");
const redirectButton = findButtonOrFail(document.body, "#redirect"); const redirectButton = findButtonOrFail(document.body, "#redirect");
const redirectAlwaysButton = findButtonOrFail(document.body, "#redirectAlways"); const redirectAlwaysButton = findButtonOrFail(document.body, "#redirectAlways");
const pathText = findPreOrFail(document.body, "#path");
showAddInstanceDialogButton.addEventListener("click", e => showAddInstanceDialog());
redirectButton.addEventListener("click", e => { redirectButton.addEventListener("click", e => {
// Can be assumed to not fail because the button is disabled if there are no options and the first one is selected by default // Can be assumed to not fail because the button is disabled if there are no options and the first one is selected by default
@ -23,29 +28,25 @@ redirectAlwaysButton.addEventListener("click", e => {
redirect(option); redirect(option);
}); });
export const getMainDialog = () => findDialogOrFail(document.body, "#mainDialog"); let showAddInstanceDialog = () => { };
let hideAddInstanceDialog = () => { };
export const {
showAddInstanceDialog,
hideAddInstanceDialog
} = ((): {
showAddInstanceDialog: () => void,
hideAddInstanceDialog: () => void
} => {
// Don't bother initializing if we're performing autoredirect // Don't bother initializing if we're performing autoredirect
if (autoRedirect()) return { if (!autoRedirect()) {
showAddInstanceDialog: () => { },
hideAddInstanceDialog: () => { }
}
createInstanceSelectOptions(); createInstanceSelectOptions();
storageManager.addSaveCallback(createInstanceSelectOptions); storageManager.addSaveCallback(createInstanceSelectOptions);
updateNoInstanceHint(); updateNoInstanceHint();
storageManager.addSaveCallback(updateNoInstanceHint); storageManager.addSaveCallback(updateNoInstanceHint);
findPreOrFail(document.body, "#path").innerText = getTargetPath(); pathText.innerText = getTargetPath();
return initializeAddInstanceFlow(detailsDialog, addDialog); ({
})(); showAddInstanceDialog,
hideAddInstanceDialog
} = initializeAddInstanceFlow(detailsDialog, addDialog));
mainDialog.show();
};
function updateNoInstanceHint() { function updateNoInstanceHint() {
findParagraphOrFail(document.body, "#no-instance").style.display = findParagraphOrFail(document.body, "#no-instance").style.display =
@ -140,5 +141,3 @@ function redirect(to: string) {
url.pathname = getTargetPath(); url.pathname = getTargetPath();
location.href = url.toString(); location.href = url.toString();
} }
export { storageManager };

View file

@ -11,6 +11,7 @@ html,
body { body {
background: linear-gradient(300deg, var(--red), var(--blue)); background: linear-gradient(300deg, var(--red), var(--blue));
background-size: 100vw 100vh; background-size: 100vw 100vh;
background-attachment: fixed;
margin: 0; margin: 0;
min-height: 100vh; min-height: 100vh;
height: 100vh; height: 100vh;