Skip to content

Instantly share code, notes, and snippets.

@shaobos
Last active August 29, 2015 14:20
Show Gist options
  • Save shaobos/e11802d5edacc123fc0b to your computer and use it in GitHub Desktop.
Save shaobos/e11802d5edacc123fc0b to your computer and use it in GitHub Desktop.
var trs = document.getElementsByTagName("tr")
var length = trs.length
var failed_projects = ["failed projects:"]
var failed_projects_without_link = ["these failed projects don't have a link to failure:"]
for (var i = 0; i<length; i++) {
var product_name = null
var is_failed = false
var link
var tds = trs[i].getElementsByTagName("td")
for (var j = 0; j<tds.length; j++) {
var a = tds[j].getElementsByTagName("a")
// one of the td does not have <a>
if (a.length == 0) {
product_name = tds[j].innerText
} else {
link = a[0].getAttribute('href')
if (a[0].innerText == 'FAILED') {
is_failed = true
}
}
}
if (is_failed) {
failed_projects.push(product_name)
var xhr = new XMLHttpRequest();
try
{
//xhr.open("GET", link, true);
// it needs to be ended up with slash. TODO: why?
link = link + '/'
xhr.open("GET", link, false);
xhr.setRequestHeader("Content-type", "text/html;charset=UTF-8");
xhr.onload = function () {
var parser = new DOMParser();
var xmlDoc = parser.parseFromString(xhr.responseText, "text/html");
var as = xmlDoc.getElementsByTagName('a');
var has_failure_link = false
for (var i = 0; i < as.length; i++) {
if (as[i].innerText == 'failure') {
has_failure_link = true
if (as[i].getAttribute('href') != null) {
console.log('going to open the terminal')
window.open(as[i].getAttribute('href'))
}
}
}
if (!has_failure_link) {
failed_projects_without_link.push(product_name)
}
}
xhr.send( null );
}
catch (e) {
console.log("Unable to load " + link);
}
}
}
//console.log(failed_projects.join("\n") + "\n" + failed_projects_without_link.join("\n"))
//alert(failed_projects.join("\n") + "\n" + failed_projects_without_link.join("\n"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment