Follow JS errors from Deepsource

Remove jsmin as it breaks code
This commit is contained in:
Michał Gdula 2023-04-19 17:55:41 +00:00
parent dc7f1ff1d4
commit 0cc5f70e4f
4 changed files with 50 additions and 55 deletions

View file

@ -106,7 +106,7 @@ def create_app(): # pylint: disable=R0914
# ASSETS # ASSETS
assets.init_app(app) assets.init_app(app)
scripts = Bundle("js/*.js", filters="jsmin", output="gen/js.js", depends="js/*.js") scripts = Bundle("js/*.js", output="gen/js.js", depends="js/*.js") # filter jsmin is broken :c
styles = Bundle( styles = Bundle(
"sass/*.sass", "sass/*.sass",
filters="libsass, cssmin", filters="libsass, cssmin",

View file

@ -12,9 +12,9 @@ function loadOnView() {
let image = lazyLoad[i]; let image = lazyLoad[i];
if (image.getBoundingClientRect().top < window.innerHeight && image.getBoundingClientRect().bottom > 0) { if (image.getBoundingClientRect().top < window.innerHeight && image.getBoundingClientRect().bottom > 0) {
if (!image.src && webpSupport) { if (!image.src && webpSupport) {
image.src = image.getAttribute('data-src') + '&e=webp' image.src = `${image.getAttribute('data-src')}&e=webp`;
} else if (!image.src) { } else if (!image.src) {
image.src = image.getAttribute('data-src') image.src = image.getAttribute('data-src');
} }
} }
} }
@ -23,27 +23,24 @@ function loadOnView() {
window.onload = function () { window.onload = function () {
loadOnView(); loadOnView();
let times = document.querySelectorAll('.time'); const times = document.querySelectorAll('.time');
for (let i = 0; i < times.length; i++) { for (let i = 0; i < times.length; i++) {
// Remove milliseconds // Remove milliseconds
const raw = times[i].innerHTML.split('.')[0]; const raw = times[i].innerHTML.split('.')[0];
// Parse YYYY-MM-DD HH:MM:SS to Date object // Parse YYYY-MM-DD HH:MM:SS to Date object
const time = raw.split(' ')[1] const time = raw.split(' ')[1];
const date = raw.split(' ')[0].split('-'); const date = raw.split(' ')[0].split('-');
// Format to YYYY/MM/DD HH:MM:SS // Format to YYYY/MM/DD HH:MM:SS and convert to UTC Date object
let formatted = date[0] + '/' + date[1] + '/' + date[2] + ' ' + time + ' UTC'; const dateTime = new Date(`${date[0]}/${date[1]}/${date[2]} ${time} UTC`);
// Convert to UTC Date object
let dateTime = new Date(formatted);
// Convert to local time // Convert to local time
times[i].innerHTML = dateTime.toLocaleDateString() + ' ' + dateTime.toLocaleTimeString(); times[i].innerHTML = `${dateTime.toLocaleDateString()} ${dateTime.toLocaleTimeString()}`;
} }
// Top Of Page button // Top Of Page button
let topOfPage = document.querySelector('.top-of-page'); const topOfPage = document.querySelector('.top-of-page');
if (document.body.scrollTop > 300 || document.documentElement.scrollTop > 20) { if (document.body.scrollTop > 300 || document.documentElement.scrollTop > 20) {
topOfPage.classList.add('show'); topOfPage.classList.add('show');
} else { } else {
@ -55,8 +52,7 @@ window.onload = function () {
} }
// Info button // Info button
let infoButton = document.querySelector('.info-button'); const infoButton = document.querySelector('.info-button');
if (infoButton) { if (infoButton) {
if (document.body.scrollTop > 300 || document.documentElement.scrollTop > 20) { if (document.body.scrollTop > 300 || document.documentElement.scrollTop > 20) {
infoButton.classList.remove('show'); infoButton.classList.remove('show');
@ -75,7 +71,7 @@ window.onscroll = function () {
loadOnView(); loadOnView();
// Top Of Page button // Top Of Page button
let topOfPage = document.querySelector('.top-of-page'); const topOfPage = document.querySelector('.top-of-page');
if (document.body.scrollTop > 300 || document.documentElement.scrollTop > 20) { if (document.body.scrollTop > 300 || document.documentElement.scrollTop > 20) {
topOfPage.classList.add('show'); topOfPage.classList.add('show');
} else { } else {
@ -83,8 +79,7 @@ window.onscroll = function () {
} }
// Info button // Info button
let infoButton = document.querySelector('.info-button'); const infoButton = document.querySelector('.info-button');
if (infoButton) { if (infoButton) {
if (document.body.scrollTop > 300 || document.documentElement.scrollTop > 20) { if (document.body.scrollTop > 300 || document.documentElement.scrollTop > 20) {
infoButton.classList.remove('show'); infoButton.classList.remove('show');

View file

@ -62,9 +62,9 @@ function login(event) {
// AJAX takes control of subby form :3 // AJAX takes control of subby form :3
event.preventDefault(); event.preventDefault();
let formUsername = document.querySelector("#username").value; const formUsername = document.querySelector("#username").value;
let formPassword = document.querySelector("#password").value; const formPassword = document.querySelector("#password").value;
let formRememberMe = document.querySelector("#remember-me").checked; const formRememberMe = document.querySelector("#remember-me").checked;
if (formUsername === "" || formPassword === "") { if (formUsername === "" || formPassword === "") {
addNotification("Please fill in all fields!!!!", 3); addNotification("Please fill in all fields!!!!", 3);
@ -158,10 +158,10 @@ function register(event) {
// AJAX takes control of subby form // AJAX takes control of subby form
event.preventDefault(); event.preventDefault();
let formUsername = document.querySelector("#username").value; const formUsername = document.querySelector("#username").value;
let formEmail = document.querySelector("#email").value; const formEmail = document.querySelector("#email").value;
let formPassword = document.querySelector("#password").value; const formPassword = document.querySelector("#password").value;
let formPasswordRepeat = document.querySelector("#password-repeat").value; const formPasswordRepeat = document.querySelector("#password-repeat").value;
if (formUsername === "" || formEmail === "" || formPassword === "" || formPasswordRepeat === "") { if (formUsername === "" || formEmail === "" || formPassword === "" || formPasswordRepeat === "") {
addNotification("Please fill in all fields!!!!", 3); addNotification("Please fill in all fields!!!!", 3);

View file

@ -9,7 +9,7 @@ window.addEventListener("drop", (event) => {
// open upload tab // open upload tab
function openUploadTab() { function openUploadTab() {
let uploadTab = document.querySelector(".upload-panel"); const uploadTab = document.querySelector(".upload-panel");
// Stop scrolling and open upload tab // Stop scrolling and open upload tab
document.querySelector("html").style.overflow = "hidden"; document.querySelector("html").style.overflow = "hidden";
@ -19,8 +19,8 @@ function openUploadTab() {
// close upload tab // close upload tab
function closeUploadTab() { function closeUploadTab() {
let uploadTab = document.querySelector(".upload-panel"); const uploadTab = document.querySelector(".upload-panel");
let uploadTabContainer = document.querySelector(".upload-panel .container"); const uploadTabContainer = document.querySelector(".upload-panel .container");
// un-Stop scrolling and close upload tab // un-Stop scrolling and close upload tab
document.querySelector("html").style.overflow = "auto"; document.querySelector("html").style.overflow = "auto";
@ -35,7 +35,7 @@ function closeUploadTab() {
// toggle upload tab // toggle upload tab
function toggleUploadTab() { function toggleUploadTab() {
let uploadTab = document.querySelector(".upload-panel"); const uploadTab = document.querySelector(".upload-panel");
if (uploadTab.classList.contains("open")) { if (uploadTab.classList.contains("open")) {
closeUploadTab(); closeUploadTab();
@ -47,8 +47,8 @@ function toggleUploadTab() {
function tabDragStart(event) { function tabDragStart(event) {
event.preventDefault(); event.preventDefault();
let uploadTab = document.querySelector(".upload-panel .container"); const uploadTab = document.querySelector(".upload-panel .container");
let offset = uploadTab.getBoundingClientRect().y; const offset = uploadTab.getBoundingClientRect().y;
uploadTab.classList.add("dragging"); uploadTab.classList.add("dragging");
@ -67,7 +67,7 @@ function tabDragStart(event) {
function tabDragStopped(event) { function tabDragStopped(event) {
event.preventDefault(); event.preventDefault();
let uploadTab = document.querySelector(".upload-panel .container"); const uploadTab = document.querySelector(".upload-panel .container");
uploadTab.classList.remove("dragging"); uploadTab.classList.remove("dragging");
@ -85,16 +85,16 @@ function tabDragStopped(event) {
function fileActivate(event) { function fileActivate(event) {
event.preventDefault() event.preventDefault()
let fileDrop = document.querySelector('.fileDrop-block'); const fileDrop = document.querySelector('.fileDrop-block');
let fileDropTitle = fileDrop.querySelector('.status'); const fileDropTitle = fileDrop.querySelector('.status');
fileDrop.classList.remove('error'); fileDrop.classList.remove('error');
fileDrop.classList.add('edging'); fileDrop.classList.add('edging');
fileDropTitle.innerHTML = 'Drop to upload!'; fileDropTitle.innerHTML = 'Drop to upload!';
} }
function fileDefault() { function fileDefault() {
let fileDrop = document.querySelector('.fileDrop-block'); const fileDrop = document.querySelector('.fileDrop-block');
let fileDropTitle = fileDrop.querySelector('.status'); const fileDropTitle = fileDrop.querySelector('.status');
fileDrop.classList.remove('error'); fileDrop.classList.remove('error');
fileDrop.classList.remove('edging'); fileDrop.classList.remove('edging');
@ -104,8 +104,8 @@ function fileDefault() {
function fileDropHandle(event) { function fileDropHandle(event) {
event.preventDefault() event.preventDefault()
let fileDrop = document.querySelector('.fileDrop-block'); const fileDrop = document.querySelector('.fileDrop-block');
let fileUpload = fileDrop.querySelector('#file'); const fileUpload = fileDrop.querySelector('#file');
fileUpload.files = event.dataTransfer.files; fileUpload.files = event.dataTransfer.files;
@ -114,9 +114,9 @@ function fileDropHandle(event) {
} }
function fileChanged() { function fileChanged() {
let dropBlock = document.querySelector('.fileDrop-block'); const dropBlock = document.querySelector('.fileDrop-block');
let dropBlockStatus = dropBlock.querySelector('.status'); const dropBlockStatus = dropBlock.querySelector('.status');
let dropBlockInput = dropBlock.querySelector('#file'); const dropBlockInput = dropBlock.querySelector('#file');
if (dropBlockInput.value !== "") { if (dropBlockInput.value !== "") {
dropBlock.classList.add('active'); dropBlock.classList.add('active');
@ -127,12 +127,12 @@ function fileChanged() {
} }
function clearUpload() { function clearUpload() {
let fileDrop = document.querySelector('#uploadForm'); const fileDrop = document.querySelector('#uploadForm');
let fileUpload = fileDrop.querySelector('#file'); const fileUpload = fileDrop.querySelector('#file');
let fileAlt = fileDrop.querySelector('#alt'); const fileAlt = fileDrop.querySelector('#alt');
let fileDescription = fileDrop.querySelector('#description'); const fileDescription = fileDrop.querySelector('#description');
let fileTags = fileDrop.querySelector('#tags'); const fileTags = fileDrop.querySelector('#tags');
fileUpload.value = ""; fileUpload.value = "";
fileAlt.value = ""; fileAlt.value = "";
@ -169,21 +169,21 @@ function clearUpload() {
document.addEventListener('DOMContentLoaded', () => { document.addEventListener('DOMContentLoaded', () => {
// Function to upload images // Function to upload images
let uploadTab = document.querySelector(".upload-panel"); const uploadTab = document.querySelector(".upload-panel");
if (!uploadTab) { return; } // If upload tab doesn't exist, don't run this code :3 if (!uploadTab) { return; } // If upload tab doesn't exist, don't run this code :3
let uploadTabDrag = uploadTab.querySelector("#dragIndicator"); const uploadTabDrag = uploadTab.querySelector("#dragIndicator");
let uploadForm = uploadTab.querySelector('#uploadForm'); const uploadForm = uploadTab.querySelector('#uploadForm');
// let jobList = document.querySelector(".upload-jobs"); // let jobList = document.querySelector(".upload-jobs");
let fileDrop = uploadForm.querySelector('.fileDrop-block'); const fileDrop = uploadForm.querySelector('.fileDrop-block');
let fileDropTitle = fileDrop.querySelector('.status'); const fileDropTitle = fileDrop.querySelector('.status');
let fileUpload = fileDrop.querySelector('#file'); const fileUpload = fileDrop.querySelector('#file');
let fileAlt = uploadForm.querySelector('#alt'); const fileAlt = uploadForm.querySelector('#alt');
let fileDescription = uploadForm.querySelector('#description'); const fileDescription = uploadForm.querySelector('#description');
let fileTags = uploadForm.querySelector('#tags'); const fileTags = uploadForm.querySelector('#tags');
clearUpload(); clearUpload();
@ -221,7 +221,7 @@ document.addEventListener('DOMContentLoaded', () => {
} }
// Make form // Make form
let formData = new FormData(); const formData = new FormData();
formData.append("file", fileUpload.files[0]); formData.append("file", fileUpload.files[0]);
formData.append("alt", fileAlt.value); formData.append("alt", fileAlt.value);