2018-10-29 16:54:11 +01:00
|
|
|
export function findLink (target, parentClass = 'toot') {
|
2018-06-02 18:06:31 +02:00
|
|
|
if (target.localName === 'a') {
|
|
|
|
return target.href
|
|
|
|
}
|
|
|
|
if (target.parentNode === undefined || target.parentNode === null) {
|
|
|
|
return null
|
|
|
|
}
|
2018-10-29 16:54:11 +01:00
|
|
|
if (target.parentNode.getAttribute('class') === parentClass) {
|
2018-06-02 18:06:31 +02:00
|
|
|
return null
|
|
|
|
}
|
2018-10-29 16:54:11 +01:00
|
|
|
return findLink(target.parentNode, parentClass)
|
2018-06-02 18:06:31 +02:00
|
|
|
}
|
|
|
|
|
2018-10-29 16:54:11 +01:00
|
|
|
export function isTag (target, parentClass = 'toot') {
|
2018-06-02 18:06:31 +02:00
|
|
|
if (target.getAttribute('class') && target.getAttribute('class').includes('hashtag')) {
|
|
|
|
return true
|
|
|
|
}
|
2018-10-10 18:13:31 +02:00
|
|
|
// In Pleroma, link does not have class.
|
|
|
|
// So I have to check URL.
|
|
|
|
if (target.href && target.href.match(/^https:\/\/[a-zA-Z0-9-.]+\/(tag|tags)\/.+/)) {
|
|
|
|
return true
|
|
|
|
}
|
2018-06-02 18:06:31 +02:00
|
|
|
if (target.parentNode === undefined || target.parentNode === null) {
|
|
|
|
return false
|
|
|
|
}
|
2018-10-29 16:54:11 +01:00
|
|
|
if (target.parentNode.getAttribute('class') === parentClass) {
|
2018-06-02 18:06:31 +02:00
|
|
|
return false
|
|
|
|
}
|
2018-10-29 16:54:11 +01:00
|
|
|
return isTag(target.parentNode, parentClass)
|
2018-06-02 18:06:31 +02:00
|
|
|
}
|
2018-06-05 17:42:15 +02:00
|
|
|
|
2018-10-29 16:54:11 +01:00
|
|
|
export function findAccount (target, parentClass = 'toot') {
|
2018-06-05 17:42:15 +02:00
|
|
|
if (target.getAttribute('class') && target.getAttribute('class').includes('u-url')) {
|
2018-10-10 18:13:31 +02:00
|
|
|
return parseAccount(target.href)
|
|
|
|
}
|
|
|
|
// In Pleroma, link does not have class.
|
|
|
|
// So I have to check URL.
|
|
|
|
if (target.href && target.href.match(/^https:\/\/[a-zA-Z0-9-.]+\/@[a-zA-Z0-9-_.]+/)) {
|
|
|
|
return parseAccount(target.href)
|
2018-06-05 17:42:15 +02:00
|
|
|
}
|
|
|
|
if (target.parentNode === undefined || target.parentNode === null) {
|
|
|
|
return null
|
|
|
|
}
|
2018-10-29 16:54:11 +01:00
|
|
|
if (target.parentNode.getAttribute('class') === parentClass) {
|
2018-06-05 17:42:15 +02:00
|
|
|
return null
|
|
|
|
}
|
2018-10-29 16:54:11 +01:00
|
|
|
return findAccount(target.parentNode, parentClass)
|
2018-06-05 17:42:15 +02:00
|
|
|
}
|
2018-10-10 18:13:31 +02:00
|
|
|
|
|
|
|
export function parseAccount (accountURL) {
|
|
|
|
const res = accountURL.match(/^https:\/\/([a-zA-Z0-9-.]+)\/(@[a-zA-Z0-9-_.]+)/)
|
|
|
|
const domainName = res[1]
|
|
|
|
const accountName = res[2]
|
2018-10-20 14:55:25 +02:00
|
|
|
return {
|
|
|
|
username: accountName,
|
|
|
|
acct: `${accountName}@${domainName}`
|
|
|
|
}
|
2018-10-10 18:13:31 +02:00
|
|
|
}
|