mirror of
https://codeberg.org/tacerus/teddit.git
synced 2025-01-24 19:44:06 +01:00
fix localizing post URL #1
This commit is contained in:
parent
744617a49b
commit
620a400e89
@ -75,6 +75,18 @@ meta(name="viewport", content="width=device-width, initial-scale=1.0")
|
|||||||
if(u.host === 'www.reddit.com' || u.host === 'reddit.com') {
|
if(u.host === 'www.reddit.com' || u.host === 'reddit.com') {
|
||||||
url = url.replace(u.host, 'teddit.net')
|
url = url.replace(u.host, 'teddit.net')
|
||||||
}
|
}
|
||||||
|
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_')
|
||||||
|
if(video_exts.includes(file_ext))
|
||||||
|
url = url.replace(u.host, 'teddit.net/vids') + '.mp4'
|
||||||
|
if(!video_exts.includes(file_ext) && !image_exts.includes(file_ext))
|
||||||
|
url = url.replace(u.host, 'teddit.net/vids') + '.mp4'
|
||||||
|
}
|
||||||
|
|
||||||
} catch(e) { }
|
} catch(e) { }
|
||||||
return url
|
return url
|
||||||
}
|
}
|
||||||
@ -95,6 +107,22 @@ meta(name="viewport", content="width=device-width, initial-scale=1.0")
|
|||||||
return new Date(time * 1000).toISOString().substr(14,5)
|
return new Date(time * 1000).toISOString().substr(14,5)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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 ''
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function cleanTitle(s) {
|
function cleanTitle(s) {
|
||||||
if(s) {
|
if(s) {
|
||||||
var re = /&(?:amp|#38|lt|#60|gt|#62|apos|#39|quot|#34);/g;
|
var re = /&(?:amp|#38|lt|#60|gt|#62|apos|#39|quot|#34);/g;
|
||||||
|
Loading…
Reference in New Issue
Block a user