Last active
April 21, 2019 01:13
-
-
Save idolpx/ad6dc06a1513b77996b2c770356d7c05 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// ==UserScript== | |
// @name Scoreholio Dashboard Scraper | |
// @namespace http://techknowpro.com/ | |
// @version 0.1 | |
// @description Scrape data to send to electronic boards via MQTT | |
// @author James Johnston | |
// @match https://app.scoreholio.com/dashboard.html?account=* | |
// @match https://app.scoreholio.com/dashboard-bracket.html?account=* | |
// @match https://app.scoreholio.com/dashboard-finals.html?account=* | |
// @grant none | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
var hexDigits = new Array | |
("0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f"); | |
//Function to convert rgb color to hex format | |
function rgb2hex(rgb) { | |
rgb = rgb.match(/^rgb\((\d+),\s*(\d+),\s*(\d+)\)$/); | |
return "#" + hex(rgb[1]) + hex(rgb[2]) + hex(rgb[3]); | |
} | |
function hex(x) { | |
return isNaN(x) ? "00" : hexDigits[(x - x % 16) / 16] + hexDigits[x % 16]; | |
} | |
$('.grid-court').on("DOMSubtreeModified",function(){ | |
// Get Data | |
var court_num = $(this).find('.court-num').text(); | |
var court_color = rgb2hex($(this).parent().css("background-color")); | |
var court_time = $(this).find('.court-teamtime').text(); | |
var team1_score = parseInt($(this).find('.court-team1score').text()) || 0; | |
var team2_score = parseInt($(this).find('.court-team2score').text()) || 0; | |
var team1_score_last = parseInt($(this).find('.court-team1score').attr('last')) || 0; | |
var team2_score_last = parseInt($(this).find('.court-team2score').attr('last')) || 0; | |
if ( team1_score != team1_score_last || team2_score != team2_score_last) | |
{ | |
// Display Data | |
console.log("court_num: " + court_num + " " + court_time); | |
console.log("court_color: " + court_color); | |
console.log("team1_score: " + team1_score_last + "->" + team1_score ); | |
console.log("team2_score: " + team2_score_last + "->" + team2_score ); | |
// Update last scores to use on next pass | |
$(this).find('.court-team1score').attr('last', team1_score); | |
$(this).find('.court-team2score').attr('last', team2_score); | |
} | |
}); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment