y252328 / Instagram_Download_Button

Add download button to download media in the post and the story in Instagram
MIT License
234 stars 32 forks source link

User script download same media despite it shouldn't #54

Open sn-o-w opened 9 months ago

sn-o-w commented 9 months ago

@y252328 @Patty-OFurniture

Something is wrong with one of your recent commits. Have a look: https://youtu.be/YVPzZcLqOL0

Steps to reproduce: 1) Copy the URL of any post and paste it into a new tab. 2) Once the page has loaded in the new tab, go to the author's profile page. 3) Choose any picture and download it. 4) From that post page, choose any other account. 5) Download another photo. 6) You simply downloaded the same image you downloaded before, but with the filename slightly updated to include the other account name.

This didn't happen on v1.17.10.

sn-o-w commented 9 months ago

Looks like the issue is caused by method 2 which was introduced in this commit: https://github.com/y252328/Instagram_Download_Button/commit/7b114cc4967ad4696c369d8de36025c2bd13796c

I commented out the lines of method 2, and the issue seems to be gone.

sn-o-w commented 9 months ago

@y252328 According to the commit message of https://github.com/y252328/Instagram_Download_Button/commit/7b114cc4967ad4696c369d8de36025c2bd13796c, that method is supposed to run for some stories. Therefore, the second method shouldn't be something like this?!

let scriptJson = document.querySelectorAll('script[type="application/json"]');
for (let i = 0; i < scriptJson.length; i++) {
    if (window.location.href.match(/www.instagram.com\/stories\/[^\/]+\/(\d+)/)) {
        let match = scriptJson[i].text.match(/"pk":"(\d+)","id":"[\d_]+"/);
        if (match) return match[1];
    }
}

I tested this, and it looks like it doesn't trigger my reported issue. 🤔