CSPT CrowdSurfWork extension

CSPT extension for CSW. Hide the copyright footer, automatically scroll the page down to the work frame, move the control buttons and timer to the header, job control hotkeys, etc.

2016-04-08 기준 버전입니다. 최신 버전을 확인하세요.

이 스크립트를 설치하려면 Tampermonkey, Greasemonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

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

이 스크립트를 설치하려면 Tampermonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey 또는 Userscripts와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 유저 스크립트 관리자 확장 프로그램이 필요합니다.

(이미 유저 스크립트 관리자가 설치되어 있습니다. 설치를 진행합니다!)

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

(이미 유저 스타일 관리자가 설치되어 있습니다. 설치를 진행합니다!)

// ==UserScript==
// @name         CSPT CrowdSurfWork extension
// @namespace    mobiusevalon.tibbius.com
// @version      0.4
// @require      https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js
// @include      /^https{0,1}:\/\/work\.crowdsurfwork\.com\/tasks\/\w{32}.*?$/
// @author       Mobius Evalon
// @description  CSPT extension for CSW.  Hide the copyright footer, automatically scroll the page down to the work frame, move the control buttons and timer to the header, job control hotkeys, etc.
// @grant        none
// @noframes
// ==/UserScript==

$.noConflict(true); // CrowdSurf is using jQuery as part of their platform so i have to defer to the version they loaded

function use_button(btn)
{
    switch(btn)
    {
        case "return": case "skip":
            // these buttons cannot exist at the same time so we use the same hotkey/command for both
            var $button = $("#task-detail-nav .inline-block .btn-info").first();
            if(!$button.length) $button = $("#task-detail-nav .inline-block .btn-danger").first();

            $button.get(0).click();
            break;
        case "accept":
            $("#accept-button").get(0).click();
            break;
        case "auto-accept":
            // todo: function of the auto accept switch must be an appended jquery handler -- figure out how to hook into that from here
            // $("#task-detail-nav .inline-block .auto-accept-button .bootstrap-switch .bootstrap-switch-container").first().click();
            break;
    }
}

function cspt_ext_hotkeys(event)
{
    if(event.altKey === true)
    {
        if(event.which === 8) {use_button("return"); return false;}
        else if(event.which === 13) {use_button("accept"); return false;}
        else if(event.which === 190) {use_button("auto-accept"); return false;}
    }
}

function cspt_ext_message(event)
{
    // using dom messaging in this frame throws an error every single time but it doesn't 
    // seem to affect anything
    // the only reason this is here is because the iframe that contains the actual job content
    // is considered to be its own window/tab for all intents and purposes, so the hotkeys defined
    // in this script don't work in the job frame without a completely separate keboard listener
    // and sending the data along the dom to this function
    if(event.originalEvent.origin === "https://ops.cielo24.com")
    {
        var data = event.originalEvent.data.split("-");
        if(data[0] === "cspt")
        {
            if(data[1] === "hotkey")
            {
                use_button(data[2]);
            }
            return false;
        }
    }
}

$(document).ready(function() {
    $("head").append(
        $("<style/>")
        .attr("type","text/css")
        .text("#task-detail-nav {margin: 0px !important; padding: 0px !important; color: #ffffff !important;} "+
              "#task-detail-nav a.btn {margin: 0px 10px !important; padding: 6px 15px !important;} "+
              "#task-detail-nav #Countdown h4 {margin: 0px 10px !important;} ")
    ); // these styles refine the appearance of task controls in the header, not particularly necessary

    $("footer").hide(); // footer only contains a copyright notice -- this is in our way as a worker

    var $accept_button = $("#accept-button");
    if($accept_button.length) $("#task-detail-nav .inline-block").prepend($accept_button); // move accept button before skip button

    $("header .headerwrapper .header-right").prepend($("#task-detail-nav").removeClass("pull-right")); // put task controls in the header

    $(window)
        .on("message onmessage",cspt_ext_message)
        .on("keydown onkeydown",cspt_ext_hotkeys)
        .scrollTop($("#innerframe").offset().top-$("header .headerwrapper").height()+8); // 8 pixels of margin/padding somewhere
});