Made the website automatically fetch and upgrade

This commit is contained in:
Tracker-Friendly 2024-05-11 10:35:19 +01:00
parent a4851fa6d3
commit cabd84710e
20 changed files with 1636 additions and 302 deletions

Binary file not shown.

8
go.mod
View File

@ -2,5 +2,9 @@ module hectabit.org/burgernotes-app
go 1.22.2 go 1.22.2
require github.com/arzumify/webview_go-4.1 v0.0.0-20240425153857-cdb51de8ba32 // indirect require (
replace github.com/arzumify/webview_go-4.1 v0.0.0-20240425153857-cdb51de8ba32 => "./webkit-4.1" github.com/arzumify/webview_go-4.1 v0.0.0-20240425153857-cdb51de8ba32
github.com/gotk3/gotk3 v0.6.3
)
replace github.com/arzumify/webview_go-4.1 v0.0.0-20240425153857-cdb51de8ba32 => ./webkit-4.1

6
go.sum
View File

@ -1,4 +1,2 @@
github.com/arzumify/webview_go-4.1 v0.0.0-20240425153334-e12795daefc2 h1:yDtRFTJw5KVTCADMjM10fze4K+3G0uZ7gFFLkoVa8UE= github.com/gotk3/gotk3 v0.6.3 h1:+Ke4WkM1TQUNOlM2TZH6szqknqo+zNbX3BZWVXjSHYw=
github.com/arzumify/webview_go-4.1 v0.0.0-20240425153334-e12795daefc2/go.mod h1:5oDdOhCdYkLdjNnr/+tZO65M+oUlEa/ddnevtaIb7LM= github.com/gotk3/gotk3 v0.6.3/go.mod h1:/hqFpkNa9T3JgNAE2fLvCdov7c5bw//FHNZrZ3Uv9/Q=
github.com/arzumify/webview_go-4.1 v0.0.0-20240425153857-cdb51de8ba32 h1:BmQ/UMgzmODmCqX3wKDGfwlrPWYoL7ZLNY0bYHvhjno=
github.com/arzumify/webview_go-4.1 v0.0.0-20240425153857-cdb51de8ba32/go.mod h1:5oDdOhCdYkLdjNnr/+tZO65M+oUlEa/ddnevtaIb7LM=

145
main.go
View File

@ -1,20 +1,155 @@
package main package main
import ( import (
"fmt"
"path/filepath"
"archive/zip"
"github.com/arzumify/webview_go-4.1" "github.com/arzumify/webview_go-4.1"
"net/http" "net/http"
"os" "os"
"path/filepath" "io"
"strconv"
) )
func main() { func upgrade(path string) {
go func() { err := os.RemoveAll(filepath.Join(path, "website"))
exepath, _ := os.Executable() if err != nil {
path, _ := filepath.EvalSymlinks(exepath) fmt.Println("[ERROR] Failed to delete current version:", err)
return
}
err = os.MkdirAll(filepath.Join(path, "website"), os.ModePerm)
if err != nil {
fmt.Println("[ERROR] Failed to create website directory:", err)
return
}
resp, err := http.Get("https://centrifuge.hectabit.org/HectaBit/Burgernotes-client-web/archive/main.zip")
if err != nil {
fmt.Println("[ERROR] Cannot fetch latest version:", err)
return
}
defer resp.Body.Close()
tempFile, err := os.CreateTemp("", "upgrade_*.zip")
if err != nil {
fmt.Println("[ERROR] Failed to create temporary file:", err)
return
}
defer os.Remove(tempFile.Name())
_, err = io.Copy(tempFile, resp.Body)
if err != nil {
fmt.Println("[ERROR] Failed to copy zip content to temporary file:", err)
return
}
zipReader, err := zip.OpenReader(tempFile.Name())
if err != nil {
fmt.Println("[ERROR] Failed to open zip file:", err)
return
}
defer zipReader.Close()
for _, file := range zipReader.File {
dstPath := filepath.Join(filepath.Join(path, "website"), file.Name)
if file.FileInfo().IsDir() {
os.MkdirAll(dstPath, os.ModePerm)
continue
}
fileReader, err := file.Open()
if err != nil {
fmt.Println("[ERROR] Failed to open file in zip:", err)
return
}
defer fileReader.Close()
dstFile, err := os.Create(dstPath)
if err != nil {
fmt.Println("[ERROR] Failed to create destination file:", err)
return
}
defer dstFile.Close()
_, err = io.Copy(dstFile, fileReader)
if err != nil {
fmt.Println("[ERROR] Failed to copy file contents:", err)
return
}
}
src, err := os.Open(filepath.Join(filepath.Join(path, "website"), "burgernotes-client-web"))
if err != nil {
fmt.Println("[ERROR] Cannot find created folder:", err)
return
}
files, err := src.Readdir(-1)
if err != nil {
fmt.Println("[ERROR] Failed to read files:", err)
return
}
for _, file := range files {
srcPath := filepath.Join(filepath.Join(filepath.Join(path, "website"), "burgernotes-client-web"), file.Name())
dstPath := filepath.Join(filepath.Join(path, "website"), file.Name())
err := os.Rename(srcPath, dstPath)
if err != nil {
fmt.Println("[ERROR] Failed to move files:", err)
return
}
}
err = os.Remove(filepath.Join(filepath.Join(path, "website"), "burgernotes-client-web"))
if err != nil {
fmt.Println("[ERROR] Failed to delete source directory:", err)
return
}
file, err := os.OpenFile(filepath.Join(filepath.Join(path, "website"), "index.html"), os.O_WRONLY|os.O_TRUNC|os.O_CREATE, 0644)
if err != nil {
fmt.Println("[ERROR] Failed to open index.html:", err)
return
}
defer file.Close()
filecontent := "<!DOCTYPE html><html><head><title>Burgernotes</title><meta charset=\"UTF-8\" /><meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\" /><meta http-equiv=\"refresh\" content=\"0; url=/app\"><head>Redirecting...<script>window.location.replace(\"/app\")</script>"
_, err = file.WriteString(filecontent)
if err != nil {
fmt.Println("[ERROR] Failed to replace index.html:", err)
return
}
}
func vcheck(path string) {
localVersion, err := os.ReadFile(path + "/website/static/version.txt")
if err != nil {
fmt.Println("[ERROR] Cannot get local version:", err)
os.Exit(1)
}
localVersionNum, err := strconv.Atoi(string(localVersion))
if err != nil {
fmt.Println("[ERROR] Failed to convert local version to integer:", err)
return
}
resp, err := http.Get("https://notes.hectabit.org/static/version.txt")
if err != nil {
fmt.Println("[ERROR] Cannot fetch remote version:", err)
return
}
remoteVersion, err := io.ReadAll(resp.Body)
if err != nil {
fmt.Println("[ERROR] Failed to read remote version:", err)
return
}
defer resp.Body.Close()
remoteVersionNum, err := strconv.Atoi(string(remoteVersion))
if err != nil {
fmt.Println("[ERROR] Failed to convert remote version to integer:", err)
return
}
if localVersionNum < remoteVersionNum {
fmt.Println("[INFO] Local version is old. Attempting upgrade...")
upgrade(path)
} else {
fmt.Println("[INFO] Up to date")
}
}
func main() {
exepath, _ := os.Executable()
path, _ := filepath.EvalSymlinks(exepath)
go func() {
http.Handle("/", http.StripPrefix("/", http.FileServer(http.Dir(filepath.Dir(path) + "/website")))) http.Handle("/", http.StripPrefix("/", http.FileServer(http.Dir(filepath.Dir(path) + "/website"))))
http.ListenAndServe("localhost:52064", nil) http.ListenAndServe("localhost:52064", nil)
}() }()
vcheck(filepath.Dir(path))
w := webview.New(false) w := webview.New(false)
defer w.Destroy() defer w.Destroy()

View File

@ -1,13 +0,0 @@
<!DOCTYPE html>
<html>
<head>
<title>Burgernotes</title>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta http-equiv="refresh" content="0; url=/app">
<head>
Redirecting...
<script>
window.location.replace("/app")
</script>

1
website/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
.idea

View File

@ -1,23 +1,15 @@
<!DOCTYPE html> <!DOCTYPE html>
<html> <html lang="en">
<head> <head>
<title>Burgernotes</title> <title>Burgernotes</title>
<meta charset="UTF-8" /> <meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" /> <meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"> <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<link rel="stylesheet" type="text/css" href="../static/css/style.css" /> <link rel="stylesheet" type="text/css" href="/static/css/style.css" />
<script type="text/javascript" src="../static/js/crypto-js.js"></script> <script type="text/javascript" src="/static/js/crypto-js.js"></script>
<link rel="icon" href="../static/svg/favicon.svg"> <script type="text/javascript" src="/static/js/marked.js"></script>
<script> <link rel="icon" href="/static/svg/favicon.svg">
if (window.location.href.endsWith('/index.html')) {
if (window.location.origin !== null) {
var currentUrl = window.location.href;
var newUrl = currentUrl.replace('/index.html', '');
window.location.href = newUrl;
}
}
</script>
</head> </head>
<body> <body>
@ -29,6 +21,7 @@
<div class="bottomBar"> <div class="bottomBar">
<button id="removeBox" class="removeButton"></button> <button id="removeBox" class="removeButton"></button>
<button id="wordCountBox">0 words</button> <button id="wordCountBox">0 words</button>
<button onclick="toggleMarkdown()">Toggle Markdown</button>
<div class="textManipulator"> <div class="textManipulator">
<button id="textMinusBox">-</button> <button id="textMinusBox">-</button>
<button id="textSizeBox">16px</button> <button id="textSizeBox">16px</button>
@ -38,7 +31,7 @@
<div id="notesBar" class="notesBar"> <div id="notesBar" class="notesBar">
<button id="newNote" class="newNote"><img id="newNoteImage" draggable="false" alt="" <button id="newNote" class="newNote"><img id="newNoteImage" draggable="false" alt=""
src="../static/svg/add.svg">New note</button> src="/static/svg/add.svg">New note</button>
<div id="notesDiv" class="notesDiv"> <div id="notesDiv" class="notesDiv">
<button class="loadingStuff" id="loadingStuff"></button> <button class="loadingStuff" id="loadingStuff"></button>
</div> </div>
@ -56,10 +49,10 @@
<p id="storageThing"></p> <p id="storageThing"></p>
<div class="section"></div> <div class="section"></div>
<p>Account managment</p> <p>Account managment</p>
<button id="deleteMyAccountButton"><img src="../static/svg/delete_forever.svg">Delete my account</button> <button id="deleteMyAccountButton"><img src="/static/svg/delete_forever.svg" alt="">Delete my account</button>
<button id="exportNotesButton"><img src="../static/svg/download.svg">Export notes</button> <button id="exportNotesButton"><img src="/static/svg/download.svg" alt="">Export notes</button>
<button id="sessionManagerButton"><img src="../static/svg/list.svg">Session manager</button> <button id="sessionManagerButton"><img src="/static/svg/list.svg" alt="">Session manager</button>
<button class="lastButton" id="logOutButton"><img src="../static/svg/logout.svg">Log out</button> <button class="lastButton" id="logOutButton"><img src="/static/svg/logout.svg" alt="">Log out</button>
</div> </div>
<div id="sessionManagerDiv" class="optionsDiv hidden"> <div id="sessionManagerDiv" class="optionsDiv hidden">
<button class="exit" id="exitSessionsThing">X</button> <button class="exit" id="exitSessionsThing">X</button>
@ -69,18 +62,20 @@
<div class="sessionDiv" id="sessionDiv"> <div class="sessionDiv" id="sessionDiv">
</div> </div>
</div> </div>
</div>
<div id="errorDiv" class="optionsDiv hidden"> <div id="errorDiv" class="optionsDiv hidden">
<p id="errorMessageThing"></p> <p id="errorMessageThing"></p>
<input class="hidden" id="errorInput" type="text" placeholder=""><br></input> <input class="hidden" id="errorInput" type="text" placeholder=""><br>
<button class="normalButton" id="closeErrorButton">Ok</button> <button class="normalButton" id="closeErrorButton">Ok</button>
<button class="normalButton hidden" id="cancelErrorButton">Cancel</button> <button class="normalButton hidden" id="cancelErrorButton">Cancel</button>
</div> </div>
</div> </div>
<textarea id="noteBox" class="noteBox"></textarea> <div class="noteBox">
<textarea id="noteBox" class="noteBoxText"></textarea>
<iframe id="markdown" style="display: none;" sandbox="allow-scripts"></iframe>
</div>
<script type="text/javascript" src="../static/js/main.js"></script> <script type="text/javascript" src="/static/js/main.js"></script>
<script> <script>
for (let i = 0; i < 40; i++) { for (let i = 0; i < 40; i++) {
notesDiv.appendChild(loadingStuff.cloneNode()) notesDiv.appendChild(loadingStuff.cloneNode())

View File

@ -1,33 +0,0 @@
<!DOCTYPE html>
<html>
<head>
<title>Burgernotes</title>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<link rel="stylesheet" type="text/css" href="../static/css/style.css" />
<link rel="icon" href="../static/svg/favicon.svg">
<script>
if (window.location.href.endsWith('/index.html')) {
if (window.location.origin !== null) {
var currentUrl = window.location.href;
var newUrl = currentUrl.replace('/index.html', '');
window.location.href = newUrl;
}
}
</script>
</head>
<body>
<h2 class="w300">{{ errorMessage }}</h2>
{{ errorCode }} | {{ errorMessage }}
</body>
<style>
body {
margin-left: 15px;
}
</style>
</html>

View File

@ -1,5 +1,5 @@
<!DOCTYPE html> <!DOCTYPE html>
<html> <html lang="en">
<head> <head>
<title>Signup - Burgernotes</title> <title>Signup - Burgernotes</title>
@ -7,13 +7,13 @@
<meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"> <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<link rel="stylesheet" type="text/css" href="../static/css/style.css"> <link rel="stylesheet" type="text/css" href="../static/css/style.css">
<link rel="icon" href="./static/svg/favicon.svg"> <link rel="icon" href="/static/svg/favicon.svg">
<script src="../static/js/hash-wasm.js"></script> <script src="/static/js/hash-wasm.js"></script>
</head> </head>
<body> <body>
<p class="credit">Image by perga (@pergagreen on discord)</p> <p class="credit">Image by perga (@pergagreen on discord)</p>
<img src="/static/img/background.jpg" class="background"> <img src="/static/img/background.jpg" class="background" alt="">
<div class="inoutdiv"> <div class="inoutdiv">
<h2 class="w300">Homeserver</h2> <h2 class="w300">Homeserver</h2>
<p>Change your Burgernotes homeserver</p> <p>Change your Burgernotes homeserver</p>
@ -24,7 +24,7 @@
<p>Please put in the URL in standard format; https://, http://, etc.</p> <p>Please put in the URL in standard format; https://, http://, etc.</p>
</div> </div>
<script type="text/javascript" src="../static/js/homeserver.js"></script> <script type="text/javascript" src="/static/js/homeserver.js"></script>
</body> </body>
</html> </html>

View File

@ -1,13 +1 @@
<!DOCTYPE html> <!DOCTYPE html><html><head><title>Burgernotes</title><meta charset="UTF-8" /><meta http-equiv="X-UA-Compatible" content="IE=edge" /><meta http-equiv="refresh" content="0; url=/app"><head>Redirecting...<script>window.location.replace("/app")</script>
<html>
<head>
<title>Burgernotes</title>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta http-equiv="refresh" content="0; url=/app">
<head>
Redirecting...
<script>
window.location.replace("/app")
</script>

View File

@ -1,28 +1,19 @@
<!DOCTYPE html> <!DOCTYPE html>
<html> <html lang="en">
<head> <head>
<title>Login - Burgernotes</title> <title>Login - Burgernotes</title>
<meta charset="UTF-8" /> <meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" /> <meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"> <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<link rel="stylesheet" type="text/css" href="../static/css/style.css" /> <link rel="stylesheet" type="text/css" href="/static/css/style.css" />
<script src="../static/js/hash-wasm.js"></script> <script src="/static/js/hash-wasm.js"></script>
<link rel="icon" href="../static/svg/favicon.svg"> <link rel="icon" href="/static/svg/favicon.svg">
<script>
if (window.location.href.endsWith('/index.html')) {
if (window.location.origin !== null) {
var currentUrl = window.location.href;
var newUrl = currentUrl.replace('/index.html', '');
window.location.href = newUrl;
}
}
</script>
</head> </head>
<body> <body>
<p class="credit">Image by perga (@pergagreen on discord)</p> <p class="credit">Image by perga (@pergagreen on discord)</p>
<img src="/static/img/background.jpg" class="background"> <img src="/static/img/background.jpg" class="background" alt="">
<div class="inoutdiv"> <div class="inoutdiv">
<h2 class="w300">Login</h2> <h2 class="w300">Login</h2>
<p id="statusBox"></p> <p id="statusBox"></p>
@ -33,9 +24,9 @@
<button id="backButton" class="hidden">Back</button> <button id="backButton" class="hidden">Back</button>
<br> <br>
<br> <br>
<p>Don't have an account? If so, <a href="../signup/index.html">Create one here!</a></p> <p>Don't have an account? If so, <a href="/signup/">Create one here!</a></p>
<div style="display: flex;"><p id="homeserver">Your homeserver is loading... </p><div style="display: flex;flex-direction: column;justify-content: center;"><a href="/homeserver">Change</a></div></div> <div style="display: flex;"><p id="homeserver">Your homeserver is loading... </p><div style="display: flex;flex-direction: column;justify-content: center;"><a href="/homeserver">Change</a></div></div>
<a href="../privacy/index.html">Privacy &amp; Terms</a> <a href="/privacy/">Privacy &amp; Terms</a>
</div> </div>
<script type="text/javascript" src="../static/js/login.js"></script> <script type="text/javascript" src="../static/js/login.js"></script>

View File

@ -1,25 +1,16 @@
<!DOCTYPE html> <!DOCTYPE html>
<html> <html lang="en">
<head> <head>
<title>Burgernotes</title> <title>Burgernotes</title>
<meta charset="UTF-8" /> <meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" /> <meta http-equiv="X-UA-Compatible" content="IE=edge" />
<link rel="icon" href="../static/svg/favicon.svg"> <link rel="icon" href="/static/svg/favicon.svg">
<script> </head>
if (window.location.href.endsWith('/index.html')) { <p>Logging out...</p>
if (window.location.origin !== null) {
var currentUrl = window.location.href;
var newUrl = currentUrl.replace('/index.html', '');
window.location.href = newUrl;
}
}
</script>
<head>
Logging out..
<script> <script>
localStorage.removeItem("DONOTSHARE-secretkey") localStorage.removeItem("DONOTSHARE-secretkey")
localStorage.removeItem("DONOTSHARE-password") localStorage.removeItem("DONOTSHARE-password")
localStorage.removeItem("CACHE-username") localStorage.removeItem("CACHE-username")
window.location.replace("../login/index.html") window.location.replace("/login")
</script> </script>

View File

@ -1,22 +1,13 @@
<!DOCTYPE html> <!DOCTYPE html>
<html> <html lang="en">
<head> <head>
<title>Burgernotes Privacy &amp; Terms</title> <title>Burgernotes Privacy &amp; Terms</title>
<meta charset="UTF-8" /> <meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" /> <meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"> <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<link rel="stylesheet" type="text/css" href="../static/css/style.css" /> <link rel="stylesheet" type="text/css" href="/static/css/style.css" />
<link rel="icon" href="../static/svg/favicon.svg"> <link rel="icon" href="/static/svg/favicon.svg">
<script>
if (window.location.href.endsWith('/index.html')) {
if (window.location.origin !== null) {
var currentUrl = window.location.href;
var newUrl = currentUrl.replace('/index.html', '');
window.location.href = newUrl;
}
}
</script>
</head> </head>
<body> <body>
@ -39,21 +30,21 @@
<li>Web browser "User agent"</li> <li>Web browser "User agent"</li>
</ul> </ul>
<h2 class="w300">Information we collect while using our services</h2> <h2 class="w300">Information we collect while using our services</h2>
<p>When you create an note, we collect and use this information:</p> <p>When you create a note, we collect and use this information:</p>
<ul> <ul>
<li>Encrypted note content and title</li> <li>Encrypted note content and title</li>
<li>Note creator</li> <li>Note creator</li>
<li>Note creation date</li> <li>Note creation date</li>
<li>Note last edited date</li> <li>Note last edited date</li>
</ul> </ul>
<p>When you edit an note, we collect and use this information:</p> <p>When you edit a note, we collect and use this information:</p>
<ul> <ul>
<li>Encrypted note content and title</li> <li>Encrypted note content and title</li>
<li>Note last edited date</li> <li>Note last edited date</li>
</ul> </ul>
<h2 class="w300">How we use your data</h2> <h2 class="w300">How we use your data</h2>
<p>We use your data to make our services work. We don't share your information with third-parties.</p> <p>We use your data to make our services work. We don't share your information with third-parties.</p>
<h2 class="w300">We can't see notes you create's content and title</h2> <h2 class="w300">We can't see the content and title of the notes you create</h2>
<p>Your notes are <a href="https://en.wikipedia.org/wiki/End-to-end_encryption">encrypted end-to-end</a> using AES <p>Your notes are <a href="https://en.wikipedia.org/wiki/End-to-end_encryption">encrypted end-to-end</a> using AES
(Advanced Encryption Standard) 256-bit encryption.</p> (Advanced Encryption Standard) 256-bit encryption.</p>
<p>We can only see:</p> <p>We can only see:</p>
@ -79,7 +70,7 @@
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
SUCH DAMAGES.</p> SUCH DAMAGES.</p>
<br> <br>
<button onclick="if(document.referrer!==' '){if(document.referrer!==''){window.location.href=document.referrer;}else{window.location.href='../index.html';}window.location.href=document.referrer; }else{window.location.href='../index.html';}" style="cursor: pointer; padding: 15px 20px;margin-right: auto;color: white;text-decoration: none;background-color: var(--theme-color);border-radius: 8px;border: medium;font-size: 15px;">Take me back where I was!</button> <button onclick="if(document.referrer!==' '){if(document.referrer!==''){window.location.href=document.referrer;}else{window.location.href='/';}window.location.href=document.referrer; }else{window.location.href='../index.html';}" style="cursor: pointer; padding: 15px 20px;margin-right: auto;color: white;text-decoration: none;background-color: var(--theme-color);border-radius: 8px;border: medium;font-size: 15px;">Take me back where I was!</button>
<br><br> <br><br>
</body> </body>

View File

@ -1,28 +1,19 @@
<!DOCTYPE html> <!DOCTYPE html>
<html> <html lang="en">
<head> <head>
<title>Signup - Burgernotes</title> <title>Signup - Burgernotes</title>
<meta charset="UTF-8" /> <meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" /> <meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"> <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<link rel="stylesheet" type="text/css" href="../static/css/style.css" /> <link rel="stylesheet" type="text/css" href="/static/css/style.css" />
<script src="../static/js/hash-wasm.js"></script> <script src="/static/js/hash-wasm.js"></script>
<link rel="icon" href="../static/svg/favicon.svg"> <link rel="icon" href="/static/svg/favicon.svg">
<script>
if (window.location.href.endsWith('/index.html')) {
if (window.location.origin !== null) {
var currentUrl = window.location.href;
var newUrl = currentUrl.replace('/index.html', '');
window.location.href = newUrl;
}
}
</script>
</head> </head>
<body> <body>
<p class="credit">Image by perga (@pergagreen on discord)</p> <p class="credit">Image by perga (@pergagreen on discord)</p>
<img src="/static/img/background.jpg" class="background"> <img src="/static/img/background.jpg" class="background" alt="">
<div class="inoutdiv"> <div class="inoutdiv">
<h2 class="w300">Signup</h2> <h2 class="w300">Signup</h2>
<p>Signup for a Burgernotes account</p> <p>Signup for a Burgernotes account</p>
@ -30,10 +21,10 @@
<input id="usernameBox" type="text" placeholder="Username"> <input id="usernameBox" type="text" placeholder="Username">
<input id="passwordBox" type="password" placeholder="Password"><br> <input id="passwordBox" type="password" placeholder="Password"><br>
<button id="signupButton">Signup</button><br><br> <button id="signupButton">Signup</button><br><br>
<p>Already have an account? If so, <a href="../login/index.html">Login</a> instead!</p> <p>Already have an account? If so, <a href="/login/">Login</a> instead!</p>
<p>Please note that it's impossible to reset your password, do not forget it!</p> <p>Please note that it's impossible to reset your password, do not forget it!</p>
<div style="display: flex;"><p id="homeserver">Your homeserver is loading... </p><div style="display: flex;flex-direction: column;justify-content: center;"><a href="/homeserver">Change</a></div></div> <div style="display: flex;"><p id="homeserver">Your homeserver is loading... </p><div style="display: flex;flex-direction: column;justify-content: center;"><a href="/homeserver">Change</a></div></div>
<a href="../privacy/index.html">Privacy &amp; Terms</a> <a href="/privacy/">Privacy &amp; Terms</a>
</div> </div>
<script type="text/javascript" src="../static/js/signup.js"></script> <script type="text/javascript" src="/static/js/signup.js"></script>
</body> </body>

View File

@ -345,6 +345,21 @@ body {
width: calc(100% - 180px - 7px - 6px); width: calc(100% - 180px - 7px - 6px);
height: calc(100% - 50px - 6px - 8px - 30px); height: calc(100% - 50px - 6px - 8px - 30px);
font-family: "Inter", sans-serif; font-family: "Inter", sans-serif;
display: flex;
}
.noteBoxText {
background-color: var(--editor);
color: var(--text-color);
border: none;
width: 100%;
font-family: "Inter", sans-serif;
}
iframe#markdown {
width: 100%;
border: none;
border-left: solid var(--bar) 1px;
} }
.noteBox:focus { .noteBox:focus {

View File

@ -1,10 +1,10 @@
if (localStorage.getItem("DONOTSHARE-secretkey") !== null) { if (localStorage.getItem("DONOTSHARE-secretkey") !== null) {
window.location.replace("../app/index.html") window.location.replace("/app/")
document.body.innerHTML = "Redirecting..." document.body.innerHTML = "Redirecting..."
throw new Error(); throw new Error();
} }
if (localStorage.getItem("DONOTSHARE-password") !== null) { if (localStorage.getItem("DONOTSHARE-password") !== null) {
window.location.replace("../app/index.html") window.location.replace("/app/")
document.body.innerHTML = "Redirecting..." document.body.innerHTML = "Redirecting..."
throw new Error(); throw new Error();
} }
@ -28,20 +28,20 @@ inputNameBox.innerText = "Username:"
let currentInputType = 0 let currentInputType = 0
function showInput(inputType) { function showInput(inputType) {
if (inputType == 0) { if (inputType === 0) {
usernameBox.classList.remove("hidden") usernameBox.classList.remove("hidden")
passwordBox.classList.add("hidden") passwordBox.classList.add("hidden")
backButton.classList.add("hidden") backButton.classList.add("hidden")
inputNameBox.innerText = "Username:" inputNameBox.innerText = "Username:"
statusBox.innerText = "Login to your Burgernotes account!" statusBox.innerText = "Login to your Burgernotes account!"
currentInputType = 0 currentInputType = 0
} else if (inputType == 1) { } else if (inputType === 1) {
usernameBox.classList.add("hidden") usernameBox.classList.add("hidden")
passwordBox.classList.remove("hidden") passwordBox.classList.remove("hidden")
backButton.classList.remove("hidden") backButton.classList.remove("hidden")
inputNameBox.innerText = "Password:" inputNameBox.innerText = "Password:"
currentInputType = 1 currentInputType = 1
} else if (inputType == 2) { } else if (inputType === 2) {
usernameBox.classList.add("hidden") usernameBox.classList.add("hidden")
passwordBox.classList.add("hidden") passwordBox.classList.add("hidden")
signupButton.classList.add("hidden") signupButton.classList.add("hidden")
@ -75,9 +75,9 @@ document.addEventListener('DOMContentLoaded', function() {
document.getElementById("homeserver").innerText = "Your homeserver is: " + remote + ". " document.getElementById("homeserver").innerText = "Your homeserver is: " + remote + ". "
}); });
signupButton.addEventListener("click", (event) => { signupButton.addEventListener("click", () => {
if (passwordBox.classList.contains("hidden")) { if (passwordBox.classList.contains("hidden")) {
if (usernameBox.value == "") { if (usernameBox.value === "") {
statusBox.innerText = "A username is required!" statusBox.innerText = "A username is required!"
return return
} else { } else {
@ -89,7 +89,7 @@ signupButton.addEventListener("click", (event) => {
let username = usernameBox.value let username = usernameBox.value
let password = passwordBox.value let password = passwordBox.value
if (password == "") { if (password === "") {
statusBox.innerText = "A password is required!" statusBox.innerText = "A password is required!"
return return
} }
@ -99,7 +99,7 @@ signupButton.addEventListener("click", (event) => {
statusBox.innerText = "Signing in..." statusBox.innerText = "Signing in..."
async function hashpassold(pass) { async function hashpassold(pass) {
const key = await hashwasm.argon2id({ return await hashwasm.argon2id({
password: pass, password: pass,
salt: await hashwasm.sha512(pass), salt: await hashwasm.sha512(pass),
parallelism: 1, parallelism: 1,
@ -107,9 +107,8 @@ signupButton.addEventListener("click", (event) => {
memorySize: 512, memorySize: 512,
hashLength: 32, hashLength: 32,
outputType: "encoded" outputType: "encoded"
}); })
return key }
};
async function hashpass(pass) { async function hashpass(pass) {
let key = pass let key = pass
@ -117,7 +116,7 @@ signupButton.addEventListener("click", (event) => {
key = await hashwasm.sha3(key) key = await hashwasm.sha3(key)
} }
return key return key
}; }
fetch(remote + "/api/login", { fetch(remote + "/api/login", {
method: "POST", method: "POST",
@ -135,13 +134,13 @@ signupButton.addEventListener("click", (event) => {
.then((response) => { .then((response) => {
async function doStuff() { async function doStuff() {
let responseData = await response.json() let responseData = await response.json()
if (response.status == 200) { if (response.status === 200) {
localStorage.setItem("DONOTSHARE-secretkey", responseData["key"]) localStorage.setItem("DONOTSHARE-secretkey", responseData["key"])
localStorage.setItem("DONOTSHARE-password", await hashwasm.sha512(password)) localStorage.setItem("DONOTSHARE-password", await hashwasm.sha512(password))
window.location.href = "../app/index.html" window.location.href = "/app/"
} }
else if (response.status == 401) { else if (response.status === 401) {
console.log("Trying oldhash") console.log("Trying oldhash")
fetch(remote + "/api/login", { fetch(remote + "/api/login", {
method: "POST", method: "POST",
@ -159,13 +158,13 @@ signupButton.addEventListener("click", (event) => {
.then((response) => { .then((response) => {
async function doStuff2() { async function doStuff2() {
let responseData = await response.json() let responseData = await response.json()
if (response.status == 200) { if (response.status === 200) {
localStorage.setItem("DONOTSHARE-secretkey", responseData["key"]) localStorage.setItem("DONOTSHARE-secretkey", responseData["key"])
localStorage.setItem("DONOTSHARE-password", await hashwasm.sha512(password)) localStorage.setItem("DONOTSHARE-password", await hashwasm.sha512(password))
window.location.href = "../app/index.html" window.location.href = "/app/"
} }
else if (response.status == 401) { else if (response.status === 401) {
statusBox.innerText = "Wrong username or password..." statusBox.innerText = "Wrong username or password..."
showInput(1) showInput(1)
showElements(true) showElements(true)
@ -192,7 +191,7 @@ signupButton.addEventListener("click", (event) => {
} }
}); });
backButton.addEventListener("click", (event) => { backButton.addEventListener("click", () => {
showInput(0) showInput(0)
}); });

View File

@ -1,10 +1,10 @@
if (localStorage.getItem("DONOTSHARE-secretkey") === null) { if (localStorage.getItem("DONOTSHARE-secretkey") === null) {
window.location.replace("../login/index.html") window.location.replace("/login")
document.body.innerHTML = "Redirecting..." document.body.innerHTML = "Redirecting..."
throw new Error(); throw new Error();
} }
if (localStorage.getItem("DONOTSHARE-password") === null) { if (localStorage.getItem("DONOTSHARE-password") === null) {
window.location.replace("../login/index.html") window.location.replace("/login")
document.body.innerHTML = "Redirecting..." document.body.innerHTML = "Redirecting..."
throw new Error(); throw new Error();
} }
@ -21,16 +21,10 @@ if (remote == null) {
function formatBytes(a, b = 2) { if (!+a) return "0 Bytes"; const c = 0 > b ? 0 : b, d = Math.floor(Math.log(a) / Math.log(1000)); return `${parseFloat((a / Math.pow(1000, d)).toFixed(c))} ${["Bytes", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"][d]}` } function formatBytes(a, b = 2) { if (!+a) return "0 Bytes"; const c = 0 > b ? 0 : b, d = Math.floor(Math.log(a) / Math.log(1000)); return `${parseFloat((a / Math.pow(1000, d)).toFixed(c))} ${["Bytes", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"][d]}` }
function truncateString(str, num) {
if (str.length > num) {
return str.slice(0, num) + "...";
} else {
return str;
}
}
let secretkey = localStorage.getItem("DONOTSHARE-secretkey") let secretkey = localStorage.getItem("DONOTSHARE-secretkey")
let password = localStorage.getItem("DONOTSHARE-password") let password = localStorage.getItem("DONOTSHARE-password")
let currentFontSize = 16
let markdowntoggle = false
let usernameBox = document.getElementById("usernameBox") let usernameBox = document.getElementById("usernameBox")
let optionsCoverDiv = document.getElementById("optionsCoverDiv") let optionsCoverDiv = document.getElementById("optionsCoverDiv")
@ -45,7 +39,6 @@ let exitSessionsThing = document.getElementById("exitSessionsThing")
let sessionManagerButton = document.getElementById("sessionManagerButton") let sessionManagerButton = document.getElementById("sessionManagerButton")
let sessionManagerDiv = document.getElementById("sessionManagerDiv") let sessionManagerDiv = document.getElementById("sessionManagerDiv")
let sessionDiv = document.getElementById("sessionDiv") let sessionDiv = document.getElementById("sessionDiv")
let mfaDiv = document.getElementById("mfaDiv")
let deleteMyAccountButton = document.getElementById("deleteMyAccountButton") let deleteMyAccountButton = document.getElementById("deleteMyAccountButton")
let storageThing = document.getElementById("storageThing") let storageThing = document.getElementById("storageThing")
let storageProgressThing = document.getElementById("storageProgressThing") let storageProgressThing = document.getElementById("storageProgressThing")
@ -56,8 +49,13 @@ let notesDiv = document.getElementById("notesDiv")
let newNote = document.getElementById("newNote") let newNote = document.getElementById("newNote")
let noteBox = document.getElementById("noteBox") let noteBox = document.getElementById("noteBox")
let loadingStuff = document.getElementById("loadingStuff") let loadingStuff = document.getElementById("loadingStuff")
let burgerButton = document.getElementById("burgerButton")
let exportNotesButton = document.getElementById("exportNotesButton") let exportNotesButton = document.getElementById("exportNotesButton")
let markdown = document.getElementById('markdown');
let textSizeBox = document.getElementById('textSizeBox');
let textPlusBox = document.getElementById('textPlusBox');
let textMinusBox = document.getElementById('textMinusBox');
let wordCountBox = document.getElementById('wordCountBox');
let removeBox = document.getElementById("removeBox")
let selectedNote = 0 let selectedNote = 0
let timer let timer
@ -70,6 +68,8 @@ if (/Android|iPhone|iPod/i.test(navigator.userAgent)) {
noteBox.style.fontSize = "18px" noteBox.style.fontSize = "18px"
noteBox.classList.add("hidden") noteBox.classList.add("hidden")
let touchstartX, touchstartY, touchendX, touchendY
notesBar.addEventListener("touchstart", function (event) { notesBar.addEventListener("touchstart", function (event) {
touchstartX = event.changedTouches[0].screenX; touchstartX = event.changedTouches[0].screenX;
touchstartY = event.changedTouches[0].screenY; touchstartY = event.changedTouches[0].screenY;
@ -96,7 +96,7 @@ if (/Android|iPhone|iPod/i.test(navigator.userAgent)) {
if (touchendX > touchstartX + 75) { if (touchendX > touchstartX + 75) {
notesBar.style.width = "calc(100% - 10px)"; notesBar.style.width = "calc(100% - 10px)";
noteBox.style.width = "10px" noteBox.style.width = "10px"
if (selectedNote != 0) { if (selectedNote !== 0) {
noteBox.readOnly = true noteBox.readOnly = true
} }
notesDiv.classList.remove("hidden") notesDiv.classList.remove("hidden")
@ -107,7 +107,7 @@ if (/Android|iPhone|iPod/i.test(navigator.userAgent)) {
if (touchendX < touchstartX - 75) { if (touchendX < touchstartX - 75) {
noteBox.style.width = "calc(100% - 30px)"; noteBox.style.width = "calc(100% - 30px)";
notesBar.style.width = "10px" notesBar.style.width = "10px"
if (selectedNote != 0) { if (selectedNote !== 0) {
noteBox.readOnly = false noteBox.readOnly = false
} }
notesDiv.classList.add("hidden") notesDiv.classList.add("hidden")
@ -129,50 +129,11 @@ function displayError(message) {
errorMessageThing.innerHTML = message errorMessageThing.innerHTML = message
} }
closeErrorButton.addEventListener("click", (event) => { closeErrorButton.addEventListener("click", () => {
errorDiv.classList.add("hidden") errorDiv.classList.add("hidden")
optionsCoverDiv.classList.add("hidden") optionsCoverDiv.classList.add("hidden")
}); });
closeErrorButton.addEventListener("click", () => {
function displayPrompt(message, placeholdertext, callback) {
errorMessageThing.innerText = message
errorInput.value = ""
errorInput.placeholder = placeholdertext
closeErrorButton.addEventListener("click", (event) => {
if (callback) {
callback(errorInput.value)
callback = undefined
}
});
errorInput.addEventListener("keyup", (event) => {
if (event.key == "Enter") {
callback(errorInput.value)
callback = undefined
errorDiv.classList.add("hidden")
optionsCoverDiv.classList.add("hidden")
errorInput.classList.add("hidden")
cancelErrorButton.classList.add("hidden")
}
});
cancelErrorButton.addEventListener("click", (event) => {
callback = undefined
errorDiv.classList.add("hidden")
optionsCoverDiv.classList.add("hidden")
errorInput.classList.add("hidden")
cancelErrorButton.classList.add("hidden")
});
errorDiv.classList.remove("hidden")
optionsCoverDiv.classList.remove("hidden")
errorInput.classList.remove("hidden")
cancelErrorButton.classList.remove("hidden")
errorInput.focus()
}
closeErrorButton.addEventListener("click", (event) => {
errorDiv.classList.add("hidden") errorDiv.classList.add("hidden")
optionsCoverDiv.classList.add("hidden") optionsCoverDiv.classList.add("hidden")
errorInput.classList.add("hidden") errorInput.classList.add("hidden")
@ -180,9 +141,12 @@ closeErrorButton.addEventListener("click", (event) => {
}); });
function updateFont() { function updateFont() {
let currentFontSize = localStorage.getItem("SETTING-fontsize") currentFontSize = localStorage.getItem("SETTING-fontsize")
noteBox.style.fontSize = currentFontSize + "px" noteBox.style.fontSize = currentFontSize + "px"
textSizeBox.innerText = currentFontSize + "px" textSizeBox.innerText = currentFontSize + "px"
if (markdowntoggle) {
markdown.srcdoc = "<!DOCTYPE html><html lang='en'><style>html { height: 100% } body { font-family: 'Inter', sans-serif; height: 100%; color: " + getComputedStyle(document.documentElement).getPropertyValue('--text-color') + "; font-size: " + currentFontSize + "px; }</style>" + marked.parse(noteBox.value) + "</html>";
}
} }
async function waitforedit() { async function waitforedit() {
@ -200,13 +164,13 @@ async function waitforedit() {
async function doStuff() { async function doStuff() {
const data = await response.json(); const data = await response.json();
// Access the "note" field from the response // Access the "note" field from the response
const note = data.note; const note = data["note"];
if (note == selectedNote) { if (note === selectedNote) {
selectNote(selectedNote) selectNote(selectedNote)
} }
} }
doStuff(); doStuff()
}) });
} }
} }
@ -217,11 +181,11 @@ if (localStorage.getItem("SETTING-fontsize") === null) {
updateFont() updateFont()
} }
textPlusBox.addEventListener("click", (event) => { textPlusBox.addEventListener("click", () => {
localStorage.setItem("SETTING-fontsize", String(Number(localStorage.getItem("SETTING-fontsize")) + Number(1))) localStorage.setItem("SETTING-fontsize", String(Number(localStorage.getItem("SETTING-fontsize")) + Number(1)))
updateFont() updateFont()
}); });
textMinusBox.addEventListener("click", (event) => { textMinusBox.addEventListener("click", () => {
localStorage.setItem("SETTING-fontsize", String(Number(localStorage.getItem("SETTING-fontsize")) - Number(1))) localStorage.setItem("SETTING-fontsize", String(Number(localStorage.getItem("SETTING-fontsize")) - Number(1)))
updateFont() updateFont()
}); });
@ -246,19 +210,19 @@ function updateUserInfo() {
"Content-Type": "application/json; charset=UTF-8" "Content-Type": "application/json; charset=UTF-8"
} }
}) })
.catch((error) => { .catch(() => {
noteBox.readOnly = true noteBox.readOnly = true
noteBox.value = "" noteBox.value = ""
noteBox.placeholder = "Failed to connect to the server.\nPlease check your internet connection." noteBox.placeholder = "Failed to connect to the server.\nPlease check your internet connection."
}) })
.then((response) => { .then((response) => {
async function doStuff() { async function doStuff() {
if (response.status == 500) { 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")
usernameBox.innerText = "" usernameBox.innerText = ""
setTimeout(function () { setTimeout(function () {
window.location.replace("../logout/index.html") window.location.replace("/logout")
}, 2500); }, 2500);
} else { } else {
let responseData = await response.json() let responseData = await response.json()
@ -274,20 +238,20 @@ function updateUserInfo() {
doStuff() doStuff()
}); });
} }
usernameBox.addEventListener("click", (event) => { usernameBox.addEventListener("click", () => {
optionsCoverDiv.classList.remove("hidden") optionsCoverDiv.classList.remove("hidden")
optionsDiv.classList.remove("hidden") optionsDiv.classList.remove("hidden")
updateUserInfo() updateUserInfo()
}); });
logOutButton.addEventListener("click", (event) => { logOutButton.addEventListener("click", () => {
window.location.replace("../logout/index.html") window.location.replace("/logout")
}); });
exitThing.addEventListener("click", (event) => { exitThing.addEventListener("click", () => {
optionsDiv.classList.add("hidden") optionsDiv.classList.add("hidden")
optionsCoverDiv.classList.add("hidden") optionsCoverDiv.classList.add("hidden")
}); });
deleteMyAccountButton.addEventListener("click", (event) => { deleteMyAccountButton.addEventListener("click", () => {
if (confirm("Are you REALLY sure that you want to delete your account? There's no going back!") == true) { if (confirm("Are you REALLY sure that you want to delete your account? There's no going back!") === true) {
fetch(remote + "/api/deleteaccount", { fetch(remote + "/api/deleteaccount", {
method: "POST", method: "POST",
body: JSON.stringify({ body: JSON.stringify({
@ -298,15 +262,15 @@ deleteMyAccountButton.addEventListener("click", (event) => {
} }
}) })
.then((response) => { .then((response) => {
if (response.status == 200) { if (response.status === 200) {
window.location.href = "../logout/index.html" window.location.href = "/logout"
} else { } else {
displayError("Failed to delete account (HTTP error code " + response.status + ")") displayError("Failed to delete account (HTTP error code " + response.status + ")")
} }
}) })
} }
}); });
sessionManagerButton.addEventListener("click", (event) => { sessionManagerButton.addEventListener("click", () => {
optionsDiv.classList.add("hidden") optionsDiv.classList.add("hidden")
sessionManagerDiv.classList.remove("hidden") sessionManagerDiv.classList.remove("hidden")
@ -323,13 +287,14 @@ sessionManagerButton.addEventListener("click", (event) => {
async function doStuff() { 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;
for (let i in responseData) { for (let i in responseData) {
let sessionElement = document.createElement("div") let sessionElement = document.createElement("div")
let sessionText = document.createElement("p") let sessionText = document.createElement("p")
let sessionImage = document.createElement("img") let sessionImage = document.createElement("img")
let sessionRemoveButton = document.createElement("button") let sessionRemoveButton = document.createElement("button")
sessionText.classList.add("w300") sessionText.classList.add("w300")
if (responseData[i]["thisSession"] == true) { if (responseData[i]["thisSession"] === true) {
sessionText.innerText = "(current) " + responseData[i]["device"] sessionText.innerText = "(current) " + responseData[i]["device"]
} else { } else {
sessionText.innerText = responseData[i]["device"] sessionText.innerText = responseData[i]["device"]
@ -344,11 +309,11 @@ sessionManagerButton.addEventListener("click", (event) => {
if (ua.includes("NT") || ua.includes("Linux")) { if (ua.includes("NT") || ua.includes("Linux")) {
sessionImage.src = "/static/svg/device_computer.svg" sessionImage.src = "/static/svg/device_computer.svg"
} }
if (ua.includes("iPhone" || ua.includes("Android") || ua.include("iPod"))) { if (ua.includes("iPhone" || ua.includes("Android") || ua.includes("iPod"))) {
sessionImage.src = "/static/svg/device_smartphone.svg" sessionImage.src = "/static/svg/device_smartphone.svg"
} }
sessionRemoveButton.addEventListener("click", (event) => { sessionRemoveButton.addEventListener("click", () => {
fetch(remote + "/api/sessions/remove", { fetch(remote + "/api/sessions/remove", {
method: "POST", method: "POST",
body: JSON.stringify({ body: JSON.stringify({
@ -359,9 +324,9 @@ sessionManagerButton.addEventListener("click", (event) => {
"Content-Type": "application/json; charset=UTF-8" "Content-Type": "application/json; charset=UTF-8"
} }
}) })
.then((response) => { .then(() => {
if (responseData[i]["thisSession"] == true) { if (responseData[i]["thisSession"] === true) {
window.location.replace("../logout/index.html") window.location.replace("/logout")
} }
}); });
sessionElement.remove() sessionElement.remove()
@ -379,7 +344,7 @@ sessionManagerButton.addEventListener("click", (event) => {
doStuff() doStuff()
}); });
}); });
exitSessionsThing.addEventListener("click", (event) => { exitSessionsThing.addEventListener("click", () => {
optionsDiv.classList.remove("hidden") optionsDiv.classList.remove("hidden")
sessionManagerDiv.classList.add("hidden") sessionManagerDiv.classList.add("hidden")
}); });
@ -388,15 +353,21 @@ updateUserInfo()
function updateWordCount() { function updateWordCount() {
let wordCount = noteBox.value.split(" ").length let wordCount = noteBox.value.split(" ").length
if (wordCount == 1) { if (wordCount === 1) {
wordCount = 0 wordCount = 0
} }
wordCountBox.innerText = wordCount + " words" wordCountBox.innerText = wordCount + " words"
} }
function renderMarkDown() {
if (markdowntoggle) {
markdown.srcdoc = "<!DOCTYPE html><html lang='en'><style>html { height: 100% } body { font-family: 'Inter', sans-serif; height: 100%; color: " + getComputedStyle(document.documentElement).getPropertyValue('--text-color') + "; font-size: " + currentFontSize + "px; }</style>" + marked.parse(noteBox.value) + "</html>"
}
}
function selectNote(nameithink) { function selectNote(nameithink) {
document.querySelectorAll(".noteButton").forEach((el) => el.classList.remove("selected")); document.querySelectorAll(".noteButton").forEach((el) => el.classList.remove("selected"));
let thingArray = Array.from(document.querySelectorAll(".noteButton")).find(el => el.id == nameithink); let thingArray = Array.from(document.querySelectorAll(".noteButton")).find(el => String(nameithink) === String(el.id));
thingArray.classList.add("selected") thingArray.classList.add("selected")
fetch(remote + "/api/readnote", { fetch(remote + "/api/readnote", {
@ -409,7 +380,7 @@ function selectNote(nameithink) {
"Content-Type": "application/json; charset=UTF-8" "Content-Type": "application/json; charset=UTF-8"
} }
}) })
.catch((error) => { .catch(() => {
noteBox.readOnly = true noteBox.readOnly = true
noteBox.value = "" noteBox.value = ""
noteBox.placeholder = "" noteBox.placeholder = ""
@ -424,17 +395,17 @@ function selectNote(nameithink) {
let responseData = await response.json() let responseData = await response.json()
let bytes = CryptoJS.AES.decrypt(responseData["content"], password); let bytes = CryptoJS.AES.decrypt(responseData["content"], password);
let originalText = bytes.toString(CryptoJS.enc.Utf8); noteBox.value = bytes.toString(CryptoJS.enc.Utf8)
noteBox.value = originalText
updateWordCount() updateWordCount()
renderMarkDown()
noteBox.addEventListener("input", (event) => { noteBox.addEventListener("input", () => {
updateWordCount() updateWordCount()
renderMarkDown()
clearTimeout(timer); clearTimeout(timer);
timer = setTimeout(() => { timer = setTimeout(() => {
let encryptedTitle = "New note" let encryptedTitle = "New note"
if (noteBox.value.substring(0, noteBox.value.indexOf("\n")) != "") { if (noteBox.value.substring(0, noteBox.value.indexOf("\n")) !== "") {
let firstTitle = noteBox.value.substring(0, noteBox.value.indexOf("\n")); let firstTitle = noteBox.value.substring(0, noteBox.value.indexOf("\n"));
document.getElementById(nameithink).innerText = firstTitle document.getElementById(nameithink).innerText = firstTitle
@ -442,7 +413,7 @@ function selectNote(nameithink) {
} }
let encryptedText = CryptoJS.AES.encrypt(noteBox.value, password).toString(); let encryptedText = CryptoJS.AES.encrypt(noteBox.value, password).toString();
if (selectedNote == nameithink) { if (selectedNote === nameithink) {
fetch(remote + "/api/editnote", { fetch(remote + "/api/editnote", {
method: "POST", method: "POST",
body: JSON.stringify({ body: JSON.stringify({
@ -456,11 +427,11 @@ function selectNote(nameithink) {
} }
}) })
.then((response) => { .then((response) => {
if (response.status == 418) { if (response.status === 418) {
displayError("You've ran out of storage... Changes will not be saved until you free up storage!") displayError("You've ran out of storage... Changes will not be saved until you free up storage!")
} }
}) })
.catch((error) => { .catch(() => {
displayError("Failed to save changes, please try again later...") displayError("Failed to save changes, please try again later...")
}) })
} }
@ -490,6 +461,7 @@ function updateNotes() {
noteBox.value = "" noteBox.value = ""
clearTimeout(timer) clearTimeout(timer)
updateWordCount() updateWordCount()
renderMarkDown()
let responseData = await response.json() let responseData = await response.json()
for (let i in responseData) { for (let i in responseData) {
@ -515,10 +487,10 @@ function updateNotes() {
"Content-Type": "application/json; charset=UTF-8" "Content-Type": "application/json; charset=UTF-8"
} }
}) })
.then((response) => { .then(() => {
updateNotes() updateNotes()
}) })
.catch((error) => { .catch(() => {
displayError("Something went wrong! Please try again later...") displayError("Something went wrong! Please try again later...")
}) })
} else { } else {
@ -534,9 +506,9 @@ function updateNotes() {
updateNotes() updateNotes()
newNote.addEventListener("click", (event) => { newNote.addEventListener("click", () => {
let noteName = "New note" let noteName = "New note"
let encryptedName = CryptoJS.AES.encrypt(noteName, password).toString(); let encryptedName = CryptoJS.AES.encrypt(noteName, password).toString(CryptoJS.enc.Utf8);
fetch(remote + "/api/newnote", { fetch(remote + "/api/newnote", {
method: "POST", method: "POST",
body: JSON.stringify({ body: JSON.stringify({
@ -547,7 +519,7 @@ newNote.addEventListener("click", (event) => {
"Content-Type": "application/json; charset=UTF-8" "Content-Type": "application/json; charset=UTF-8"
} }
}) })
.catch((error) => { .catch(() => {
displayError("Failed to create new note, please try again later...") displayError("Failed to create new note, please try again later...")
}) })
.then((response) => { .then((response) => {
@ -560,8 +532,8 @@ newNote.addEventListener("click", (event) => {
}); });
}); });
function downloadObjectAsJson(exportObj, exportName) { function downloadObjectAsJson(exportObj, exportName) {
var dataStr = "data:text/json;charset=utf-8," + encodeURIComponent(JSON.stringify(exportObj)); let dataStr = "data:text/json;charset=utf-8," + encodeURIComponent(JSON.stringify(exportObj));
var downloadAnchorNode = document.createElement("a"); let downloadAnchorNode = document.createElement("a");
downloadAnchorNode.setAttribute("href", dataStr); downloadAnchorNode.setAttribute("href", dataStr);
downloadAnchorNode.setAttribute("download", exportName + ".json"); downloadAnchorNode.setAttribute("download", exportName + ".json");
document.body.appendChild(downloadAnchorNode); document.body.appendChild(downloadAnchorNode);
@ -570,7 +542,6 @@ function downloadObjectAsJson(exportObj, exportName) {
} }
function exportNotes() { function exportNotes() {
let noteExport = []
fetch(remote + "/api/exportnotes", { fetch(remote + "/api/exportnotes", {
method: "POST", method: "POST",
body: JSON.stringify({ body: JSON.stringify({
@ -587,14 +558,10 @@ function exportNotes() {
exportNotes.innerText = "Decrypting " + i + "/" + noteCount exportNotes.innerText = "Decrypting " + i + "/" + noteCount
let bytes = CryptoJS.AES.decrypt(responseData[i]["title"], password); let bytes = CryptoJS.AES.decrypt(responseData[i]["title"], password);
let originalTitle = bytes.toString(CryptoJS.enc.Utf8); responseData[i]["title"] = bytes.toString(CryptoJS.enc.Utf8)
responseData[i]["title"] = originalTitle
let bytesd = CryptoJS.AES.decrypt(responseData[i]["content"], password); let bytesd = CryptoJS.AES.decrypt(responseData[i]["content"], password);
let originalContent = bytesd.toString(CryptoJS.enc.Utf8); responseData[i]["content"] = bytesd.toString(CryptoJS.enc.Utf8)
responseData[i]["content"] = originalContent
} }
let jsonString = JSON.parse(JSON.stringify(responseData)) let jsonString = JSON.parse(JSON.stringify(responseData))
@ -618,7 +585,7 @@ function isFirstTimeVisitor() {
} }
function firstNewVersion() { function firstNewVersion() {
if (localStorage.getItem("NEWVERSION") == "1.2") { if (localStorage.getItem("NEWVERSION") === "1.2") {
return false; return false;
} else { } else {
localStorage.setItem("NEWVERSION", "1.2") localStorage.setItem("NEWVERSION", "1.2")
@ -626,13 +593,25 @@ function firstNewVersion() {
} }
} }
exportNotesButton.addEventListener("click", (event) => { function toggleMarkdown() {
if (markdown.style.display === 'none') {
markdown.style.display = 'inherit';
markdowntoggle = true
renderMarkDown()
} else {
markdown.style.display = 'none';
markdowntoggle = false
markdown.srcdoc = ""
}
}
exportNotesButton.addEventListener("click", () => {
exportNotesButton.innerText = "Downloading..." exportNotesButton.innerText = "Downloading..."
exportNotes() exportNotes()
}); });
removeBox.addEventListener("click", (event) => { removeBox.addEventListener("click", () => {
if (selectedNote == 0) { if (selectedNote === 0) {
displayError("You need to select a note first!") displayError("You need to select a note first!")
} else { } else {
fetch(remote + "/api/removenote", { fetch(remote + "/api/removenote", {
@ -645,15 +624,19 @@ removeBox.addEventListener("click", (event) => {
"Content-Type": "application/json; charset=UTF-8" "Content-Type": "application/json; charset=UTF-8"
} }
}) })
.then((response) => { .then(() => {
updateNotes() updateNotes()
}) })
.catch((error) => { .catch(() => {
displayError("Something went wrong! Please try again later...") displayError("Something went wrong! Please try again later...")
}) })
} }
}); });
document.addEventListener("DOMContentLoaded", function() {
markdown.srcdoc = "<!DOCTYPE html><html lang='en'><style>html { height: 100% } body { font-family: 'Inter', sans-serif; height: 100%; color: " + getComputedStyle(document.documentElement).getPropertyValue('--text-color') + "; font-size: " + currentFontSize + "px; }</style>" + marked.parse(noteBox.value) + "</html>"
});
if (isFirstTimeVisitor() && /Android|iPhone|iPod/i.test(navigator.userAgent)) { if (isFirstTimeVisitor() && /Android|iPhone|iPod/i.test(navigator.userAgent)) {
displayError("To use Burgernotes:\n Swipe Right on a note to open it\n Swipe left in the text boxes to return to notes\n Click on a note to highlight it") displayError("To use Burgernotes:\n Swipe Right on a note to open it\n Swipe left in the text boxes to return to notes\n Click on a note to highlight it")
} }

1297
website/static/js/marked.js Normal file

File diff suppressed because it is too large Load Diff

View File

@ -1,10 +1,10 @@
if (localStorage.getItem("DONOTSHARE-secretkey") !== null) { if (localStorage.getItem("DONOTSHARE-secretkey") !== null) {
window.location.replace("../app/index.html") window.location.replace("/app/")
document.body.innerHTML = "Redirecting..." document.body.innerHTML = "Redirecting..."
throw new Error(); throw new Error();
} }
if (localStorage.getItem("DONOTSHARE-password") !== null) { if (localStorage.getItem("DONOTSHARE-password") !== null) {
window.location.replace("../app/index.html") window.location.replace("/app/")
document.body.innerHTML = "Redirecting..." document.body.innerHTML = "Redirecting..."
throw new Error(); throw new Error();
} }
@ -37,12 +37,12 @@ document.addEventListener('DOMContentLoaded', function() {
document.getElementById("homeserver").innerText = "Your homeserver is: " + remote + ". " document.getElementById("homeserver").innerText = "Your homeserver is: " + remote + ". "
}); });
signupButton.addEventListener("click", (event) => { signupButton.addEventListener("click", () => {
async function doStuff() { async function doStuff() {
let username = usernameBox.value let username = usernameBox.value
let password = passwordBox.value let password = passwordBox.value
if (username == "") { if (username === "") {
statusBox.innerText = "A username is required!" statusBox.innerText = "A username is required!"
return return
} }
@ -50,7 +50,7 @@ signupButton.addEventListener("click", (event) => {
statusBox.innerText = "Username cannot be more than 20 characters!" statusBox.innerText = "Username cannot be more than 20 characters!"
return return
} }
if (password == "") { if (password === "") {
statusBox.innerText = "A password is required!" statusBox.innerText = "A password is required!"
return return
} }
@ -68,7 +68,7 @@ signupButton.addEventListener("click", (event) => {
key = await hashwasm.sha3(key) key = await hashwasm.sha3(key)
} }
return key return key
}; }
fetch(remote + "/api/signup", { fetch(remote + "/api/signup", {
@ -86,14 +86,14 @@ signupButton.addEventListener("click", (event) => {
async function doStuff() { async function doStuff() {
let responseData = await response.json() let responseData = await response.json()
if (response.status == 200) { if (response.status === 200) {
statusBox.innerText == "redirecting.." statusBox.innerText = "Redirecting...."
localStorage.setItem("DONOTSHARE-secretkey", responseData["key"]) localStorage.setItem("DONOTSHARE-secretkey", responseData["key"])
localStorage.setItem("DONOTSHARE-password", await hashwasm.sha512(password)) localStorage.setItem("DONOTSHARE-password", await hashwasm.sha512(password))
window.location.href = "../app/index.html" window.location.href = "/app/"
} }
else if (response.status == 409) { else if (response.status === 409) {
statusBox.innerText = "Username already taken!" statusBox.innerText = "Username already taken!"
showElements(true) showElements(true)
} }

View File

@ -0,0 +1 @@
121