Skip to content

Instantly share code, notes, and snippets.

@qgustavor
Last active September 30, 2015 20:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save qgustavor/7309f3a628cc1c2688c0 to your computer and use it in GitHub Desktop.
Save qgustavor/7309f3a628cc1c2688c0 to your computer and use it in GitHub Desktop.
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
Copy link
Author

Nota: não funcionou.

@qgustavor
Copy link
Author

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

@qgustavor
Copy link
Author

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

@qgustavor
Copy link
Author

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