Skip to content

Commit f004c53

Browse files
committed
fix: mastodon page observer
1 parent 872e1d4 commit f004c53

File tree

2 files changed

+10
-26
lines changed

2 files changed

+10
-26
lines changed

layouts/_default/mastodon.html

Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -194,26 +194,6 @@ <h1 class="mt-0 text-4xl font-extrabold text-neutral-900 dark:text-neutral">
194194

195195
});
196196

197-
// 拦截 fetch 请求,替换头像
198-
const originalFetch = window.fetch;
199-
window.fetch = async function(resource, options) {
200-
const response = await originalFetch(resource, options);
201-
202-
// 检查请求的 URL
203-
if (resource.includes('https://files.e5n.cc/accounts/avatars/')) {
204-
// 创建一个新的响应,返回 /eallion.webp
205-
const newResponse = new Response(null, {
206-
status: 302,
207-
headers: {
208-
'Location': '/eallion.webp'
209-
}
210-
});
211-
return newResponse;
212-
}
213-
214-
return response;
215-
};
216-
217197
</script>
218198

219199
<script>
@@ -248,10 +228,14 @@ <h1 class="mt-0 text-4xl font-extrabold text-neutral-900 dark:text-neutral">
248228
const images = document.querySelectorAll('img');
249229
images.forEach(img => {
250230
const src = img.getAttribute('src');
251-
if (src && src.includes('https://files.e5n.cc/accounts/avatars/')) {
252-
img.setAttribute('src', '/eallion.webp');
253-
img.setAttribute('data-original-src', src); // 添加调试信息
254-
}
231+
if (src && src.includes('https://files.e5n.cc/accounts/')) {
232+
img.setAttribute('src', '/eallion.webp');
233+
img.setAttribute('data-original-src', src);
234+
} else if (src && src.includes('https://files.e5n.cc/media_attachments/')) {
235+
const newSrc = src.replace('https://files.e5n.cc/media_attachments/', 'https://mastodon-s3-files.eallion.com/media_attachments/');
236+
img.setAttribute('src', newSrc);
237+
img.setAttribute('data-original-src', src);
238+
}
255239
});
256240
});
257241

wrangler.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name = "eallion-com-cf-pages-origin"
22
pages_build_output_dir = "./public"
33

44
[vars]
5-
HUGO_VERSION = "v0.136.4"
5+
HUGO_VERSION = "v0.136.5"
66

77
[env.production.vars]
8-
HUGO_VERSION = "v0.136.4"
8+
HUGO_VERSION = "v0.136.5"

0 commit comments

Comments
 (0)