Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
pr0gramm Favoriten Download
// ==UserScript==
// @name pr0gramm Favoriten Download
// @namespace http://tampermonkey.net/
// @version 0.1
// @description try to take over the world!
// @author Rene8888
// @match http://pr0gramm.com/user/*/likes
// @grant GM_xmlhttpRequest
// @grant GM_download
// @connect pr0gramm.com
// @require https://cdnjs.cloudflare.com/ajax/libs/babel-standalone/6.18.2/babel.js
// @require https://cdnjs.cloudflare.com/ajax/libs/babel-polyfill/6.16.0/polyfill.js
// ==/UserScript==
/* jshint ignore:start */
var inline_src = (<><![CDATA[
/* jshint ignore:end */
/* jshint esnext: false */
/* jshint esversion: 6 */
async function saveImage(post, cb) {
return new Promise((resolve, reject) => {
GM_xmlhttpRequest({
url: 'http://img.pr0gramm.com/' + post.image,
method: 'GET',
responseType: 'blob',
onload: (res) => {
let a = document.createElement('a');
a.href = URL.createObjectURL(res.response);
a.download = post.id + '.' + post.image.substr(post.image.lastIndexOf('.') + 1);
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
resolve();
}
});
});
}
async function download(user) {
console.log("Downloading " + user + "'s favorites");
let res = await $.ajax({type: 'GET', url: 'http://pr0gramm.com/api/items/get?flags=15&likes=' + user + '&self=true', dataType: 'JSON'});
let cnt = 0;
while (!res.atEnd) {
console.log("Page " + (++cnt));
let lastId;
for (let item of res.items) {
lastId = item.id;
console.log("Post " + item.id);
await saveImage(item);
}
res = await $.ajax({type: 'GET', url: 'http://pr0gramm.com/api/items/get?flags=15&likes=' + user + '&self=true&older=' + lastId, dataType: 'JSON'});
}
}
let user = window.location.href.split('/')[4];
download(user).catch((err) => console.log(err));
/* jshint ignore:start */
]]></>).toString();
var c = Babel.transform(inline_src, { presets: [ "es2015", "es2016" ] });
eval(c.code);
/* jshint ignore:end */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment