Skip to content

Instantly share code, notes, and snippets.

@KevOrr
Last active July 14, 2020 17:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save KevOrr/43b10b3bd731b57a8879ac78e4457f96 to your computer and use it in GitHub Desktop.
Save KevOrr/43b10b3bd731b57a8879ac78e4457f96 to your computer and use it in GitHub Desktop.
Ordinal Markup - Incrementy upgrade ETA
// ==UserScript==
// @name Ordinal Markup - Incrementy upgrade ETA
// @namespace https://kevorr.com
// @version 0.5
// @description Shows estimated time until incrementy upgrades on hover
// @author Kevin Orr
// @match https://patcailmemer.github.io/Ordinal-Markup/
// @grant none
// @downloadURL https://gist.githubusercontent.com/KevOrr/43b10b3bd731b57a8879ac78e4457f96/raw/ordinal-incrementy-eta.user.js
// @updateURL https://gist.githubusercontent.com/KevOrr/43b10b3bd731b57a8879ac78e4457f96/raw/ordinal-incrementy-eta.user.js
// ==/UserScript==
(function() {
'use strict';
function getIncrementy() {
const el = document.querySelector('#incrementyText');
const incr = parseFloat(el.innerText.match(/You have ([0-9e.]+) incrementy/)[1]);
return incr;
}
function getIncrementyPS() {
const el = document.querySelector('#incrementyText2');
const ips = parseFloat(el.innerText.match(/You are getting ([0-9e.]+) incrementy per second/)[1]);
return ips;
}
// stolen from orbital-markup/script.js
function time(x) {
let timeList = [
Math.floor(x / 86400),
Math.floor((x % 86400) / 3600),
Math.floor((x % 3600) / 60),
Math.floor(x % 60)
];
let timeUnits = ["d ", "h ", "m ", "s"];
while (timeList[0] == 0) {
timeList.shift();
timeUnits.shift();
}
let timeOut = "";
for (let i = 0; i < timeList.length; i++) {
timeOut += timeList[i];
timeOut += timeUnits[i];
}
if (timeOut == "") timeOut = "<1s";
return timeOut;
}
function onHover(e) {
if (!e.target.classList.contains('locked')) {
return;
}
const text = e.target.innerText;
const matches = text.match(/Cost: ([0-9e.]+)/);
if (matches === null || matches === undefined || matches.length != 2) {
return;
}
const cost = parseFloat(matches[1]);
const timeLeft = (cost - getIncrementy())/getIncrementyPS();
//let timeLeftEl = e.target.querySelector('.timeLeft');
//if (timeLeftEl === null) {
// timeLeftEl = document.createElement('span');
// timeLeftEl.classList = ['timeLeft'];
// e.target.append(timeLeftEl);
//}
//timeLeftEl.innerText = 'Time left: ' + time(timeLeft);
e.target.title = 'Time left: ' + time(timeLeft);
}
document.querySelectorAll('#bsubTab4 .treeButton').forEach((e) => e.addEventListener('mouseover', onHover));
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment