// ==UserScript== // @name OGame Board : correctif temps écoulé // @namespace http://tampermonkey.net/ // @version 1.0 // @author Xanatos // @description Corrige les erreurs du forum du type "{if $days > 1}{$day}{else}Hier{/if}, {$time}" // @match https://board.fr.ogame.gameforge.com/* // @grant none // @downloadURL none // ==/UserScript== window.onload = function() { let items = document.querySelectorAll('time.datetime'), now = new Date(), nowTimestamp = Math.floor(now.valueOf() / 1000), yesterdayStep = (now.getSeconds() + now.getMinutes() * 60 + now.getHours() * 3600) + 86400; for (let i = 0; i < items.length; i++) { let item = items[i], itemTimestamp = parseInt(item.getAttribute('data-timestamp'), 10), diff = nowTimestamp - itemTimestamp, text = undefined; if (diff < 60) { // 1 minute text = `Il y a ${diff} seconde${(diff > 1) ? 's' : ''}`; } else if (diff < 3600) { // 1 heure let minutes = Math.floor(diff / 60); text = `Il y a ${minutes} minute${(minutes > 1) ? 's' : ''}`; } else if (diff < 86400) { // 1 jour let hours = Math.floor(diff / 3600); text = `Il y a ${hours} heure${(hours > 1) ? 's' : ''}`; } else if (diff < yesterdayStep) { // hier let time = item.getAttribute('data-time'); text = `Hier, ${time}`; } else { text = item.getAttribute('title'); } item.innerHTML = text; } }