From 66e3f29f4f6fc81e72afac6648d28e22b96b43b0 Mon Sep 17 00:00:00 2001 From: fatchan Date: Wed, 1 Jan 2020 03:33:19 +0100 Subject: [PATCH] same improvements to timeutils as in frontend, and remove old method of showing ban with document write --- gulp/res/js/forms.js | 9 +-------- gulp/res/js/quote.js | 4 ++++ helpers/timeutils.js | 10 ++++++++-- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/gulp/res/js/forms.js b/gulp/res/js/forms.js index 5a25a980..4f720c4a 100644 --- a/gulp/res/js/forms.js +++ b/gulp/res/js/forms.js @@ -10,13 +10,6 @@ function doModal(data) { document.getElementsByClassName('modal-bg')[0].onclick = removeModal; } -function doTextResponse(text, url) { - window.history.pushState({}, null, url); - document.open('text/html', true); - document.write(text); - document.close(); -} - const checkTypes = ['checkbox', 'radio']; function isCheckBox(element) { return checkTypes.includes(element.type) @@ -143,7 +136,7 @@ class formHandler { if (json) { doModal(json); } else { - //for bans, post form to show +//for bans, post form to show TODO: make modal support bans json and send dynamicresponse from it this.clearFiles(); //dont resubmit files this.banned = true; this.form.dispatchEvent(new Event('submit')); diff --git a/gulp/res/js/quote.js b/gulp/res/js/quote.js index a62c54a0..81fe5c07 100644 --- a/gulp/res/js/quote.js +++ b/gulp/res/js/quote.js @@ -9,6 +9,10 @@ window.addEventListener('DOMContentLoaded', (event) => { messageBox.scrollTop = messageBox.scrollHeight; messageBox.focus(); messageBox.setSelectionRange(messageBox.value.length, messageBox.value.length); + const quotingPost = document.getElementById(number); + if (quotingPost) { + quotingPost.scrollIntoView(); + } } const quote = function(e) { diff --git a/helpers/timeutils.js b/helpers/timeutils.js index 9fc45944..d11065ef 100644 --- a/helpers/timeutils.js +++ b/helpers/timeutils.js @@ -21,6 +21,11 @@ module.exports = { const difference = now.getTime() - relativeTo.getTime(); let amount = 0; let ret = ''; + let isFuture = false; + if (difference < 0) { + difference = Math.abs(difference); + isFuture = true; + } if (difference < MINUTE) { return 'Now'; } else if (difference < MINUTE*59.5) { @@ -39,9 +44,10 @@ module.exports = { amount = Math.round(difference / MONTH); ret += `${amount} month`; } else { - return 'More than a year ago'; + amount = Math.round(difference / YEAR); + ret = `${amount} year`; } - return `${ret}${amount > 1 ? 's' : ''} ago`; + return `${ret}${amount > 1 ? 's' : ''} ${isFuture ? 'from now' : 'ago'}`; }, 'relativeColor': (now, relativeTo) => {