Skip to content

Instantly share code, notes, and snippets.

@kudorgyozo
Created December 18, 2020 20:40
Show Gist options
  • Save kudorgyozo/5faf653eac570e49d4d8c0489001a897 to your computer and use it in GitHub Desktop.
Save kudorgyozo/5faf653eac570e49d4d8c0489001a897 to your computer and use it in GitHub Desktop.
very basic tampermonkey instagram downloader, shows urls in console, createUI also shows them in a popup
// ==UserScript==
// @name New Userscript
// @namespace http://tampermonkey.net/
// @version 0.1
// @description try to take over the world!
// @author You
// @match https://www.instagram.com/p/*
// @require http://code.jquery.com/jquery-3.5.1.min.js
// @grant none
// ==/UserScript==
(function () {
'use strict';
setTimeout(() => {
const url = window.location.href + "?__a=1";
const urls = [];
fetch(url)
.then(response => response.json())
.then(data => {
//debugger;
if (data.graphql.shortcode_media.edge_sidecar_to_children) {
//multiple
const nodes = data.graphql.shortcode_media.edge_sidecar_to_children.edges;
for (const node of nodes) {
urls.push(get_url(node.node));
}
} else {
const node = data.graphql.shortcode_media;
urls.push(get_url(node));
}
//createUI(urls);
});
}, 500);
function get_url(node) {
if (node.is_video) {
console.log(node.video_url);
return node.video_url;
} else {
console.log(node.display_url);
return node.display_url;
}
}
function createUI(urls) {
var div = document.createElement('div');
div.style.position = 'absolute';
div.style.width = '500px';
div.style.height = '300px';
div.style.border = '1px solid black';
div.style.top = '5px';
div.style.left = '5px';
div.style.zIndex = '1';
div.style.backgroundColor = 'white';
div.style.overflow = 'auto';
document.body.appendChild(div);
var btn = document.createElement("button");
btn.innerHTML = "X";
btn.style.width = "30px";
btn.style.display = 'inline-block';
document.body.appendChild(btn);
div.appendChild(btn);
btn.addEventListener('click', () => {
div.remove();
});
var content = document.createElement('textarea');
content.style.width = '100%';
content.style.height = 'calc(100% - 30px)';
content.style.boxSizing = 'border-box';
content.innerHTML = urls.join('\n');
div.appendChild(content);
navigator.clipboard.writeText(urls.join('\n'));
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment