/* returns a relative date format, e.g. "5 minutes" */ function timeSince(date) { // taken from https://stackoverflow.com/a/3177838/3678023 var seconds = Math.floor((new Date() - date) / 1000); var interval = Math.floor(seconds / 31536000); if (interval > 1) return interval + " years"; interval = Math.floor(seconds / 2592000); if (interval > 1) return interval + " months"; interval = Math.floor(seconds / 86400); if (interval > 1) return interval + " days"; interval = Math.floor(seconds / 3600); if (interval > 1) return interval + " hours"; interval = Math.floor(seconds / 60); if (interval > 1) return interval + " minutes"; return Math.floor(seconds) + " seconds"; } /* replace all instances of string */ String.prototype.replaceAll = function(search, replacement) { // taken from https://stackoverflow.com/a/17606289/3678023 var target = this; return target.split(search).join(replacement); }; /* sanitizes HTML in a string */ function encodeHTML(html) { return String(html).replace(/&/g, '&').replace(//g, '>').replace(/"/g, '"'); } /* URL encodes a string */ function encodeURL(url) { return encodeURIComponent(url); } /* user class */ class User { constructor() { this.name = 'Unknown'; this.id = 'unknown'; this.image = 'img/default.png'; } setName(name) { this.name = name; } getName() { return this.name; } setID(id) { this.id = id; } getID() { return this.id; } setIcon(image) { this.image = image; } getIcon() { return this.image; } } /* post class */ class Post { /* returns the html content of a post */ getHTML() { var postTemplate = '\