Skip to content

Commit

Permalink
fix: mastodon page observer
Browse files Browse the repository at this point in the history
  • Loading branch information
eallion committed Oct 24, 2024
1 parent 872e1d4 commit f004c53
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 26 deletions.
32 changes: 8 additions & 24 deletions layouts/_default/mastodon.html
Original file line number Diff line number Diff line change
Expand Up @@ -194,26 +194,6 @@ <h1 class="mt-0 text-4xl font-extrabold text-neutral-900 dark:text-neutral">

});

// 拦截 fetch 请求,替换头像
const originalFetch = window.fetch;
window.fetch = async function(resource, options) {
const response = await originalFetch(resource, options);

// 检查请求的 URL
if (resource.includes('https://files.e5n.cc/accounts/avatars/')) {
// 创建一个新的响应,返回 /eallion.webp
const newResponse = new Response(null, {
status: 302,
headers: {
'Location': '/eallion.webp'
}
});
return newResponse;
}

return response;
};

</script>

<script>
Expand Down Expand Up @@ -248,10 +228,14 @@ <h1 class="mt-0 text-4xl font-extrabold text-neutral-900 dark:text-neutral">
const images = document.querySelectorAll('img');
images.forEach(img => {
const src = img.getAttribute('src');
if (src && src.includes('https://files.e5n.cc/accounts/avatars/')) {
img.setAttribute('src', '/eallion.webp');
img.setAttribute('data-original-src', src); // 添加调试信息
}
if (src && src.includes('https://files.e5n.cc/accounts/')) {
img.setAttribute('src', '/eallion.webp');
img.setAttribute('data-original-src', src);
} else if (src && src.includes('https://files.e5n.cc/media_attachments/')) {
const newSrc = src.replace('https://files.e5n.cc/media_attachments/', 'https://mastodon-s3-files.eallion.com/media_attachments/');
img.setAttribute('src', newSrc);
img.setAttribute('data-original-src', src);
}
});
});

Expand Down
4 changes: 2 additions & 2 deletions wrangler.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name = "eallion-com-cf-pages-origin"
pages_build_output_dir = "./public"

[vars]
HUGO_VERSION = "v0.136.4"
HUGO_VERSION = "v0.136.5"

[env.production.vars]
HUGO_VERSION = "v0.136.4"
HUGO_VERSION = "v0.136.5"

0 comments on commit f004c53

Please sign in to comment.