From c23a0935b08bfe942e976fc796662f6103bbf5e2 Mon Sep 17 00:00:00 2001 From: Dalia Alawneh Date: Sat, 22 Jul 2023 15:36:56 +0300 Subject: [PATCH 1/3] Refactor: Change var to let or const --- app.js | 6 +- client/js/account.js | 22 +- client/js/admin_similar_users.js | 2 +- client/js/admin_users.js | 4 +- client/js/mod_tools.js | 128 ++++---- client/js/place.js | 302 +++++++++---------- client/js/popout.js | 102 +++---- client/js/site.js | 58 ++-- controllers/AdminActionsController.js | 6 +- controllers/AuthController.js | 6 +- controllers/ChangelogController.js | 6 +- controllers/ChatController.js | 4 +- controllers/FeatureAvailabilityController.js | 2 +- controllers/ModeratorUserController.js | 18 +- controllers/PasswordChangeController.js | 4 +- controllers/PixelInfoController.js | 2 +- controllers/PlaceController.js | 12 +- controllers/TOTPSetupController.js | 4 +- models/access.js | 8 +- models/action.js | 6 +- models/chatMessage.js | 4 +- models/pixel.js | 12 +- models/report.js | 2 +- models/user.js | 46 +-- models/warp.js | 4 +- public/js/bootbox.min.js | 2 +- public/js/cookies-eu-banner.min.js | 2 +- public/js/jquery.confetti.js | 42 +-- routes/api.js | 2 +- scripts/migrate-ips.js | 2 +- scripts/resize.js | 2 +- util/ActionLogger.js | 4 +- util/ChangelogManager.js | 34 ++- util/DataModelManager.js | 18 +- util/HTTPServer.js | 8 +- util/JavaScriptProcessor.js | 4 +- util/LeaderboardManager.js | 14 +- util/ModuleManager.js | 52 ++-- util/PaintingManager.js | 16 +- util/ResponseFactory.js | 12 +- util/UserActivityManager.js | 6 +- util/logger.js | 6 +- util/passport.js | 2 +- views/admin/dashboard.pug | 4 +- views/admin/similar_users.pug | 4 +- views/admin/users.pug | 4 +- views/admin_layout.pug | 12 +- views/errors/404.pug | 2 +- views/errors/500.pug | 2 +- views/layout.pug | 16 +- views/public/account.pug | 20 +- views/public/deactivated.pug | 2 +- views/public/deleted.pug | 2 +- views/public/force-pw-reset.pug | 4 +- views/public/index.pug | 12 +- views/public/pick-username.pug | 4 +- views/public/popout.pug | 8 +- 57 files changed, 548 insertions(+), 546 deletions(-) diff --git a/app.js b/app.js index 03ede300..c1f1bc9d 100644 --- a/app.js +++ b/app.js @@ -18,13 +18,13 @@ const User = require("./models/user"); const fs = require("fs"); const path = require("path"); -var app = {}; +const app = {}; app.logger = require('./util/logger'); app.loadConfig = (path = "./config/config") => { delete require.cache[require.resolve(path)]; - var oldConfig = app.config; + const oldConfig = app.config; app.config = require(path); app.colours = [... new Set((app.config.colours || ["#FFFFFF", "#E4E4E4", "#888888", "#222222", "#FFA7D1", "#E50000", "#E59500", "#A06A42", "#E5D900", "#94E044", "#02BE01", "#00D3DD", "#0083C7", "#0000EA", "#CF6EE4", "#820080"]).map((c) => c.toUpperCase()))]; if(!app.config.siteName) app.config.siteName = "Place"; @@ -150,7 +150,7 @@ app.recreateRoutes = () => { app.recreateRoutes(); readline.on('line', i => { try { - var output = eval(i) + const output = eval(i) output instanceof Promise ? output.then(a => { console.log('Promise Resolved') diff --git a/client/js/account.js b/client/js/account.js index 5b4b8d79..4c2f9922 100644 --- a/client/js/account.js +++ b/client/js/account.js @@ -1,6 +1,6 @@ -var passwordProgressAlert = $("div[name=\"changePasswordProgressAlert\"]"); -var deactivateProgressAlert = $("div[name=\"deactivateAccountProgressAlert\"]"); -var enableTOTPAlert = $("div[name=\"enableTOTPAlert\"]"); +let passwordProgressAlert = $("div[name=\"changePasswordProgressAlert\"]"); +let deactivateProgressAlert = $("div[name=\"deactivateAccountProgressAlert\"]"); +let enableTOTPAlert = $("div[name=\"enableTOTPAlert\"]"); function setAlert(alert, success = true, text) { alert.attr("class", "").addClass(`alert alert-${success ? "success" : "danger"}`).html(`${success ? "Success!" : "Uh oh!"} ${text || "An unknown error occurred."}`); @@ -8,9 +8,9 @@ function setAlert(alert, success = true, text) { $("form#changePasswordForm").submit(function (e) { e.preventDefault(); - var oPassword = $(this).find("input[name=\"password\"]").val(); - var nPassword = $(this).find("input[name=\"newPassword\"]").val(); - var nCPassword = $(this).find("input[name=\"newConfPassword\"]").val(); + let oPassword = $(this).find("input[name=\"password\"]").val(); + let nPassword = $(this).find("input[name=\"newPassword\"]").val(); + let nCPassword = $(this).find("input[name=\"newConfPassword\"]").val(); if (oPassword == "" || nPassword == "" || nCPassword == "") return setAlert(passwordProgressAlert, false, "Please fill out all the fields."); if (nPassword !== nCPassword) return setAlert(passwordProgressAlert, false, "The passwords you entered did not match."); @@ -23,7 +23,7 @@ const passwordField = $("#deactivateAccount").find("input[name=\"password\"]"); $("#deactivateButton").click(function(e) { e.preventDefault(); - var password = passwordField.val(); + let password = passwordField.val(); if (password == "") return setAlert(deactivateProgressAlert, false, "Please enter your password."); placeAjax.post("/api/user/deactivate", { password: password }, null).then((response) => { window.location.href = "/deactivated"; @@ -32,7 +32,7 @@ $("#deactivateButton").click(function(e) { $("#deleteButton").click(function(e) { e.preventDefault(); - var password = passwordField.val(); + let password = passwordField.val(); if (password == "") return setAlert(deactivateProgressAlert, false, "Please enter your password."); placeAjax.delete("/api/user", { password: password }, null).then((response) => { window.location.href = "/deleted"; @@ -40,7 +40,7 @@ $("#deleteButton").click(function(e) { }); $("#disableTwoFactorAuth").click(function () { - var elem = $(this).addClass("disabled"); + let elem = $(this).addClass("disabled"); placeAjax.delete("/api/user/totp-setup", null, "An unknown error occurred while trying to disable two-factor authentication.", () => { elem.removeClass("disabled"); }).then((response) => { @@ -50,7 +50,7 @@ $("#disableTwoFactorAuth").click(function () { $("form#enableTOTPForm").submit(function (e) { e.preventDefault(); - var submitBtn = $(this).find("button[type=submit]").text("Verifying").addClass("disabled"); + let submitBtn = $(this).find("button[type=submit]").text("Verifying").addClass("disabled"); placeAjax.post("/api/user/totp-setup", $(this).serialize(), null, () => { submitBtn.text("Verify").removeClass("disabled"); }).then((response) => { @@ -59,7 +59,7 @@ $("form#enableTOTPForm").submit(function (e) { }); $("#enableTwoFactorAuth").click(function () { - var elem = $(this).addClass("disabled"); + let elem = $(this).addClass("disabled"); placeAjax.get("/api/user/totp-setup", null, "An unknown error occurred while trying to load two-factor authentication setup.", () => { elem.removeClass("disabled"); }).then((response) => { diff --git a/client/js/admin_similar_users.js b/client/js/admin_similar_users.js index 76808733..63b6168b 100644 --- a/client/js/admin_similar_users.js +++ b/client/js/admin_similar_users.js @@ -1,6 +1,6 @@ $(document).ready(function() { $(".timeago").timeago(); - var getUserRow = function(user, relationString) { + let getUserRow = function(user, relationString) { return `