Skip to content

Commit

Permalink
feat: サムネイル画像をダウンロードできるようにする (#447)
Browse files Browse the repository at this point in the history
* fix: リード文のみの場合でも一括DLボタンを配置する

* feat: サムネイル画像をダウンロードできるようにする
  • Loading branch information
mnao305 authored Aug 26, 2023
1 parent 1f95e05 commit e6962d4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/content/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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++) {
Expand Down
7 changes: 7 additions & 0 deletions src/content/modules/postPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,15 @@ export const downloadEverythingFromPost = async (): Promise<void> => {

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

0 comments on commit e6962d4

Please sign in to comment.