summaryrefslogtreecommitdiff
path: root/public
diff options
context:
space:
mode:
authorJules Laplace <julescarbon@gmail.com>2022-01-12 14:22:26 +0100
committerJules Laplace <julescarbon@gmail.com>2022-01-12 14:22:26 +0100
commit438a8a83f0a816fecc64ebcf3c18b7d6b6822bc4 (patch)
treefedb9e919ce9fac517dbff38cc43aac4a76c3f0d /public
parentb3d8c90e85d2122d06804c802967ae054359ef22 (diff)
is_image
Diffstat (limited to 'public')
-rw-r--r--public/assets/js/util/format.js511
1 files changed, 297 insertions, 214 deletions
diff --git a/public/assets/js/util/format.js b/public/assets/js/util/format.js
index d868ddd..6a23430 100644
--- a/public/assets/js/util/format.js
+++ b/public/assets/js/util/format.js
@@ -1,279 +1,362 @@
-var is_iphone = (navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i))
-var is_ipad = (navigator.userAgent.match(/iPad/i))
-var is_android = (navigator.userAgent.match(/Android/i))
-var is_mobile = is_iphone || is_ipad || is_android
-var is_desktop = ! is_mobile;
-document.body.classList.add(is_desktop ? 'desktop' : 'mobile');
+var is_iphone =
+ navigator.userAgent.match(/iPhone/i) || navigator.userAgent.match(/iPod/i);
+var is_ipad = navigator.userAgent.match(/iPad/i);
+var is_android = navigator.userAgent.match(/Android/i);
+var is_mobile = is_iphone || is_ipad || is_android;
+var is_desktop = !is_mobile;
+document.body.classList.add(is_desktop ? "desktop" : "mobile");
-function choice(a){ return a[randint(a.length)] }
+function choice(a) {
+ return a[randint(a.length)];
+}
function csrf() {
- return $("[name=_csrf]").attr("value")
+ return $("[name=_csrf]").attr("value");
}
-function bold_terms (s, terms) {
- s = sanitizeHTML(s)
- terms.forEach( (term) => {
- s = s.replace(new RegExp(term, "ig"), "<b>" + term + "</b>")
- })
- return s
+function bold_terms(s, terms) {
+ s = sanitizeHTML(s);
+ terms.forEach((term) => {
+ s = s.replace(new RegExp(term, "ig"), "<b>" + term + "</b>");
+ });
+ return s;
}
-function querystring(opt){
- return '?' + Object.keys(opt).map((key) => {
- return encodeURIComponent(key) + "=" + encodeURIComponent(opt[key])
- }).join("&")
+function querystring(opt) {
+ return (
+ "?" +
+ Object.keys(opt)
+ .map((key) => {
+ return encodeURIComponent(key) + "=" + encodeURIComponent(opt[key]);
+ })
+ .join("&")
+ );
}
-function commatize (n, radix) {
- radix = radix || 1000
- var nums = [], i, counter = 0, r = Math.floor
+function commatize(n, radix) {
+ radix = radix || 1000;
+ var nums = [],
+ i,
+ counter = 0,
+ r = Math.floor;
if (radix !== -1 && n > radix) {
- n /= radix
- nums.unshift(r((n * 10) % 10))
- nums.unshift(".")
+ n /= radix;
+ nums.unshift(r((n * 10) % 10));
+ nums.unshift(".");
}
do {
- i = r(n % 10)
- n = r(n / 10)
- counter += 1
- if (n && ! (counter % 3))
- { i = ' ' + r(i) }
- nums.unshift(i)
- }
- while (n)
- return nums.join("")
+ i = r(n % 10);
+ n = r(n / 10);
+ counter += 1;
+ if (n && !(counter % 3)) {
+ i = " " + r(i);
+ }
+ nums.unshift(i);
+ } while (n);
+ return nums.join("");
}
-function privacy_dot (p) {
- if (! p) return "&middot;"
- else return ".:"
+function privacy_dot(p) {
+ if (!p) return "&middot;";
+ else return ".:";
}
-var short_months = "Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec".split(" ")
-function verbose_date (date, no_pad_hours) {
- var date = new Date(date * 1000)
- var d = date.getDate()
- var m = date.getMinutes()
- var h = date.getHours()
- var meridian
+var short_months = "Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec".split(" ");
+function verbose_date(date, no_pad_hours) {
+ var date = new Date(date * 1000);
+ var d = date.getDate();
+ var m = date.getMinutes();
+ var h = date.getHours();
+ var meridian;
- if (h == 0) {
- h = 12
- meridian = "&nbsp;am"
+ if (h == 0) {
+ h = 12;
+ meridian = "&nbsp;am";
+ } else if (h == 12) {
+ meridian = "&nbsp;pm";
+ } else if (h > 12) {
+ h -= 12;
+ meridian = "&nbsp;pm";
+ } else {
+ meridian = "&nbsp;am";
}
- else if (h == 12) {
- meridian = "&nbsp;pm"
- }
- else if (h > 12) {
- h -= 12
- meridian = "&nbsp;pm"
- }
- else {
- meridian = "&nbsp;am"
- }
- if (d < 10) d = "0" + d
- if (m < 10) m = "0" + m
- if (! no_pad_hours && h < 10) h = "0" + h
+ if (d < 10) d = "0" + d;
+ if (m < 10) m = "0" + m;
+ if (!no_pad_hours && h < 10) h = "0" + h;
// non-breaking hyphen: &#8209;
- var date = d + '&nbsp;' + short_months[date.getMonth()] + '&nbsp;' + date.getFullYear()
- var time = h + ':' + m + meridian
+ var date =
+ d +
+ "&nbsp;" +
+ short_months[date.getMonth()] +
+ "&nbsp;" +
+ date.getFullYear();
+ var time = h + ":" + m + meridian;
- return [date, time]
+ return [date, time];
}
-function carbon_date (date, no_bold) {
- var span = (+new Date() / 1000 - date)
- if (! no_bold && span < 86400) // modified today
- { color = "new" }
- else if (span < 604800) // modifed this week
- { color = "recent" }
- else if (span < 1209600) // modifed 2 weeks ago
- { color = "med" }
- else if (span < 3024000) // modifed 5 weeks ago
- { color = "old" }
- else if (span < 12315200) // modifed 6 months ago
- { color = "older" }
- else
- { color = "quiet" }
- return color
+function carbon_date(date, no_bold) {
+ var span = +new Date() / 1000 - date;
+ if (!no_bold && span < 86400) {
+ // modified today
+ color = "new";
+ } else if (span < 604800) {
+ // modifed this week
+ color = "recent";
+ } else if (span < 1209600) {
+ // modifed 2 weeks ago
+ color = "med";
+ } else if (span < 3024000) {
+ // modifed 5 weeks ago
+ color = "old";
+ } else if (span < 12315200) {
+ // modifed 6 months ago
+ color = "older";
+ } else {
+ color = "quiet";
+ }
+ return color;
}
-function hush_views (n, bias, no_bold) {
- var txt = commatize(n, 1000)
- bias = bias || 1
- n = n || 0
- if (n < 30) { return["quiet", n + "&nbsp;v."] }
- if (n < 200) { return ["quiet", txt + "&nbsp;v."] }
- else if (n < 500) { return ["old", txt + "&nbsp;v."] }
- else if (n < 1000) { return ["med", txt + "&nbsp;v."] }
- else if (n < 5000) { return ["recent", txt + "&nbsp;kv."] }
- else if (no_bold || n < 10000) { return ["recent", txt + "&nbsp;kv."] }
- else { return ["new", txt + "&nbsp;kv."] }
+function hush_views(n, bias, no_bold) {
+ var txt = commatize(n, 1000);
+ bias = bias || 1;
+ n = n || 0;
+ if (n < 30) {
+ return ["quiet", n + "&nbsp;v."];
+ }
+ if (n < 200) {
+ return ["quiet", txt + "&nbsp;v."];
+ } else if (n < 500) {
+ return ["old", txt + "&nbsp;v."];
+ } else if (n < 1000) {
+ return ["med", txt + "&nbsp;v."];
+ } else if (n < 5000) {
+ return ["recent", txt + "&nbsp;kv."];
+ } else if (no_bold || n < 10000) {
+ return ["recent", txt + "&nbsp;kv."];
+ } else {
+ return ["new", txt + "&nbsp;kv."];
+ }
}
-function hush_threads (n, bias, no_bold) {
- var txt = commatize(n, -1)
- bias = bias || 1
- n = n || 0
- if (n < 10) { return["quiet", n + "&nbsp;t."] }
- else if (n < 25) { return ["old", txt + "&nbsp;t."] }
- else if (n < 50) { return ["med", txt + "&nbsp;t."] }
- else if (no_bold || n < 100) { return ["recent", txt + "&nbsp;t."] }
- else { return ["new", txt + "&nbsp;t."] }
+function hush_threads(n, bias, no_bold) {
+ var txt = commatize(n, -1);
+ bias = bias || 1;
+ n = n || 0;
+ if (n < 10) {
+ return ["quiet", n + "&nbsp;t."];
+ } else if (n < 25) {
+ return ["old", txt + "&nbsp;t."];
+ } else if (n < 50) {
+ return ["med", txt + "&nbsp;t."];
+ } else if (no_bold || n < 100) {
+ return ["recent", txt + "&nbsp;t."];
+ } else {
+ return ["new", txt + "&nbsp;t."];
+ }
}
-function hush_size (n, bias, no_bold) {
- var txt = commatize(Math.floor(n / 1024), 1000)
- bias = 1 || bias
- n = n || 0
+function hush_size(n, bias, no_bold) {
+ var txt = commatize(Math.floor(n / 1024), 1000);
+ bias = 1 || bias;
+ n = n || 0;
if (n < 1024) {
- return ["quiet", n + "&nbsp;b."]
+ return ["quiet", n + "&nbsp;b."];
}
- if (n < 1000*1000) {
- return ["quiet", txt + "&nbsp;kb."]
+ if (n < 1000 * 1000) {
+ return ["quiet", txt + "&nbsp;kb."];
}
- if (n < (20000000/bias)) {
- return ["quiet", txt + "&nbsp;mb."]
+ if (n < 20000000 / bias) {
+ return ["quiet", txt + "&nbsp;mb."];
}
- if (n < (50000000/bias)) {
- return ["old", txt + "&nbsp;mb."]
+ if (n < 50000000 / bias) {
+ return ["old", txt + "&nbsp;mb."];
}
- if (n < (80000000/bias)) {
- return ["med", txt + "&nbsp;mb."]
+ if (n < 80000000 / bias) {
+ return ["med", txt + "&nbsp;mb."];
}
- if (no_bold || n < (170000000/bias)) {
- return ["recent", txt + "&nbsp;mb."]
+ if (no_bold || n < 170000000 / bias) {
+ return ["recent", txt + "&nbsp;mb."];
}
- if (n >= 10000*1000*1000) {
- console.log(n)
- txt = commatize(Math.floor(n / (1024 * 1024 * 1024)))
- return ["new", txt + "&nbsp;gb."]
+ if (n >= 10000 * 1000 * 1000) {
+ console.log(n);
+ txt = commatize(Math.floor(n / (1024 * 1024 * 1024)));
+ return ["new", txt + "&nbsp;gb."];
}
- return ["new", txt + "&nbsp;mb."]
+ return ["new", txt + "&nbsp;mb."];
}
-function hush_null (n, unit, no_bold) {
- n = commatize(n, -1)
- var s = unit ? n + "&nbsp;" + unit + "." : n
+function hush_null(n, unit, no_bold) {
+ n = commatize(n, -1);
+ var s = unit ? n + "&nbsp;" + unit + "." : n;
if (n < 3) {
- return ["quiet", s]
- }
- else if (n < 6) {
- return ["older", s]
- }
- else if (n < 10) {
- return ["old", s]
- }
- else if (n < 16) {
- return ["med", s]
- }
- else if (no_bold || n < 21) {
- return ["recent", s]
- }
- else {
- return ["new", s]
+ return ["quiet", s];
+ } else if (n < 6) {
+ return ["older", s];
+ } else if (n < 10) {
+ return ["old", s];
+ } else if (n < 16) {
+ return ["med", s];
+ } else if (no_bold || n < 21) {
+ return ["recent", s];
+ } else {
+ return ["new", s];
}
}
-function courtesy_s (n, s) { return n == 1 ? "" : (s || "s") }
+function courtesy_s(n, s) {
+ return n == 1 ? "" : s || "s";
+}
-var revision_letters = "z a b c d f g h j k l m n p q r s t v w x y".split(" ")
-function get_revision (thread) {
- if (! thread.revision) return ""
- var rev = thread.revision
- var n = 0
- var digits = ""
+var revision_letters = "z a b c d f g h j k l m n p q r s t v w x y".split(" ");
+function get_revision(thread) {
+ if (!thread.revision) return "";
+ var rev = thread.revision;
+ var n = 0;
+ var digits = "";
do {
- n = rev % 21
- rev = Math.floor(rev / 21)
- digits = revision_letters[n] + digits
- }
- while (rev !== 0)
- return digits
+ n = rev % 21;
+ rev = Math.floor(rev / 21);
+ digits = revision_letters[n] + digits;
+ } while (rev !== 0);
+ return digits;
}
-function get_age (t, long) {
- var age = Math.abs( Date.now()/1000 - t)
- var r = Math.floor
- var m
- if (age < 5) { return "now" }
- if (age < 60) { return r(age) + (long ? ' seconds' : "s") }
- age /= 60
- if (age < 60) { return r(age) + (long ? ' minutes' : "m") }
- m = r(age % 60)
- age /= 60
- if (m > 0 && age < 2) { return r(age) + (long ? ' hours ' + m + ' minutes' : "h" + m + "m") }
- if (age < 24) { return r(age) + (long ? ' hours' : "h") }
- age /= 24
- if (age < 7) { return r(age) + (long ? ' days' : "d") }
- age /= 7
- if (age < 12) { return r(age) + (long ? ' weeks' : "w") }
- age /= 4
- if (age < 12) { return r(age) + (long ? ' months' : "m") }
- age /= 12
- return r(age) + (long ? ' years' : "y")
+function get_age(t, long) {
+ var age = Math.abs(Date.now() / 1000 - t);
+ var r = Math.floor;
+ var m;
+ if (age < 5) {
+ return "now";
+ }
+ if (age < 60) {
+ return r(age) + (long ? " seconds" : "s");
+ }
+ age /= 60;
+ if (age < 60) {
+ return r(age) + (long ? " minutes" : "m");
+ }
+ m = r(age % 60);
+ age /= 60;
+ if (m > 0 && age < 2) {
+ return r(age) + (long ? " hours " + m + " minutes" : "h" + m + "m");
+ }
+ if (age < 24) {
+ return r(age) + (long ? " hours" : "h");
+ }
+ age /= 24;
+ if (age < 7) {
+ return r(age) + (long ? " days" : "d");
+ }
+ age /= 7;
+ if (age < 12) {
+ return r(age) + (long ? " weeks" : "w");
+ }
+ age /= 4;
+ if (age < 12) {
+ return r(age) + (long ? " months" : "m");
+ }
+ age /= 12;
+ return r(age) + (long ? " years" : "y");
}
-function tidy_urls (s, short_urls) {
- var ret = s.split("\n").map(function(line){
- if (line.indexOf("<") !== -1) {
- return line
- }
- return line.replace(/https?:\/\/[^ ]+/g, function(url){
- if (is_image(url)) {
- return '<a href="' + url + '" target="_blank" rel="noopener noreferrer"><img src="' + url + '"></a>'
- }
- else if (short_urls) {
- return '<a href="' + url + '" target="_blank" rel="noopener noreferrer">[' + get_domain(url) + ']</a>'
- }
- else {
- return '<a href="' + url + '" target="_blank" rel="noopener noreferrer">' + url + '</a>'
+function tidy_urls(s, short_urls) {
+ var ret = s
+ .split("\n")
+ .map(function (line) {
+ if (line.indexOf("<") !== -1) {
+ return line;
}
- });
- })
- .join("\n")
- .replace(/\r/g, "")
- .replace(/<code>\n/g, "<code>")
- .replace(/<\/code>\n/g, "</code>")
- return ret
+ return line.replace(/https?:\/\/[^ ]+/g, function (url) {
+ if (is_image(url)) {
+ return (
+ '<a href="' +
+ url +
+ '" target="_blank" rel="noopener noreferrer"><img src="' +
+ url +
+ '"></a>'
+ );
+ } else if (short_urls) {
+ return (
+ '<a href="' +
+ url +
+ '" target="_blank" rel="noopener noreferrer">[' +
+ get_domain(url) +
+ "]</a>"
+ );
+ } else {
+ return (
+ '<a href="' +
+ url +
+ '" target="_blank" rel="noopener noreferrer">' +
+ url +
+ "</a>"
+ );
+ }
+ });
+ })
+ .join("\n")
+ .replace(/\r/g, "")
+ .replace(/<code>\n/g, "<code>")
+ .replace(/<\/code>\n/g, "</code>");
+ return ret;
}
-function get_domain(url){
- return url.replace(/https?:\/\//,"").replace(/\/.*/,"").replace(/www\./, "")
+function get_domain(url) {
+ return url
+ .replace(/https?:\/\//, "")
+ .replace(/\/.*/, "")
+ .replace(/www\./, "");
}
-function is_image(url){
- return !! url.match(/\.(gif|jpe?g|png)\??.*$/i)
+function is_image(url) {
+ return !!url.match(/\.(gif|jpe?g|png)(\?.*)?$/i);
}
-function make_link(file){
+function make_link(file) {
if (file.storage) {
- return "//s3.amazonaws.com/" + file.storage + sdk.opt.s3.path + "/data/" + file.thread + "/" + encodeURIComponent(file.filename)
+ return (
+ "//s3.amazonaws.com/" +
+ file.storage +
+ sdk.opt.s3.path +
+ "/data/" +
+ file.thread +
+ "/" +
+ encodeURIComponent(file.filename)
+ );
}
if (file.filename.indexOf("http") !== 0) {
- return "/data/" + file.thread + "/" + encodeURIComponent(file.filename)
+ return "/data/" + file.thread + "/" + encodeURIComponent(file.filename);
}
- return file.filename
+ return file.filename;
}
-function profile_image(username){
- return "//s3.amazonaws.com/i.asdf.us/bucky/profile/" + username + ".jpg"
+function profile_image(username) {
+ return "//s3.amazonaws.com/i.asdf.us/bucky/profile/" + username + ".jpg";
}
-function make_thumb(file){
+function make_thumb(file) {
if (file.storage) {
- return "//s3.amazonaws.com/" + file.storage + sdk.opt.s3.path + "/data/" + file.thread + "/" + encodeURIComponent(file.filename)
+ return (
+ "//s3.amazonaws.com/" +
+ file.storage +
+ sdk.opt.s3.path +
+ "/data/" +
+ file.thread +
+ "/" +
+ encodeURIComponent(file.filename)
+ );
}
if (file.filename.indexOf("http") !== 0) {
- return "/data/" + file.thread + "/" + file.filename
+ return "/data/" + file.thread + "/" + file.filename;
}
- return "/data/" + file.thread + "/" + file.filename
+ return "/data/" + file.thread + "/" + file.filename;
// var partz = file.filename.toLowerCase().split("/")
// return partz.splice(partz.length-2, 0, ".thumb").join("/")
}
-var metadataTemplate = $(".metadata_template").html()
-function metadata(thread){
- var datetime = verbose_date(thread.createdate, true)
- var age = get_age(thread.lastmodified, true)
+var metadataTemplate = $(".metadata_template").html();
+function metadata(thread) {
+ var datetime = verbose_date(thread.createdate, true);
+ var age = get_age(thread.lastmodified, true);
var t = metadataTemplate
- .replace(/{{username}}/g, thread.username)
- .replace(/{{date}}/g, datetime[0])
- .replace(/{{time}}/g, datetime[1])
- .replace(/{{active}}/g, age + " ago")
- .replace(/{{views}}/g, thread.viewed + " view" + courtesy_s(thread.viewed))
- return t
+ .replace(/{{username}}/g, thread.username)
+ .replace(/{{date}}/g, datetime[0])
+ .replace(/{{time}}/g, datetime[1])
+ .replace(/{{active}}/g, age + " ago")
+ .replace(/{{views}}/g, thread.viewed + " view" + courtesy_s(thread.viewed));
+ return t;
}