Created
May 4, 2016 05:40
-
-
Save behcet/8bde445fe6804338488d21f630f1ad8f to your computer and use it in GitHub Desktop.
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
function getShowHash (element) { | |
return Array.prototype.map.call(element.querySelectorAll('table.data tr'), function (row) { | |
var key = row.querySelector('.sortkey'); | |
var city = row.querySelector('a[href*="City"]'); | |
if (!key || !city) { return; } | |
key = key.textContent; | |
city = city.href.match(/\d+$/).pop(); | |
return { city: city, key: key }; | |
}) | |
.filter(function (i) { return i; }) | |
.reduce(function (hash, curr) { | |
hash[curr.city] = hash[curr.city] || []; | |
hash[curr.city].push(curr.key); | |
return hash; | |
}, {}); | |
} | |
function findHashDiff (hash1, hash2, diff) { | |
return Array.from(new Set(Object.keys(hash1).map(function (city) { | |
if (!hash2[city]) { return; } | |
return hash1[city].map(function (time) { | |
return hash2[city].map(function (time2) { | |
return Math.abs(time - time2) < diff ? time : undefined; | |
}) | |
.filter(function (e) { return e }); | |
}) | |
.filter(function (e) { return e && e.length > 0 }) | |
}) | |
.filter(function (e) { return e && e.length > 0 }) | |
.reduce(function (prev, curr) { return prev.concat(curr); }, []) | |
.reduce(function (prev, curr) { return prev.concat(curr); }, []))); | |
} | |
function highlightOverlaps (keys) { | |
Array.prototype.slice.call(document.querySelectorAll('table.data tr')).forEach(function (row) { | |
var key = row.querySelector('.sortkey'); | |
if (!key) { return } | |
key = key.textContent; | |
if (keys.indexOf(key) < 0) { return } | |
row.querySelector('td').style.fontWeight = 'bold'; | |
}); | |
} | |
jQuery | |
.get(document.location.href.replace(/\/\d+$/, '')) | |
.then(function (res) { | |
var resDom = document.createElement('div'); | |
resDom.innerHTML = res.replace(/<script(.|\s)*?\/script>/ig, ''); | |
Array.prototype.slice.call(resDom.querySelectorAll('img')) | |
.forEach(function (el) { | |
el.parentNode.removeChild(el); | |
}); | |
highlightOverlaps(findHashDiff( | |
getShowHash(document), | |
getShowHash(resDom), | |
6)); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment