Skip to content

Instantly share code, notes, and snippets.

@gkucmierz
Last active December 14, 2015 01:58
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 gkucmierz/7c718a0db9aa0405b68c to your computer and use it in GitHub Desktop.
Save gkucmierz/7c718a0db9aa0405b68c to your computer and use it in GitHub Desktop.
AM - get data about auctions
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