mirror of
https://github.com/KivotosRailway/website.git
synced 2026-11-03 19:07:56 +09:00
Add solitude
This commit is contained in:
@@ -0,0 +1,78 @@
|
||||
- const { server, site, option } = theme.artalk
|
||||
|
||||
script(pjax).
|
||||
(async () => {
|
||||
document.querySelector('#comments-page').textContent = `#{__("loading")}`
|
||||
const emojiReg = /<img [^>]+ atk-emoticon="[^"]+">/g
|
||||
let cache = utils.saveToLocal.get('artalk-recent-comments')
|
||||
if (cache) {
|
||||
setHtml(document.querySelector('#comments-page'), cache)
|
||||
return
|
||||
}
|
||||
let ls = []
|
||||
const searchParams = new URLSearchParams({'site_name': "!{site}", 'limit': '!{limit}'})
|
||||
await fetch(`!{server}/api/v2/stats/latest_comments?${searchParams}`, {method: 'GET'}).then(async res => res.json())
|
||||
.then(async data => {
|
||||
for (const i of data.data) {
|
||||
if (checkEmoji(i.content)) continue
|
||||
let title = ''
|
||||
if (i.page_key) {
|
||||
await fetch(i.page_key).then(res => res.text()).then(html => {
|
||||
const parser = new DOMParser()
|
||||
const doc = parser.parseFromString(html, 'text/html')
|
||||
title = doc.querySelector('title').innerText
|
||||
}).catch(() => {
|
||||
title = i.page_key
|
||||
})
|
||||
}
|
||||
if (title.indexOf('|') > 0) {
|
||||
title = title.split('|')[0]
|
||||
}
|
||||
ls.push({
|
||||
title: title,
|
||||
url: i.page_key + '#atk-comment-' + i.id,
|
||||
nick: i.nick,
|
||||
avatar: '!{avatar}' + '/avatar/' + i.email_encrypted,
|
||||
time: i.date,
|
||||
content: formatContent(i.content)
|
||||
})
|
||||
}
|
||||
setHtml(document.querySelector('#comments-page'), ls)
|
||||
utils.saveToLocal.set('artalk-recent-comments', ls, !{cache})
|
||||
})
|
||||
|
||||
function setHtml(el, data) {
|
||||
el.innerHTML = data.map(i => `
|
||||
<div class="comment-card" title="${i.title}" onclick="pjax.loadUrl('${i.url}')">
|
||||
<div class="comment-info">
|
||||
<img src="${i.avatar}" class="nolazyload" alt="${i.nick}">
|
||||
<div>
|
||||
<span class="comment-user">${i.nick}</span>
|
||||
</div>
|
||||
<time class="comment-time" datetime="${i.time}"></time>
|
||||
</div>
|
||||
<div class="comment-content">${i.content}</div>
|
||||
<div class="comment-title">
|
||||
<i class="solitude st-chat-fill"></i>
|
||||
${i.title}</div>
|
||||
</div>
|
||||
`).join('')
|
||||
if (typeof sco !== 'undefined') sco.changeTimeFormat(document.querySelectorAll('.comment-time'))
|
||||
else {
|
||||
document.addEventListener('pjax:complete', () => sco.changeTimeFormat(document.querySelectorAll('.comment-time')))
|
||||
document.addEventListener('DOMContentLoaded', () => sco.changeTimeFormat(document.querySelectorAll('.comment-time')))
|
||||
}
|
||||
}
|
||||
|
||||
function checkEmoji(content) {
|
||||
return emojiReg.test(content)
|
||||
}
|
||||
|
||||
function formatContent(content) {
|
||||
content = content.replace(emojiReg, '[!{__("console.newest_comment.emoji")}]')
|
||||
content = content.replace(/!\[.*?\]\((.*?)\)/g, '[!{__("console.newest_comment.image")}]')
|
||||
content = content.replace(/\[.*?\]\((.*?)\)/g, '[!{__("console.newest_comment.link")}]')
|
||||
content = content.replace(/```.*?```/g, '[!{__("console.newest_comment.code")}]')
|
||||
return content
|
||||
}
|
||||
})()
|
||||
@@ -0,0 +1,83 @@
|
||||
- const {envId} = theme.twikoo
|
||||
|
||||
script(pjax).
|
||||
(async () => {
|
||||
document.querySelector('#comments-page').textContent = `#{__("loading")}`
|
||||
const emojiReg = /<img class="tk-owo-emotion" [^>]+>/g
|
||||
let cache = utils.saveToLocal.get('twikoo-recent-comments')
|
||||
if (cache) {
|
||||
setHtml(document.querySelector('#comments-page'), cache)
|
||||
return
|
||||
}
|
||||
let ls = []
|
||||
|
||||
await fetch('!{envId}', {
|
||||
method: "POST",
|
||||
body: JSON.stringify({
|
||||
"event": "GET_RECENT_COMMENTS",
|
||||
"includeReply": true,
|
||||
"pageSize": !{limit}
|
||||
}),
|
||||
headers: {'Content-Type': 'application/json'}
|
||||
}).then(res => res.json()).then(async ({data}) => {
|
||||
for (const i of data) {
|
||||
if (i.avatar === undefined) i.avatar = '!{avatar}/avatar/d615d5793929e8c7d70eab5f00f7f5f1?d=mp'
|
||||
let title = ''
|
||||
if (i.url) {
|
||||
await fetch(i.url).then(res => res.text()).then(html => {
|
||||
const parser = new DOMParser()
|
||||
const doc = parser.parseFromString(html, 'text/html')
|
||||
title = doc.querySelector('title').innerText
|
||||
}).catch(() => {
|
||||
title = i.url
|
||||
})
|
||||
}
|
||||
if (title.indexOf('|') > 0) {
|
||||
title = title.split('|')[0]
|
||||
}
|
||||
ls.push({
|
||||
avatar: i.avatar,
|
||||
nick: i.nick,
|
||||
title: title,
|
||||
content: i.comment,
|
||||
url: i.url + '#' + i.id,
|
||||
time: i.created
|
||||
})
|
||||
}
|
||||
setHtml(document.querySelector('#comments-page'), ls)
|
||||
utils.saveToLocal.set('twikoo-recent-comments', ls, !{cache})
|
||||
});
|
||||
|
||||
function setHtml(el, data) {
|
||||
el.innerHTML = data.map(i => `
|
||||
<div class="comment-card" title="${i.title}" onclick="pjax.loadUrl('${i.url}')">
|
||||
<div class="comment-info">
|
||||
<img src="${i.avatar}" class="nolazyload" alt="${i.nick}">
|
||||
<div>
|
||||
<span class="comment-user">${i.nick}</span>
|
||||
</div>
|
||||
<time class="comment-time" datetime="${new Date(i.time)}"></time>
|
||||
</div>
|
||||
<div class="comment-content">${formatContent(i.content)}</div>
|
||||
<div class="comment-title">
|
||||
<i class="solitude st-chat-fill"></i>
|
||||
${i.title}</div>
|
||||
</div>
|
||||
`).join('')
|
||||
if (typeof sco !== 'undefined') sco.changeTimeFormat(document.querySelectorAll('.comment-time'))
|
||||
else {
|
||||
document.addEventListener('pjax:complete', () => sco.changeTimeFormat(document.querySelectorAll('.comment-time')))
|
||||
document.addEventListener('DOMContentLoaded', () => sco.changeTimeFormat(document.querySelectorAll('.comment-time')))
|
||||
}
|
||||
}
|
||||
|
||||
function formatContent(content) {
|
||||
content = content.replace(emojiReg, '!{__("console.newest_comment.emoji")}')
|
||||
content = content.replace(/<\/*br>|[\s\uFEFF\xA0]+/g, '');
|
||||
content = content.replace(/<img.*?>/g, '[!{__("console.newest_comment.image")}]');
|
||||
content = content.replace(/<a.*?>.*?<\/a>/g, '[!{__("console.newest_comment.link")}]');
|
||||
content = content.replace(/<pre.*?>.*?<\/pre>/g, '[!{__("console.newest_comment.code")}]');
|
||||
content = content.replace(/<.*?>/g, '');
|
||||
return content
|
||||
}
|
||||
})()
|
||||
@@ -0,0 +1,79 @@
|
||||
- const { appId, appKey, serverURLs } = theme.valine
|
||||
|
||||
script(pjax).
|
||||
(async () => {
|
||||
document.querySelector('#comments-page').textContent = `#{__("loading")}`
|
||||
const emojiReg = /:[a-z0-9_\u4e00-\u9fa5]+:/g
|
||||
let cache = utils.saveToLocal.get('valine-recent-comments')
|
||||
if (cache) {
|
||||
setHtml(document.querySelector('#comments-page'), cache)
|
||||
return
|
||||
}
|
||||
let ls = []
|
||||
if (typeof md5 === "undefined") await utils.getScript('!{url_for(theme.cdn.blueimp_md5)}')
|
||||
await fetch('!{serverURLs}/1.1/classes/Comment?limit=8&order=-createdAt', {
|
||||
method: "GET",
|
||||
headers: {
|
||||
"X-LC-Id": '!{appId}',
|
||||
"X-LC-Key": '!{appKey}',
|
||||
"Content-Type": "application/json"
|
||||
}
|
||||
}).then(async res => res.json()).then(async results => {
|
||||
for (const i of results.results) {
|
||||
let title = ''
|
||||
if (i.url) {
|
||||
await fetch(i.url).then(res => res.text()).then(html => {
|
||||
const parser = new DOMParser()
|
||||
const doc = parser.parseFromString(html, 'text/html')
|
||||
title = doc.querySelector('title').innerText
|
||||
}).catch(() => {
|
||||
title = i.url
|
||||
})
|
||||
}
|
||||
if (title.indexOf('|') > 0) {
|
||||
title = title.split('|')[0]
|
||||
}
|
||||
ls.push({
|
||||
title: title,
|
||||
url: i.url,
|
||||
nick: i.nick,
|
||||
avatar: '!{avatar}' + '/avatar/' + md5(i.mail.trim().toLowerCase()),
|
||||
time: i.createdAt,
|
||||
content: formatContent(i.comment)
|
||||
})
|
||||
}
|
||||
setHtml(document.querySelector('#comments-page'), ls)
|
||||
utils.saveToLocal.set('valine-recent-comments', ls, !{cache})
|
||||
})
|
||||
|
||||
function setHtml(el, data) {
|
||||
el.innerHTML = data.map(i => `
|
||||
<div class="comment-card" title="${i.title}" onclick="pjax.loadUrl('${i.url}')">
|
||||
<div class="comment-info">
|
||||
<img src="${i.avatar}" class="nolazyload" alt="${i.nick}">
|
||||
<div>
|
||||
<span class="comment-user">${i.nick}</span>
|
||||
</div>
|
||||
<time class="comment-time" datetime="${i.time}"></time>
|
||||
</div>
|
||||
<div class="comment-content">${i.content}</div>
|
||||
<div class="comment-title">
|
||||
<i class="solitude st-chat-fill"></i>
|
||||
${i.title}</div>
|
||||
</div>
|
||||
`).join('')
|
||||
if (typeof sco !== 'undefined') sco.changeTimeFormat(document.querySelectorAll('.comment-time'))
|
||||
else {
|
||||
document.addEventListener('pjax:complete', () => sco.changeTimeFormat(document.querySelectorAll('.comment-time')))
|
||||
document.addEventListener('DOMContentLoaded', () => sco.changeTimeFormat(document.querySelectorAll('.comment-time')))
|
||||
}
|
||||
}
|
||||
|
||||
function formatContent(content) {
|
||||
content = content.replace(emojiReg, '[!{__("console.newest_comment.emoji")}]')
|
||||
content = content.replace(/!\[.*?\]\((.*?)\)/g, '[!{__("console.newest_comment.image")}]')
|
||||
content = content.replace(/\[.*?\]\((.*?)\)/g, '[!{__("console.newest_comment.link")}]')
|
||||
content = content.replace(/```.*?```/g, '[!{__("console.newest_comment.code")}]')
|
||||
return content
|
||||
}
|
||||
})()
|
||||
@@ -0,0 +1,72 @@
|
||||
script(pjax).
|
||||
(async () => {
|
||||
document.querySelector('#comments-page').textContent = `#{__("loading")}`
|
||||
const emojiReg = /<img [^>]+ class="wl-emoji">/g
|
||||
let cache = utils.saveToLocal.get('waline-recent-comments')
|
||||
if (cache) {
|
||||
setHtml(document.querySelector('#comments-page'), cache)
|
||||
return
|
||||
}
|
||||
let ls = []
|
||||
await fetch('!{theme.waline.envId}/api/comment?type=recent&count=!{limit}', {method: 'GET'}).then(async res => res.json())
|
||||
.then(async data => {
|
||||
console.log(data)
|
||||
for (const i of data.data) {
|
||||
let title = ''
|
||||
if (i.url) {
|
||||
await fetch(i.url).then(res => res.text()).then(html => {
|
||||
const parser = new DOMParser()
|
||||
const doc = parser.parseFromString(html, 'text/html')
|
||||
title = doc.querySelector('title').innerText
|
||||
}).catch(() => {
|
||||
title = i.url
|
||||
})
|
||||
}
|
||||
if (title.indexOf('|') > 0) {
|
||||
title = title.split('|')[0]
|
||||
}
|
||||
ls.push({
|
||||
title: title,
|
||||
url: i.url,
|
||||
nick: i.nick,
|
||||
avatar: i.avatar,
|
||||
time: new Date(i.time),
|
||||
content: formatContent(i.comment)
|
||||
})
|
||||
}
|
||||
setHtml(document.querySelector('#comments-page'), ls)
|
||||
utils.saveToLocal.set('waline-recent-comments', ls, !{cache})
|
||||
})
|
||||
|
||||
function setHtml(el, data) {
|
||||
el.innerHTML = data.map(i => `
|
||||
<div class="comment-card" title="${i.title}" onclick="pjax.loadUrl('${i.url}')">
|
||||
<div class="comment-info">
|
||||
<img src="${i.avatar}" class="nolazyload" alt="${i.nick}">
|
||||
<div>
|
||||
<span class="comment-user">${i.nick}</span>
|
||||
</div>
|
||||
<time class="comment-time" datetime="${i.time}"></time>
|
||||
</div>
|
||||
<div class="comment-content">${i.content}</div>
|
||||
<div class="comment-title">
|
||||
<i class="solitude st-chat-fill"></i>
|
||||
${i.title}</div>
|
||||
</div>
|
||||
`).join('')
|
||||
if (typeof sco !== 'undefined') sco.changeTimeFormat(document.querySelectorAll('.comment-time'))
|
||||
else {
|
||||
document.addEventListener('pjax:complete', () => sco.changeTimeFormat(document.querySelectorAll('.comment-time')))
|
||||
document.addEventListener('DOMContentLoaded', () => sco.changeTimeFormat(document.querySelectorAll('.comment-time')))
|
||||
}
|
||||
}
|
||||
|
||||
function formatContent(content) {
|
||||
content = content.replace(emojiReg, '[!{__("console.newest_comment.emoji")}]')
|
||||
content = content.replace(/<img.*?>/g, '[!{__("console.newest_comment.image")}]');
|
||||
content = content.replace(/<a.*?>.*?<\/a>/g, '[!{__("console.newest_comment.link")}]');
|
||||
content = content.replace(/<pre.*?>.*?<\/pre>/g, '[!{__("console.newest_comment.code")}]');
|
||||
content = content.replace(/<.*?>/g, '');
|
||||
return content
|
||||
}
|
||||
})()
|
||||
Reference in New Issue
Block a user