import _ from 'lodash';
import $ from 'jquery';
import 'bootstrap';
import 'popper.js';
import punycode from 'punycode';
import 'datatables.net';
import LazyLoad from 'vanilla-lazyload';
$(function(){
var trunc = function(s, length) {
if (s.length > length) {
s = s.substring(0, length) + '…';
}
return s;
};
var table = null;
$.getJSON('data/screenshots.json', function(screenshots){
$.getJSON('data/spider_result.json', function(data){
var tbody = $('tbody');
$.each(data, function(index, item) {
var row = $(document.createElement('tr'));
// typ
var level = null;
if (item.meta.level === 'DE:ORTSVERBAND') {
level = 'OV';
} else if (item.meta.level === 'DE:KREISVERBAND') {
level = 'KV';
} else if (item.meta.level === 'DE:LANDESVERBAND') {
level = 'LV';
}
row.append('
' + (level === null ? '' : level) + ' | ');
// land
row.append('' + (item.meta.state === null ? '' : item.meta.state) + ' | ');
// kreis
row.append('' + (item.meta.district === null ? '' : item.meta.district) + ' | ');
// stadt
row.append('' + (item.meta.city === null ? '' : item.meta.city) + ' | ');
// input URL
row.append('' + trunc(punycode.toUnicode(item.input_url), 60) + ' | ');
// score
row.append('' + item.score.toFixed(1) + ' | ');
// IPs
var ips = _.join(item.details.ipv4_addresses, ', ');
row.append('' + (ips === '' ? '❌' : ips) + ' | ');
// SITE_REACHABLE
row.append('' + (item.result.SITE_REACHABLE.value ? '✅' : '❌') + ' | ');
// HTTP_RESPONSE_DURATION
var durationClass = 'bad';
if (item.result.HTTP_RESPONSE_DURATION.score > 0) { durationClass = 'medium'; }
if (item.result.HTTP_RESPONSE_DURATION.score > 0.5) { durationClass = 'good'; }
row.append('' + item.result.HTTP_RESPONSE_DURATION.value + ' ms | ');
// FAVICON
var icon = item.result.FAVICON.value;
row.append('' + (icon ? ('') : '❌') + ' | ');
// HTTPS
var hasHTTPS = item.result.HTTPS.value;
row.append('' + (hasHTTPS ? '✅' : '❌') + ' | ');
// WWW_OPTIONAL
var wwwOptional = item.result.WWW_OPTIONAL.value;
row.append('' + (wwwOptional ? '✅' : '❌') + ' | ');
// one canonical URL
var canonical = item.result.CANONICAL_URL.value;
row.append('' + (canonical ? '✅' : '❌') + ' | ');
var responsive = item.result.RESPONSIVE.value;
row.append('' + (responsive ? '✅' : '❌') + ' | ');
// feeds
var feeds = item.result.FEEDS.value;
row.append('' + (feeds ? '✅' : '❌') + ' | ');
// screenshots
var screenshot = false;
if (item.details.canonical_urls.length > 0) {
if (typeof screenshots[item.details.canonical_urls[0]] !== 'undefined') {
var surl = 'http://green-spider-screenshots.sendung.de/320x640/'+screenshots[item.details.canonical_urls[0]];
var lurl = 'http://green-spider-screenshots.sendung.de/1500x1500/'+screenshots[item.details.canonical_urls[0]];
screenshot = 'M';
screenshot += 'D';
}
}
row.append('' + (screenshot ? screenshot : '❌') + ' | ');
// cms
row.append('' + (item.details.cms ? item.details.cms : '') + ' | ');
tbody.append(row);
});
// enable data table funcionts (sorting)
table = $('table.table').DataTable({
order: [[0, "asc"]],
paging: false,
pageLength: 10000,
language: {
"search": "Suche"
}
});
});
});
});