-
-
Save gkucmierz/7c718a0db9aa0405b68c to your computer and use it in GitHub Desktop.
AM - get data about auctions
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
var lcs = function(a, b) { | |
var aSub = a.substr(0, a.length-1); | |
var bSub = b.substr(0, b.length-1); | |
if (a.length == 0 || b.length == 0) { | |
return ""; | |
} else if (a.charAt(a.length-1) == b.charAt(b.length-1)) { | |
return lcs(aSub, bSub) + a.charAt(a.length-1); | |
} else { | |
var x = lcs(a, bSub); | |
var y = lcs(aSub, b); | |
return (x.length > y.length) ? x : y; | |
} | |
}; | |
var unique = function(arr){ | |
return arr.reverse().filter(function(el, i){ | |
return arr.indexOf(el, i+1) === -1; | |
}).reverse(); | |
}; | |
var get = function(url, fn){ | |
var xhr = new XMLHttpRequest(); | |
xhr.open('GET', url); | |
xhr.onabort = xhr.onerror = function(){ | |
fn(false); | |
}; | |
xhr.onreadystatechange = function(resp){ | |
if( xhr.readyState === 4 ){ | |
fn(resp.target.responseText, resp); | |
} | |
}; | |
xhr.send(); | |
}; | |
if( typeof links === 'undefined' ){ | |
var links = unique(prompt().trim().split(/\n/)); | |
} | |
var res = []; | |
(function check(i, sum){ | |
if( typeof links[i] === 'undefined' ){ | |
console.log('Ilość wystwaionych domen: ' + sum); | |
return alert('done'); | |
} | |
get(links[i], function(html){ | |
var num = parseInt(html.match(/lista domen \(([0-9]+)\)/)[1], 10); | |
var tf = html.match(/\<textarea[^\>]*\>([\s\S]+)\<\/textarea\>/im)[1]; | |
var spl = (tf).trim().split(/\n/); | |
var lcsRes = spl[0]; | |
spl.map(function(line){ | |
lcsRes = lcs(lcsRes, line); | |
}); | |
console.log([links[i], ' (', num, ') ', lcsRes, "\n"].join('')); | |
check(i+1, sum + num); | |
}); | |
})(0, 0); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment