From e6962d4d71ef4cd4234fbf216a0ad2f6a71a7194 Mon Sep 17 00:00:00 2001 From: mnao305 Date: Sat, 26 Aug 2023 23:07:14 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=E3=82=B5=E3=83=A0=E3=83=8D=E3=82=A4?= =?UTF-8?q?=E3=83=AB=E7=94=BB=E5=83=8F=E3=82=92=E3=83=80=E3=82=A6=E3=83=B3?= =?UTF-8?q?=E3=83=AD=E3=83=BC=E3=83=89=E3=81=A7=E3=81=8D=E3=82=8B=E3=82=88?= =?UTF-8?q?=E3=81=86=E3=81=AB=E3=81=99=E3=82=8B=20(#447)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix: リード文のみの場合でも一括DLボタンを配置する * feat: サムネイル画像をダウンロードできるようにする --- src/content/index.ts | 15 +++++++++------ src/content/modules/postPage.ts | 7 +++++++ 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/content/index.ts b/src/content/index.ts index 50febc6a..432cf9e5 100644 --- a/src/content/index.ts +++ b/src/content/index.ts @@ -67,16 +67,19 @@ const elementIdTocontentId = (id: string) => { const main = () => { const target = document.getElementById('page') if (!target) return + + let postBtnFlag = false const observer = new MutationObserver((mutations) => { for (const mutation of mutations) { - // 対象のElementが見つかるまでループ - if ((mutation.target as HTMLElement).className.includes('content-block')) { - // 投稿ページ全体一括保存ボタン作成 + // 投稿ページ全体一括保存ボタン作成 + if (!postBtnFlag && (mutation.target as HTMLElement).className.includes('post-btns')) { const postBtnEl = document.getElementsByClassName('post-btns') - if (postBtnEl.length > 0) { - injectPageAllContentsDlBtn((postBtnEl[0] as HTMLElement)) - } + injectPageAllContentsDlBtn((postBtnEl[0] as HTMLElement)) + postBtnFlag = true + } + // 対象のElementが見つかるまでループ + if ((mutation.target as HTMLElement).className.includes('content-block')) { // ギャラリーの一括保存ボタン作成 const galleryElements = document.getElementsByClassName('content-block type-photo-gallery ng-scope') for (let i = 0; i < galleryElements.length; i++) { diff --git a/src/content/modules/postPage.ts b/src/content/modules/postPage.ts index c40f88c7..6722b472 100644 --- a/src/content/modules/postPage.ts +++ b/src/content/modules/postPage.ts @@ -19,8 +19,15 @@ export const downloadEverythingFromPost = async (): Promise => { const baseFilepath = `${idAndTitlePath(data.fanclub.id, data.fanclub.fanclub_name_with_creator_name)}/${idAndTitlePath(data.id, data.title)}` + if (data.thumb.original) { + // サムネイル画像がある場合 + const ext = data.thumb.original.split('.').at(-1) + fileDownload(data.thumb.original, baseFilepath, `thumbnail.${ext}`) + } + if (data.comment) { // リード文がある場合 + // TODO: リード文に埋め込まれた画像をダウンロードできるようにblog_commentをパースしてダウンロードできるようにする const text = `data:text/plain;charset=UTF-8,${data.comment}` fileDownload(text, baseFilepath, 'text.txt') }