Replace betting odds with chances calculated by the odds
// ==UserScript==
// @name Sofascore Chances
// @namespace https://greasyfork.org/users/21515
// @version 0.2.2
// @description Replace betting odds with chances calculated by the odds
// @author CennoxX
// @homepage https://twitter.com/CennoxX
// @match https://www.sofascore.com/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=sofascore.com
// @license MIT
// @grant none
// ==/UserScript==
/* jshint esversion: 11 */
(function() {
"use strict";
var getChances = (nodes) => {
if (nodes[0].innerHTML?.includes("%"))
return null;
var values = nodes.map(n => Number(n.innerHTML));
var all = values.reduce((sum, v) => sum + 1 / v, 0);
return values.map(v => Math.round((1 / v) / all * 100) + " %");
};
setInterval(()=>{
var results = [];
var selector = "span.textStyle_display\\.micro";
document.querySelectorAll(selector).forEach(span => {
for (var el = span.parentElement; el; el = el.parentElement) {
var matches = el.querySelectorAll(selector);
if (matches.length == 3 && Number(matches[0].innerHTML)) {
results.push([...matches]);
break;
}
}
});
results.forEach(r => {
var chances = getChances(r);
if (chances)
requestAnimationFrame(() => r.forEach((node, i) => { node.innerHTML = chances[i] }));
});
},500);
})();