Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Caçada ao tesouro
// Second ~~Flight~~ Round: a jQuery based web-spider
var taskQueue = ['https://tracker.uniotaku.com/torrents.php', 'https://tracker.uniotaku.com/forums.php'];
var fetchedPages = [];
var fetchedImages = {};
var unique = ((e, n, a) => n === a.indexOf(e));
var TARGET_IMAGE = 'http://i60.tinypic.com/oa6cqw.jpg';
checkQueue();
function processData(href, data){
var $data = $(data);
taskQueue = taskQueue.concat(
$data.find('a')
.get().map(e => e.href.replace(/#.*/, '').replace('&hit=1', '').replace('&page=1', '').replace('?page=1', '').replace(/[&?]page=$/, '').replace('http://', 'https://'))
.filter(e => -1 === fetchedPages.indexOf(e) && -1 === e.indexOf('page=last') && e.includes('tracker.uniotaku.com') && !e.includes('report') && !e.includes('mailbox') && !e.includes('download.php') && !e.startsWith('javascript'))
).filter(unique);
fetchedImages[href] = $data
.find('img[src^="http"]:not([src^="https://tracker.uniotaku.com/"]):not([src*="gravatar.com"]):not([src*="analytics.kap"]):not(.post_avatar)')
.get().map(e => e.src)
.filter(unique);
checkQueue();
}
function checkQueue() {
if (taskQueue.length === 0) {
console.log(Object.keys(fetchedImages).filter(e=>fetchedImages[e].includes(TARGET_IMAGE)));
open('data:text/html,<!doctype html><style>*{margin:0}body{-webkit-columns:5;columns:5}img{width:100%;float:left}</style>'+Object.keys(fetchedImages).reduce((a,b)=>a.concat(fetchedImages[b]),[]).filter((a,b,c)=>b===c.indexOf(a)).map(e=>`<img src="${e}">`).join(''))
return;
}
var nextPage = taskQueue.pop();
$.ajax(nextPage).always(data => {
console.log('Loading', nextPage);
console.log(fetchedPages.length, 'pages loaded. Still', taskQueue.length, 'pages to load.');
fetchedPages.push(nextPage);
if (typeof data === 'string') {
processData(nextPage, data);
} else { // 404
checkQueue();
}
});
}
@qgustavor

This comment has been minimized.

Copy link
Owner Author

qgustavor commented Jun 22, 2015

Nota: não funcionou.

@qgustavor

This comment has been minimized.

Copy link
Owner Author

qgustavor commented Jun 22, 2015

Nota: até funcionou, mas demorei tanto tempo programando que acharam antes de mim.

@qgustavor

This comment has been minimized.

Copy link
Owner Author

qgustavor commented Sep 2, 2015

Nota: funciona tão bem que ele ganhou duas vezes seguidas (embora só rendeu na segunda por erros humanos graves).

@qgustavor

This comment has been minimized.

Copy link
Owner Author

qgustavor commented Sep 30, 2015

Se você está lendo descobriu como ganhei o jogo, yeay oni no onii-chan.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.