-
Notifications
You must be signed in to change notification settings - Fork 0
/
tm-odds-to-percentage.js
45 lines (40 loc) · 1.66 KB
/
tm-odds-to-percentage.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// ==UserScript==
// @name Odds to Percentage Converter
// @namespace http:https://tampermonkey.net/
// @version 0.3
// @description Convert fractional odds to percentage probabilities directly on Oddschecker Politics page
// @author Steve Condylios
// @match https://www.oddschecker.com/*
// @icon https://raw.githubusercontent.com/stevecondylios/odds-to-percentage-converter/main/icon.png
// @grant none
// ==/UserScript==
(function() {
'use strict';
// Convert odds to percentage
function oddsToPercentage(odds) {
const parts = odds.split('/');
if (parts.length === 2) {
const numerator = parseInt(parts[0]);
const denominator = parseInt(parts[1]);
if (!isNaN(numerator) && !isNaN(denominator)) {
const percentage = (denominator / (numerator + denominator)) * 100;
return percentage.toFixed(1) + '%';
}
}
return null;
}
// Update odds display
function updateOddsDisplay() {
const oddsElements = document.querySelectorAll('span.odds.basket-add.beta-footnote.bold.participant-info.ng-isolate-scope');
oddsElements.forEach(element => {
const oddsText = element.textContent;
const percentage = oddsToPercentage(oddsText);
if (percentage && !element.dataset.updated) {
element.textContent = percentage;
element.dataset.updated = 'true'; // mark as updated to avoid reprocessing
}
});
}
// Run update function every second to capture dynamic content updates
setInterval(updateOddsDisplay, 1000);
})();