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,45 @@
|
||||
- const { server, site, option } = theme.artalk
|
||||
|
||||
script(pjax).
|
||||
(async () => {
|
||||
const emojiReg = /<img [^>]+ atk-emoticon="[^"]+">/g
|
||||
if (typeof EasyDanmaku === "undefined") await utils.getScript('!{url_for(theme.cdn.envelope_js)}')
|
||||
const envel = new EasyDanmaku({
|
||||
page: '!{theme.envelope.page}',
|
||||
el: '#barrage',
|
||||
line: !{line},
|
||||
speed: !{speed},
|
||||
hover: !{hover},
|
||||
loop: !{loop},
|
||||
})
|
||||
const data = utils.saveToLocal.get('enevlope')
|
||||
if (data) {
|
||||
envel.batchSend(data, true)
|
||||
return
|
||||
}
|
||||
|
||||
const searchParams = new URLSearchParams({'site_name': "!{site}", 'limit': '100'})
|
||||
await fetch(`!{server}/api/v2/stats/latest_comments?${searchParams}`, {method: 'GET'}).then(async res => res.json())
|
||||
.then(async data => {
|
||||
let ls = []
|
||||
for (const i of data.data) {
|
||||
ls.push({
|
||||
content: i.nick + ': ' + formatDanmaku(i.content),
|
||||
avatar: '!{avatar}' + '/avatar/' + i.email_encrypted,
|
||||
url: i.page_key + '#atk-comment-' + i.id,
|
||||
})
|
||||
}
|
||||
envel.batchSend(ls, true)
|
||||
utils.saveToLocal.set('enevlope', ls, .02)
|
||||
}).catch(error => {
|
||||
console.error("An error occurred while fetching comments: ", error)
|
||||
})
|
||||
|
||||
function formatDanmaku(str) {
|
||||
str = str.replace(emojiReg, '[!{__("console.newest_comment.emoji")}]')
|
||||
str = str.replace(/!\[.*?\]\((.*?)\)/g, '[!{__("console.newest_comment.image")}]')
|
||||
str = str.replace(/\[.*?\]\((.*?)\)/g, '[!{__("console.newest_comment.link")}]')
|
||||
str = str.replace(/```.*?```/g, '[!{__("console.newest_comment.code")}]')
|
||||
return str
|
||||
}
|
||||
})()
|
||||
@@ -0,0 +1,9 @@
|
||||
#article-container
|
||||
!= page.content
|
||||
if theme.envelope.enable
|
||||
.switch_message
|
||||
button.open(type='button' onclick="document.getElementById('barrage').classList.remove('hide')")
|
||||
span(aria-hidden='true')= __('message.open')
|
||||
button.close(type='button' onclick="document.getElementById('barrage').classList.add('hide')")
|
||||
span(aria-hidden='true')= __('message.close')
|
||||
#barrage
|
||||
@@ -0,0 +1,12 @@
|
||||
- const {use,avatar} = theme.comment
|
||||
|
||||
if use
|
||||
case use[0]
|
||||
when "Valine"
|
||||
include ./valine
|
||||
when "Twikoo"
|
||||
include ./twikoo
|
||||
when "Waline"
|
||||
include ./waline
|
||||
when "Artalk"
|
||||
include ./artalk
|
||||
@@ -0,0 +1,47 @@
|
||||
- const {envId} = theme.twikoo
|
||||
|
||||
script(pjax).
|
||||
(async () => {
|
||||
const emojiReg = /<img class="tk-owo-emotion" [^>]+>/g
|
||||
if (typeof EasyDanmaku === "undefined") await utils.getScript('!{url_for(theme.cdn.envelope_js)}')
|
||||
const Danmaku = new EasyDanmaku({
|
||||
page: '!{theme.envelope.page}',
|
||||
el: '#barrage',
|
||||
line: !{line},
|
||||
speed: !{speed},
|
||||
hover: !{hover},
|
||||
loop: !{loop},
|
||||
})
|
||||
const data = utils.saveToLocal.get('enevlope')
|
||||
if (data) {
|
||||
Danmaku.batchSend(data, true)
|
||||
return
|
||||
}
|
||||
let ls = []
|
||||
fetch('!{envId}/', {
|
||||
method: "POST",
|
||||
body: JSON.stringify({
|
||||
"event": "GET_RECENT_COMMENTS",
|
||||
"includeReply": false,
|
||||
"pageSize": 100
|
||||
}),
|
||||
headers: {'Content-Type': 'application/json'}
|
||||
}).then(res => res.json()).then(({data}) => {
|
||||
for (const i of data) {
|
||||
if (i.avatar === undefined) i.avatar = '!{avatar}/avatar/d615d5793929e8c7d70eab5f00f7f5f1?d=mp'
|
||||
ls.push({avatar: i.avatar, content: i.nick + ': ' + formatDanmaku(i.comment), url: i.url + '#' + i.id})
|
||||
}
|
||||
Danmaku.batchSend(ls, true);
|
||||
utils.saveToLocal.set('envelope', ls, 0.02)
|
||||
});
|
||||
|
||||
function formatDanmaku(str) {
|
||||
str = str.replace(emojiReg, '!{__("console.newest_comment.emoji")}')
|
||||
str = str.replace(/<\/*br>|[\s\uFEFF\xA0]+/g, '');
|
||||
str = str.replace(/<img.*?>/g, '[!{__("console.newest_comment.image")}]');
|
||||
str = str.replace(/<a.*?>.*?<\/a>/g, '[!{__("console.newest_comment.link")}]');
|
||||
str = str.replace(/<pre.*?>.*?<\/pre>/g, '[!{__("console.newest_comment.code")}]');
|
||||
str = str.replace(/<.*?>/g, '');
|
||||
return str
|
||||
}
|
||||
})()
|
||||
@@ -0,0 +1,57 @@
|
||||
- const {serverURLs,appId,appKey} = theme.valine
|
||||
|
||||
script(pjax).
|
||||
(async () => {
|
||||
const emojiReg = /:[a-z0-9_\u4e00-\u9fa5]+:/g
|
||||
if(typeof EasyDanmaku === "undefined") await utils.getScript('!{url_for(theme.cdn.envelope_js)}')
|
||||
const envel = new EasyDanmaku({
|
||||
page: '!{theme.envelope.page}',
|
||||
el: '#barrage',
|
||||
line: !{line},
|
||||
speed: !{speed},
|
||||
hover: !{hover},
|
||||
loop: !{loop},
|
||||
})
|
||||
const data = utils.saveToLocal.get('enevlope')
|
||||
if(data){
|
||||
envel.batchSend(data,true)
|
||||
return
|
||||
}
|
||||
const url = new URL('!{serverURLs}/1.1/classes/Comment')
|
||||
const params = {
|
||||
url: window.location.pathname,
|
||||
order: '-createdAt'
|
||||
}
|
||||
Object.entries(params).forEach(([key, value]) => url.searchParams.append(key, value))
|
||||
try {
|
||||
const res = await fetch(url, {
|
||||
method: "GET",
|
||||
headers: {
|
||||
"X-LC-Id": "#{appId}",
|
||||
"X-LC-Key": "#{appKey}",
|
||||
"Content-Type": "application/json"
|
||||
},
|
||||
})
|
||||
if (!res.ok) throw new Error(`HTTP error! status: ${res.status}`)
|
||||
const data = await res.json()
|
||||
const init = () =>
|
||||
data.results.map(item => ({
|
||||
content: item.nick + ': ' + formatDanmaku(item.comment),
|
||||
avatar: '!{avatar}/avatar/'+md5(item.mail),
|
||||
url: item.url
|
||||
}))
|
||||
if (typeof md5 === "undefined") await utils.getScript('!{url_for(theme.cdn.blueimp_md5)}')
|
||||
envel.batchSend(init(),true)
|
||||
utils.saveToLocal.set('enevlope',init(),.02)
|
||||
} catch (error) {
|
||||
console.error("An error occurred while fetching comments: ", error)
|
||||
}
|
||||
|
||||
function formatDanmaku(str) {
|
||||
str = str.replace(emojiReg, '[!{__("console.newest_comment.emoji")}]')
|
||||
str = str.replace(/!\[.*?\]\((.*?)\)/g, '[!{__("console.newest_comment.image")}]')
|
||||
str = str.replace(/\[.*?\]\((.*?)\)/g, '[!{__("console.newest_comment.link")}]')
|
||||
str = str.replace(/```.*?```/g, '[!{__("console.newest_comment.code")}]')
|
||||
return str
|
||||
}
|
||||
})()
|
||||
@@ -0,0 +1,42 @@
|
||||
script(pjax).
|
||||
(async () => {
|
||||
const emojiReg = /<img [^>]+ class="wl-emoji">/g
|
||||
if(typeof EasyDanmaku === "undefined") await utils.getScript('!{url_for(theme.cdn.envelope_js)}')
|
||||
const envel = new EasyDanmaku({
|
||||
page: '!{theme.envelope.page}',
|
||||
el: '#barrage',
|
||||
line: !{line},
|
||||
speed: !{speed},
|
||||
hover: !{hover},
|
||||
loop: !{loop},
|
||||
})
|
||||
const data = utils.saveToLocal.get('enevlope')
|
||||
if(data){
|
||||
envel.batchSend(data,true)
|
||||
return
|
||||
}
|
||||
await fetch('!{theme.waline.envId}/api/comment?type=recent&count=50', {method: 'GET'}).then(async res => res.json())
|
||||
.then(async data => {
|
||||
let ls = []
|
||||
for (const i of data.data) {
|
||||
ls.push({
|
||||
content: i.nick + ': ' + formatContent(i.comment),
|
||||
avatar: i.avatar,
|
||||
url: i.url
|
||||
})
|
||||
}
|
||||
envel.batchSend(ls,true)
|
||||
utils.saveToLocal.set('enevlope',ls,.02)
|
||||
}).catch(error => {
|
||||
console.error("An error occurred while fetching comments: ", error)
|
||||
})
|
||||
|
||||
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