Made it not redirect to /migrate when not connected to the internet, made fontManipulator's buttons centered, made a 401 response log out the user from loggedin and userinfo

This commit is contained in:
Tracker-Friendly 2024-07-30 11:03:05 +01:00
parent f3d0a9c696
commit e63fa13553
2 changed files with 281 additions and 291 deletions

View File

@ -593,6 +593,7 @@ button:hover {
background-color: var(--nonimporant-theme-color); background-color: var(--nonimporant-theme-color);
color: var(--nonimportant-text-color); color: var(--nonimportant-text-color);
transition: 0.125s; transition: 0.125s;
margin-bottom: 0;
} }
.optionsDiv .fontManipulator button:hover { .optionsDiv .fontManipulator button:hover {

View File

@ -21,6 +21,7 @@ let secretkey = localStorage.getItem("DONOTSHARE-secretkey")
let password = localStorage.getItem("DONOTSHARE-password") let password = localStorage.getItem("DONOTSHARE-password")
let currentFontSize = 16 let currentFontSize = 16
let offlineMode = false
let backButton = document.getElementById("backButton") let backButton = document.getElementById("backButton")
let usernameBox = document.getElementById("usernameBox") let usernameBox = document.getElementById("usernameBox")
let optionsCoverDiv = document.getElementById("optionsCoverDiv") let optionsCoverDiv = document.getElementById("optionsCoverDiv")
@ -152,10 +153,10 @@ function handleGesture() {
} }
// Init the note box // Init the note box
document.addEventListener("DOMContentLoaded", function() { document.addEventListener("DOMContentLoaded", async function () {
pell.init({ pell.init({
element: pellAttacher, element: pellAttacher,
onChange: function(html) { onChange: function (html) {
// Having a nice day? This does nothing. // Having a nice day? This does nothing.
}, },
defaultParagraphSeparator: 'br', defaultParagraphSeparator: 'br',
@ -184,8 +185,7 @@ document.addEventListener("DOMContentLoaded", function() {
name: 'uploadimage', name: 'uploadimage',
icon: '📁', icon: '📁',
title: 'Upload image', title: 'Upload image',
result: function result() { result: async function result() {
async function doStuff() {
browseButton.classList.remove("hidden") browseButton.classList.remove("hidden")
displayError("Select an image to upload:") displayError("Select an image to upload:")
await waitForConfirm() await waitForConfirm()
@ -200,8 +200,6 @@ document.addEventListener("DOMContentLoaded", function() {
} }
} }
} }
doStuff();
}
}, },
"image", "image",
], ],
@ -292,22 +290,24 @@ document.addEventListener("DOMContentLoaded", function() {
} }
}) })
.catch(() => { .catch(() => {
offlineMode = true
noteBox.contentEditable = false noteBox.contentEditable = false
noteBox.innerHTML = "<h1>You are currently offline.</h1>" noteBox.innerHTML = "<h1>You are currently offline.</h1>"
displayError("Failed to connect to the server.\nPlease check your internet connection.") displayError("Failed to connect to the server.\nPlease check your internet connection.")
}) })
.then((response) => response) .then((response) => response)
.then((response) => { .then((response) => {
if (response.status === 400) { if (response.status === 400 || response.status === 401) {
offlineMode = true
displayError("Something went wrong! Signing you out...") displayError("Something went wrong! Signing you out...")
closeErrorButton.classList.add("hidden") closeErrorButton.classList.add("hidden")
//usernameBox.innerText = ""
setTimeout(function () { setTimeout(function () {
window.location.replace("/logout") window.location.replace("/logout")
}, 2500); }, 2500);
} else if (response.status === 200) { } else if (response.status === 200) {
updateUserInfo() updateUserInfo()
} else { } else {
offlineMode = true
noteBox.readOnly = true noteBox.readOnly = true
noteBox.innerHTML = "<h1>You are currently offline.</h1>" noteBox.innerHTML = "<h1>You are currently offline.</h1>"
displayError("Failed to connect to the server.\nPlease check your internet connection.") displayError("Failed to connect to the server.\nPlease check your internet connection.")
@ -351,9 +351,8 @@ document.addEventListener("DOMContentLoaded", function() {
"Content-Type": "application/json; charset=UTF-8" "Content-Type": "application/json; charset=UTF-8"
} }
}) })
.then((response) => { .then(async (response) => {
async function doStuff() { if (response.status === 500 || response.status === 401) {
if (response.status === 500) {
displayError("Something went wrong! Signing you out...") displayError("Something went wrong! Signing you out...")
closeErrorButton.classList.add("hidden") closeErrorButton.classList.add("hidden")
setTimeout(function () { setTimeout(function () {
@ -367,9 +366,6 @@ document.addEventListener("DOMContentLoaded", function() {
storageProgressThing.max = responseData["storagemax"] storageProgressThing.max = responseData["storagemax"]
noteCount = responseData["notecount"] noteCount = responseData["notecount"]
} }
}
doStuff()
}); });
} }
@ -427,10 +423,9 @@ document.addEventListener("DOMContentLoaded", function() {
}) })
} }
changePasswordButton.addEventListener("click", () => { changePasswordButton.addEventListener("click", async () => {
optionsDiv.classList.add("hidden") optionsDiv.classList.add("hidden")
async function doStuff() {
async function fatalError(notes, passwordBackup) { async function fatalError(notes, passwordBackup) {
displayError("Something went wrong! Your password change has failed. Attempting to revert changes...") displayError("Something went wrong! Your password change has failed. Attempting to revert changes...")
password = passwordBackup password = passwordBackup
@ -548,9 +543,6 @@ document.addEventListener("DOMContentLoaded", function() {
} }
} }
} }
}
doStuff()
}) })
importNotesButton.addEventListener("click", () => { importNotesButton.addEventListener("click", () => {
optionsDiv.classList.add("hidden") optionsDiv.classList.add("hidden")
@ -569,8 +561,7 @@ document.addEventListener("DOMContentLoaded", function() {
"Content-Type": "application/json; charset=UTF-8" "Content-Type": "application/json; charset=UTF-8"
} }
}) })
.then((response) => { .then(async (response) => {
async function doStuff() {
let responseData = await response.json() let responseData = await response.json()
document.querySelectorAll(".burgerSession").forEach((el) => el.remove()); document.querySelectorAll(".burgerSession").forEach((el) => el.remove());
let ua; let ua;
@ -626,9 +617,6 @@ document.addEventListener("DOMContentLoaded", function() {
sessionDiv.append(sessionElement) sessionDiv.append(sessionElement)
} }
}
doStuff()
}); });
}); });
exitImportThing.addEventListener("click", () => { exitImportThing.addEventListener("click", () => {
@ -668,7 +656,7 @@ document.addEventListener("DOMContentLoaded", function() {
noteBox.innerHTML = "" noteBox.innerHTML = ""
displayError("Something went wrong... Please try again later!") displayError("Something went wrong... Please try again later!")
}) })
.then((response) => { .then(async (response) => {
selectedNote = nameithink selectedNote = nameithink
if (mobile) { if (mobile) {
handleGesture() handleGesture()
@ -676,7 +664,6 @@ document.addEventListener("DOMContentLoaded", function() {
noteBox.contentEditable = true noteBox.contentEditable = true
noteBox.click() noteBox.click()
async function doStuff() {
let responseData = await response.json() let responseData = await response.json()
let htmlNote let htmlNote
@ -734,13 +721,11 @@ document.addEventListener("DOMContentLoaded", function() {
} }
}, waitTime); }, waitTime);
}); });
}
doStuff()
}); });
} }
function updateNotes() { function updateNotes() {
if (!offlineMode) {
fetch(remote + "/api/listnotes", { fetch(remote + "/api/listnotes", {
method: "POST", method: "POST",
body: JSON.stringify({ body: JSON.stringify({
@ -750,8 +735,7 @@ document.addEventListener("DOMContentLoaded", function() {
"Content-Type": "application/json; charset=UTF-8" "Content-Type": "application/json; charset=UTF-8"
} }
}) })
.then((response) => { .then(async (response) => {
async function doStuff() {
noteBox.contentEditable = false noteBox.contentEditable = false
selectedNote = 0 selectedNote = 0
noteBox.innerHTML = "" noteBox.innerHTML = ""
@ -769,8 +753,10 @@ document.addEventListener("DOMContentLoaded", function() {
try { try {
noteData["title"] = await decrypt(noteData["title"]) noteData["title"] = await decrypt(noteData["title"])
} catch (e) { } catch (e) {
if (!offlineMode) {
location.href = "/migrate" location.href = "/migrate"
} }
}
if (noteData["id"] > highestID) { if (noteData["id"] > highestID) {
highestID = noteData["id"] highestID = noteData["id"]
@ -823,13 +809,11 @@ document.addEventListener("DOMContentLoaded", function() {
selectNote(highestID) selectNote(highestID)
selectLatestNote = false selectLatestNote = false
} }
}
doStuff()
}); });
} else {
console.log("Currently offline, refusing to update notes.")
}
} }
updateNotes()
newNote.addEventListener("click", async () => { newNote.addEventListener("click", async () => {
let noteName = "New note" let noteName = "New note"
@ -882,6 +866,7 @@ document.addEventListener("DOMContentLoaded", function() {
} }
async function exportNotes() { async function exportNotes() {
if (!offlineMode) {
let exportNotesFetch = await fetch(remote + "/api/exportnotes", { let exportNotesFetch = await fetch(remote + "/api/exportnotes", {
method: "POST", method: "POST",
body: JSON.stringify({ body: JSON.stringify({
@ -903,6 +888,9 @@ document.addEventListener("DOMContentLoaded", function() {
} }
} }
return responseData return responseData
} else {
displayError("You can't export notes while offline!")
}
} }
async function importNotes(plaintextNotes) { async function importNotes(plaintextNotes) {
@ -993,6 +981,7 @@ document.addEventListener("DOMContentLoaded", function() {
displayError("What's new in Burgernotes 2.0?\nRestyled client\nAdded changing passwords\nAdded importing notes\nChange the use of CryptoJS to Native AES GCM\nUse Argon2ID for hashing rather than the SHA family\nAdded a Proof-Of-Work CAPTCHA during signup\nMade the signup and login statuses more descriptive\nFixed various bugs and issues\nAdded markdown notes\nAdded support for uploading photos\nImproved privacy policy to be clearer about what is and isn't added\nRemoved some useless uses of cookies and replaced with localStorage\nFixed the privacy policy not redirecting correctly\nAdded a list of native clients\nMade the client support LibreJS and therefore GNU Icecat") displayError("What's new in Burgernotes 2.0?\nRestyled client\nAdded changing passwords\nAdded importing notes\nChange the use of CryptoJS to Native AES GCM\nUse Argon2ID for hashing rather than the SHA family\nAdded a Proof-Of-Work CAPTCHA during signup\nMade the signup and login statuses more descriptive\nFixed various bugs and issues\nAdded markdown notes\nAdded support for uploading photos\nImproved privacy policy to be clearer about what is and isn't added\nRemoved some useless uses of cookies and replaced with localStorage\nFixed the privacy policy not redirecting correctly\nAdded a list of native clients\nMade the client support LibreJS and therefore GNU Icecat")
} }
checknetwork() await checknetwork()
updateNotes()
}) })
// @license-end // @license-end