mgianni / Sankaku Private Firefox Fixer

// ==UserScript==
// @name        Sankaku Private Firefox Fixer
// @author      mgianni
// @copyright   2018+
// @license     MIT
// @namespace   mgianni
// @description Fix image loading on sankaku when using firefox private mode
// @include     https://chan.sankakucomplex.com/post/show/*
// @grant GM_xmlhttpRequest
// @require     http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js
// @require     https://cdnjs.cloudflare.com/ajax/libs/axios/0.18.0/axios.min.js
// @version     0.1
// @compatible        firefox >=52
// @compatible        chrome >=55
// ==/UserScript==

const img_selector = '#post-content a img';

const makeAxiosConfig = imgUrl => ({
  url: imgUrl,
  maxRedirects: 0,
  responseType: 'blob',
  headers: {'Referer': window.location},
})

const main = async () => {
  // Add '&ver=no-cache' to the img_url to avoid using browser cache;
  const img_url = 'https:' + $(img_selector).attr('src') + '&ver=no-cache';
  
  const config = makeAxiosConfig(img_url);
  
  const response = await axios.request(makeAxiosConfig(img_url));
  
  const file = new Blob([response.data], {type:'image/jpg'});
  
  const objurl = window.URL.createObjectURL(file);

  $(img_selector).attr('src',objurl);
}

main();