Cielo job frame tinkerer

Improvements to and tinkering with the CrowdSurf job frame, such as managing your own list of ignored words in the spellchecker

当前为 2016-03-18 提交的版本,查看 最新版本

// ==UserScript==
// @name         Cielo job frame tinkerer
// @namespace    mobiusevalon.tibbius.com
// @version      0.2
// @require      https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js
// @include      /^https{0,1}:\/\/ops.cielo24.com\/mediatool\/.*$/
// @author       Mobius Evalon
// @description  Improvements to and tinkering with the CrowdSurf job frame, such as managing your own list of ignored words in the spellchecker
// @grant        none
// ==/UserScript==

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

function cjft_message(event)
{
    // i have to use dom messaging to work around security protocols and sandboxing limitations
    if(event.originalEvent.origin === "https://ops.cielo24.com")
    {
        var data = event.originalEvent.data.split("-");
        if(data[0] === "cjft")
        {
            if(data[1] === "response")
            {
                if(data[2] === "ignored_words")
                {
                    var ignored_words = ((data[3].indexOf(",") > -1) ? data[3].split(",") : []);
                    cjft_display(ignored_words.length);
                    for(var i=0;i<ignored_words.length;i++) AtD.setIgnoreStrings(decodeURIComponent(ignored_words[i]));
                }
            }
            return false;
        }
    }
}

function cjft_display(n)
{
    if(typeof n === "number")
    {
        n = Math.floor(n);
        $("#cjft-count").text(n+" ignored spellcheck words.");
    }
}

$(document).ready(function() {
    // i can tinker with the spellchecker by overloading the functions
    AtD.__suggest = AtD.suggest;
    AtD.suggest = function() {
        AtD.__suggest.apply(AtD,arguments);

        $("#suggestmenu").append(
            $("<a/>")
            .text("CSPT: Ignore forever")
            .click(function() {
                var target = AtD.errorElement.text(),
                    removed = AtD._removeWords(AtD.container,target);
                
                AtD.core.setIgnoreStrings(target);
                AtD.counter -= removed;
                if(AtD.counter === 0 && AtD.callback_f !== undefined && AtD.callback_f.success !== undefined)
                {
                    AtD.callback_f.success(AtD.count);
                    globalController.dispatcher.trigger('spellcheck:cleared',AtD.counter);
                }
                if(AtD.callback_f !== undefined && AtD.callback_f.ignore !== undefined)
                {
                    AtD.callback_f.ignore(target);
                    AtD.core.setIgnoreStrings(target);
                }
                
                window.postMessage(("cspt-request-add_ignored_word-"+encodeURIComponent(target)),"https://ops.cielo24.com");
            })
        );
    };
    // load ignored words list
    window.postMessage("cspt-request-ignored_words_list","https://ops.cielo24.com");
    
    // interface
    $("#tab_content").before(
        $("<div/>")
        .attr("id","cjft-display")
        .css("margin-bottom","15px")
        .append(
            $("<span/>")
            .attr("id","cjft-count")
            .text("0 ignored spellcheck words."),
            $("<span/>")
            .css("color","#775555")
            .css("margin-left","10px")
            .css("cursor","pointer")
            .text("[Empty]")
            .click(function() {
                window.postMessage("cspt-request-purge_ignored_list","https://ops.cielo24.com");
                cjft_display(0);
            })
        )
    );
    
    $(window).on("message onmessage",cjft_message);
});