Last active
September 30, 2015 20:24
-
-
Save qgustavor/7309f3a628cc1c2688c0 to your computer and use it in GitHub Desktop.
Caçada ao tesouro
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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(); | |
} | |
}); | |
} |
Nota: até funcionou, mas demorei tanto tempo programando que acharam antes de mim.
Nota: funciona tão bem que ele ganhou duas vezes seguidas (embora só rendeu na segunda por erros humanos graves).
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
Nota: não funcionou.