Skip to content

Commit

Permalink
Clean code, prepare for release
Browse files Browse the repository at this point in the history
  • Loading branch information
HOAIAN2 committed Dec 31, 2022
1 parent 8d568cf commit 557d97c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
20 changes: 10 additions & 10 deletions src/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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')
Expand All @@ -139,7 +139,7 @@ async function handleDownload() {
setDownloadState('fail')
return
}
displayTitle = appLog.current.shortcode
title = appLog.current.shortcode
appLog.currentDisplay = 'post'
break
case 'stories':
Expand All @@ -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':
Expand All @@ -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
}
Expand All @@ -169,30 +169,30 @@ 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 => {
video.setAttribute(key, videoAttributes[key])
})
PHOTOS_CONTAINER.appendChild(video)
video.addEventListener('click', () => {
saveMedia(video, `${displayTitle}_${index}`)
saveMedia(video, `${title}_${index}`)
})
}
else {
const img = document.createElement('img')
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`)
})
}
})
Expand Down
2 changes: 1 addition & 1 deletion src/js/story.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 557d97c

Please sign in to comment.