Skip to content

Instantly share code, notes, and snippets.

@twinsdbv
Created March 7, 2017 18:03
Show Gist options
  • Save twinsdbv/72b7e1244b9ada0f9db7f63d0769c99f to your computer and use it in GitHub Desktop.
Save twinsdbv/72b7e1244b9ada0f9db7f63d0769c99f to your computer and use it in GitHub Desktop.
Instagram download
(function ($) {
function download(strData, strFileName, strMimeType) {
var D = document,
A = arguments,
a = D.createElement("a"),
d = A[0],
n = A[1],
t = A[2] || "text/plain";
//build download link:
a.href = "data:" + strMimeType + "charset=utf-8," + strData;
if (window.MSBlobBuilder) { // IE10
var bb = new MSBlobBuilder();
bb.append(strData);
return navigator.msSaveBlob(bb, strFileName);
}
/* end if(window.MSBlobBuilder) */
if ('download' in a) { //FF20, CH19
a.setAttribute("download", n);
a.innerHTML = "downloading...";
D.body.appendChild(a);
setTimeout(function () {
var e = D.createEvent("MouseEvents");
e.initMouseEvent("click", true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
a.dispatchEvent(e);
D.body.removeChild(a);
}, 66);
return true;
}
;
/* end if('download' in a) */
//do iframe dataURL download: (older W3)
var f = D.createElement("iframe");
D.body.appendChild(f);
f.src = "data:" + (A[2] ? A[2] : "application/octet-stream") + (window.btoa ? ";base64" : "") + "," + (window.btoa ? window.btoa : escape)(strData);
setTimeout(function () {
D.body.removeChild(f);
}, 333);
return true;
}
function SaveToDisk(fileUrl, fileName) {
var hyperlink = document.createElement('a');
hyperlink.href = fileUrl;
hyperlink.target = '_blank';
hyperlink.download = fileName || fileUrl;
var mouseEvent = new MouseEvent('click', {
view: window,
bubbles: true,
cancelable: true
});
hyperlink.dispatchEvent(mouseEvent);
(window.URL || window.webkitURL).revokeObjectURL(hyperlink.href);
}
setInterval(function () {
var img = $('img');
if (img && img.src !== undefined) {
console.log(img);
SaveToDisk(img.src, img.id + '.jpg');
download(decodeURI(img.alt), img.src.split("/").pop(-1) + '.txt', 'text/plain');
img.remove();
}
}, 1000);
})($);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment