diff --git a/README.md b/README.md index f09aa5a..1c41a86 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ This extension should work fine on the following browsers with `fetch()` API: ### Customize * Put your favourite one Instagram id on this function in `main.js` file, when app load it's gonna download latest post from that user, by default it's gonna download latest Tzuyu post ```js -setDefaultShortcode(PROFILE_ID) +setDefaultShortcode(profileID) ``` * If you know something about CSS, you can edit Hide / Show Transition effects ```css @@ -34,6 +34,6 @@ setDefaultShortcode(PROFILE_ID) ### Keyboard shortcut ### * Download: `D` `d` * Close: `esc` `C` `c` -* Keyboard shortcut should work if you don't focus on special HTML Elements like `input` `textarea` +* Keyboard shortcut should work if you don't focus on special HTML Elements like `input` `textarea` (ex: comment, search, ...) ## Here is Demo [Demo](https://user-images.githubusercontent.com/98139595/208013689-2b731fc1-75fb-48b1-b6a6-6d84ab46e740.mp4) diff --git a/src/js/main.js b/src/js/main.js index ca9255e..6d54e47 100644 --- a/src/js/main.js +++ b/src/js/main.js @@ -56,8 +56,8 @@ function shouldDownload() { if (!document.querySelector('.photos-container').childElementCount) return 'post' return 'none' } -async function setDefaultShortcode(PROFILE_ID = '51963237586') { - const profileAPI = `https://www.instagram.com/graphql/query/?query_hash=${PROFILE_HASH}&variables=${encodeURIComponent(`{"id":"${PROFILE_ID}","first":1}`)}` +async function setDefaultShortcode(profileID = '51963237586') { + const profileAPI = `https://www.instagram.com/graphql/query/?query_hash=${PROFILE_HASH}&variables=${encodeURIComponent(`{"id":"${profileID}","first":1}`)}` try { const respone = await fetch(profileAPI) const json = await respone.json() @@ -125,7 +125,7 @@ async function handleDownload() { setCurrentUsername() setCurrentHightlightsID() let data = null - let displayTitle = '' + let title = '' const DISPLAY_CONTAINER = document.querySelector('.display-container') const PHOTOS_CONTAINER = document.querySelector('.photos-container') DISPLAY_CONTAINER.classList.remove('hide') @@ -139,7 +139,7 @@ async function handleDownload() { setDownloadState('fail') return } - displayTitle = appLog.current.shortcode + title = appLog.current.shortcode appLog.currentDisplay = 'post' break case 'stories': @@ -149,7 +149,7 @@ async function handleDownload() { setDownloadState('fail') return } - displayTitle = `${data.user.username}-latest-stories` + title = `${data.user.username}-latest-stories` appLog.currentDisplay = 'stories' break case 'highlights': @@ -159,7 +159,7 @@ async function handleDownload() { setDownloadState('fail') return } - displayTitle = `${data.user.username}-${appLog.current.highlights}-stories` + title = `${data.user.username}-${appLog.current.highlights}-stories` appLog.currentDisplay = 'highlights' break } @@ -169,7 +169,7 @@ async function handleDownload() { const videoAttributes = { class: 'photos-items', src: item.url, - title: `${data.user.fullName} | ${data.user.username} | ${displayTitle}_${index}`, + title: `${data.user.fullName} | ${data.user.username} | ${title}_${index}`, controls: '' } Object.keys(videoAttributes).forEach(key => { @@ -177,7 +177,7 @@ async function handleDownload() { }) PHOTOS_CONTAINER.appendChild(video) video.addEventListener('click', () => { - saveMedia(video, `${displayTitle}_${index}`) + saveMedia(video, `${title}_${index}`) }) } else { @@ -185,14 +185,14 @@ async function handleDownload() { const photoAttributes = { class: 'photos-items', src: item.url, - title: `${data.user.fullName} | ${data.user.username} | ${displayTitle}_${index}` + title: `${data.user.fullName} | ${data.user.username} | ${title}_${index}` } Object.keys(photoAttributes).forEach(key => { img.setAttribute(key, photoAttributes[key]) }) PHOTOS_CONTAINER.appendChild(img) img.addEventListener('click', () => { - saveMedia(img, `${displayTitle}_${index}.jpeg`) + saveMedia(img, `${title}_${index}.jpeg`) }) } }) diff --git a/src/js/story.js b/src/js/story.js index 84ea5c9..e404ed3 100644 --- a/src/js/story.js +++ b/src/js/story.js @@ -19,7 +19,7 @@ async function getUserID(options) { return '' } } -async function getStoryPhotos(userID = '51963237586', options) { +async function getStoryPhotos(userID, options) { const storiesAPI = `https://www.instagram.com/api/v1/feed/reels_media/?reel_ids=${userID}` try { const respone = await fetch(storiesAPI, options)