-
Notifications
You must be signed in to change notification settings - Fork 0
/
InstaStoryLoggerBookmarklet.js
1 lines (1 loc) · 5.35 KB
/
InstaStoryLoggerBookmarklet.js
1
javascript:(function()%7Blet usersArray %3D %5B%5D%3B%0Alet usersLikedArray %3D %5B%5D%3B%0Alet linkArray %3D %5B%5D%3B%0Aconst delayOpenList %3D 5000%3B%0Aconst delayOpenStory %3D 2000%3B%0Aconst delayPerScroll %3D 5000%3B%0Alet currentTry %3D 0%3B%0Aconst totalTries %3D 5%3B%0A%0AopenStories()%3B%0A%0AsetTimeout(()%3D>%7B%0A main()%3B%0A%7D%2C delayOpenStory)%3B%0A%0A%0Afunction main()%7B%0A %2F%2Freset arrays%0A usersArray.length %3D usersLikedArray.length %3D linkArray.length %3D 0%3B%0A%0A if(!stopIfPlaying() %26%26 !isStoryOn())%7B %2F%2Fif story popup is not visible%0A return false%3B %2F%2Fno more stories%0A %7D%0A%0A if(!openList() %26%26 !storyIsOn())%0A return false%3B%0A%0A setTimeout(()%3D>%7B%0A saveAndScroll()%3B%0A %7D%2C delayOpenList)%3B%0A%7D%0A%0Afunction stopIfPlaying()%7B%0A let svg %3D document.querySelector('svg%5Baria-label%3D"Pause"%5D')%3B%0A if(!svg) return false%3B%0A svg.closest('button').click()%3B%0A console.log("Story was paused")%3B%0A return true%3B%0A%7D%0A%0Afunction getTextOfElementWithoutChildren(element)%7B%0A let text %3D ""%3B%0A %5B...element.childNodes%5D.forEach(node%3D>%7B%0A if (node.nodeType %3D%3D%3D Node.TEXT_NODE)%0A text %2B%3D node.nodeValue%3B%0A %7D)%3B%0A return text%3B%0A%7D%0A%0Afunction openList()%7B%0A let seenSpan %3D document.querySelector('button%5Btype%3D"button"%5D > div > span > span').parentElement%3B%0A%0A if (getTextOfElementWithoutChildren(seenSpan).trim()!%3D%3D"Seen by")%0A return false%3B%0A seenSpan.click()%3B%0A return true%3B%0A%7D%0A%0Afunction saveAndScroll()%7B%0A let %5BsavedUsers%2C lastUser%5D %3D saveUsers()%3B%0A%0A console.log(%60savedUsers%3A %24%7BsavedUsers%7D%60)%3B%0A%0A savedUsers%3D%3D%3D0 %3F currentTry%2B%2B %3A currentTry %3D 0%3B%0A%0A if(savedUsers>0 %7C%7C currentTry<totalTries)%7B%0A scrollToLastUser(lastUser)%3B%0A setTimeout(()%3D>%7B%0A saveAndScroll()%3B%0A %7D%2C delayPerScroll)%3B%0A %7Delse%7B%0A let mergedArray %3D %5B...usersLikedArray%2C ...usersArray%5D%3B%0A console.dir(usersArray)%3B%0A%0A let storyId %3D document.location.href.match(%2F%5C%2F(%5Cd%2B)%5C%2F%24%2F)%3F.%5B1%5D%3B%0A if(!storyId)%0A storyId %3D "Unknown"%3B%0A%0A%09 download(storyId.toString() %2B ".txt"%2C mergedArray.join("%5Cn"))%3B%0A%0A %2F%2Fclose list%0A closeList()%3B%0A%0A setTimeout(()%3D>%7B%0A %2F%2Fhit next story %0A nextStory()%3B%0A %7D%2C delayOpenList)%3B%0A%0A %7D%0A%7D%0A%0Afunction nextStory()%7B%0A let next %3D document.querySelector('button%5Baria-label%3D"Next"%5D')%3B%0A next %26%26 next.click()%3B%0A%0A setTimeout(()%3D>%7B%0A main()%3B%0A %7D%2C delayOpenStory)%3B%0A%7D%0A%0Afunction openStories()%7B%0A let profilePic %3D document.querySelector('div%5Baria-disabled%3D"false"%5D%5Brole%3D"button"%5D%5Btabindex%3D"0"%5D%5Bstyle%5D > span > img%5Balt%5D%5Bdraggable%3D"false"%5D')%3B%0A%0A profilePic %26%26 profilePic.click()%3B%0A%7D%0A%0Afunction scrollToLastUser(lastUser)%7B%0A lastUser.scrollIntoView()%3B%0A%7D%0A%0Afunction saveUsers()%7B%0A console.log("Saving users...")%3B%0A let images %3D document.querySelectorAll('div%5Baria-labelledby%5D%5Bclass%5D a%5Brole%3D"link"%5D%5Btabindex%3D"0"%5D%5Bhref%5D%5Bstyle%5D > img%5Balt%5D')%3B%0A let newUsers %3D 0%3B%0A %5B...images%5D.forEach(image%3D>%7B%0A let link %3D image.parentElement.href%3B%0A %0A %2F%2Fskip users that have already been saved%0A if(linkArray.indexOf(link) !%3D%3D -1)%0A return false%3B%0A%0A newUsers%2B%2B%3B%0A%0A let liked %3D image.parentElement.parentElement.querySelector('svg%5Baria-label%3D"Liked"%5D')%3B%0A liked!%3D%3Dnull %26%26 liked!%3D%3Dundefined %3F liked %3D true %3A liked %3D false%3B%0A%0A liked %3F usersLikedArray.push(%5Blink%2C "Liked"%5D) %3A usersArray.push(link)%3B%0A%0A %2F%2F usersArray.push(liked %3F %5Blink%2C "Liked"%5D %3A link)%3B%0A linkArray.push(link)%3B%0A %7D%2C newUsers)%3B%0A return %5BnewUsers%2C images%5Bimages.length-1%5D%5D%3B%0A%7D%0A%0Afunction download(filename%2C text) %7B%0A%09var element %3D document.createElement('a')%3B%0A%09element.setAttribute('href'%2C 'data%3Atext%2Fplain%3Bcharset%3Dutf-8%2C' %2B encodeURIComponent(text))%3B%0A%09element.setAttribute('download'%2C filename)%3B%0A%09element.style.display %3D 'none'%3B%0A%09document.body.appendChild(element)%3B%0A%09element.click()%3B%0A%09document.body.removeChild(element)%3B%0A%7D%0A%0Afunction isStoryOn()%7B%0A let storyIsOn %3D document.querySelector('svg%5Baria-label%3D"Pause"%5D%2C svg%5Baria-label%3D"Play"%5D')%3B%0A if(storyIsOn!%3D%3Dnull %26%26 storyIsOn!%3D%3Dundefined)%0A return true%3B%0A return false%3B%0A%7D%0A%0Afunction closeList()%7B%0A let closeButtons %3D document.querySelectorAll('svg%5Baria-label%3D"Close"%5D')%3B%0A if(closeButtons.length%3D%3D%3D2)%7B%0A closeButtons%5B1%5D.closest('button').click()%3B%0A return true%3B%0A %7D%0A return false%3B%0A%7D%0A%0Afunction isListOn()%7B%0A let closeButtons %3D document.querySelectorAll('svg%5Baria-label%3D"Close"%5D')%3B%0A if(closeButtons.length%3D%3D%3D2)%0A return true%3B%0A return false%3B%0A%7D%7D)()%3B