IRC Export (reformatted output mod)

Export HIT information for IRC chat

Per 12-11-2014. Zie de nieuwste versie.

Voor het installeren van scripts heb je een extensie nodig, zoals Tampermonkey, Greasemonkey of Violentmonkey.

Voor het installeren van scripts heb je een extensie nodig, zoals Tampermonkey of Violentmonkey.

Voor het installeren van scripts heb je een extensie nodig, zoals Tampermonkey of Violentmonkey.

Voor het installeren van scripts heb je een extensie nodig, zoals Tampermonkey of Userscripts.

Voor het installeren van scripts heb je een extensie nodig, zoals {tampermonkey_link:Tampermonkey}.

Voor het installeren van scripts heb je een gebruikersscriptbeheerder nodig.

(Ik heb al een user script manager, laat me het downloaden!)

Voor het installeren van gebruikersstijlen heb je een extensie nodig, zoals {stylus_link:Stylus}.

Voor het installeren van gebruikersstijlen heb je een extensie nodig, zoals {stylus_link:Stylus}.

Voor het installeren van gebruikersstijlen heb je een extensie nodig, zoals {stylus_link:Stylus}.

Voor het installeren van gebruikersstijlen heb je een gebruikersstijlbeheerder nodig.

Voor het installeren van gebruikersstijlen heb je een gebruikersstijlbeheerder nodig.

Voor het installeren van gebruikersstijlen heb je een gebruikersstijlbeheerder nodig.

(Ik heb al een beheerder - laat me doorgaan met de installatie!)

// ==UserScript==
// @name          IRC Export (reformatted output mod)
// @description   Export HIT information for IRC chat
// @version       3.0c
// @include       https://www.mturk.com/mturk/searchbar*
// @include       https://www.mturk.com/mturk/findhits*
// @include       https://www.mturk.com/mturk/viewhits*
// @include       https://www.mturk.com/mturk/viewsearchbar*
// @include       https://www.mturk.com/mturk/sortsearchbar*
// @include       https://www.mturk.com/mturk/sorthits*
// @grant         GM_setClipboard
// @author        Cristo
// @namespace     mturkgrind
// ==/UserScript==

// modified by clickhappier to reformat output in more logical ordering/separating/labeling,
//   since I thought it was unnecessarily unclear to read with the separators in the middle of each 
//   type of information (label, value, separator, relevant url) instead of between the different types,
//   and wanted to be clearer about what the TO values represented;
// also wanted to remove unnecessary linebreaks in the output that caused it to spread one HIT's info 
//   across several IRC comments, which made it hard to tell where one HIT's info stopped and another began
//   (though after the version I initially modified, Cristo did later do away with all but one linebreak);
// also fixed Amazon fiddling with HIT name cell contents after Oct 20, 2014 change;
// also fixed Turkopticon mirror API domain to keep working after Oct 27, 2014 change


var caps = document.getElementsByClassName('capsulelink');
for (var c = 0; c < caps.length/2; c++){
    button = document.createElement('button');
    button.setAttribute("place",c);
    button.textContent = 'IRC';
    button.style.height = '14px';
    button.style.width = '30px';
    button.style.fontSize = '8px';
    button.style.border = '1px solid';
    button.style.padding = '0px';
    button.style.backgroundColor = 'transparent';
    button.title = 'Click to save Hit information to your clipboard';
    button.addEventListener("click", display, false);
    document.getElementById('capsule'+c+'-0').parentNode.appendChild(button);
}
function getTO(f){
    var toComp = [];
    var toUrl = 'https://mturk-api.istrack.in/multi-attrs.php?ids='+f;
    requestTO = new XMLHttpRequest();
    requestTO.onreadystatechange = function () {
        if ((requestTO.readyState ===4) && (requestTO.status ===200)) {
            if(requestTO.responseText.split(':').length > 2){
                var toInfo = requestTO.responseText.split('{')[3].split('}')[0].split(',');
                for (var t = 0; t < 3; t++){
                    var arrTo = toInfo[t].split(':');
                    toComp.push(arrTo[1].substring(1,4));
                }
            } else {
                toComp = ['-','-','-'];
            }
        }
    }
    requestTO.open('GET', toUrl, false);
    requestTO.send(null);
    return toComp;
}

function tinyURL(u){
    var shortRes;
    var urlG = "https://www.googleapis.com/urlshortener/v1/url";
    var gimmieG = new XMLHttpRequest();
    gimmieG.open("POST", urlG, false);
    gimmieG.setRequestHeader("Content-Type", "application/json");
    gimmieG.onreadystatechange = function (event) {
        if (gimmieG.readyState == 4) {
            var title = "Google URL Shortener";
            if (gimmieG.status == 200) {
                shortRes = JSON.parse(gimmieG.response).id;
            } else {
                console.log('nothing');
            }
        }
    }
    var data = new Object();
    data.longUrl = u;
    gimmieG.send(JSON.stringify(data));
    return shortRes;
}
function display(e){
    var theButton = e.target;
    theButton.style.backgroundColor = '#FD2B2B';
    setTimeout(function(){theButton.style.backgroundColor = 'transparent';},600);
    
    var capHand = document.getElementById('capsule'+theButton.getAttribute("place")+'-0');
    var tBodies = capHand.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode;
    
    var capReq = tBodies.getElementsByClassName('requesterIdentity')[0].textContent;
    var capReqId = tBodies.getElementsByClassName('requesterIdentity')[0].parentNode.href.split('requesterId=')[1];
    
    var capTitle = capHand.textContent.trim();
    capTitle = capTitle.replace(/<(\w+)[^>]*>.*<\/\1>/gi, "").trim();  // addition to strip html tags and their contents, appearing inside the title link (re 10-20-2014 appearance of "<span class="tags"></span>")
    var capGId = capHand.parentNode.parentNode.getElementsByClassName('capsulelink')[1].firstChild.nextSibling.href.split('groupId=')[1];
    
    var capRew = tBodies.getElementsByClassName('reward')[0].textContent;

    var capTime = tBodies.getElementsByClassName('capsule_field_text')[2].textContent;

    var capAvailable = tBodies.getElementsByClassName('capsule_field_text')[4].textContent;

    var qualList = document.getElementById('capsule'+theButton.getAttribute("place")+'target').getElementsByTagName('tbody')[2];
    var qualColl = qualList.getElementsByTagName('td');
    var masterStat = '';
    for ( var m = 3; m < qualColl.length; m++ ) {
        if ( qualColl[m].textContent.indexOf('Masters') > -1 ) {
            masterStat = 'MASTERS • ';
        }
    }
    
    var capUrl = tinyURL('https://www.mturk.com/mturk/preview?groupId='+capGId);
    var capReqUrl = tinyURL('https://www.mturk.com/mturk/searchbar?selectedSearchType=hitgroups&requesterId='+capReqId);
    var toLink = tinyURL('http://turkopticon.ucsd.edu/'+capReqId);
    var capToStats = getTO(capReqId);
    
    var exString = masterStat + 'Requester: ' + capReq + ' ' + capReqUrl + ' • ' + 'HIT: ' + capTitle + ' ' + capUrl + ' • ' + 'Pay: ' + capRew + ' • ' + 'Avail: ' + capAvailable + ' • ' + 'Time Limit: ' + capTime + ' • ' + 'TO: ' + 'Pay='+capToStats[1] + ' Fair='+capToStats[2] + ' Comm='+capToStats[0] + ' ' + toLink ;
    GM_setClipboard(exString);
}