Skip to content

Instantly share code, notes, and snippets.

@mcs
Created October 4, 2020 16:39
Show Gist options
  • Save mcs/d761d7b460b873802db2015dabf768bc to your computer and use it in GitHub Desktop.
Save mcs/d761d7b460b873802db2015dabf768bc to your computer and use it in GitHub Desktop.
tcec-interest-alert.userscript.js oder so
// ==UserScript==
// @name Alert on interesting events - tcec-chess.com
// @namespace Violentmonkey Scripts
// @match https://tcec-chess.com/
// @grant none
// @version 1.0
// @author M.C.S.
// @description Plays a sound when the boards becomes somewhat interesting, i.e. one engine rates |eval| > 1 or both engines see different positional leaders
// ==/UserScript==
(function (window) {
var interesting = document.createElement('audio');
interesting.src = 'https://drive.google.com/u/0/uc?id\u003d0B5HGnusrDyfgQ09pWm9SbWdOek0\u0026export\u003ddownload';
interesting.preload = 'auto';
var boring = document.createElement('audio');
boring.src = 'https://drive.google.com/u/0/uc?id\u003d1Lu1bN9JtOikT_FFbTtgH6e9gxIWJ_OYc\u0026export\u003ddownload';
boring.preload = 'auto';
var T = {
evalWhite: 0,
evalBlack: 0,
interesting: false
}
function getEvalFromString(strEval) {
if (strEval && strEval === "book") {
boring.pause();
boring.currentTime = 0;
interesting.pause();
interesting.currentTime = 0;
T.interesting = false;
}
return strEval && strEval !== "book"
? parseFloat(strEval)
: 0.0;
}
function updateEvalsFromDom() {
T.evalWhite = getEvalFromString(document.getElementById("eval0").innerHTML);
T.evalBlack = getEvalFromString(document.getElementById("eval1").innerHTML);
}
function evalBecameInteresting() {
return !T.interesting && (Math.abs(T.evalWhite) >= 0.7 || Math.abs(T.evalBlack) >= 0.7);
}
function evalBecameUninteresting() {
return T.interesting && Math.abs(T.evalWhite) < 0.5 && Math.abs(T.evalBlack) < 0.5;
}
function runPeriodically () {
updateEvalsFromDom();
console.log("Current state: %o", T);
if (evalBecameInteresting()) {
console.log("Imbalance detected! Could become a win :-)");
boring.pause();
boring.currentTime = 0;
interesting.play();
T.interesting = true;
} else if (evalBecameUninteresting()) {
console.log("Too sad, quite balanced again...");
interesting.pause();
interesting.currentTime = 0;
boring.play();
T.interesting = false;
} else {
console.log(T.interesting ? "Still interesting" : "Booooring as hell");
}
}
setInterval(runPeriodically, 10000);
})(window)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment