Skip to content

Commit

Permalink
fix: 🐛 修复部分网站无法下载漫画的 bug
Browse files Browse the repository at this point in the history
  • Loading branch information
hymbz committed Aug 23, 2024
1 parent 92f28fb commit 46b06a9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/userscript/main/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export const request = async <T = any>(
// 为了支持 ios 端只能自己实现一下了
if (
details?.fetch ??
(/^(\/|blob:)/.test(url) || url.startsWith(window.location.origin))
(url.startsWith('/') || url.startsWith(window.location.origin))
) {
const res = await fetch(url, {
method: 'GET',
Expand Down
12 changes: 8 additions & 4 deletions src/userscript/useComponents/DownloadButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,18 @@ import { request } from '../main/request';

import { toast } from './Toast';

const Accept =
'image/avif,image/webp,image/apng,image/svg+xml,image/*,*/*;q=0.8';

/** 下载按钮 */
export const DownloadButton = () => {
const [statu, setStatu] = createSignal('button.download');

const handleDownload = async () => {
const headers = {
Accept:
'image/avif,image/webp,image/apng,image/svg+xml,image/*,*/*;q=0.8',
'User-Agent': navigator.userAgent,
Referer: window.location.href,
};

const fileData: Zippable = {};

const { imgList } = store;
Expand All @@ -41,7 +45,7 @@ export const DownloadButton = () => {
let fileName: string;
try {
const res = await request<Blob>(url, {
headers: { Accept },
headers,
responseType: 'blob',
errorText: `${t('alert.download_failed')}: ${index}`,
});
Expand Down

0 comments on commit 46b06a9

Please sign in to comment.