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') }