Skip to content

Instantly share code, notes, and snippets.

@pfgray
Created October 27, 2025 13:58
Show Gist options
  • Select an option

  • Save pfgray/340c4b85195adc1adcc40c2dbabdb893 to your computer and use it in GitHub Desktop.

Select an option

Save pfgray/340c4b85195adc1adcc40c2dbabdb893 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name ScoreCount Live Streamer
// @namespace http://tampermonkey.net/
// @version 1.0
// @description Stream scoreboard data from scorecount.com to a server
// @author You
// @match https://scorecount.com/*
// @grant none
// ==/UserScript==
(function() {
'use strict';
// Configuration
const SERVER_URL = 'http://localhost:3000/api/scoreboard'; // Change this to your server endpoint
const UPDATE_INTERVAL = 1000; // Check for updates every 1 second
let lastScoreboardState = null;
let isStreaming = true; // Start streaming immediately
// Silent background operation - no UI
// Extract scoreboard data
function extractScoreboardData() {
const data = {
timestamp: new Date().toISOString(),
teams: [],
timer: null,
period: null,
status: 'unknown'
};
try {
// Look for common scoreboard elements
const team1Name = document.getElementById('teamName1').value;
const team1Score = document.getElementById('score1').value;
const team2Name = document.getElementById('teamName2').value;
const team2Score = document.getElementById('score2').value;
const period = document.getElementById('period').value;
const minutes = document.getElementById('minutes').value;
const seconds = document.getElementById('seconds').value;
data.teams.push({ name: team1Name, score: parseInt(team1Score) || 0, index: 0 });
data.teams.push({ name: team2Name, score: parseInt(team2Score) || 0, index: 1 });
data.timer = `${minutes}:${seconds}`;
data.period = period;
data.status = 'extracted';
} catch (error) {
console.error('Error extracting scoreboard data:', error);
data.status = 'error';
data.error = error.message;
}
return data;
}
// Send data to server
async function sendToServer(data) {
try {
const response = await fetch(SERVER_URL, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(data)
});
if (!response.ok) {
throw new Error(`HTTP ${response.status}: ${response.statusText}`);
}
console.log('Scoreboard data sent successfully');
return true;
} catch (error) {
console.error('Error sending to server:', error);
return false;
}
}
// Check for changes and update
function checkForUpdates() {
if (!isStreaming) return;
const currentState = extractScoreboardData();
const stateString = JSON.stringify(currentState);
// Only send if data has changed
if (stateString !== lastScoreboardState) {
console.log('Scoreboard updated:', currentState);
sendToServer(currentState);
lastScoreboardState = stateString;
}
setTimeout(checkForUpdates, UPDATE_INTERVAL);
}
// Start streaming automatically
function startStreaming() {
console.log('ScoreCount Streamer: Starting automatic background streaming');
// Send initial state
const initialState = extractScoreboardData();
lastScoreboardState = JSON.stringify(initialState);
sendToServer(initialState);
// Start monitoring with polling
checkForUpdates();
}
// Initialize when page loads
function init() {
console.log('ScoreCount Streamer: Initializing background streaming');
// Wait for page to be fully loaded
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', () => {
setTimeout(() => {
// Check if elements are available for debugging
console.log('Available elements:', {
teamName1: !!document.getElementById('teamName1'),
score1: !!document.getElementById('score1'),
teamName2: !!document.getElementById('teamName2'),
score2: !!document.getElementById('score2'),
period: !!document.getElementById('period'),
minutes: !!document.getElementById('minutes'),
seconds: !!document.getElementById('seconds')
});
// Start streaming automatically
startStreaming();
}, 1000);
});
} else {
setTimeout(() => {
// Check if elements are available for debugging
console.log('Available elements:', {
teamName1: !!document.getElementById('teamName1'),
score1: !!document.getElementById('score1'),
teamName2: !!document.getElementById('teamName2'),
score2: !!document.getElementById('score2'),
period: !!document.getElementById('period'),
minutes: !!document.getElementById('minutes'),
seconds: !!document.getElementById('seconds')
});
// Start streaming automatically
startStreaming();
}, 1000);
}
}
// Start the script
init();
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment