Instagram Manga Fix (Greasemonkey)

Discussion in 'Manga Discussion' started by lnv, Jul 6, 2020.

?

Does instagram suck?

  1. Yes, it wasn't meant for humans to use

    77.8%
  2. No, I am a social butterfly, weee~

    22.2%
  1. lnv

    lnv ✪ Well-Known Hypocrite

    Joined:
    Jan 24, 2017
    Messages:
    7,702
    Likes Received:
    9,044
    Reading List:
    Link
    So, has anyone ever stumbled upon manga, well mostly Manwha that are posted only on instagram by the translator? Have you ever wondered if maybe the translator enjoys the suffering of their readers? Or why instagram even exists? If your answer is yes, this might be for you.

    What this script does:
    When you visit a users page, it loads up all the galleries into session storage. Then when you click on one, it will make all the images as a full screen vertical scroll. So you can read the pages like a human being was meant to. Then all the galleries that came after will show up on the bottom so you can easily go to the next chapter. It will also get rid of the log into instagram screens that might get in the way.

    How To Use:
    You load it up into greasemonkey for desktop and USI (firefox for android, do note it isn't available on firefox preview which limits addons, there might be a way to load it but I haven't looked)

    Warning:
    1) I did this script quickly so it might be a bit messy but it works for the most part, if you wish to modify it or make it better feel free to. Do note that all rights belong to cats, like everything humans do and will ever do.
    [​IMG]

    2) Session storage is wiped when you close the browser, and if you revisit the user the script will refill from scratch. This isn't generally a problem unless you revisit the user page before you are done reading. This is a pretty easy thing to fix but I'm lazy busy so *shrug*

    Code:
    // ==UserScript==
    // @name Instagram Manga Fix
    // @include     https://www.instagram.com/*
    // ==/UserScript==
    
    var imf_loc = window.location.href;
    
    var imf_database = sessionStorage.getItem( 'imf_database' );
    
    
    if ( /https:\/\/www\.instagram\.com\/p\//.test(imf_loc) ) {
    
    var footer = document.createElement("div");
    
    
    
    if ( imf_database ) {
    imf_database = JSON.parse( imf_database  );
    
    Object.keys(imf_database).forEach( function (imf_user) {
    
    var imf_found = 0;
    
    imf_database[imf_user].list.reverse().forEach( function (gitem) {
    
    
    
    if (  gitem.url == imf_loc  ) {
    imf_found=1;
    
    }
    
    if ( imf_found == 1 ) {
    
    var titem = document.createElement("a");
    titem.href = gitem.url;
    var timg= document.createElement("img");
    timg.src = gitem.img_url;
    titem.style.display = 'inline-block';
    timg.style.width = '10%';
    
    if (  gitem.url == window.location.href  ) {
    timg.style.border = '2px solid #f00';
    
    }
    
    
    titem.appendChild( timg );
    footer.appendChild( titem );
    
    }
    
    
    });
    
    
    });
    
    } else {
    imf_database = {};
    }
    
    
    
    
    var overlay = document.createElement("div");
    overlay.style.position = "absolute";
    overlay.style.top = "0";
    overlay.style.left = "0";
    overlay.style.height = "100%";
    overlay.style.width = "100%";
    overlay.style.backgroundColor = "#000";
    
    document.body.appendChild(overlay);
    
    
    var imgHistory = {};
    var imgList = [];
    
    
    
    var nextBtn;
    
    setTimeout(function () {
    nextBtn = document.querySelector('.coreSpriteRightChevron').parentElement;
    
    
    
    nextBtn.addEventListener('click', imf_get_next  )
    imf_get_next();
    },1000);
    
    
    function imf_get_next () {
    
    
    
    
    var img = document.querySelectorAll('main article div[role="presentation"] li img');
    
    
    img.forEach(function (cimg) {
    if ( !imgHistory[cimg.src] ) {
    imgHistory[cimg.src]=1;
    imgList.push( cimg.src );
    
    }
    
    
    })
    
    
    if ( document.querySelector('.coreSpriteRightChevron') ) {
    setTimeout(function () { nextBtn.click() }, 100);
    } else {
    
    imgList.forEach(function (cimg) {
    var newImg = document.createElement("img")
    newImg.src = cimg;
    
    overlay.appendChild( newImg );
    });
    
    overlay.appendChild( footer );
    
    document.querySelector('nav > div:last-child').style.display = 'none';
    
    }
    
    
    }
    
    
    } else {
    
    
    
    
    window.addEventListener('click', function (event) {
        event.stopPropagation();
    }, true);
    
    
    
    
    var imf_user = imf_loc.replace(/^.*?\..*?\/([^\/]+)\/*/, '$1' );
    
    var imf_length = 0;
    
    if ( imf_database ) {
    imf_database = JSON.parse( imf_database  );
    
    } else {
    imf_database = {};
    }
    
    imf_update();
    
    
    var timer = null;
    window.addEventListener('scroll', function() {
        if(timer !== null) {
            clearTimeout(timer);     
        }
        timer = setTimeout(function() {
              imf_update();
        }, 150);
    }, false);
    
    
    function imf_update() {
    
    var imf_glist = document.querySelectorAll('main article div a[href^="/p"]');
    
    if (  imf_glist.length > imf_length ) {
    
    imf_length = imf_glist.length;
    
    imf_database[ imf_user ] = {  list:[], time: Date.now()  };
    
    imf_glist.forEach( function (gitem) {
    
    
    imf_database[ imf_user ].list.push( {  url: gitem.href, img_url:gitem.querySelector( 'img' ).src  }  );
    
    });
    
    
    sessionStorage.setItem( 'imf_database', JSON.stringify( imf_database )  );
    }
    
    }
    
    }
    
    
     
  2. otaku31

    otaku31 Well-Known Member

    Joined:
    Nov 26, 2015
    Messages:
    6,603
    Likes Received:
    26,146
    Reading List:
    Link
    Strange. Most credit pgs of manhwa/webtoons I read hv scanlators requesting not to post their scans on insta since it would be more likely to catch publishers'/authors' attentions that way. Really strange... :hmm::blobconfused:
     
    Sabruness likes this.
  3. lnv

    lnv ✪ Well-Known Hypocrite

    Joined:
    Jan 24, 2017
    Messages:
    7,702
    Likes Received:
    9,044
    Reading List:
    Link
    Yes, I would think that too. But some translators are instagram only for whatever reason.
     
  4. Not Red Yet

    Not Red Yet Well-Known Member

    Joined:
    Feb 15, 2017
    Messages:
    1,110
    Likes Received:
    1,338
    Reading List:
    Link
    Do they want the likes and such to show off?

    Seems extremely stupid to post it in a place such as that, but the world is full of idiots so
    :blob_coffee::blob_coffee::blob_coffee:
     
    Sabruness likes this.