2020-11-17 21:44:32 +01:00
|
|
|
|
link(rel="stylesheet", type="text/css", href="/css/fontello.css")
|
|
|
|
|
link(rel="stylesheet", type="text/css", href="/css/styles.css")
|
|
|
|
|
link(rel="icon", type="image/png", sizes="32x32", href="/favicon.png")
|
|
|
|
|
meta(name="viewport", content="width=device-width, initial-scale=1.0")
|
|
|
|
|
-
|
|
|
|
|
function kFormatter(num) {
|
|
|
|
|
return Math.abs(num) > 999 ? Math.sign(num)*((Math.abs(num)/1000).toFixed(1)) + 'k' : Math.sign(num)*Math.abs(num)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function timeDifference(time) {
|
|
|
|
|
time = parseInt(time) * 1000
|
|
|
|
|
let ms_per_minute = 60 * 1000
|
|
|
|
|
let ms_per_hour = ms_per_minute * 60
|
|
|
|
|
let ms_per_day = ms_per_hour * 24
|
|
|
|
|
let ms_per_month = ms_per_day * 30
|
|
|
|
|
let ms_per_year = ms_per_day * 365
|
|
|
|
|
let current = + new Date()
|
|
|
|
|
|
|
|
|
|
let elapsed = Math.abs(time - current)
|
|
|
|
|
let r = ''
|
|
|
|
|
let e
|
|
|
|
|
|
|
|
|
|
if (elapsed < ms_per_minute) {
|
|
|
|
|
e = Math.round(elapsed/1000)
|
|
|
|
|
r = `${e} seconds ago`
|
|
|
|
|
if(e === 1)
|
|
|
|
|
r = 'just now'
|
|
|
|
|
return r
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else if (elapsed < ms_per_hour) {
|
|
|
|
|
e = Math.round(elapsed/ms_per_minute)
|
|
|
|
|
r = `${e} minutes ago`
|
|
|
|
|
if(r === 1)
|
|
|
|
|
r = 'a minute ago'
|
|
|
|
|
return r
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else if (elapsed < ms_per_day ) {
|
|
|
|
|
e = Math.round(elapsed/ms_per_hour)
|
|
|
|
|
r = `${e} hours ago`
|
|
|
|
|
if(e === 1)
|
|
|
|
|
r = 'an hour ago'
|
|
|
|
|
return r
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else if (elapsed < ms_per_month) {
|
|
|
|
|
e = Math.round(elapsed/ms_per_day)
|
|
|
|
|
r = `${e} days ago`
|
|
|
|
|
if(e === 1)
|
|
|
|
|
r = '1 day ago'
|
|
|
|
|
return r
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else if (elapsed < ms_per_year) {
|
|
|
|
|
e = Math.round(elapsed/ms_per_month)
|
|
|
|
|
r = `${e} months ago`
|
|
|
|
|
if(e === 1)
|
|
|
|
|
r = '1 month ago'
|
|
|
|
|
return r
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else {
|
|
|
|
|
e = Math.round(elapsed/ms_per_year)
|
|
|
|
|
r = `${e} years ago`
|
|
|
|
|
if(e === 1)
|
|
|
|
|
r = '1 year ago'
|
|
|
|
|
return r
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function localize(url) {
|
2020-11-21 12:40:31 +01:00
|
|
|
|
try {
|
|
|
|
|
let u = new URL(url)
|
|
|
|
|
if(u.host === 'www.reddit.com' || u.host === 'reddit.com') {
|
|
|
|
|
url = url.replace(u.host, 'teddit.net')
|
|
|
|
|
}
|
2020-12-02 21:02:54 +01:00
|
|
|
|
if(u.host === 'i.redd.it' || u.host === 'v.redd.it') {
|
|
|
|
|
let image_exts = ['png', 'jpg', 'jpeg']
|
|
|
|
|
let video_exts = ['mp4', 'gif', 'gifv']
|
|
|
|
|
let file_ext = getFileExtension(url)
|
|
|
|
|
if(image_exts.includes(file_ext))
|
|
|
|
|
url = url.replace(`${u.host}/`, 'teddit.net/pics/w:null_')
|
2020-12-02 21:06:28 +01:00
|
|
|
|
if(video_exts.includes(file_ext) || !image_exts.includes(file_ext))
|
2020-12-02 21:02:54 +01:00
|
|
|
|
url = url.replace(u.host, 'teddit.net/vids') + '.mp4'
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-21 12:40:31 +01:00
|
|
|
|
} catch(e) { }
|
2020-11-17 21:44:32 +01:00
|
|
|
|
return url
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function toDateString(time) {
|
|
|
|
|
let d = new Date();
|
|
|
|
|
d.setTime(time*1000);
|
|
|
|
|
return d.toDateString();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function toUTCString(time) {
|
|
|
|
|
let d = new Date();
|
|
|
|
|
d.setTime(time*1000);
|
|
|
|
|
return d.toUTCString();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function secondsToMMSS(time) {
|
|
|
|
|
return new Date(time * 1000).toISOString().substr(14,5)
|
|
|
|
|
}
|
2020-12-02 17:02:32 +01:00
|
|
|
|
|
2020-12-02 21:02:54 +01:00
|
|
|
|
function getFileExtension(url) {
|
|
|
|
|
try {
|
|
|
|
|
url = new URL(url)
|
|
|
|
|
let pathname = url.pathname
|
|
|
|
|
let file_ext = pathname.substring(pathname.lastIndexOf('.') + 1)
|
|
|
|
|
if(file_ext) {
|
|
|
|
|
return file_ext
|
|
|
|
|
} else {
|
|
|
|
|
return ''
|
|
|
|
|
}
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.error(`Invalid url supplied to getFileExtension(). URL: ${url}`, error)
|
|
|
|
|
return ''
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-02 17:08:55 +01:00
|
|
|
|
function cleanTitle(s) {
|
|
|
|
|
if(s) {
|
|
|
|
|
var re = /&(?:amp|#38|lt|#60|gt|#62|apos|#39|quot|#34);/g;
|
|
|
|
|
var unescaped = {
|
|
|
|
|
'&': '&',
|
|
|
|
|
'&': '&',
|
|
|
|
|
'<': '<',
|
|
|
|
|
'<': '<',
|
|
|
|
|
'>': '>',
|
|
|
|
|
'>': '>',
|
|
|
|
|
''': "'",
|
|
|
|
|
''': "'",
|
|
|
|
|
'"': '"',
|
|
|
|
|
'"': '"'
|
|
|
|
|
}
|
|
|
|
|
return s.replace(re, (m) => {
|
|
|
|
|
return unescaped[m]
|
|
|
|
|
})
|
|
|
|
|
} else {
|
|
|
|
|
return ''
|
|
|
|
|
}
|
2020-12-02 17:02:32 +01:00
|
|
|
|
}
|