See local time on org logs

Hey guys, I'm back with another tampermonkey script! This time, it'll turn the date/time to local from UTC. This one can only be done in Tampermonkey, and you have to ensure you select the ES6 option. This isn't as instant as some of the other scripts because of the way the page layout is, but it does the job in no more than one or two seconds.

// ==UserScript==
// @name         Add local time to org logs
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  Fix stuff that shouldn't be so silly
// @author       Patroklos
// @match       http://www.ironrealms.com/game/orglog?org=*
// @require      https://cdnjs.cloudflare.com/ajax/libs/babel-core/5.6.15/browser-polyfill.min.js
// @require      https://cdnjs.cloudflare.com/ajax/libs/babel-core/5.6.15/browser.min.js
// @grant        none
// ==/UserScript==

/* jshint ignore:start */
var inline_src = (<><![CDATA[
    /* jshint ignore:end */
    /* jshint esnext: true */

    var regEX = /(\d+)\/(\d+)\/(\d+)\s(\d+):(\d+):(\d+)\s-\s(.+)/;

    var container = document.getElementById('content-area');
    var nav = document.getElementById('navdiv');
    var newDiv = document.createElement("div");

    newDiv.id = 'logReports';

    container.textContent.match(new RegExp(regEX, 'g')).forEach(function(line) {
    var newLine = regEX.exec(line);
    if (!newLine) return console.log(regEX + " - " + line);
    var localDate = new Date(Date.UTC(...newLine.slice(1, -1)));

    var lineDiv = document.createElement('div');
    lineDiv.textContent = getLocalString(localDate) + " - " + newLine.slice(-1);

    newDiv.appendChild(lineDiv);
    });


    while (container.firstChild) container.firstChild.remove();

    container.appendChild(nav);
    container.appendChild(newDiv);

    function getLocalString(thisDate) {
    var month = padString(thisDate.getMonth().toString());
    var day = padString(thisDate.getDate().toString());
    var hours = padString(thisDate.getHours().toString());
    var minutes = padString(thisDate.getMinutes().toString());
    return month + "/" + day + "/16 at " + hours + ":" + minutes;
    }

    function padString(myString) {
    var pad = "00";
    myString = pad.substring(0, pad.length - myString.length) + myString;
    return myString;
    }

    /* jshint ignore:start */
]]></>).toString();
                  var c = babel.transform(inline_src);
eval(c.code);
/* jshint ignore:end */
Sign In or Register to comment.