LiuShen

LiuShen / ech0说说展示到前端网站

Last active 4 months ago

Like 0

将ech0说说展示到前端网站页面

LiuShen revised this gist 5 months ago · 3166090

1 file changed, 413 insertions, 337 deletions

ech0-shuoshuo.js

Diff is too large to be shown

LiuShen revised this gist 1 year ago · ba272c3

1 file changed, 8 insertions

twikoo-comments.js (file created)
@@ -0,0 +1,8 @@
1 + const goComment = (e) => {
2 + const n = document.querySelector(".el-textarea__inner");
3 + n.value = `> ${e}\n\n`;
4 + n.focus();
5 + btf.snackbarShow("已为您引用该说说,不删除空格效果更佳");
6 + };
7 +
8 + // 如果是twikoo评论区,请自行替换goComment函数,注意,如果评论区开了懒加载可能导致无法找到元素。

LiuShen revised this gist 1 year ago · abdb6f1

1 file changed, 3 insertions, 3 deletions

ech0-shuoshuo.js
@@ -76,7 +76,7 @@ function renderTalks() {
76 76 };
77 77
78 78 const fetchAndRenderTalks = () => {
79 - const url = 'https://says.liushen.fun/api/messages/page';
79 + const url = 'https://says.liushen.fun/api';
80 80 const cacheKey = 'talksCache';
81 81 const cacheTimeKey = 'talksCacheTime';
82 82 const cacheDuration = 30 * 60 * 1000; // 半个小时 (30 分钟)
@@ -92,7 +92,7 @@ function renderTalks() {
92 92 } else {
93 93 if (talkContainer) {
94 94 talkContainer.innerHTML = '';
95 - fetch(url, {
95 + fetch(url + "/messages/page", {
96 96 method: 'POST',
97 97 headers: {
98 98 'Content-Type': 'application/json',
@@ -134,7 +134,7 @@ function renderTalks() {
134 134 const formatTalk = (item, url) => {
135 135 let date = formatTime(new Date(item.created_at).toString());
136 136 let content = item.content;
137 - const baseUrl = new URL(url).origin;
137 + const baseUrl = url;
138 138 let imgs = Array.isArray(item.images) ? item.images.map(img => {
139 139 const imageUrl = img.image_url;
140 140 // 如果是相对地址(不以 http 或 https 开头),则拼接 baseUrl

LiuShen revised this gist 1 year ago · 1eb69ec

1 file changed, 8 insertions, 3 deletions

ech0-shuoshuo.js
@@ -121,7 +121,7 @@ function renderTalks() {
121 121 function renderTalks(list) {
122 122 // 确保 data 是一个数组
123 123 if (Array.isArray(list)) {
124 - let items = list.map(item => formatTalk(item));
124 + let items = list.map(item => formatTalk(item, url));
125 125 items.forEach(item => talkContainer.appendChild(generateTalkElement(item)));
126 126 waterfall('#talk');
127 127 } else {
@@ -131,10 +131,15 @@ function renderTalks() {
131 131 };
132 132
133 133
134 - const formatTalk = (item) => {
134 + const formatTalk = (item, url) => {
135 135 let date = formatTime(new Date(item.created_at).toString());
136 136 let content = item.content;
137 - let imgs = Array.isArray(item.images) ? item.images.map(img => img.image_url) : [];
137 + const baseUrl = new URL(url).origin;
138 + let imgs = Array.isArray(item.images) ? item.images.map(img => {
139 + const imageUrl = img.image_url;
140 + // 如果是相对地址(不以 http 或 https 开头),则拼接 baseUrl
141 + return /^https?:\/\//.test(imageUrl) ? imageUrl : `${baseUrl}${imageUrl}`;
142 + }) : [];
138 143 let text = content;
139 144 content = text.replace(/\[(.*?)\]\((.*?)\)/g, `<a href="$2" target="_blank" rel="nofollow noopener noreferrer">@$1</a>`)
140 145 .replace(/- \[ \]/g, '⚪')

LiuShen revised this gist 1 year ago · cb382e8

1 file changed, 425 insertions

ech0-shuoshuo.js (file created)

Diff is too large to be shown