recognize all youtube links
This commit is contained in:
parent
a10e4aa637
commit
15c76aa134
@ -472,13 +472,13 @@ export default {
|
||||
let similar = `(http(s)?://)?${uri}/?`
|
||||
|
||||
const whitelist = ['news.ycombinator.com/item', 'bitcointalk.org/index.php']
|
||||
const youtube = ['www.youtube.com', 'youtu.be']
|
||||
const youtube = ['www.youtube.com', 'youtube.com', 'youtu.be']
|
||||
if (whitelist.includes(uri)) {
|
||||
similar += `\\${urlObj.search}`
|
||||
} else if (youtube.includes(urlObj.hostname)) {
|
||||
// extract id and create both links
|
||||
const matches = url.match(/(https?:\/\/)?((www\.)?(youtube(-nocookie)?|youtube.googleapis)\.com.*(v\/|v=|vi=|vi\/|e\/|embed\/|user\/.*\/u\/\d+\/)|youtu\.be\/)(?<id>[_0-9a-z-]+)/i)
|
||||
similar = `(http(s)?://)?(www.youtube.com/watch\\?v=${matches?.groups?.id}|youtu.be/${matches?.groups?.id})`
|
||||
similar = `(http(s)?://)?((www.)?youtube.com/watch\\?v=${matches?.groups?.id}|youtu.be/${matches?.groups?.id})`
|
||||
} else {
|
||||
similar += '((\\?|#)%)?'
|
||||
}
|
||||
|
@ -5,14 +5,13 @@ export function ensureProtocol (value) {
|
||||
return value
|
||||
}
|
||||
|
||||
|
||||
export function removeTracking (value) {
|
||||
const exprs = [
|
||||
// twitter URLs
|
||||
/^(?<url>https?:\/\/twitter\.com\/(?:#!\/)?(?<user>\w+)\/status(?:es)?\/(?<id>\d+))/,
|
||||
/^(?<url>https?:\/\/twitter\.com\/(?:#!\/)?(?<user>\w+)\/status(?:es)?\/(?<id>\d+))/
|
||||
]
|
||||
for (const expr of exprs) {
|
||||
value = expr.exec(value)?.groups.url ?? value;
|
||||
value = expr.exec(value)?.groups.url ?? value
|
||||
}
|
||||
return value
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user