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:
parent
f3d0a9c696
commit
e63fa13553
|
@ -593,6 +593,7 @@ button:hover {
|
|||
background-color: var(--nonimporant-theme-color);
|
||||
color: var(--nonimportant-text-color);
|
||||
transition: 0.125s;
|
||||
margin-bottom: 0;
|
||||
}
|
||||
|
||||
.optionsDiv .fontManipulator button:hover {
|
||||
|
|
|
@ -21,6 +21,7 @@ let secretkey = localStorage.getItem("DONOTSHARE-secretkey")
|
|||
let password = localStorage.getItem("DONOTSHARE-password")
|
||||
let currentFontSize = 16
|
||||
|
||||
let offlineMode = false
|
||||
let backButton = document.getElementById("backButton")
|
||||
let usernameBox = document.getElementById("usernameBox")
|
||||
let optionsCoverDiv = document.getElementById("optionsCoverDiv")
|
||||
|
@ -152,7 +153,7 @@ function handleGesture() {
|
|||
}
|
||||
|
||||
// Init the note box
|
||||
document.addEventListener("DOMContentLoaded", function() {
|
||||
document.addEventListener("DOMContentLoaded", async function () {
|
||||
pell.init({
|
||||
element: pellAttacher,
|
||||
onChange: function (html) {
|
||||
|
@ -184,8 +185,7 @@ document.addEventListener("DOMContentLoaded", function() {
|
|||
name: 'uploadimage',
|
||||
icon: '📁',
|
||||
title: 'Upload image',
|
||||
result: function result() {
|
||||
async function doStuff() {
|
||||
result: async function result() {
|
||||
browseButton.classList.remove("hidden")
|
||||
displayError("Select an image to upload:")
|
||||
await waitForConfirm()
|
||||
|
@ -200,8 +200,6 @@ document.addEventListener("DOMContentLoaded", function() {
|
|||
}
|
||||
}
|
||||
}
|
||||
doStuff();
|
||||
}
|
||||
},
|
||||
"image",
|
||||
],
|
||||
|
@ -292,22 +290,24 @@ document.addEventListener("DOMContentLoaded", function() {
|
|||
}
|
||||
})
|
||||
.catch(() => {
|
||||
offlineMode = true
|
||||
noteBox.contentEditable = false
|
||||
noteBox.innerHTML = "<h1>You are currently offline.</h1>"
|
||||
displayError("Failed to connect to the server.\nPlease check your internet connection.")
|
||||
})
|
||||
.then((response) => response)
|
||||
.then((response) => {
|
||||
if (response.status === 400) {
|
||||
if (response.status === 400 || response.status === 401) {
|
||||
offlineMode = true
|
||||
displayError("Something went wrong! Signing you out...")
|
||||
closeErrorButton.classList.add("hidden")
|
||||
//usernameBox.innerText = ""
|
||||
setTimeout(function () {
|
||||
window.location.replace("/logout")
|
||||
}, 2500);
|
||||
} else if (response.status === 200) {
|
||||
updateUserInfo()
|
||||
} else {
|
||||
offlineMode = true
|
||||
noteBox.readOnly = true
|
||||
noteBox.innerHTML = "<h1>You are currently offline.</h1>"
|
||||
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"
|
||||
}
|
||||
})
|
||||
.then((response) => {
|
||||
async function doStuff() {
|
||||
if (response.status === 500) {
|
||||
.then(async (response) => {
|
||||
if (response.status === 500 || response.status === 401) {
|
||||
displayError("Something went wrong! Signing you out...")
|
||||
closeErrorButton.classList.add("hidden")
|
||||
setTimeout(function () {
|
||||
|
@ -367,9 +366,6 @@ document.addEventListener("DOMContentLoaded", function() {
|
|||
storageProgressThing.max = responseData["storagemax"]
|
||||
noteCount = responseData["notecount"]
|
||||
}
|
||||
}
|
||||
|
||||
doStuff()
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -427,10 +423,9 @@ document.addEventListener("DOMContentLoaded", function() {
|
|||
})
|
||||
}
|
||||
|
||||
changePasswordButton.addEventListener("click", () => {
|
||||
changePasswordButton.addEventListener("click", async () => {
|
||||
optionsDiv.classList.add("hidden")
|
||||
|
||||
async function doStuff() {
|
||||
async function fatalError(notes, passwordBackup) {
|
||||
displayError("Something went wrong! Your password change has failed. Attempting to revert changes...")
|
||||
password = passwordBackup
|
||||
|
@ -548,9 +543,6 @@ document.addEventListener("DOMContentLoaded", function() {
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
doStuff()
|
||||
})
|
||||
importNotesButton.addEventListener("click", () => {
|
||||
optionsDiv.classList.add("hidden")
|
||||
|
@ -569,8 +561,7 @@ document.addEventListener("DOMContentLoaded", function() {
|
|||
"Content-Type": "application/json; charset=UTF-8"
|
||||
}
|
||||
})
|
||||
.then((response) => {
|
||||
async function doStuff() {
|
||||
.then(async (response) => {
|
||||
let responseData = await response.json()
|
||||
document.querySelectorAll(".burgerSession").forEach((el) => el.remove());
|
||||
let ua;
|
||||
|
@ -626,9 +617,6 @@ document.addEventListener("DOMContentLoaded", function() {
|
|||
|
||||
sessionDiv.append(sessionElement)
|
||||
}
|
||||
}
|
||||
|
||||
doStuff()
|
||||
});
|
||||
});
|
||||
exitImportThing.addEventListener("click", () => {
|
||||
|
@ -668,7 +656,7 @@ document.addEventListener("DOMContentLoaded", function() {
|
|||
noteBox.innerHTML = ""
|
||||
displayError("Something went wrong... Please try again later!")
|
||||
})
|
||||
.then((response) => {
|
||||
.then(async (response) => {
|
||||
selectedNote = nameithink
|
||||
if (mobile) {
|
||||
handleGesture()
|
||||
|
@ -676,7 +664,6 @@ document.addEventListener("DOMContentLoaded", function() {
|
|||
noteBox.contentEditable = true
|
||||
noteBox.click()
|
||||
|
||||
async function doStuff() {
|
||||
let responseData = await response.json()
|
||||
|
||||
let htmlNote
|
||||
|
@ -734,13 +721,11 @@ document.addEventListener("DOMContentLoaded", function() {
|
|||
}
|
||||
}, waitTime);
|
||||
});
|
||||
}
|
||||
|
||||
doStuff()
|
||||
});
|
||||
}
|
||||
|
||||
function updateNotes() {
|
||||
if (!offlineMode) {
|
||||
fetch(remote + "/api/listnotes", {
|
||||
method: "POST",
|
||||
body: JSON.stringify({
|
||||
|
@ -750,8 +735,7 @@ document.addEventListener("DOMContentLoaded", function() {
|
|||
"Content-Type": "application/json; charset=UTF-8"
|
||||
}
|
||||
})
|
||||
.then((response) => {
|
||||
async function doStuff() {
|
||||
.then(async (response) => {
|
||||
noteBox.contentEditable = false
|
||||
selectedNote = 0
|
||||
noteBox.innerHTML = ""
|
||||
|
@ -769,8 +753,10 @@ document.addEventListener("DOMContentLoaded", function() {
|
|||
try {
|
||||
noteData["title"] = await decrypt(noteData["title"])
|
||||
} catch (e) {
|
||||
if (!offlineMode) {
|
||||
location.href = "/migrate"
|
||||
}
|
||||
}
|
||||
|
||||
if (noteData["id"] > highestID) {
|
||||
highestID = noteData["id"]
|
||||
|
@ -823,13 +809,11 @@ document.addEventListener("DOMContentLoaded", function() {
|
|||
selectNote(highestID)
|
||||
selectLatestNote = false
|
||||
}
|
||||
}
|
||||
|
||||
doStuff()
|
||||
});
|
||||
} else {
|
||||
console.log("Currently offline, refusing to update notes.")
|
||||
}
|
||||
}
|
||||
|
||||
updateNotes()
|
||||
|
||||
newNote.addEventListener("click", async () => {
|
||||
let noteName = "New note"
|
||||
|
@ -882,6 +866,7 @@ document.addEventListener("DOMContentLoaded", function() {
|
|||
}
|
||||
|
||||
async function exportNotes() {
|
||||
if (!offlineMode) {
|
||||
let exportNotesFetch = await fetch(remote + "/api/exportnotes", {
|
||||
method: "POST",
|
||||
body: JSON.stringify({
|
||||
|
@ -903,6 +888,9 @@ document.addEventListener("DOMContentLoaded", function() {
|
|||
}
|
||||
}
|
||||
return responseData
|
||||
} else {
|
||||
displayError("You can't export notes while offline!")
|
||||
}
|
||||
}
|
||||
|
||||
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")
|
||||
}
|
||||
|
||||
checknetwork()
|
||||
await checknetwork()
|
||||
updateNotes()
|
||||
})
|
||||
// @license-end
|
||||
|
|
Reference in New Issue