NOTICE: By continued use of this site you understand and agree to the binding Terms of Service and Privacy Policy.
// ==UserScript== // @name Trimps precise number hover // @namespace http://tampermonkey.net/ // @version 0.1 // @description Displays a tooltip with precise number when hovering over all numbers in Trimps. Warning: the numbers rendered before the plugin is loaded won't register the tooltip handlers, so for example HPs before you fight might not react. // @author Maurycy Zarzycki, Retrocade.net // @match https://trimps.github.io/ // @require http://code.jquery.com/jquery-latest.js // @grant none // ==/UserScript== (function() { 'use strict'; var mouseX = 0; var mouseY = 0; var $tooltip = $('<div class="number-tooltip"></div>').appendTo('body'); $('<style>.number-tooltip{position: absolute; display: none; background: black; padding: 10px; color: white;}</style>').appendTo('head'); $(document).mousemove(function(event) { mouseX = event.pageX; mouseY = event.pageY; }); function number_format (number, decimals, decPoint, thousandsSep) { // Taken from: http://locutus.io/php/strings/number_format/ number = (number + '').replace(/[^0-9+\-Ee.]/g, ''); var n = !isFinite(+number) ? 0 : +number; var prec = !isFinite(+decimals) ? 0 : Math.abs(decimals); var sep = (typeof thousandsSep === 'undefined') ? ',' : thousandsSep; var dec = (typeof decPoint === 'undefined') ? '.' : decPoint; var s = ''; var toFixedFix = function (n, prec) { var k = Math.pow(10, prec); return '' + (Math.round(n * k) / k) .toFixed(prec); }; // @todo: for IE parseFloat(0.55).toFixed(0) = 0; s = (prec ? toFixedFix(n, prec) : '' + Math.round(n)).split('.'); if (s[0].length > 3) { s[0] = s[0].replace(/\B(?=(?:\d{3})+(?!\d))/g, sep); } if ((s[1] || '').length < prec) { s[1] = s[1] || ''; s[1] += new Array(prec - s[1].length + 1).join('0'); } return s.join(dec); } var prettify_old = window.prettify; window.prettify = function(n, d){ var prettyNumber = number_format(n, 2, ".", " "); return '<span onmouseout="numberTooltipOut()" onmousemove="numberTooltipHover(\'' +prettyNumber+ '\')">'+prettify_old(n, d)+'</span>'; }; window.numberTooltipHover = function(number){ $tooltip.text(number).show(); $tooltip.css('left', mouseX + 10); $tooltip.css('top', mouseY + 10); }; window.numberTooltipOut = function(){ $tooltip.hide(); }; })();