mmmturkeybacon Floating Timers

Adds total time elapsed, time remaining, and task time elapsed to a floating display. The task timer keeps track of page load times to more accurately reflect the amount of required to finish a HIT.

目前為 2015-02-04 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name        mmmturkeybacon Floating Timers
// @author      mmmturkeybacon
// @description Adds total time elapsed, time remaining, and task time elapsed to a floating display. The task timer keeps track of page load times to more accurately reflect the amount of required to finish a HIT.
// @namespace   http://userscripts.org/users/523367
// @match       https://*.mturk.com/mturk/preview*
// @match       https://*.mturk.com/mturk/accept*
// @match       https://*.mturk.com/mturk/continue*
// @match       https://*.mturk.com/mturk/submit*
// @match       https://*.mturk.com/mturk/return*
// @require     http://code.jquery.com/jquery-latest.min.js
// @version     1.04
// @grant       none
// ==/UserScript==

/* Code for calculating time remaining modified from mTurk Title Bar Timer (http://userscripts-mirror.org/scripts/review/169153)
 * The offset calculation is much more simplistic than https://www.mturk.com/js/timer.js uses but it is probably sufficient. */

// try to get serverTimestamp and set offset immediately, if that fails try again when the document is ready.
var offset;
var serverTimestamp = unsafeWindow.serverTimestamp;
if (serverTimestamp)
{
    offset = (new Date()).getTime() - serverTimestamp;
}

/* Set task_start_time as soon as possible, because page load time affects how long it takes to complete
 * a task. */
var task_start_time = localStorage.getItem('mtb_page_unload_time');
if (task_start_time == null)
{
    task_start_time = (new Date()).getTime();
}

//$(document).ready(function()
window.addEventListener('load', function()
{
    if (offset)
    {
        serverTimestamp = unsafeWindow.serverTimestamp;
        if (serverTimestamp)
        {
            offset = (new Date()).getTime() - serverTimestamp;
        }
    }

    var endTime = unsafeWindow.endTime;
    if (endTime)
    {
        endTime = endTime.getTime();
    }

    var timer_holder = document.createElement("DIV");
    timer_holder.style = "position: fixed; top: 0px; left: 0px; z-index: 20; background-color: black;";
    timer_holder.align = "right";

    var timer_holder_innerHTML = '<div><span id="elapsed_timer" style="font-size: 14px; color: white; font-family: verdana,arial,sans-serif; text-align: right;"></span></div>';
    timer_holder_innerHTML += '<div><span id="remaining_timer" style="font-size: 14px; color: white; font-family: verdana,arial,sans-serif; text-align: right;"></span></div>';
    timer_holder_innerHTML += '<div><span id="task_timer" style="font-size: 14px; color: white; font-family: verdana,arial,sans-serif; text-align: right;"></span></div>';

    timer_holder.innerHTML = timer_holder_innerHTML;

    document.body.insertBefore(timer_holder, document.body.firstChild);

    var theTime = document.getElementById("theTime");
    var elapsed_timer = document.getElementById("elapsed_timer");
    var remaining_timer = document.getElementById("remaining_timer");
    var task_timer = document.getElementById("task_timer");

    var observer = new MutationObserver(function (mutations)
    {
        var now = (new Date()).getTime();

        elapsed_timer.innerHTML = theTime.innerHTML;

        var task_seconds_elapsed = Math.floor((now - task_start_time)/1000);
        task_timer.innerHTML = format_time(task_seconds_elapsed);

        if (endTime && offset)
        {
            var seconds_remaining = Math.floor((endTime - (now + offset))/1000);
            remaining_timer.innerHTML = format_time(seconds_remaining);
        }
        else
        {
            remaining_timer.innerHTML = "error";
        }

    });
    var options = {
      subtree: true,
      childList: true,
      attributes: false
    };

    observer.observe(theTime, options);

    window.addEventListener('beforeunload', function(){if(typeof(Storage)!=="undefined"){localStorage.setItem('mtb_page_unload_time', (new Date()).getTime());}});

});


function format_time(time_in_seconds)
{
    var time_str = "error";

    if (time_in_seconds >= 0)
    {
        // time formatting code modified from http://userscripts.org/scripts/show/169154
        var days  = Math.floor((time_in_seconds/(60*60*24)));
        var hours = Math.floor((time_in_seconds/(60*60)) % 24);
        var minutes  = Math.floor((time_in_seconds/60) % 60);
        var seconds  = time_in_seconds % 60;

        time_str = (days == 0 ? '' : days + (days > 1 ? ' days ' : ' day '));

        if (hours   < 10) {hours   = "0"+hours;}
        if (minutes < 10) {minutes = "0"+minutes;}
        if (seconds < 10) {seconds = "0"+seconds;}

        time_str += hours + ':' +minutes + ':' + seconds;
    }

    return time_str;
}