make the warning dialog a <dialog>

This commit is contained in:
rhiannon morris 2024-08-05 23:36:30 +02:00
parent 5e64e9ea1b
commit 43af72aa4d
3 changed files with 97 additions and 122 deletions

View file

@ -1,21 +1,17 @@
const nsfwOk = 'nsfw-ok';
function dismiss() {
const dialog = document.getElementById('nsfw-dialog')!;
dialog.parentElement!.removeChild(dialog);
}
const dialog = document.getElementById('nsfw-dialog')! as HTMLDialogElement;
function yes() {
localStorage.setItem(nsfwOk, '1');
dismiss();
dialog.close();
}
function setup() {
if (localStorage.getItem(nsfwOk)) {
dismiss();
} else {
document.getElementById('nsfw-yes')!.onclick = yes;
if (!localStorage.getItem(nsfwOk)) {
(dialog.querySelector('#nsfw-yes') as HTMLElement).onclick = yes;
// nsfw-no is a normal link
dialog.showModal();
}
}