Unmirror toggle

main
Holly McFarland 2 years ago
parent 7e51e1adc0
commit a1bc514f14

@ -8,4 +8,10 @@ Requires Tampermonkey ([chrome](https://chrome.google.com/webstore/detail/tamper
[Install here](https://git.hollymcfarland.com/monorail/easier-blaseball-betting/raw/branch/main/easier-blaseball-betting.user.js)
![](https://git.hollymcfarland.com/monorail/easier-blaseball-betting/raw/branch/main/screenshot.png)
![](https://git.hollymcfarland.com/monorail/easier-blaseball-betting/raw/branch/main/screenshot.png)
# config
Personally I think the mirrored text in the bets that had to be modified is very blaseball, but it can be turned off in your settings. Note that despite being changed near your account settings, this preference is saved locally to your device.
![](https://git.hollymcfarland.com/monorail/easier-blaseball-betting/raw/branch/main/unmirror.gif)

@ -1,18 +1,43 @@
// ==UserScript==
// @name Easier Blaseball Betting
// @namespace https://glaceon.social/@monorail
// @version 0.4
// @version 0.5
// @description Put every favoured team on the left of its matchup
// @author monorail
// @match https://blaseball.com/*
// @match https://www.blaseball.com/*
// @grant none
// @updateURL https://git.hollymcfarland.com/monorail/easier-blaseball-betting/raw/branch/main/easier-blaseball-betting.user.js
// ==/UserScript==
(function() {
'use strict';
const storage = window.localStorage;
let unmirror = (storage.getItem("unmirror") ?? "false") === "true";
function mirrorToggle() {
const checkbox = document.getElementById("easier-betting-mirror-config");
checkbox.checked ^= true;
unmirror = checkbox.checked;
storage.setItem("unmirror", unmirror);
// Update immediately
for (const matchup of document.getElementsByClassName("Bet-List-MatchUps-Group")) {
reorderMatchupIfNeeded(matchup);
}
const closeupWrapper = document.getElementsByClassName("Bet-CloseUp-Group-Wrapper")[0];
if (closeupWrapper) {
// ...flip games in sidebar where home team is favoured
for (const matchup of document.getElementsByClassName("Bet-CloseUp-Group")) {
reorderMatchupIfNeeded(matchup);
}
// ...sort games in sidebar
sortCloseup(closeupWrapper);
}
}
function getOdds(matchup) {
const away = matchup.children[0];
const home = matchup.children[1];
@ -27,6 +52,8 @@
const [awayOdds, homeOdds] = getOdds(matchup);
matchup.style.transform = (homeOdds > awayOdds) ? "scale(-1, 1)" : "";
matchup.children[0].style.transform = (homeOdds > awayOdds && unmirror) ? "scale(-1, 1)" : "";
matchup.children[1].style.transform = (homeOdds > awayOdds && unmirror) ? "scale(-1, 1)" : "";
}
function sortCloseup(closeupWrapper) {
@ -60,6 +87,62 @@
const callback = function(mutationsList, observer) {
// Every time there's an update in the DOM (yuck)...
// ...handle options
const settingsTab = document.getElementById("ModalTabs-Container-tabpane-Settings");
if (settingsTab && settingsTab.getAttribute("aria-hidden") === "false" && !document.getElementById("easier-betting-mirror-config")) {
let configElement = null;
let e = null;
[
[["form", ["ModalForm-Form", "Account-Content-Section"], null, null]],
[["div", ["ModalForm-Form-Amount", "form-group"], null, null]],
[
["label", ["ModalItem-Subheader", "form-label"], "userscript-settings", "Userscript Settings"],
["div", ["ModalForm-Switch", "custom-control", "custom-switch"], null, null]
],
[
["input", ["custom-control-input"], "easier-betting-mirror-config", null],
["label", ["custom-control-label"], "easier-betting-mirror-config-label", null],
],
].forEach(function(s) {
let newElement = null;
s.forEach(function (l) {
const [tag, classes, id, text] = l;
newElement = document.createElement(tag);
classes.forEach(function (s) { newElement.classList.add(s); });
if (id) newElement.id = id;
if (text) newElement.innerText = text;
if (e) {
e.appendChild(newElement);
} else {
configElement = newElement;
}
});
e = newElement;
});
observer.disconnect(); // Turn off the observer while we make DOM changes
settingsTab.children[0].insertAdjacentElement("beforeend", configElement);
console.log(e);
const checkbox = document.getElementById("easier-betting-mirror-config");
if (unmirror) {
checkbox.checked = "checked";
}
checkbox.type = "checkbox";
checkbox.parentElement.addEventListener("click", mirrorToggle);
const label = document.getElementById("easier-betting-mirror-config-label");
label.for = "easier-betting-mirror-config";
label.innerText = "Unmirror Bets";
checkbox.insertAdjacentElement("afterend", label);
observer.observe(main, config);
}
// ...flip games in main list where home team is favoured
for (const matchup of document.getElementsByClassName("Bet-List-MatchUps-Group")) {
reorderMatchupIfNeeded(matchup);

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 MiB

Loading…
Cancel
Save