FAH Timeout Display (Chrome, Tampermonkey)

Display timeout and other WU related information

02.10.2016 itibariyledir. En son verisyonu görün.

Bu betiği kurabilmeniz için Tampermonkey, Greasemonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

You will need to install an extension such as Tampermonkey to install this script.

Bu betiği kurabilmeniz için Tampermonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Userscripts gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

You will need to install an extension such as Tampermonkey to install this script.

Bu komut dosyasını yüklemek için bir kullanıcı komut dosyası yöneticisi uzantısı yüklemeniz gerekecek.

(Zaten bir kullanıcı komut dosyası yöneticim var, kurmama izin verin!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Zateb bir user-style yöneticim var, yükleyeyim!)

// ==UserScript==
// @name         FAH Timeout Display (Chrome, Tampermonkey)
// @namespace    http://tampermonkey.net/
// @version      0.2
// @description  Display timeout and other WU related information
// @author       Rejutka Lupex
// @match        http://folding.stanford.edu/nacl/
// @grant        none
// @run-at document-body
// ==/UserScript==

var myConsole = null;
const fahInfoBox = "_fahExtInfoBox";
const fahTimeField = "_fahExtTimeField";
var weekday = new Array(7);
weekday[0]=  "Sunday";
weekday[1] = "Monday";
weekday[2] = "Tuesday";
weekday[3] = "Wednesday";
weekday[4] = "Thursday";
weekday[5] = "Friday";
weekday[6] = "Saturday";

var month = new Array(12);
month[0] = "January";
month[1] = "February";
month[2] = "March";
month[3] = "April";
month[4] = "May";
month[5] = "June";
month[6] = "July";
month[7] = "August";
month[8] = "September";
month[9] = "October";
month[10] = "November";
month[11] = "December";

(function() {
    'use strict';

    //We take over console.log, which is used by FAH, so we can catch log entries of interest.
    if (myConsole === null)
    {
        //Easier to make a copy of the whole console object
        myConsole = window.console;

        //Now replace the original log method with ours
        window.console.log = function()
        {
            //This is only supposesd to be called once, but we have to check it here
            //because at the time this script is called there is no body.onLoad yet
            if (document.getElementById("panel"))
            {
                if (document.getElementById(fahInfoBox) === null ||document.getElementById(fahInfoBox) === undefined )
                {
                    var iField = document.createElement('div');
                    iField.id = fahInfoBox;
                    document.getElementById("panel").appendChild(iField);

                    var timeField = document.createElement("div");
                    timeField.id = fahTimeField;
                    document.getElementById(fahInfoBox).appendChild(timeField);
                }
            }

            //Send the original data on its way, so the log doesn't get disturbed
            console.info.apply(myConsole, arguments);

            var infoLine = arguments[0];
            //We only need the client id data block
            if (infoLine.indexOf('DEBUG: WU: {"client_id":"') != -1)
            {
                //As I understand it, this huge line is a JSon object/array:
                //Parsing probably takes time - but it ensures we get the right info
                var WUData = JSON.parse(infoLine.substr(10, infoLine.length));
                var wu_ts = new Date(WUData.wu_ts);
                var wu_dl = new Date(WUData.deadline);
                var wu_to = new Date(WUData.timeout);

                var wu_maxtime = (wu_to - wu_ts) / 1000;
                var wu_maxmin = wu_maxtime / 60;

                var wuTimeMessage = document.createElement("span");
                wuTimeMessage.innerHTML = "Start of WU: " + wu_ts.getHours() + ":" + wu_ts.getMinutes()+ " "  + weekday[wu_ts.getDay()] + " " + month[wu_ts.getMonth()] + " " + wu_ts.getFullYear();
                wuTimeMessage.innerHTML += "<br />";                
                wuTimeMessage.innerHTML += "Timeout: " + wu_to.getHours() + ":" + wu_to.getMinutes() + " " +  weekday[wu_to.getDay()] + " " + month[wu_to.getMonth()] + " " + wu_to.getFullYear();
                wuTimeMessage.innerHTML += "<br />";
                wuTimeMessage.innerHTML += "Minutes from start to timeout:" + wu_maxmin;

                var tmpTimeField = document.getElementById(fahTimeField);
                while (tmpTimeField.firstChild)
                    tmpTimeField.removeChild(tmpTimeField.firstChild);

                tmpTimeField.appendChild(wuTimeMessage);
            }

        };
    }
})();