:not(#control_panel)').hide(); //hide all nodes directly under the body
// --- settings panel
var settings = {};
settings.panel = { mainDiv: document.createElement("DIV"),
containers: document.createElement("DIV"),
sections: document.createElement("SECTION"),
accessButton: document.createElement("BUTTON"),
closeSpan: document.createElement("SPAN"),
init: function() {
this.mainDiv.className = "settings settingsPanelMainDiv";
this.mainDiv.id = "settingsPanel";
this.mainDiv.tabIndex = "0";
this.mainDiv.style.display = "none";
//this.mainDiv.addEventListener("blur", function() { settings.panel.mainDiv.style.display = "none"; });
this.mainDiv.appendChild(this.closeSpan);
this.mainDiv.appendChild(settings.sidebar.mainDiv);
this.mainDiv.appendChild(settings.general.mainDiv);
this.accessButton.className = "settings cpButtons"+sufTheme;
this.accessButton.id = "settingsButton";
this.accessButton.textContent = "Settings";
this.accessButton.onclick = function() { settings.display(); };
this.closeSpan.className = "settings settingsCloseSpan";
this.closeSpan.innerHTML = " ✘ ";
this.closeSpan.addEventListener("click", function() { settings.panel.mainDiv.style.display = "none"; });
this.closeSpan.title = "Close";
this.containers.className = "settings settingsOptionContainers";
this.sections.className = "settings settingsOptionSections";
}
};
settings.sidebar = { mainDiv: document.createElement("DIV"),
generalSpan: document.createElement("SPAN"),
blocklistSpan: document.createElement("SPAN"),
init: function() {
this.mainDiv.className = "settings settingsInnerDiv settingsSidebarMainDiv";
this.mainDiv.appendChild(this.generalSpan);
this.mainDiv.appendChild(this.blocklistSpan);
this.generalSpan.className = "settings settingsSidebarSpans settingsSidebarGeneralSpan";
this.generalSpan.textContent = "General";
this.generalSpan.addEventListener("click", function() { settings.sidebar._click("generalSpan", "general") });
this.blocklistSpan.className = "settings settingsSidebarSpans settingsSidebarBlocklistSpan";
this.blocklistSpan.textContent = "Blocklist";
this.blocklistSpan.addEventListener("click", function() { settings.sidebar._click("blocklistSpan", "blocklist") });
},
_click: function(v, div) {
if (!settings.sidebar[v].classList.contains("settingsSidebarSpans-selected")) {
settings.sidebar[v].classList.toggle("settingsSidebarSpans-selected");
var last = settings.panel.mainDiv.lastChild;
settings.sidebar[last.dataset.category.concat("Span")].classList.toggle("settingsSidebarSpans-selected");
settings.panel.mainDiv.replaceChild(settings[div].mainDiv, last);
}
}
};
settings.general = { mainDiv: document.createElement("DIV"),
colorTypeSimple: document.createElement("INPUT"),
colorTypeAdjusted: document.createElement("INPUT"),
sortTypeSimple: document.createElement("INPUT"),
sortTypeAdjusted: document.createElement("INPUT"),
colorTSLabel: document.createElement("LABEL"),
colorTALabel: document.createElement("LABEL"),
sortTSLabel: document.createElement("LABEL"),
sortTALabel: document.createElement("LABEL"),
commWeight: document.createElement("DIV"),
payWeight: document.createElement("DIV"),
fairWeight: document.createElement("DIV"),
fastWeight: document.createElement("DIV"),
commLabel: document.createElement("LABEL"),
payLabel: document.createElement("LABEL"),
fairLabel: document.createElement("LABEL"),
fastLabel: document.createElement("LABEL"),
init: function() {
this.mainDiv.className = "settings settingsInnerDiv settingsMainContainer settingsGeneralMainDiv";
this.mainDiv.dataset.category = "general";
var colorTypeContainer = settings.panel.containers.cloneNode(false);
var colorTypeSectionSimple = settings.panel.sections.cloneNode(false);
var colorTypeSectionAdjusted = settings.panel.sections.cloneNode(false);
var sortTypeContainer = settings.panel.containers.cloneNode(false);
var sortTypeSectionSimple = settings.panel.sections.cloneNode(false);
var sortTypeSectionAdjusted = settings.panel.sections.cloneNode(false);
var weightContainer = settings.panel.containers.cloneNode(false);
var weightSection = settings.panel.sections.cloneNode(false);
this.mainDiv.appendChild(colorTypeContainer);
this.mainDiv.appendChild(sortTypeContainer);
this.mainDiv.appendChild(weightContainer);
this.colorTypeSimple.className = "settings settingsRadio settingsGeneralColorTypeSimple";
this.colorTypeSimple.type = "radio";
this.colorTypeSimple.name = "colorType";
this.colorTypeSimple.id = "colorTypeSimple";
this.colorTypeSimple.addEventListener("click", function() { settings.options.commit("resultsColorType", "colorType", "sim"); });
this.colorTSLabel.htmlFor = "colorTypeSimple";
this.colorTSLabel.textContent = "Simple";
this.colorTSLabel.className = "settings settingsLabelSA";
this.colorTypeAdjusted.className = "settings settingsRadio settingsGeneralColorTypeAdjusted";
this.colorTypeAdjusted.type = "radio";
this.colorTypeAdjusted.name = "colorType";
this.colorTypeAdjusted.id = "colorTypeAdjusted";
this.colorTypeAdjusted.addEventListener("click", function() { settings.options.commit("resultsColorType", "colorType", "adj"); });
this.colorTALabel.htmlFor = "colorTypeAdjusted";
this.colorTALabel.textContent = "Adjusted";
this.colorTALabel.className = "settings settingsLabelSA";
var tempDiv = document.createElement("DIV")
tempDiv.style.float = "left";
tempDiv.style.marginLeft = "15px";
tempDiv.innerHTML = "Color Type
";
tempDiv.appendChild(this.colorTSLabel);
tempDiv.appendChild(this.colorTypeSimple);
tempDiv.appendChild(document.createElement("P"));
tempDiv.appendChild(this.colorTALabel);
tempDiv.appendChild(this.colorTypeAdjusted);
colorTypeContainer.appendChild(tempDiv);
colorTypeContainer.appendChild(colorTypeSectionSimple);
colorTypeContainer.appendChild(colorTypeSectionAdjusted);
colorTypeSectionSimple.innerHTML = "simple
HIT Scraper will use a simple weighted average to ";
colorTypeSectionSimple.innerHTML += "determine the overall TO rating and colorize results off that value. Use this setting to equalize coloration between ";
colorTypeSectionSimple.innerHTML += "HIT Scraper and Color Coded Search.";
colorTypeSectionAdjusted.innerHTML = "adjusted
HIT Scraper will calculate an adjusted average based on ";
colorTypeSectionAdjusted.innerHTML += "confidence of the TO rating to colorize results. Confidence is proportional to the number of reviews.";
this.sortTypeSimple.className = "settings settingsRadio settingsGeneralSortTypeSimple";
this.sortTypeSimple.type = "radio";
this.sortTypeSimple.name = "sortType";
this.sortTypeSimple.id = "sortTypeSimple";
this.sortTypeSimple.addEventListener("click", function() { settings.options.commit("resultsSortType", "sortType", "sim"); });
this.sortTSLabel.htmlFor = "sortTypeSimple";
this.sortTSLabel.textContent = "Simple";
this.sortTSLabel.className = "settings settingsLabelSA";
this.sortTypeAdjusted.className = "settings settingsRadio settingsGeneralSortTypeAdjusted";
this.sortTypeAdjusted.type = "radio";
this.sortTypeAdjusted.name = "sortType";
this.sortTypeAdjusted.id = "sortTypeAdjusted";
this.sortTypeAdjusted.addEventListener("click", function() { settings.options.commit("resultsSortType", "sortType", "adj"); });
this.sortTALabel.htmlFor = "sortTypeAdjusted";
this.sortTALabel.textContent = "Adjusted";
this.sortTALabel.className = "settings settingsLabelSA";
var tempDiv2 = tempDiv.cloneNode(false);
tempDiv2.innerHTML = "Sort Type
";
tempDiv2.appendChild(this.sortTSLabel);
tempDiv2.appendChild(this.sortTypeSimple);
tempDiv2.appendChild(document.createElement("P"));
tempDiv2.appendChild(this.sortTALabel);
tempDiv2.appendChild(this.sortTypeAdjusted);
sortTypeContainer.appendChild(tempDiv2);
sortTypeContainer.appendChild(sortTypeSectionSimple);
sortTypeContainer.appendChild(sortTypeSectionAdjusted);
sortTypeSectionSimple.innerHTML = "simple
";
sortTypeSectionSimple.innerHTML += "HIT Scraper will sort results based simply on value regardless of the number of reviews.";
sortTypeSectionAdjusted.innerHTML = "adjusted
HIT Scraper will adjust ratings based on ";
sortTypeSectionAdjusted.innerHTML += "reliability (ie. confidence) of the data. It factors in the number of reviews such that, for example, a requester ";
sortTypeSectionAdjusted.innerHTML += "with 100 reviews rated at 4.6 will rightfully be ranked higher than a requester with 3 reviews rated at 5. ";
sortTypeSectionAdjusted.innerHTML += "This gives a more accurate representation of the data.";
this.commWeight.className = "settings settingsDivInput settingsGeneralCommWeight";
this.commWeight.contentEditable = true;
this.commWeight.title = "default value: 1";
this.commWeight.addEventListener("keyup", function() {
var num = Math.abs(Number(settings.general.commWeight.textContent));
if (!isNaN(num))
settings.options.commit("comm", "commWeight", num);
});
this.commLabel.textContent = "comm: ";
this.commLabel.className = "settings settingsLabelSA";
this.payWeight.className = "settings settingsDivInput settingsGeneralPayWeight";
this.payWeight.contentEditable = true;
this.payWeight.title = "default value: 3";
this.payWeight.addEventListener("keyup", function() {
var num = Math.abs(Number(settings.general.payWeight.textContent));
if (!isNaN(num))
settings.options.commit("pay", "payWeight", num);
});
this.payLabel.textContent = "pay: ";
this.payLabel.className = "settings settingsLabelSA";
this.fairWeight.className = "settings settingsDivInput settingsGeneralFairWeight";
this.fairWeight.contentEditable = true;
this.fairWeight.title = "default value: 3";
this.fairWeight.addEventListener("keyup", function() {
var num = Math.abs(Number(settings.general.fairWeight.textContent));
if (!isNaN(num))
settings.options.commit("fair", "fairWeight", num);
});
this.fairLabel.textContent = "fair: ";
this.fairLabel.className = "settings settingsLabelSA";
this.fastWeight.className = "settings settingsDivInput settingsGeneralFastWeight";
this.fastWeight.contentEditable = true;
this.fastWeight.title = "default value: 1";
this.fastWeight.addEventListener("keyup", function() {
var num = Math.abs(Number(settings.general.fastWeight.textContent));
if (!isNaN(num))
settings.options.commit("fast", "fastWeight", num);
});
this.fastLabel.textContent = "fast: ";
this.fastLabel.className = "settings settingsLabelSA";
var tempDiv3 = tempDiv.cloneNode(false);
tempDiv3.innerHTML = "TO Weighting
";
tempDiv3.appendChild(this.commLabel);
tempDiv3.appendChild(this.commWeight);
tempDiv3.appendChild(document.createElement("BR"));
tempDiv3.appendChild(this.payLabel);
tempDiv3.appendChild(this.payWeight);
tempDiv3.appendChild(document.createElement("BR"));
tempDiv3.appendChild(this.fairLabel);
tempDiv3.appendChild(this.fairWeight);
tempDiv3.appendChild(document.createElement("BR"));
tempDiv3.appendChild(this.fastLabel);
tempDiv3.appendChild(this.fastWeight);
weightContainer.appendChild(tempDiv3);
weightContainer.appendChild(weightSection);
weightSection.innerHTML = "Specify weights for TO attributes to place greater importance on certain attributes over others.
";
weightSection.innerHTML += "The default values respect backwards compatibility; recommended settings are [1, 6, 3.5, 1].";
},
_init: function() {
var checked = settings.options.resultsColorType;
this.colorTypeSimple.checked = (checked === "adj") ? false : true;
this.colorTypeAdjusted.checked = (checked === "adj") ? true : false;
checked = settings.options.resultsSortType;
this.sortTypeSimple.checked = (checked === "adj") ? false : true;
this.sortTypeAdjusted.checked = (checked === "adj") ? true : false;
this.commWeight.textContent = settings.options.toWeighting.comm;
this.payWeight.textContent = settings.options.toWeighting.pay;
this.fairWeight.textContent = settings.options.toWeighting.fair;
this.fastWeight.textContent = settings.options.toWeighting.fast;
}
};
settings.blocklist = { mainDiv: document.createElement("DIV"),
theListBox: document.createElement("DIV"),
useWildcards: document.createElement("INPUT"),
wildcardLabel: document.createElement("LABEL"),
init: function() {
this.mainDiv.className = "settings settingsInnerDiv settingsMainContainer settingsBlocklistMainDiv";
this.mainDiv.dataset.category = "blocklist";
var wildcardContainer = settings.panel.containers.cloneNode(false);
var listEditorContainer = settings.panel.containers.cloneNode(false);
var wildcardSection = settings.panel.sections.cloneNode(false);
var tempDiv = document.createElement("DIV");
tempDiv.style.float = "left";
this.mainDiv.appendChild(wildcardContainer);
//this.mainDiv.appendChild(listEditorContainer);
this.useWildcards.className = "settings settingsCheckbox settingsBlocklistUseWildcards";
this.useWildcards.type = "checkbox";
this.useWildcards.id = "useWildcards";
this.useWildcards.addEventListener("click", function() { settings.options.commit("blocklistWildcards", "wildblocks", settings.blocklist.useWildcards.checked); });
this.wildcardLabel.className = "settings settingsLabelBlocklist";
this.wildcardLabel.htmlFor = "useWildcards";
this.wildcardLabel.textContent = "Allow Wildcards";
this.theListBox.className = "settings settingsDivInput settingsDivInput-large settingsBlocklistList";
this.theListBox.contentEditable = true;
wildcardContainer.innerHTML = "Advanced Matching
";
wildcardContainer.appendChild(tempDiv);
wildcardContainer.appendChild(wildcardSection);
tempDiv.appendChild(this.wildcardLabel);
tempDiv.appendChild(this.useWildcards);
wildcardSection.style.marginLeft = "150px";
wildcardSection.innerHTML = "Allows for the use of asterisks (*)
as wildcards in the blocklist for simple glob matching. Any blocklist entry without ";
wildcardSection.innerHTML += "an asterisk is treated the same as the default behavior; the entry must exactly match a HIT title or requester to trigger ";
wildcardSection.innerHTML += "a block. Wildcards have the potential to block more HITs than intended if using a pattern that's too generic.
";
wildcardSection.innerHTML += "Matching is not case sensitive regardless of the wildcard setting. Entries without an opening asterisk are expected ";
wildcardSection.innerHTML += "to match the beginning of a line, likewise, entries without a closing asterisk are expected to match the end of a line. ";
wildcardSection.innerHTML += "Example usage below. | Matches | \
Does not match | Notes |
---|
foo*baz | foo bar bat baz | bar foo bat baz\
| no leading or closing asterisks; foo must be at the start of a line, and baz must be at the end of a line for a \
positive match |
foobarbatbaz | foo bar bat |
*foo | \
bar baz foo | foo baz | matches and blocks any line ending in foo \
|
foo* | foo bat bar | bat foo baz | \
matches and blocks any line beginning with foo |
*bar* | foo bar bat baz | \
foo bat baz | matches and blocks any line containing bar |
bar bat baz | \
foo bar |
foobatbarbaz |
** foo | ** foo | \
** foo bar baz | Multiple consecutive asterisks will be treated as a string rather than a wildcard. \
This makes it compatible with HITs using multiple asterisks in their titles, eg., *** contains peanuts *** . |
\
** *bar* *** | ** foo bar baz bat *** | foo bar baz | Consecutive asterisks used in conjunction with single asterisks.\
|
* | | everything | A single asterisk would usually match anything and everything, \
but here, it matches nothing. This prevents accidentally blocking everything from the results table. |
";
listEditorContainer.innerHTML = "Blocklist Editor
";
listEditorContainer.appendChild(this.theListBox)
},
_init: function() {
this.useWildcards.checked = settings.options.blocklistWildcards;
this.theListBox.textContent = "placeholder";
}
};
settings.options = { resultsColorType: null,
resultsSortType: null,
toWeighting: { comm: null, pay: null, fair: null, fast: null },
blocklistWildcards: null,
init: function() {
this.resultsColorType = saveState.getItem("colorType") || "sim";
this.resultsSortType = saveState.getItem("sortType") || "adj";
this.toWeighting = {comm: saveState.getItem("commWeight") || 1,
pay: saveState.getItem("payWeight") || 3,
fair: saveState.getItem("fairWeight") || 3,
fast: saveState.getItem("fastWeight") || 1
};
this.blocklistWildcards = saveState.getItem("wildblocks") || false;
},
commit: function(v, key, val) {
if (this[v] || this[v] === false)
this[v] = val;
else if (this.toWeighting[v] || this.toWeighting[v] == 0)
this.toWeighting[v] = val;
else {
return;
}
saveState.setItem(key, val);
saveState.save();
}
};
settings.display = function() {
var swidth = window.innerWidth*0.9;
var sheight = window.innerHeight*0.9;
var _display = document.querySelector(".settingsSidebarSpans-selected");
this.panel.mainDiv.style.height = String(sheight).concat("px");
this.panel.mainDiv.style.width = String(swidth).concat("px");
this.panel.mainDiv.style.top = String(window.innerHeight*0.05).concat("px");
this.panel.mainDiv.style.left = String(window.innerWidth*0.05).concat("px");
this.panel.closeSpan.style.left = String(swidth - 128).concat("px");
this.sidebar.mainDiv.style.height = String(sheight-45).concat("px");
this.sidebar.mainDiv.style.maxHeight = this.sidebar.mainDiv.style.height;
if (!_display)
this.sidebar.generalSpan.className += " settingsSidebarSpans-selected";
this.general.mainDiv.style.height = String(sheight-59).concat("px");
this.general.mainDiv.style.width = String(swidth-126).concat("px");
this.blocklist.mainDiv.style.height = String(sheight-59).concat("px");
this.blocklist.mainDiv.style.width = String(swidth-126).concat("px");
var containers = document.querySelectorAll(".settingsOptionContainers");
for (var i=0; i-1; --i) { mt[i].className = mt[i].className.replace(/toBlockedRow/, "toBlockedRowOff"); }
showButton.textContent = "Hide ignored hits";
}
else {
mt = document.getElementsByClassName("toBlockedRowOff");
for (var i=mt.length-1; i>-1; i--) { mt[i].className = mt[i].className.replace(/toBlockedRowOff/, "toBlockedRow"); }
showButton.textContent = "Show ignored hits";
}
}
show_interface();
// --- theme randomization
function yiqBrightness(hc,yiq) { // hc type "#000000", "000000", "[00, 00, 00]"
var r = 0, b = 0, g = 0;
if (yiq===true) {
if (typeof hc === 'object') { r = hc[0]; g = hc[1]; b = hc[2]; }
else if (hc.substr(0,1) == "#") {
r = parseInt(hc.substr(1,2), 16);
g = parseInt(hc.substr(3,2), 16);
b = parseInt(hc.substr(5,2), 16);
}
else {
r = parseInt(hc.substr(0,2), 16);
g = parseInt(hc.substr(2,2), 16);
b = parseInt(hc.substr(4,2), 16);
}
return r*0.299 + g*0.587 + b*0.114; // y value
}
else {
return hc[0] + hc[1]*0.956 + hc[2]*0.621; // get r value from full yiq
}
}
function randomizeScheme() {
// TODO: make randomization faster
if (!("background" in rcolors))
for (var l in cucolors) { if (cucolors.hasOwnProperty(l)) rcolors[l] = cucolors[l]; }
var r = 0, g = 0, b = 0;
var k = Object.keys(rcolors);
for (k in rcolors) {
rcolors[k] = getNewColor();
}
console.groupCollapsed("Random theme init routine");
var bg1 = yiqBrightness(rcolors.cpBackground, true), bg0 = yiqBrightness(rcolors.background,true);
var colorslice = {};
var chex = "";
k = ["defaultText", "inputText", "secondText", "export", "accent"];
for (var i in k) { colorslice[k[i]] = rcolors[k[i]]; }
for (k in colorslice) {
var iterations = 0;
if (colorslice.hasOwnProperty(k)) {
var c1 = yiqBrightness(rcolors[k],true);
while (Math.abs(bg1-c1)<69 || Math.abs(bg0-c1)<69) { // increase readability
if (iterations > 61000) {
console.log("Skipping: "+k+". Final value: " + rcolors[k]);
break;
}
chex = getNewColor();
c1 = yiqBrightness(chex,true);
rcolors[k] = chex;
iterations++;
}
console.log(k+": "+rcolors[k]+" after "+iterations + " cycles");
}
}
console.groupEnd();
}
function getNewColor() {
var ri = Math.floor( Math.random()*255 ).toString(16);
var gi = Math.floor( Math.random()*255 ).toString(16);
var bi = Math.floor( Math.random()*255 ).toString(16);
return "#".concat( ri.length<2 ? ("0".concat(ri)) : ri ).concat( gi.length<2 ? ("0".concat(gi)) : gi ).concat( bi.length<2 ? ("0".concat(bi)) : bi);
}
// ---
var global_run = false;
var statusdetail_loop_finished = false;
var date_header = "";
var scraper_history = {};
var wait_loop;
var dings = 0;
function set_progress_report(text, force)
{
if (global_run == true || force == true)
{
progress_report.textContent = text;
var status_text = status_array.join("; ");
status_report.textContent = status_text;
}
}
function get_progress_report()
{
return progress_report.textContent;
}
function wait_until_stopped()
{
if (global_run == true)
{
if (statusdetail_loop_finished == true)
{
big_red_button.textContent = "Start";
set_progress_report("Finished", false);
}
else
{
setTimeout(function(){wait_until_stopped();}, 500);
}
}
}
function display_wait_time(wait_time)
{
if (global_run == true)
{
var current_progress = get_progress_report();
if (current_progress.indexOf("Searching again in")!==-1)
{
set_progress_report(current_progress.replace(/Searching again in \d+ seconds/ , "Searching again in " + wait_time + " seconds"),false);
}
else
set_progress_report(current_progress + " Searching again in " + wait_time + " seconds.", false);
if (wait_time>1)
setTimeout(function(){display_wait_time(wait_time-1);}, 1000);
}
}
function dispArr(ar)
{
var disp = "";
for (var z = 0; z < ar.length; z++)
{
disp += "id " + z + " is " + ar[z] + " ";
}
//console.log(disp);
}
function scrape($src)
{
var $requester = $src.find('a[href^="/mturk/searchbar?selectedSearchType=hitgroups&requester"]');
if ($requester.length == 0)
$requester = $src.find('span.requesterIdentity');
var $title = $src.find('a[class="capsulelink"]');
var $reward = $src.find('span[class="reward"]');
var $preview = $src.find('a[href^="/mturk/preview?"]');
var $qualified = $src.find('a[href^="/mturk/notqualified?"],a[id^="private_hit"]');
var $times = $src.find('a[id^="duration_to_complete"]');
var $descriptions = $src.find('a[id^="description"]');
var not_qualified_group_IDs=[];
var $quals = $src.find('a[id^="qualificationsRequired"]');
var $mixed;
$qualified.each(function(){
var groupy = $(this).attr('href');
if (groupy){
groupy = groupy.replace(/\/mturk\/notqualified\?hitGroupId=([A-Z0-9]+)(&.+)?/,"$1");
groupy = groupy.replace(/\/mturk\/notqualified\?hitId=([A-Z0-9]+)(&.+)?/,"$1");
groupy = groupy.replace(/\&hitGroupId=([A-Z0-9]+)(&.+)?/,"");
groupy = groupy.replace(/\&hitId=([A-Z0-9]+)(&.+)?/,"");
}
not_qualified_group_IDs.push(groupy);
});
//console.log(not_qualified_group_IDs);
if (document.getElementById('lnkWorkerSignin'))
$mixed = $src.find('a[href^="/mturk/preview?"],a[id^="private_hit"]');
else
$mixed = $src.find('a[href^="/mturk/preview?"],a[href^="/mturk/notqualified?"]');
//console.log($mixed);
var listy =[];
$mixed.each(function(){
var groupy = $(this).attr('href');
if (groupy)
{
groupy = groupy.replace(/\/mturk\/notqualified\?hitGroupId=([A-Z0-9]+)(&.+)?/,"$1");
groupy = groupy.replace(/\/mturk\/notqualified\?hitId=([A-Z0-9]+)(&.+)?/,"$1");
groupy = groupy.replace(/\&hitGroupId=([A-Z0-9]+)(&.+)?/,"");
groupy = groupy.replace(/\&hitId=([A-Z0-9]+)(&.+)?/,"");
groupy = groupy.replace("/mturk/preview?groupId=","");
}
else
groupy = "";
//console.log($(this));
//console.log(groupy);
if (listy.indexOf(groupy) == -1)
listy.push(groupy);
else if (groupy == "")
listy.push(groupy);
});
//console.log(listy);
//listy = listy.filter(function(elem, pos) {
// return listy.indexOf(elem) == pos;
//});
//console.log(listy);
for (var j = 0; j < $requester.length; j++)
{
var $hits = $requester.eq(j).parent().parent().parent().parent().parent().parent().find('td[class="capsule_field_text"]');
var requester_name = $requester.eq(j).text().trim();
var requester_link = $requester.eq(j).attr('href');
if (!requester_link)
{
requester_link = "https://www.mturk.com/mturk/searchbar?selectedSearchType=hitgroups&searchWords="+ requester_name.replace(/ /g,"+");
requester_name += " (search)";
}
var group_ID=(listy[j] ? listy[j] : "");
var masters = false;
var title = $title.eq(j).text().trim();
var preview_link = "/mturk/preview?groupId=" + group_ID;
//console.log(listy[j]);
//console.log(title+" "+group_ID +" "+ listy[j]);
if (!group_ID || group_ID.length == 0){
preview_link = requester_link;
title += " (Preview link unavailable)";
}
var reward = $reward.eq(j).text().trim();
var hits = $hits.eq(4).text().trim();
if (hits.length == 0)
hits = "Scraper logged out";
var time = $times.eq(j).parent()[0].nextSibling.nextSibling.innerHTML;
var description = $descriptions.eq(j).parent()[0].nextSibling.nextSibling.innerHTML;
//console.log(description);
var requester_id = requester_link.replace('/mturk/searchbar?selectedSearchType=hitgroups&requesterId=','');
var accept_link;
accept_link = preview_link.replace('preview','previewandaccept');
/*HIT SCRAPER ADDITION*/
var qElements = $quals.eq(j).parent().parent().parent().find('tr');
//console.log(qElements);
var qualifications = [];
for (var i = 1; i < qElements.length; i++) {
qualifications.push((qElements[i].childNodes[1].textContent.trim().replace(/\s+/g, ' ').indexOf("Masters") != -1 ? "[color=red][b]"+qElements[i].childNodes[1].textContent.trim().replace(/\s+/g, ' ')+"[/b][/color]" : qElements[i].childNodes[1].textContent.trim().replace(/\s+/g, ' ')));
if (qElements[i].childNodes[1].textContent.trim().replace(/\s+/g, ' ').indexOf("Masters") != -1)
masters=true;
}
var qualList = (qualifications.join('; ') ? qualifications.join('; ') : "None");
var key = requester_name+title+reward+group_ID;
if (found_key_list.indexOf(key) == -1)
found_key_list.push(key);
else
{
console.log("DUPE: "+key);
continue;
}
if (scraper_history[key] === undefined)
{
scraper_history[key] = {requester:"", title:"", description:"", reward:"", hits:"", req_link:"", quals:"", prev_link:"", rid:"", acc_link:"", new_result:"", dinged:"", qualified:"", found_this_time:"", initial_time:"", reqdb:"",titledb:"",time:"",masters:false};
scraper_history[key].req_link = requester_link;
scraper_history[key].prev_link = preview_link;
scraper_history[key].requester = requester_name;
scraper_history[key].title = title;
scraper_history[key].reward = reward;
scraper_history[key].hits = hits;
scraper_history[key].rid = requester_id;
scraper_history[key].acc_link = accept_link;
scraper_history[key].time = time;
scraper_history[key].quals = qualList;
scraper_history[key].description = description.replace(/'/g, "'").replace(/"/g, """);
scraper_history[key].masters = masters;
scraper_history[key].requester_strip = requester_name.replace(" (search)","");
HITStorage.indexedDB.checkRequester(requester_id,key);
HITStorage.indexedDB.checkTitle(title,key);
if (searched_once)
{
scraper_history[key].initial_time = new Date().getTime();//-1000*(save_new_results_time - SEARCH_REFRESH);
scraper_history[key].new_result = 0;
scraper_history[key].dinged = 0;
}
else
{
scraper_history[key].initial_time = new Date().getTime()-1000*save_new_results_time;
scraper_history[key].new_result = 1000*save_new_results_time;
scraper_history[key].dinged = 1;
}
if (not_qualified_group_IDs.indexOf(group_ID) !== -1)
scraper_history[key].qualified = false;
else
scraper_history[key].qualified = true;
scraper_history[key].found_this_time = true;
}
else
{
scraper_history[key].new_result = new Date().getTime() - scraper_history[key].initial_time;
scraper_history[key].found_this_time = true;
scraper_history[key].hits = hits;
}
}
}
function statusdetail_loop(next_URL)
{
if (global_run == true)
{
if (next_URL.length != 0)
{
$.get(next_URL, function(data)
{
var $src = $(data);
var maxpagerate = $src.find('td[class="error_title"]:contains("You have exceeded the maximum allowed page request rate for this website.")');
if (maxpagerate.length == 0)
{
if (next_page > PAGES_TO_SCRAPE)
{
if(status_array.indexOf("Correcting for skips") == -1 && type != 2){
status_array.push("Correcting for skips");
}
}
set_progress_report("Processing page " + next_page, false);
scrape($src);
var $next_URL = $src.find('a[href^="/mturk/viewsearchbar"]:contains("Next")');
next_URL = ($next_URL.length != 0) ? $next_URL.attr("href") : "";
next_page++;
if (document.getElementById('lnkWorkerSignin'))
maxPages--;
if (maxPages == 0)
{
maxPages = 20;
next_URL = "";
next_page = -1;
}
if (default_type == 1)
{
var hmin = MINIMUM_HITS+1;
for (var j = 0; j < found_key_list.length; j++)
{
//console.log(scraper_history[found_key_list[j]]);
if (scraper_history[found_key_list[j]].hits < hmin)
{
next_URL = "";
next_page = -1;
break;
}
}
}
else if (next_page > PAGES_TO_SCRAPE && correct_for_skips)
{
var skipped_hits = 0;
var added_pages = 0;
for (var k = 0; k < found_key_list.length; k++)
{
var obj = scraper_history[found_key_list[k]];
if (!ignore_check(obj.requester.replace(" (search)",""),obj.title))
skipped_hits++;
}
added_pages = Math.floor(skipped_hits/10);
if (skipped_hits%10 >6)
added_pages++;
if (next_page > PAGES_TO_SCRAPE + added_pages)
{
next_URL = "";
next_page = -1;
}
}
else if (next_page > PAGES_TO_SCRAPE)
{
next_URL = "";
next_page = -1;
}
setTimeout(function(){statusdetail_loop(next_URL);}, STATUSDETAIL_DELAY);
}
else
{
//console.log("MPRE");
setTimeout(function(){statusdetail_loop(next_URL);}, MPRE_DELAY);
}
}).fail(function() {
if (qual_input)
alert("Error when searching. Are you logged out?");
global_run = false;
big_red_button.textContent = "Start";
});
}
else
{
maxPages = 20;
searched_once = true;
var found_hits = found_key_list.length;
var shown_hits = 0;
var new_hits = 0;
var blocklist_hits = 0, belowThreshold_hits = 0;
dings = 0;
var ridString = "";
var rids = [];
var rnames = [];
var lastRow = text_area.rows.length - 1;
for (var i = lastRow; i>0; i--)
text_area.deleteRow(i);
for (var j = 0; j < found_key_list.length; j++)
{
//(function(url,rids,j) {
var obj = scraper_history[found_key_list[j]];
//console.dir(obj);
var ignored = ignore_check(obj.requester.replace(" (search)",""),obj.title);
var includelisted = include_check(obj.requester.replace(" (search)", ""),obj.title);
if (!(obj.masters == true && masters_hide.checked) && (ignored && obj.found_this_time) || (!ignored && obj.found_this_time)){
++shown_hits;
//hit export will update col_heads[1]
var col_heads = [];
if(obj.req_link == obj.rid)
{
if (useTO)
col_heads = ["" + obj.requester + "","" + obj.title + "",obj.reward,obj.hits,"TO down",(obj.title.indexOf("(Preview link unavailable)") > -1) ? "Scraper logged out" : "Accept","M"];
else
col_heads = ["" + obj.requester + "","" + obj.title + "",obj.reward,obj.hits,"TO disabled",(obj.title.indexOf("(Preview link unavailable)") > -1) ? "Scraper logged out" : "Accept","M"];
}
else
{
if (useTO)
col_heads = ["" + obj.requester + "","" + obj.title + "",obj.reward,obj.hits,"TO down","Accept","M"];
else
col_heads = ["" + obj.requester + "","" + obj.title + "",obj.reward,obj.hits,"TO disabled","Accept","M"];
}
var row = text_area.insertRow(text_area.rows.length);
if (!ignored && obj.found_this_time){
if (useBlock.checked) row.setAttribute("class","scraperBlockedRow");
else row.className = "scraperBlockedRowOff";
blocklist_hits++;
obj.dinged = 1;
//console.log(blocklist_hits);
}
else if (!includelisted && obj.found_this_time){
if (highlightIncludes_input.checked) row.setAttribute("class","scraperIncludelistedRow");
else row.setAttribute("class", "scraperIncludelistedRowOff");
}
//url += obj.rid + ',';
//url2 += obj.rid + ',';
if (obj.rid == obj.req_link)
rnames.push(obj.requester_strip);
else{
ridString += obj.rid + ',';
}
rids.push(obj.rid);
if (check_hitDB)
{
col_heads.push("R");
col_heads.push("T");
}
if (!obj.qualified)
{
col_heads.push("Not Qualified");
}
for (i=0; i1)
this_cell.style.textAlign = 'center';
if (i==6)
{
var listOfQuals = obj.quals.replace(/;/g,'\n');
listOfQuals = listOfQuals.replace(/\[(.*?)\]/g,'');
this_cell.title=listOfQuals;
if (obj.masters)
{
this_cell.className = "needmaster"+sufTheme;
this_cell.innerHTML="Y";
}
else
{
this_cell.className = "nomaster"+sufTheme;
this_cell.innerHTML="N";
}
}
if (check_hitDB)
{
if (i==7)
{
if (obj.reqdb){
this_cell.className = "yeshitDB"+sufTheme;
this_cell.title = "This requester name was found in your HitDB.";
this_cell.addEventListener("click", (function (obj) { return function() {search_deleg(obj,0);}})(obj));
}
else {
this_cell.className = "nohitDB"+sufTheme;
this_cell.title = "This requester name was not found in your HitDB, or you don't have a HitDB.";
}
}
else if (i==8)
{
if (obj.titledb){
this_cell.className = "yeshitDB"+sufTheme;
this_cell.title = "This HIT title was found in your HitDB.";
this_cell.addEventListener("click", (function (obj) { return function() {search_deleg(obj,1);}})(obj));
}
else {
this_cell.className = "nohitDB"+sufTheme;
this_cell.title = "This HIT title was not found in your HitDB, or you don't have a HitDB.";
}
}
else if (i==9)
this_cell.className = "tooweak"+sufTheme;
}
else if (i==7)
this_cell.className = "tooweak"+sufTheme;
}
if (Object.keys(scraper_history).length > 0)
{
if (obj.dinged == 0)
{
if (shouldInclude && !includelisted)
{
dings++;
obj.dinged = 2; //#hookdinged
}
else if (!shouldInclude)
{
dings++;
obj.dinged = 2;
}
}
if (obj.new_result < 1000*save_new_results_time)
{
if (!ignored)
new_hits++;
for (var h = 0; h < col_heads.length; h++)
{
row.cells[h].style.fontSize = default_text_size + 1+"px";
row.cells[h].style.fontWeight = "bold";
}
}
}
var button1 = document.createElement('button'); // FORUM VBCODE EXPORT BUTTON
button1.textContent = 'vB';
button1.title = 'Export this HIT description as vBulletin formatted text';
button1.className = "vbButton";
button1.className += opt_exportvb.checked ? (" taButtons"+sufTheme) : (" taButtonsOff"+sufTheme);
button1.style.width = '30px';
var button2 = document.createElement('button'); //BUTTON TO BLOCK REQUESTER
button2.textContent = 'R';
button2.title = 'Add requester to block list';
button2.style.width = '15px';
button2.className += " taButtons"+sufTheme;
var button3 = document.createElement('button'); //BUTTON TO BLOCK TITLE
button3.textContent = 'T';
button3.title = 'Add title to block list';
button3.style.width = '15px';
button3.className += " taButtons"+sufTheme;
var button4 = document.createElement('button'); // IRC EXPORT BUTTON
button4.textContent = 'IRC';
button4.className = "ircButton";
button4.className += opt_exportirc.checked ? (" taButtons"+sufTheme) : (" taButtonsOff"+sufTheme);
button4.style.width = '30px';
button4.title = 'Click to save HIT information to your clipboard. Please wait while shortened URLs are retrieved.';
var button5 = document.createElement('button'); // REDDIT EXPORT BUTTON
button5.textContent = 'HWTF';
button5.style.width = '33px';
button5.className = "redditButton";
button5.className += opt_exportreddit.checked ? (" taButtons"+sufTheme) : (" taButtonsOff"+sufTheme);
button5.title = 'Export this HIT to r/HITsWorthTurkingFor title standards.'
button1.addEventListener("click", (function (obj,j) { return function() {export_sel_deleg(obj,j,"vb");}})(obj,j));
row.cells[1].appendChild(document.createTextNode(" "));
if (obj.rid != obj.req_link)
row.cells[1].appendChild(button1);
button4.addEventListener("click", (function (obj,j) { return function() {export_sel_deleg(obj,j,"irc");}})(obj,j));
row.cells[1].appendChild(document.createTextNode(" "));
row.cells[1].appendChild(button4);
button5.addEventListener("click", (function (obj,j) { return function() {export_sel_deleg(obj,j,"reddit");}})(obj,j));
row.cells[1].appendChild(document.createTextNode(" "));
row.cells[1].appendChild(button5);
button2.addEventListener("click", (function (obj,j) { return function() {block_deleg(obj,0);}})(obj,j));
row.cells[0].appendChild(document.createTextNode(" "));
row.cells[0].appendChild(button2);
button3.addEventListener("click", (function (obj,j) { return function() {block_deleg(obj,1);}})(obj,j));
row.cells[0].appendChild(button3);
}
//});
}
//url = url.substring(0,url.length - 1);
//console.log(url);
var success_flag = false;
var rdata = "";
if (useTO){
if (ridString != "")
rdata = getTOMulti(ridString);
else
rdata = "Scraper logged out";
}
else
rdata = "TO Down";
//var rdata = "TO Down";
//console.log(rdata);
if (rdata != "TO Down")
{
var globalMeans = { "pay":0, "paycount":0, "quality":0, "divisor":0, "reviews":0, "reviewcount":0 };
for (var r = 0; r < rids.length; r++) { // calculate global values across entire table
if (rdata[rids[r]]) {
if (rdata[rids[r]].attrs.pay > 0) {
globalMeans.quality += rdata[rids[r]].attrs.pay * settings.options.toWeighting.pay;
globalMeans.pay += rdata[rids[r]].attrs.pay * 1.0;
globalMeans.paycount++;
globalMeans.divisor += settings.options.toWeighting.pay;
}
if (rdata[rids[r]].attrs.comm.trim() > 0) {
globalMeans.quality += rdata[rids[r]].attrs.comm.trim()*settings.options.toWeighting.comm;
globalMeans.divisor += settings.options.toWeighting.comm;
}
if (rdata[rids[r]].attrs.fast.trim() > 0) {
globalMeans.quality += rdata[rids[r]].attrs.fast.trim()*settings.options.toWeighting.fast;
globalMeans.divisor += settings.options.toWeighting.fast;
}
if (rdata[rids[r]].attrs.fair.trim() > 0) {
globalMeans.quality += rdata[rids[r]].attrs.fair.trim()*settings.options.toWeighting.fair;
globalMeans.divisor += settings.options.toWeighting.fair;
}
if (rdata[rids[r]].reviews > 0) {
globalMeans.reviews += rdata[rids[r]].reviews*1.0;
globalMeans.reviewcount++;
}
}
}
globalMeans.quality = globalMeans.divisor > 0 ? globalMeans.quality/globalMeans.divisor : 0;
globalMeans.pay = globalMeans.paycount > 0 ? globalMeans.pay/globalMeans.paycount : 0;
globalMeans.reviews = globalMeans.reviewcount > 0 ? globalMeans.reviews/globalMeans.reviewcount : 0;
for (var r = 0; r < rids.length; r++)
{
if (rdata[rids[r]])
{
var pay = rdata[rids[r]].attrs.pay*1.0;
var reviews = rdata[rids[r]].reviews*1.0;
var quality = 0;
var sum = 0;
var divisor = 0;
var count = 0;
var wpayrank = 0;
var wqualityrank = 0;
//console.log(rdata[rids[r]]);
var comm = rdata[rids[r]].attrs.comm.trim()*1.0;
var fair = rdata[rids[r]].attrs.fair.trim()*1.0;
var fast = rdata[rids[r]].attrs.fast.trim()*1.0;
var tos = rdata[rids[r]].tos_flags;
if (comm > 0)
{
sum += settings.options.toWeighting.comm*comm;
divisor += settings.options.toWeighting.comm;
}
if (pay > 0)
{
sum += settings.options.toWeighting.pay*pay;
divisor += settings.options.toWeighting.pay;
}
if (fair > 0)
{
sum += settings.options.toWeighting.fair*fair;
divisor += settings.options.toWeighting.fair;
}
if (fast > 0)
{
sum += settings.options.toWeighting.fast*fast;
divisor += settings.options.toWeighting.fast;
}
if (divisor > 0)
{
quality = sum/divisor;
}
var apay = (reviews * pay + 15) / (reviews + 5);
//wpayrank = ((globalMeans.pay - (pay/globalMeans.paycount)) + reviews * pay) / globalMeans.reviewcount; // simplification
//wpayrank = (globalMeans.reviews * (globalMeans.pay - (pay/globalMeans.paycount)) + (reviews * pay)) / globalMeans.reviewcount; // unit derivation
wpayrank = apay - 1.645 * Math.sqrt((Math.pow(1.061 * apay,2) - Math.pow(apay,2)) / (reviews + 5)); // pnormal alpha = 0.10
//wpayrank = (10*globalMeans.pay + reviews*pay)/(globalMeans.reviewcount+10); // minimalist, no zs/conf - large fluctuations
var aqual = (quality * reviews + 15)/(reviews + 5);
//wqualityrank = (15*globalMeans.quality + reviews*quality)/(reviews+15);
wqualityrank = aqual - 1.645 * Math.sqrt((Math.pow(1.0693 * aqual,2) - Math.pow(aqual,2)) / (reviews + 5)); // pnormal, alpha = 0.10
var titleText = "";
titleText += "comm: "+comm+"\nfair: "+fair+"\nfast: "+fast+"\npay: "+pay+"\nReviews: "+reviews+"\nTOS violations: "+tos;
titleText += "\n\nAdjusted pay rating: " + wpayrank.toPrecision(4) + "\nGlobal pay mean: " + globalMeans.pay.toPrecision(4);
titleText += "\nWeighted quality: " + quality.toPrecision(4) + "\nAdjusted quality rating: " + wqualityrank.toPrecision(4) +
"\nGlobal quality mean: " + globalMeans.quality.toPrecision(4);
text_area.rows[r+1].cells[4].innerHTML = "" + pay.toFixed(2) + "";
text_area.rows[r+1].cells[4].title += titleText;
text_area.rows[r+1].cells[4].dataset.simPay = pay;
text_area.rows[r+1].cells[4].dataset.adjPay = wpayrank.toPrecision(4);
text_area.rows[r+1].cells[4].dataset.simQual = quality.toPrecision(4);
text_area.rows[r+1].cells[4].dataset.adjQual = wqualityrank.toPrecision(4);
if (pay < MINIMUM_TO && text_area.rows[r+1].className.match(/(scraperBlocked|toBlocked)/) == null) {
text_area.rows[r+1].className += (showButton.textContent == "Hide ignored hits") ? " toBlockedRowOff" : " toBlockedRow";
belowThreshold_hits++;
for (var m=0; m 0 && scraper_history[found_key_list[m]].rid == rids[r] && scraper_history[found_key_list[m]].dinged == 2) {
//console.log("[threshold] "+scraper_history[found_key_list[m]].requester+"; initial dings: "+dings);
dings--;
scraper_history[found_key_list[m]].dinged = 1;
//console.log("dings left: "+dings);
}
}
}
if (reviews > 4)
{
var copt = saveState.getItem("colorType") || "sim";
if (copt == "sim") {
if (quality > 4)
text_area.rows[r+1].className += " toHigh"+sufTheme;
else if (quality > 3)
text_area.rows[r+1].className += " toGood"+sufTheme;
else if (quality > 2)
text_area.rows[r+1].className += " toAverage"+sufTheme;
else if (quality > 0)
text_area.rows[r+1].className += " toPoor"+sufTheme;
}
else {
if (wqualityrank > 4.05)
text_area.rows[r+1].className += " toHigh"+sufTheme;
else if (wqualityrank > 3.06)
text_area.rows[r+1].className += " toGood"+sufTheme;
else if (wqualityrank > 2.4)
text_area.rows[r+1].className += " toAverage"+sufTheme;
else if (wqualityrank > 1.7)
text_area.rows[r+1].className += " toLow"+sufTheme;
else if (wqualityrank > 0)
text_area.rows[r+1].className += " toPoor"+sufTheme;
}
}
else if (text_area.rows[r+1].className.match(/toNone/) == null) text_area.rows[r+1].className += " toNone"+sufTheme;
}
else if(rdata == "Scraper logged out")
{
text_area.rows[r+1].cells[4].innerHTML = "Search TO";
text_area.rows[r+1].cells[4].setAttribute("title", "No Data");
text_area.rows[r+1].className += " toNone"+sufTheme;
if (block_no_to && text_area.rows[r+1].className.match(/(scraperBlocked|toBlocked)/) == null) {
text_area.rows[r+1].className += (showButton.textContent == "Hide ignored hits") ? " toBlockedRowOff" : " toBlockedRow";
belowThreshold_hits++;
for (var m=0; m 0 && scraper_history[found_key_list[m]].rid == rids[r] && scraper_history[found_key_list[m]].dinged == 2) {
//console.log("[nodata]"+scraper_history[found_key_list[m]].requester+"; initial dings: "+dings);
dings--;
scraper_history[found_key_list[m]].dinged = 1;
//console.log("dings left: "+dings);
}
}
}
}
else
{
text_area.rows[r+1].cells[4].innerHTML = "No Data";
text_area.rows[r+1].cells[4].setAttribute("title", "No Data");
text_area.rows[r+1].className += " toNone"+sufTheme;
if (block_no_to && text_area.rows[r+1].className.match(/(scraperBlocked|toBlocked)/) == null) {
text_area.rows[r+1].className += (showButton.textContent == "Hide ignored hits") ? " toBlockedRowOff" : " toBlockedRow";
belowThreshold_hits++;
for (var m=0; m 0 && scraper_history[found_key_list[m]].rid == rids[r] && scraper_history[found_key_list[m]].dinged == 2) {
//console.log("[nodata]"+scraper_history[found_key_list[m]].requester+"; initial dings: "+dings);
dings--;
scraper_history[found_key_list[m]].dinged = 1;
//console.log("dings left: "+dings);
}
}
}
}
}
if (sort_TO) table_sort("pay");
if (sort_TO2) table_sort("qual");
success_flag = true;
}
var pStr = "Scrape complete. " + shown_hits + " HITs found (" + new_hits + " new results). ";
if (!useBlock.checked) {
if (blocklist_hits > 0) pStr += blocklist_hits + " HITs shown from blocklist.";
if (belowThreshold_hits > 0) pStr += " " + belowThreshold_hits + " HITs below TO threshold.";
set_progress_report(pStr, false);
}
else {
if (blocklist_hits > 0 || belowThreshold_hits > 0) pStr += (belowThreshold_hits+blocklist_hits) + " HITs ignored: ";
if (blocklist_hits > 0) pStr += blocklist_hits + " from blocklist ";
if (belowThreshold_hits > 0) pStr += belowThreshold_hits + " below TO threshold.";
set_progress_report(pStr, false);
}
if (!success_flag)
for (var s = 0; s < rids.length; s++)
if (text_area.rows[s+1].className.match(/toNone/) === null) text_area.rows[s+1].className += " toNone"+sufTheme;
statusdetail_loop_finished = true;
if (dings > 0){
newHits(shouldDing);
}
if (SEARCH_REFRESH>0)
{
wait_loop = setTimeout(function(){if (global_run) start_it();}, 1000*SEARCH_REFRESH);
display_wait_time(SEARCH_REFRESH);
}
else
{
global_run = false;
big_red_button.textContent = "Start";
}
}
}
}
function table_sort(stype) {
//--- Get the table we want to sort.
var jTableToSort = $("#body_table");
//--- Get the rows to sort, but skip the first row, since it contains column titles.
var jRowsToSort = jTableToSort.find ("tr:gt(0)");
//--- Sort the rows in place.
jRowsToSort.sort(function(a,b) {
var opt = saveState.getItem("sortType") || "adj";
var aVal = Number( $(a).find("td:eq(4)").attr("data-"+opt+"-"+stype) );
var bVal = Number( $(b).find("td:eq(4)").attr("data-"+opt+"-"+stype) );
//--- no TO goes to the bottom
if (isNaN(aVal)) aVal = 0;
if (isNaN(bVal)) bVal = 0;
//--- sort
if (sort_asc.checked) return aVal - bVal;
else return bVal - aVal; // descending order
}).appendTo(jTableToSort);
}
//--- check block list for requester name and HIT title
function ignore_check(r,t){
var tempList = ignore_list.map(function(item) { return item.toLowerCase().replace(/\s+/g," "); });
var foundR = -1;
var foundT = -1;
if (!settings.options.blocklistWildcards) { // wildcard matching disabled
foundR = tempList.indexOf(r.toLowerCase().replace(/\s+/g," "));
foundT = tempList.indexOf(t.toLowerCase().replace(/\s+/g," "));
}
else {
var blockWilds = [], blockExact = [];
blockExact = tempList.filter(function(item) { // separate wildcard glob patterns from regular exact patterns
if (item.search(".*?[*].*")) return true; else if (item.length > 1) {blockWilds.push(item); return false;}
});
// run default matching first
foundR = blockExact.indexOf(r.toLowerCase().replace(/\s+/g," "));
foundT = blockExact.indexOf(t.toLowerCase().replace(/\s+/g," "));
// if no match, try globs
if (foundR == -1 && foundT == -1) {
for (var i=0; i0)
{
initial_url = initial_url.replace("searchWords=", "searchWords=" + search_input.value);
}
if (time_input.value.replace(/[^0-9]+/g,"") != "")
{
SEARCH_REFRESH = Number(time_input.value);
}
if (page_input.value.replace(/[^0-9]+/g,"") != "")
{
PAGES_TO_SCRAPE = Number(page_input.value);
if (PAGES_TO_SCRAPE > 20 && document.getElementById('lnkWorkerSignin')){
status_array.push("Search limited to 20 pages when logged out");
PAGES_TO_SCRAPE = 20;
}
}
if (new_time_display_input.value.replace(/[^0-9]+/g,"") != "")
{
save_new_results_time = Number(new_time_display_input.value);
}
if (reward_input.value.replace(/[^0-9]+/g,"") != "")
{
initial_url += "&minReward=" + reward_input.value;
}
else
{
initial_url += "&minReward=0.00";
}
if (qual_input.checked)
{
if (document.getElementById('lnkWorkerSignin')){
status_array.push("Logged out, ignoring qualified");
initial_url += "&qualifiedFor=off";
}
else
initial_url += "&qualifiedFor=on";
}
else
{
initial_url += "&qualifiedFor=off";
}
if (masters_input.checked)
{
initial_url += "&requiresMasterQual=on";
}
if (masters_hide.checked)
{
status_array.push("Masters hits hidden");
}
switch (sort_input[sort_input.selectedIndex].value)
{
case "late":
initial_url+= "&sortType=LastUpdatedTime%3A";
type=1;
default_type = 0;
break;
case "most":
initial_url+= "&sortType=NumHITs%3A";
default_type = 1;
type=2;
status_array.push("Sorting by NumHITs ignores Correct For Skips in favor of minimum batch size");
break;
case "amount":
initial_url+= "&sortType=Reward%3A";
type=3;
default_type = 0;
break;
case "alpha":
type=4;
initial_url += "&sortType=Title%3A";
break;
default:
alert("I don't know how you did it, but you broke it. Good job.");
}
if (min_input.value.replace(/[^0-9]+/g,"") != "")
{
if (type != 2)
status_array.push("Minimum Batch Size requires sorting by Most Available");
MINIMUM_HITS = Number(min_input.value);
}
if (sort_input_invert.checked)
{
if (sort_input[sort_input.selectedIndex].value == "alpha")
initial_url += "1";
else
initial_url += "0";
}
else
{
if (sort_input[sort_input.selectedIndex].value == "alpha")
initial_url += "0";
else
initial_url += "1";
}
if (sort_to.checked)
{
if (document.getElementById('lnkWorkerSignin')){
logged_array.push("Logged out, ignoring TO");
sort_TO = false;
sort_TO2 = false;
}
else
{
sort_TO = true;
sort_TO2 = false;
status_array.push("Sorting by TO pay is still in testing");
}
}
else if (sort_to2.checked)
{
if (document.getElementById('lnkWorkerSignin')){
status_array.push("Logged out, ignoring TO");
sort_TO = false;
sort_TO2 = false;
}
else
{
sort_TO2 = true;
sort_TO= false;
status_array.push("Sorting by TO quality is still in testing");
}
}
else
{
sort_TO = false;
sort_TO2 = false;
}
if (useTO_input.checked)
{
useTO = false;
}
else
{
useTO = true;
}
if (min_to.value.replace(/[^0-9]+/g,"") != "")
{
MINIMUM_TO = Number(min_to.value);
$("#show_TO_stuff_button").show();
}
else
{
MINIMUM_TO = -1;
}
if (friesAreDone.checked)
{
shouldDing = true;
}
else
{
shouldDing = false;
}
if (no_to_block.checked)
{
block_no_to = true;
$("#show_TO_stuff_button").show();
}
else
{
block_no_to = false;
}
if (!block_no_to && MINIMUM_TO == -1)
$("#show_TO_stuff_button").hide();
if (correctForSkips.checked)
{
if (matchOnly.checked)
{
status_array.push("Use Includelist (match only) checked, so ignoring Correct For Skips to prevent issues");
correct_for_skips = false;
}
else{
correct_for_skips = true;
}
}
else
{
correct_for_skips = false;
}
if (useBlock.checked)
{
useBlocklist = true;
}
else
{
useBlocklist = false;
}
if (matchOnly.checked)
{
if (include_list.length == 0){
status_array.push("No items in includelist, so ignoring Use Includelist checkbox");
shouldInclude = false;
}
else
{
shouldInclude = true;
if (!useBlock.checked)
{
status_array.push("Use Includelist checked, so forcing Use Blocklist for intended output behavior");
useBlocklist = true;
}
}
}
else
{
shouldInclude = false;
}
initial_url += "&pageNumber=1&searchSpec=HITGroupSearch";
audio_index = audio_option[audio_option.selectedIndex].value;
start_it();
}
else
{
global_run = false;
clearTimeout(wait_loop);
big_red_button.textContent = "Start";
set_progress_report("Stopped", true);
}
}
function start_it()
{
statusdetail_loop_finished = false;
big_red_button.textContent = "Stop";
found_key_list = [];
var ctime = new Date().getTime();
if (ctime - last_clear_time > save_results_time*666)
{
var last_history = scraper_history;
scraper_history = {};
for (var key in last_history)
{
if (last_history[key].new_resultsave_new_results_time*1000)
last_history[key].initial_time = ctime-1000*save_new_results_time;
}
}
}
last_clear_time = ctime;
}
next_page = 1;
statusdetail_loop(initial_url);
}
function themeSwitchAux(th, force) {
var carr = $("[class*='"+sufTheme+"']");
for (var i=0; i-1; i--) mt[i].className = mt[i].className+"Off";
show_checkboxes.checked = false;
thT7.textContent = "Show Checkboxes!";
saveState.setItem("checkboxes", show_checkboxes.checked);
}
else {
var mt = document.getElementsByClassName("checkboxesOff")
for (var i=mt.length-1; i>-1; i--) mt[i].className = mt[i].className.replace(/Off/, "");
show_checkboxes.checked = true;
thT7.textContent = "Hide Checkboxes!";
saveState.setItem("checkboxes", show_checkboxes.checked);
}
saveState.setItem("checkboxes", show_checkboxes.checked);
saveState.save();
});
thT1.addEventListener("click", function() { themeSwitchAux("_thSDark"); saveState.save(); }, false);
thT2.addEventListener("click", function() { themeSwitchAux("_thSLight"); saveState.save();}, false);
thT3.addEventListener("click", function() { themeSwitchAux("_thWisp"); saveState.save();}, false);
thT4.addEventListener("click", function() { themeSwitchAux("_thCustom"); saveState.save();}, false);
thT5.addEventListener("click", function() { themeSwitchAux("_thRandom"); saveState.save();}, false);
thT6.addEventListener("click", function() { themeSwitchAux("_thClassic"); saveState.save();}, false);
thC2.appendChild(thT7);
thC2.appendChild(thT6);
thC2.appendChild(thT2);
thC2.appendChild(thT3);
thC2.appendChild(thT1);
thC2.appendChild(thT4);
thC2.appendChild(thT5);
thE0.appendChild(thC2);
themeMenu.appendChild(thE0);
control_panel.parentNode.insertBefore(themeMenu, control_panel);
//---
var spacer = document.createElement("SPAN");
spacer.className = "spacer"+sufTheme;
spacer.appendChild(document.createTextNode(SPACER_TEXT));
control_panel.style.fontSize = "14px";
//control_panel.removeChild(big_red_button);
control_panel.appendChild(document.createTextNode("Auto-refresh delay: "));
time_input.onkeydown = function(event){if (event.keyCode == 13){start_running();}};
time_input.title = "Enter search refresh delay in seconds.\n" + "Enter 0 for no auto-refresh.\n" + "Default is 0 (no auto-refresh).";
time_input.size = 3;
time_input.className = "cpInput"+sufTheme;
time_input.addEventListener("keyup", function() {
time_input.value = time_input.value.replace(/.*?(\d+)?.*/, '$1');
if (time_input.value >= 0) {
saveState.setItem("refreshTime", time_input.value);
saveState.save();
}
} );
control_panel.appendChild(time_input);
control_panel.appendChild(document.createTextNode(" "));
control_panel.appendChild(spacer);
control_panel.appendChild(document.createTextNode("Pages to scrape: "));
page_input.onkeydown = function(event){if (event.keyCode == 13){start_running();}};
page_input.title = "Enter number of pages to scrape. Default is 3.\n" + "Has no effect in a batch search (Most Available sort).";
page_input.size = 3;
page_input.className = "cpInput"+sufTheme;
page_input.addEventListener("keyup", function() {
page_input.value = page_input.value.replace(/.*?(\d+)?.*/, '$1');
if (page_input.value > 0) {
saveState.setItem("numPages", page_input.value);
saveState.save();
}
} );
control_panel.appendChild(page_input);
var skipspan = document.createElement("SPAN");
skipspan.appendChild(document.createTextNode("Correct for skips"));
skipspan.className += " cpSpans"+sufTheme;
skipspan.title = "Searches additional pages to get a more consistent number of results. Helpful if you're blocking a lot of items.";
if (correctForSkips.checked) skipspan.className += " cpSpansOn"+sufTheme;
skipspan.addEventListener("click", function() {
UIAux(skipspan, correctForSkips, "skips");
}, false);
if (show_checkboxes.checked) correctForSkips.className = "checkboxes";
else correctForSkips.className = "checkboxesOff";
skipspan.appendChild(correctForSkips);
correctForSkips.onclick = function () { UIAux(skipspan, correctForSkips, "skips"); };
control_panel.appendChild(spacer.cloneNode(true));
control_panel.appendChild(skipspan);
control_panel.appendChild(document.createTextNode(" "));
control_panel.appendChild(spacer.cloneNode(true));
control_panel.appendChild(document.createTextNode("Minimum batch size: "));
min_input.onkeydown = function(event){if (event.keyCode == 13){start_running();}};
min_input.title = "Enter minimum HITs for batch search (must Sort by Most Available).\n" + "Default is 100.";
min_input.size = 3;
min_input.className = "cpInput"+sufTheme;
min_input.addEventListener("keyup", function() {
min_input.value = min_input.value.replace(/.*?(\d+)?.*/, '$1');
if (min_input.value >= 0) {
saveState.setItem("minHits", min_input.value);
saveState.save();
}
} );
control_panel.appendChild(min_input);
control_panel.appendChild(document.createTextNode(" "));
control_panel.appendChild(document.createElement("P"));
control_panel.appendChild(document.createTextNode("Minimum reward: "));
reward_input.size = 3;
reward_input.title = "Enter the minimum desired pay per HIT, such as 0.10";
reward_input.onkeydown = function(event){if (event.keyCode == 13){start_running();}};
reward_input.className = "cpInput"+sufTheme;
reward_input.addEventListener("keyup", function() {
reward_input.value = reward_input.value.replace(/.*?(\d*\.?\d*)?.*/, '$1');
if (reward_input.value >= 0) {
saveState.setItem("reward", reward_input.value);
saveState.save();
}
} );
control_panel.appendChild(reward_input);
var qualspan = document.createElement("SPAN");
qualspan.appendChild(document.createTextNode("Qualified"));
qualspan.className += " cpSpans"+sufTheme;
qualspan.title = "Only show HITs you're currently qualified for (must be logged in).";
if (qual_input.checked) qualspan.className += " cpSpansOn"+sufTheme;
qualspan.addEventListener("click", function() {
UIAux(qualspan, qual_input, "qualified");
}, false);
if (show_checkboxes.checked) qual_input.className = "checkboxes";
else qual_input.className = "checkboxesOff";
qualspan.appendChild(qual_input);
qual_input.onclick = function () { UIAux(qualspan, qual_input, "qualified"); };
control_panel.appendChild(spacer.cloneNode(true));
control_panel.appendChild(qualspan);
var forcemastersspan = document.createElement("SPAN");
forcemastersspan.appendChild(document.createTextNode("Masters Only"));
forcemastersspan.className += " cpSpans"+sufTheme;
forcemastersspan.title = "Only show HITs that require Masters qualifications.";
if (masters_input.checked) forcemastersspan.className += " cpSpansOn"+sufTheme;
forcemastersspan.addEventListener("click", function() {
UIAux(forcemastersspan, masters_input, "masters");
}, false);
if (show_checkboxes.checked) masters_input.className = "checkboxes";
else masters_input.className = "checkboxesOff";
forcemastersspan.appendChild(masters_input);
masters_input.onclick = function () { UIAux(forcemastersspan, masters_input, "masters"); };
control_panel.appendChild(spacer.cloneNode(true));
control_panel.appendChild(forcemastersspan);
var mhidespan = document.createElement("SPAN");
mhidespan.appendChild(document.createTextNode("Hide Masters"));
mhidespan.className += " cpSpans"+sufTheme;
mhidespan.title = "Remove masters hits from the results if selected, otherwise display both masters and non-masters HITS.\nThe \"qualified\" setting superceedes this option.";
if (masters_hide.checked) mhidespan.className += " cpSpansOn"+sufTheme;
mhidespan.addEventListener("click", function() {
UIAux(mhidespan, masters_hide, "mShow");
}, false);
if (show_checkboxes.checked) masters_hide.className = "checkboxes";
else masters_hide.className = "checkboxesOff";
mhidespan.appendChild(masters_hide);
masters_hide.onclick = function () { UIAux(mhidespan, masters_hide, "mShow"); };
control_panel.appendChild(spacer.cloneNode(true));
control_panel.appendChild(mhidespan);
control_panel.appendChild(spacer.cloneNode(true));
control_panel.appendChild(document.createTextNode("Sort type: "));
control_panel.appendChild(sort_input);
sort_input.className += " cpInput"+sufTheme;
sort_input.addEventListener('change', function() {
var search = this.selectedIndex;
console.log(search);
saveState.setItem("sort", search);
saveState.save();
});
sort_input.title = "Get search results by...\n Latest = HIT Creation Date (newest first),\n Most Available = HITs Available (most first),\n Reward = Reward Amount (most first),\n Title = Title (A-Z)";
var sinvertspan = document.createElement("SPAN");
sinvertspan.appendChild(document.createTextNode("Invert"));
sinvertspan.className += " cpSpans"+sufTheme;
sinvertspan.title = "Reverse the order of the Sort Type choice, so...\n Latest = HIT Creation Date (oldest first),\n Most Available = HITs Available (least first),\n Reward = Reward Amount (least first),\n Title = Title (Z-A)";
if (sort_input_invert.checked) sinvertspan.className += " cpSpansOn"+sufTheme;
sinvertspan.addEventListener("click", function() {
UIAux(sinvertspan, sort_input_invert, "invert");
}, false);
if (show_checkboxes.checked) sort_input_invert.className = "checkboxes";
else sort_input_invert.className = "checkboxesOff";
sinvertspan.appendChild(sort_input_invert);
sort_input_invert.onclick = function () { UIAux(sinvertspan, sort_input_invert, "invert"); };
control_panel.appendChild(spacer.cloneNode(true));
control_panel.appendChild(sinvertspan);
control_panel.appendChild(document.createElement("P"));
control_panel.appendChild(document.createTextNode("New HIT highlighting: "));
new_time_display_input.onkeydown = function(event){if (event.keyCode == 13){start_running();}};
new_time_display_input.title = "Enter time (in seconds) to keep new HITs highlighted.\n" + "Default is 300 (5 minutes).";
new_time_display_input.size = 6;
new_time_display_input.className = "cpInput"+sufTheme;
new_time_display_input.addEventListener("keyup", function() {
new_time_display_input.value = new_time_display_input.value.replace(/.*?(\d*)?.*/, '$1');
if (new_time_display_input.value >= 0) {
saveState.setItem("newHitHighlight", new_time_display_input.value);
saveState.save();
}
} );
control_panel.appendChild(new_time_display_input);
var soundspan = document.createElement("SPAN");
soundspan.appendChild(document.createTextNode("Sound on new HIT "));
soundspan.className += " cpSpans"+sufTheme;
soundspan.title = "Play a sound when new results are found.";
if (friesAreDone.checked) soundspan.className += " cpSpansOn"+sufTheme;
audio_option.className += " cpInput"+sufTheme;
soundspan.addEventListener("click", function() {
if (friesAreDone.checked) {
friesAreDone.checked = false;
soundspan.className = soundspan.className.replace(/(?:^| +)cpSpansOn_[a-zA-Z]+/g, "");
control_panel.removeChild(audio_option);
} else {
friesAreDone.checked = true;
soundspan.className += " cpSpansOn"+sufTheme;
control_panel.insertBefore(audio_option, soundspan.nextSibling);
}
saveState.setItem("fries", friesAreDone.checked);
saveState.save();
}, false);
if (show_checkboxes.checked) friesAreDone.className = "checkboxes";
else friesAreDone.className = "checkboxesOff";
soundspan.appendChild(friesAreDone);
friesAreDone.onclick = function () { UIAux(soundspan, friesAreDone, "fries"); };
control_panel.appendChild(spacer.cloneNode(true));
control_panel.appendChild(soundspan);
audio_option.title = "Select which sound will be played.";
audio_option.addEventListener('change', function() {
var sound = this.selectedIndex;
saveState.setItem("whichfry", sound);
saveState.save();
});
if (friesAreDone.checked) control_panel.insertBefore(audio_option, soundspan.nextSibling);
var ascspan = document.createElement("SPAN");
ascspan.className += " cpSpans"+sufTheme;
ascspan.style.fontSize = '15px';
if (sort_asc.checked) ascspan.className += " cpSpansOn"+sufTheme;
ascspan.title = "Sort results in ascending (low to high) order.";
var dscspan = document.createElement("SPAN");
dscspan.className += " cpSpans"+sufTheme;
dscspan.style.fontSize = '15px';
if (sort_dsc.checked) dscspan.className += " cpSpansOn"+sufTheme;
dscspan.title = "Sort results in descending (high to low) order.";
ascspan.addEventListener("click", function() {
if (!sort_asc.checked) {
sort_asc.checked = true;
sort_dsc.checked = false;
saveState.setItem("asc", sort_asc.checked);
saveState.setItem("dsc", sort_dsc.checked);
saveState.save();
ascspan.className += " cpSpansOn"+sufTheme;
dscspan.className = dscspan.className.replace(/(?:^| +)cpSpansOn_[a-zA-Z]+/g, "");
}
}, false);
sort_asc.addEventListener("click", function() {
saveState.setItem("asc", sort_asc.checked);
saveState.setItem("dsc", sort_dsc.checked);
saveState.save();
ascspan.className += " cpSpansOn"+sufTheme;
dscspan.className = dscspan.className.replace(/(?:^| +)cpSpansOn_[a-zA-Z]+/g, "");
}, false);
dscspan.addEventListener("click", function() {
if (!sort_dsc.checked) {
sort_dsc.checked = true;
sort_asc.checked = false;
saveState.setItem("asc", sort_asc.checked);
saveState.setItem("dsc", sort_dsc.checked);
saveState.save();
dscspan.className += " cpSpansOn"+sufTheme;
ascspan.className = ascspan.className.replace(/(?:^| +)cpSpansOn_[a-zA-Z]+/g, "");
}
}, false);
sort_dsc.addEventListener("click", function() {
saveState.setItem("asc", sort_asc.checked);
saveState.setItem("dsc", sort_dsc.checked);
saveState.save();
dscspan.className += " cpSpansOn"+sufTheme;
ascspan.className = ascspan.className.replace(/(?:^| +)cpSpansOn_[a-zA-Z]+/g, "");
}, false);
if (show_checkboxes.checked) {
sort_asc.className = "checkboxes";
sort_dsc.className = "checkboxes";
}
else {
sort_asc.className = "checkboxesOff";
sort_dsc.className = "checkboxesOff";
}
var sortdiv = document.createElement("DIV");
sortdiv.className = "cpSortdiv"+sufTheme;
sortdiv.appendChild(document.createTextNode(" ("));
sortdiv.appendChild(ascspan);
sortdiv.appendChild(dscspan);
sortdiv.appendChild(document.createTextNode(")"));
ascspan.innerHTML = " ▲ ";
ascspan.appendChild(sort_asc);
//ascspan.appendChild(sort_asc);
dscspan.innerHTML = " ▼ ";
dscspan.appendChild(sort_dsc);
//dscspan.appendChild(sort_dsc);
var topayspan = document.createElement("SPAN");
var toqualspan = document.createElement("SPAN");
topayspan.appendChild(document.createTextNode("Sort by TO pay"));
topayspan.className += " cpSpans"+sufTheme;
topayspan.title = "After getting search results based on the other selected options,\n" + "re-sort the results based on their average Turkopticon pay ratings. (Bayesian adjusted)";
if (sort_to.checked) {
topayspan.className += " cpSpansOn"+sufTheme;
} else topayspan.className = topayspan.className.replace(/(?:^| +)cpSpansOn_[a-zA-Z]+/g, "");
topayspan.addEventListener("click", function() {
if (sort_to.checked) {
sort_to.checked = false;
control_panel.removeChild(sortdiv);
topayspan.className = topayspan.className.replace(/(?:^| +)cpSpansOn_[a-zA-Z]+/g, "");
} else {
sort_to.checked = true;
sort_to2.checked = false;
control_panel.insertBefore(sortdiv, topayspan.nextSibling);
toqualspan.className = toqualspan.className.replace(/(?:^| +)cpSpansOn_[a-zA-Z]+/g, "");
topayspan.className += " cpSpansOn"+sufTheme;
}
saveState.setItem("to", sort_to.checked);
saveState.setItem("to2", sort_to2.checked);
saveState.save();
}, false);
if (show_checkboxes.checked) sort_to.className = "checkboxes";
else sort_to.className = "checkboxesOff";
topayspan.appendChild(sort_to);
sort_to.onclick = function () { UIAux(topayspan, sort_to, "to"); };
control_panel.appendChild(spacer.cloneNode(true));
control_panel.appendChild(topayspan);
if (sort_to.checked) control_panel.insertBefore(sortdiv, topayspan.nextSibling);
toqualspan.style.cursor = 'default';
toqualspan.appendChild(document.createTextNode("Sort by TO overall"));
toqualspan.className += " cpSpans"+sufTheme;
toqualspan.title = "After getting search results based on the other selected options,\n" + "re-sort the results by their overall Turkopticon rating. (Bayesian adjusted)";
if (sort_to2.checked) {
toqualspan.className += " cpSpansOn"+sufTheme;
} else toqualspan.className = toqualspan.className.replace(/(?:^| +)cpSpansOn_[a-zA-Z]+/g, "");
toqualspan.addEventListener("click", function() {
if (sort_to2.checked) {
sort_to2.checked = false;
control_panel.removeChild(sortdiv);
toqualspan.className = toqualspan.className.replace(/(?:^| +)cpSpansOn_[a-zA-Z]+/g, "");
} else {
sort_to2.checked = true;
sort_to.checked = false;
control_panel.insertBefore(sortdiv, toqualspan.nextSibling);
topayspan.className = topayspan.className.replace(/(?:^| +)cpSpansOn_[a-zA-Z]+/g, "");
toqualspan.className += " cpSpansOn"+sufTheme;
}
saveState.setItem("to", sort_to.checked);
saveState.setItem("to2", sort_to2.checked);
saveState.save();
}, false);
if (show_checkboxes.checked) sort_to2.className = "checkboxes";
else sort_to2.className = "checkboxesOff";
toqualspan.appendChild(sort_to2);
sort_to2.onclick = function () { UIAux(toqualspan, sort_to2, "to2"); };
control_panel.appendChild(spacer.cloneNode(true));
control_panel.appendChild(toqualspan);
if (sort_to2.checked) control_panel.insertBefore(sortdiv, toqualspan.nextSibling);
control_panel.appendChild(document.createElement("P"));
control_panel.appendChild(document.createTextNode("Min pay TO: "));
control_panel.appendChild(min_to);
min_to.size = 3;
min_to.className = "cpInput"+sufTheme;
min_to.addEventListener("keyup", function() {
min_to.value = min_to.value.replace(/.*?(\d*\.?\d*)?.*/, '$1');
if (min_to.value >= 0) {
saveState.setItem("minTO", min_to.value);
saveState.save();
}
} );
min_to.title = "After getting search results based on the other selected options,\n" + "hide any results below this average Turkopticon pay rating.\n" + "Minimum is 1, maximum is 5, decimals up to 2 places, such as 3.25";
var hidenotospan = document.createElement("SPAN");
hidenotospan.appendChild(document.createTextNode("Hide no TO"));
hidenotospan.className += " cpSpans"+sufTheme;
hidenotospan.title = "After getting search results based on the other selected options,\n" + "hide any results that have no Turkopticon pay ratings yet.";
if (no_to_block.checked) hidenotospan.className += " cpSpansOn"+sufTheme;
hidenotospan.addEventListener("click", function() {
UIAux(hidenotospan, no_to_block, "hideNTO");
}, false);
if (show_checkboxes.checked) no_to_block.className = "checkboxes";
else no_to_block.className = "checkboxesOff";
hidenotospan.appendChild(no_to_block);
no_to_block.onclick = function () { UIAux(hidenotospan, no_to_block, "hideNTO"); };
control_panel.appendChild(spacer.cloneNode(true));
control_panel.appendChild(hidenotospan);
var disabletospan = document.createElement("SPAN");
disabletospan.appendChild(document.createTextNode("Disable TO"));
disabletospan.className += " cpSpans"+sufTheme;
disabletospan.title = "Disable attempts to download ratings data from Turkopticon for the results table.";
if (useTO_input.checked) disabletospan.className += " cpSpansOn"+sufTheme;
disabletospan.addEventListener("click", function() {
UIAux(disabletospan, useTO_input, "useTO");
}, false);
if (show_checkboxes.checked) useTO_input.className = "checkboxes";
else useTO_input.className = "checkboxesOff";
disabletospan.appendChild(useTO_input);
useTO_input.onclick = function () { UIAux(disabletospan, useTO_input, "useTO"); };
control_panel.appendChild(spacer.cloneNode(true));
control_panel.appendChild(disabletospan);
control_panel.appendChild(spacer.cloneNode(true));
control_panel.appendChild(document.createTextNode("Display export buttons: "));
var vbspan = document.createElement("SPAN");
vbspan.className += " cpSpans"+sufTheme;
vbspan.title = 'Show a button to export the specified HIT with vBulletin formatted text.';
if (opt_exportvb.checked) vbspan.className += " cpSpansOn"+sufTheme;
vbspan.addEventListener("click", function(){
var carr = document.getElementsByClassName('vbButton');
if (!opt_exportvb.checked) {
opt_exportvb.checked=true; vbspan.className += " cpSpansOn"+sufTheme;
for (var i=0; i 0) for (var i=mt.length-1; i>-1; i--)
mt[i].className = mt[i].className.replace(/scraperBlockedRow/, "scraperBlockedRowOff");
useBlock.checked = false;
blockspan.className = blockspan.className.replace(/(?:^| +)cpSpansOn_[a-zA-Z]+/g, "");
}
else {
var mt = document.getElementsByClassName("scraperBlockedRowOff");
if (mt.length > 0) for (var i=mt.length-1; i>-1; i--)
mt[i].className = mt[i].className.replace(/scraperBlockedRowOff/, "scraperBlockedRow");
useBlock.checked = true;
blockspan.className += " cpSpansOn"+sufTheme;
}
saveState.setItem("blocklist", useBlock.checked);
saveState.save();
}, false);
if (show_checkboxes.checked) useBlock.className = "checkboxes";
else useBlock.className = "checkboxesOff";
blockspan.appendChild(useBlock);
useBlock.onclick = function () { UIAux(blockspan, useBlock, "blocklist"); };
control_panel.appendChild(spacer.cloneNode(true));
control_panel.appendChild(blockspan);
var includelistspan = document.createElement("SPAN");
includelistspan.appendChild(document.createTextNode("Restrict to includelist"));
includelistspan.className += " cpSpans"+sufTheme;
includelistspan.title = "Show only HITs that match your includelist.\n" + "Be sure to edit your includelist first or no results will be displayed.";
if (matchOnly.checked) includelistspan.className += " cpSpansOn"+sufTheme;
includelistspan.addEventListener("click", function() {
if (matchOnly.checked) {
matchOnly.checked = false;
includelistspan.className = includelistspan.className.replace(/(?:^| +)cpSpansOn_[a-zA-Z]+/g, "");
}
else {
matchOnly.checked = true;
includelistspan.className += " cpSpansOn"+sufTheme;
}
saveState.setItem("useInclude", matchOnly.checked)
saveState.save();
}, false);
if (show_checkboxes.checked) matchOnly.className = "checkboxes";
else matchOnly.className = "checkboxesOff";
includelistspan.appendChild(matchOnly);
matchOnly.onclick = function () { UIAux(includelistspan, matchOnly, "useInclude"); };
control_panel.appendChild(spacer.cloneNode(true));
control_panel.appendChild(includelistspan);
var highincspan = document.createElement("SPAN");
highincspan.appendChild(document.createTextNode("Highlight Includelisted"));
highincspan.className += " cpSpans"+sufTheme;
highincspan.title = "Outline HITs that match your includelist with a dashed green border.";
if (highlightIncludes_input.checked) highincspan.className += " cpSpansOn"+sufTheme;
highincspan.addEventListener("click", function() {
if (highlightIncludes_input.checked) {
var mt = document.getElementsByClassName("scraperIncludelistedRow");
if (mt.length > 0)
for (var i=mt.length-1; i>-1; i--) { mt[i].className = mt[i].className.replace(/scraperIncludelistedRow/, "scraperIncludelistedRowOff"); }
highlightIncludes_input.checked = false;
highincspan.className = highincspan.className.replace(/(?:^| +)cpSpansOn_[a-zA-Z]+/g, "");
}
else {
var mt = document.getElementsByClassName("scraperIncludelistedRowOff");
if ( mt.length > 0)
for (var i=mt.length-1; i>-1; i--) { mt[i].className = mt[i].className.replace(/scraperIncludelistedRowOff/, "scraperIncludelistedRow"); }
highlightIncludes_input.checked = true;
highincspan.className += " cpSpansOn"+sufTheme;
}
saveState.setItem("highlightIncl", highlightIncludes_input.checked)
saveState.save();
}, false);
if (show_checkboxes.checked) highlightIncludes_input.className = "checkboxes";
else highlightIncludes_input.className = "checkboxesOff";
highincspan.appendChild(highlightIncludes_input);
highlightIncludes_input.onclick = function () { UIAux(highincspan, highlightIncludes_input, "highlightIncl"); };
control_panel.appendChild(spacer.cloneNode(true));
control_panel.appendChild(highincspan);
control_panel.appendChild(document.createElement("BR"));
control_panel.appendChild(document.createTextNode(" "));
//------
big_red_button.textContent = "Start";
big_red_button.className += " cpButtons"+sufTheme;
big_red_button.onclick = function(){start_running();};
// open blocklist editor
reset_blocks.textContent = "Edit Blocklist";
reset_blocks.className += " cpButtons"+sufTheme;
reset_blocks.setAttribute("id","blocklist_reset_button");
reset_blocks.onclick = function(){
//console.log("in");
ignore_list = GM_getValue("scraper_ignore_list").split('^');
var textarea = $("#block_text");
var text = "";
for (var i = 0; i < ignore_list.length; i++){
text += ignore_list[i]+"^";
}
textarea.val(text.substring(0, text.length - 1));
$("#block_div").show();
};
// open includelist editor
include_button.textContent = "Edit Includelist";
include_button.className += " cpButtons"+sufTheme;
include_button.id = "includes_reset_button";
include_button.onclick = function() {
include_list = GM_getValue("scraper_include_list").split('^');
var textarea = $("#include_text");
var text = "";
for (var i = 0; i < include_list.length; i++){
text += include_list[i]+"^";
}
textarea.val(text.substring(0, text.length - 1));
$("#include_div").show();
};
control_panel.appendChild(document.createElement("P"));
text_area.style.fontWeight = "normal";
text_area.createCaption().innerHTML = 'HIT Scraper Results';
var col_heads = ['Requester','Title','Reward','# Avail','TO pay','Accept HIT','M?'];
var row = text_area.createTHead().insertRow(0);
text_area.caption.style.fontWeight = 800;
text_area.caption.className = "tabhead"+sufTheme;
text_area.caption.style.lineHeight = "1.25em";
if (default_text_size > 10)
text_area.cellPadding=Math.min(Math.max(1,Math.floor((default_text_size-10)/2)),5);
//console.log(text_area.cellPadding);
//text_area.cellPadding=2;
text_area.caption.style.fontSize = "24px";
text_area.rows[0].style.fontWeight = 800;
for (var i=0; i 1)
this_cell.style.textAlign = 'center';
}
text_area.style.width = '100%';
var table_div = document.createElement('div');
table_div.className = "bodytable"+sufTheme;
text_area.rows[0].className = "tabHead"+sufTheme;
table_div.style.fontSize = "14px";
document.body.insertBefore(table_div,control_panel.nextSibling);
var header_hide_button = document.createElement('button');
table_div.appendChild(big_red_button); // start/stop
table_div.appendChild(document.createTextNode(" "));
table_div.appendChild(header_hide_button); // hide control panel
table_div.appendChild(document.createTextNode(" "));
table_div.appendChild(reset_blocks); // blocklist editor
table_div.appendChild(document.createTextNode(" "));
table_div.appendChild(include_button); // includelist editor
table_div.appendChild(document.createTextNode(" "));
table_div.appendChild(showButton); // toggle ignored
table_div.appendChild(document.createTextNode(" "));
table_div.appendChild(btn01); // theme editor
table_div.appendChild(document.createTextNode(" "));
table_div.appendChild(settings.panel.accessButton); // settings
$("#show_TO_stuff_button").hide();
table_div.appendChild(document.createElement("P"));
var statusdiv = document.createElement("DIV");
statusdiv.className = "statusdiv"+sufTheme;
statusdiv.appendChild(progress_report);
statusdiv.appendChild(document.createElement("P"));
statusdiv.appendChild(document.createTextNode("Status messages: "));
statusdiv.appendChild(status_report);
table_div.appendChild(statusdiv);
if (document.getElementById('lnkWorkerSignin'))
{
var logged_out_warning = document.createElement("P");
logged_out_warning.style.color = "#ff3300";
logged_out_warning.innerHTML = "ATTENTION: SCRAPER IS RUNNING WHILE LOGGED OUT. SOME DATA WILL BE MISSING. GO TO REQUESTER'S LINK IN LOGGED-IN WINDOW FOR FORUM EXPORT. Click here to sign in";
table_div.appendChild(logged_out_warning);
table_div.appendChild(document.createElement("P"));
}
table_div.appendChild(text_area);
header_hide_button.textContent = "Hide Panel";
header_hide_button.className += " cpButtons"+sufTheme;
header_hide_button.onclick = function(){
if (header_hide_button.textContent == "Hide Panel"){
$('#control_panel').hide(300);
btn01.style.display = 'none';
header_hide_button.textContent = "Show Panel";
}
else{
$('#control_panel').show(300);
btn01.style.display = 'initial';
header_hide_button.textContent = "Hide Panel";
}
};
}
/********HIT EXPORT ADDITIONS*****/
var EDIT = false;
var HIT;
var TO_BASE = "http://turkopticon.ucsd.edu/";
var API_BASE = "https://mturk-api.istrack.in/";
var API_URL = API_BASE + "multi-attrs.php?ids=";
var DEFAULT_TEMPLATE = '[table][tr][td][b]Title:[/b] [url={prev_link}][COLOR=blue]{title}[/COLOR][/url]\n';
DEFAULT_TEMPLATE += '[b]Requester:[/b] [url=https://www.mturk.com/mturk/searchbar?selectedSearchType=hitgroups&requesterId={rid}][COLOR=blue]{requester}[/COLOR][/url]';
DEFAULT_TEMPLATE += ' [{rid}] ([url='+TO_BASE+'{rid}][COLOR=blue]TO[/COLOR][/url])';
DEFAULT_TEMPLATE += '\n[b]TO Ratings:[/b]{to_stuff}';
DEFAULT_TEMPLATE += '\n[b]Description:[/b] {description}';
DEFAULT_TEMPLATE += '\n[b]Time:[/b] {time}';
DEFAULT_TEMPLATE += '\n[b]Hits Available:[/b] {hits}';
DEFAULT_TEMPLATE += '\n[b]Reward:[/b] [COLOR=green][b]{reward}[/b][/COLOR]';
DEFAULT_TEMPLATE += '\n[b]Qualifications:[/b] {quals}[/td][/tr][/table]';
var TEMPLATE;
var EASYLINK;
if (typeof GM_getValue === 'undefined')
TEMPLATE = null;
else {
TEMPLATE = GM_getValue('HITScraper Template');
EASYLINK = GM_getValue('HITScraper Easylink');
}
if (TEMPLATE == null) {
TEMPLATE = DEFAULT_TEMPLATE;
}
function buildXhrUrl(rai) {
var url = API_URL;
var ri = rai;
url += rai;
return url;
}
function makeXhrQuery(url) {
var xhr = new XMLHttpRequest();
try{
xhr.open('GET', url, false);
xhr.send(null);
return $.parseJSON(xhr.response);
}
catch(err){
return "TO DOWN";
}
}
function getNamesForEmptyResponses(rai, resp) {
for (var rid in rai) {
if (rai.hasOwnProperty(rid) && resp[rid] == "") {
resp[rid] = $.parseJSON('{"name": "' + rai[rid][0].innerHTML + '"}');
}
}
return resp;
}
function getKeys(obj) {
var keys = [];
for (var key in obj) {
keys.push(key);
}
return keys;
}
function export_sel_deleg(item,index,extype) {
//console.log(item);
if (extype == "vb") export_func(item);
else display(item, extype);
}
function block_deleg(item,index) {
//console.log(item);
block(item,index);
}
function block(hit,index){
var blockType = ["requester_strip","title"];
var blockThis = hit[blockType[index]].replace(/\s+/g," ").toLowerCase().trim();
var r = confirm("Do you really want to block hits matching requester/title \""+blockThis+"\"?");
if(r)
{
ignore_list.push(blockThis);
GM_setValue("scraper_ignore_list",ignore_list.join('^'));
}
}
function search_deleg(item,index) {
//console.log(item);
var searches = ["rid","title"];
search(item,searches[index]);
}
function hit_sort_func()
{
return function(a,b) {
if (a.date == b.date) {
if (a.requesterName < b.requesterName)
return -1;
if (a.requesterName > b.requesterName)
return 1;
if (a.title < b.title)
return -1;
if (a.title > b.title)
return 1;
if (a.status < b.status)
return -1;
if (a.status > b.status)
return 1;
}
if (a.date > b.date)
return 1;
if (a.date < b.date)
return -1;
};
}
function escapeRegExp(str) {
return str.replace(/[-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&");
}
function search(item,search_type){
//return true;/*
var request = indexedDB.open("HITDB", v);
request.onsuccess = function(e) {
HITStorage.indexedDB.db = e.target.result;
var db = HITStorage.indexedDB.db;
var trans = db.transaction(["HIT"], HITStorage.IDBTransactionModes.READ_ONLY);
var store = trans.objectStore("HIT");
var req;
var results = [];
var index;
var range;
req = store.openCursor();
req.onsuccess = function(event) {
var cursor = event.target.result;
if (cursor) {
hit = cursor.value;
var keys = ['title', 'requesterId'];
var re = new RegExp(escapeRegExp(item[search_type]),"ig");
for (var k in keys)
{
if (hit[keys[k]] != null && re.test(hit[keys[k]].trim())){
results.push(cursor.value);
}
}
cursor.continue();
}
else {
//console.log(results);
results.sort(hit_sort_func());
show_results(results);
}
db.close();
};
request.onerror = HITStorage.indexedDB.onerror;/**/
};
}
function format_hit_line (hit, odd, status_color, new_day)
{
var line = '';
else
line += '">';
line += '' + hit.date + ' | ';
if (hit.requesterLink != null)
line += '' + hit.requesterName + ' | ';
else
line += '' + hit.requesterName + ' | ';
line += '' + hit.title + ' | ';
line += '$' + hit.reward.toFixed(2) + ' | ';
line += '' + hit.status + ' | ';
line += '' + hit.feedback + ' | ';
line += '
\n';
return line;
}
function status_color (status)
{
var color = "green";
if (status.match("Pending Approval"))
color = "orange";
else if (status.match("Rejected"))
color = "red";
return color;
}
function show_results (results){
var resultsWindow = window.open();
resultsWindow.document.write("Status Detail Search Results\n");
resultsWindow.document.write("HITs matching your search:
\n");
resultsWindow.document.write('\n');
resultsWindow.document.write('Date | Requester | HIT Title | Reward | Status | Feedback |
\n');
var odd = true;
var sum = 0;
var sum_rejected = 0;
var sum_approved = 0;
var sum_pending = 0;
var new_day = false;
for (var i=0; i0 && (results[i-1].date != results[i].date))
new_day = true;
else
new_day = false;
resultsWindow.document.write(format_hit_line(results[i], odd, status_color(results[i].status), new_day ));
}
resultsWindow.document.write(' | | | $' + sum.toFixed(2) + ' | | |
\n');
resultsWindow.document.write("
");
resultsWindow.document.write("Found " + results.length + " matching HITs. $" + sum_approved.toFixed(2) + " approved, " +
"$" + sum_rejected.toFixed(2) + " rejected and $" + sum_pending.toFixed(2) + " pending.
");
resultsWindow.document.write("");
resultsWindow.document.close();
}
// ---- vB
function export_func(item) {
HIT = item;
gedit_button.textContent = 'Edit Template';
apply_template(item);
gdiv.style.display = 'block';
gtextarea.select();
}
function apply_template(hit_data) {
var txt = TEMPLATE;
var vars = ['title', 'requester', 'rid', 'description', 'reward', 'quals', 'prev_link', 'time', 'hits', 'to_stuff', 'to_text'];
var resp = null;
if (txt.indexOf('{to_text}') >= 0 || txt.indexOf('{to_stuff}') >= 0){
var url = buildXhrUrl(hit_data["rid"]);
resp = getTOMulti(hit_data["rid"]);
//console.log(resp);
}
var toText = "";
var toStuff = "";
var toData = "";
var numResp = (resp == null || resp == "TO DOWN" ? "n/a" : resp[hit_data["rid"]].reviews);
if (resp == "TO DOWN"){
toStuff = " [URL=\""+TO_BASE+hit_data['rid']+"\"]TO down.[/URL]";
toText = toStuff;
}
else if (resp == null || resp[hit_data["rid"]].attrs == null && resp != "TO DOWN") {
toStuff = " No TO ";
toText = " No TO ";
toStuff += "[URL=\""+TO_BASE+"report?requester[amzn_id]=" + hit_data['rid'] + "&requester[amzn_name]=" + hit_data['requester'] + "\"]";
toStuff += "(Submit a new TO rating for this requester)[/URL]";
}
else {
for (var key in resp[hit_data["rid"]].attrs) {
//toText += "\n[*]"+key+": "+resp[hit_data["requesterId"]].attrs[key]+"\n";
var i = 0;
var color = "green";
var name = key;
var num = Math.floor(resp[hit_data["rid"]].attrs[key]);
switch (key){
case "comm":
name = "Communicativity";
break;
case "pay":
name = "Generosity";
break;
case "fast":
name = "Promptness";
break;
case "fair":
name = "Fairness";
break;
default:
name = key;
break;
}
switch (num){
case 0:
color = "red";
break;
case 1:
color = "red";
break;
case 2:
color = "orange";
break;
case 3:
color = "yellow";
break;
default:
break;
}
toText += (num > 0 ? "\n[color="+color+"]" : "\n");
for (i; i < num; i++){
toText += "[b]"+symbol+"[/b]";
}
toText += (num > 0 ? "[/color]" : "");
if (i < 5){
toText += "[color=white]";
for (i; i < 5; i++)
toText += "[b]"+symbol+"[/b]";
toText += "[/color]";
}
toText += " "+Number(resp[hit_data["rid"]].attrs[key]).toFixed(2)+" "+name;
toData += Number(resp[hit_data["rid"]].attrs[key]).toFixed(2) + ",";
}
//toText += "[/list]";
toText += (txt.indexOf('{to_stuff}') >= 0 ? "" : "\nNumber of Reviews: "+numResp+"\n[URL=\""+TO_BASE+"report?requester[amzn_id]=" + hit_data['rid'] + "&requester[amzn_name]=" + hit_data['requester'] + "\"](Submit a new TO rating for this requester)[/URL]");
toStuff = '\n[img]http://data.istrack.in/to/' + toData.slice(0,-1) + '.png[/img]';
toStuff += (txt.indexOf('{to_stuff}') >= 0 ? (txt.indexOf('{to_text}') >= 0 ? "" : toText) : "");
toStuff += "\nNumber of Reviews: "+numResp;
toStuff += "[URL=\""+TO_BASE+"report?requester[amzn_id]=" + hit_data['rid'] + "&requester[amzn_name]=" + hit_data['requester'] + "\"]";
toStuff += "\n(Submit a new TO rating for this requester)[/URL]";
}
for (var u = 0; u < vars.length; u++) {
var t = new RegExp('\{' + vars[u] + '\}', 'g');
if (vars[u] == "to_stuff") {
txt = txt.replace(t, toStuff);
}
else if (vars[u] == "to_text") {
txt = txt.replace(t, toText);
}
else if (vars[u] == "prev_link") {
txt = txt.replace(t,"https://www.mturk.com"+hit_data[vars[u]]);
}
else if (vars[u] == "acc_link") {
txt = txt.replace(t,"https://www.mturk.com"+hit_data[vars[u]]);
}
else
txt = txt.replace(t, hit_data[vars[u]]);
}
gtextarea.value = txt;
}
function export_irc(item) {
display(item);
}
function apply_template(hit_data) {
var txt = TEMPLATE;
var vars = ['title', 'requester', 'rid', 'description', 'reward', 'quals', 'prev_link', 'time', 'hits', 'to_stuff', 'to_text'];
var resp = null;
if (txt.indexOf('{to_text}') >= 0 || txt.indexOf('{to_stuff}') >= 0){
var url = buildXhrUrl(hit_data["rid"]);
resp = getTOMulti(hit_data["rid"]);
//console.log(resp);
}
var toText = "";
var toStuff = "";
var toData = "";
var numResp = (resp == null || resp == "TO DOWN" ? "n/a" : resp[hit_data["rid"]].reviews);
if (resp == "TO DOWN"){
toStuff = " [URL=\""+TO_BASE+hit_data['rid']+"\"]TO down.[/URL]";
toText = toStuff;
}
else if (resp == null || resp[hit_data["rid"]].attrs == null && resp != "TO DOWN") {
toStuff = " No TO ";
toText = " No TO ";
toStuff += "[URL=\""+TO_BASE+"report?requester[amzn_id]=" + hit_data['rid'] + "&requester[amzn_name]=" + hit_data['requester'] + "\"]";
toStuff += "(Submit a new TO rating for this requester)[/URL]";
}
else {
for (var key in resp[hit_data["rid"]].attrs) {
//toText += "\n[*]"+key+": "+resp[hit_data["requesterId"]].attrs[key]+"\n";
var i = 0;
var color = "green";
var name = key;
var num = Math.floor(resp[hit_data["rid"]].attrs[key]);
switch (key){
case "comm":
name = "Communicativity";
break;
case "pay":
name = "Generosity";
break;
case "fast":
name = "Promptness";
break;
case "fair":
name = "Fairness";
break;
default:
name = key;
break;
}
switch (num){
case 0:
color = "red";
break;
case 1:
color = "red";
break;
case 2:
color = "orange";
break;
case 3:
color = "yellow";
break;
default:
break;
}
toText += (num > 0 ? "\n[color="+color+"]" : "\n");
for (i; i < num; i++){
toText += "[b]"+symbol+"[/b]";
}
toText += (num > 0 ? "[/color]" : "");
if (i < 5){
toText += "[color=white]";
for (i; i < 5; i++)
toText += "[b]"+symbol+"[/b]";
toText += "[/color]";
}
toText += " "+Number(resp[hit_data["rid"]].attrs[key]).toFixed(2)+" "+name;
toData += Number(resp[hit_data["rid"]].attrs[key]).toFixed(2) + ",";
}
//toText += "[/list]";
toText += (txt.indexOf('{to_stuff}') >= 0 ? "" : "\nNumber of Reviews: "+numResp+"\n[URL=\""+TO_BASE+"report?requester[amzn_id]=" + hit_data['rid'] + "&requester[amzn_name]=" + hit_data['requester'] + "\"](Submit a new TO rating for this requester)[/URL]");
toStuff = '\n[img]http://data.istrack.in/to/' + toData.slice(0,-1) + '.png[/img]';
toStuff += (txt.indexOf('{to_stuff}') >= 0 ? (txt.indexOf('{to_text}') >= 0 ? "" : toText) : "");
toStuff += "\nNumber of Reviews: "+numResp;
toStuff += "[URL=\""+TO_BASE+"report?requester[amzn_id]=" + hit_data['rid'] + "&requester[amzn_name]=" + hit_data['requester'] + "\"]";
toStuff += "\n(Submit a new TO rating for this requester)[/URL]";
}
for (var u = 0; u < vars.length; u++) {
var t = new RegExp('\{' + vars[u] + '\}', 'g');
if (vars[u] == "to_stuff") {
txt = txt.replace(t, toStuff);
}
else if (vars[u] == "to_text") {
txt = txt.replace(t, toText);
}
else if (vars[u] == "prev_link") {
txt = txt.replace(t,"https://www.mturk.com"+hit_data[vars[u]]);
}
else if (vars[u] == "acc_link") {
txt = txt.replace(t,"https://www.mturk.com"+hit_data[vars[u]]);
}
else
txt = txt.replace(t, hit_data[vars[u]]);
}
gtextarea.value = txt;
}
function hide_func(div) {
if (EDIT == false)
div.style.display = 'none';
}
function edit_func() {
if (EDIT == true) {
EDIT = false;
TEMPLATE = gtextarea.value;
gedit_button.textContent = 'Edit Template';
apply_template(HIT);
}
else {
//console.log("Editing");
EDIT = true;
gedit_button.textContent = 'Show Changes';
gsave_button.disabled = false;
gtextarea.value = TEMPLATE;
}
}
function default_func() {
GM_deleteValue('HITScraper Template');
TEMPLATE = DEFAULT_TEMPLATE;
EDIT = false;
gedit_button.textContent = 'Edit Template';
apply_template(HIT);
}
function save_func() {
if (EDIT)
TEMPLATE = gtextarea.value;
GM_setValue('HITScraper Template', TEMPLATE);
}
var gdiv = document.createElement('div');
var gtextarea = document.createElement('textarea');
var gdiv2 = document.createElement('label');
gdiv.style.position = 'fixed';
gdiv.style.width = '500px';
gdiv.style.height = '235px';
gdiv.style.left = '50%';
gdiv.style.right = '50%';
gdiv.style.margin = '-250px 0px 0px -250px';
gdiv.style.top = '300px';
gdiv.style.padding = '5px';
gdiv.style.border = '2px';
gdiv.style.backgroundColor = 'black';
gdiv.style.color = 'white';
gdiv.style.zIndex = '100';
gtextarea.style.padding = '2px';
gtextarea.style.width = '500px';
gtextarea.style.height = '200px';
gtextarea.title = '{title}\n{requester}\n{rid}\n{description}\n{reward}\n{quals}\n{prev_link}\n{time}\n{hit}\n{to_stuff}\n{to_text}';
gdiv.textContent = 'Press Ctrl+C to copy to clipboard. Click textarea to close';
gdiv.style.fontSize = '12px';
gdiv.appendChild(gtextarea);
var gedit_button = document.createElement('button');
var gsave_button = document.createElement('button');
var gdefault_button = document.createElement('button');
var geasy_button = document.createElement('button');
gedit_button.textContent = 'Edit Template';
gedit_button.setAttribute('id', 'edit_button');
gedit_button.style.height = '18px';
gedit_button.style.width = '100px';
gedit_button.style.fontSize = '10px';
gedit_button.style.paddingLeft = '3px';
gedit_button.style.paddingRight = '3px';
gedit_button.style.backgroundColor = 'white';
gsave_button.textContent = 'Save Template';
gsave_button.setAttribute('id', 'save_button');
gsave_button.style.height = '18px';
gsave_button.style.width = '100px';
gsave_button.style.fontSize = '10px';
gsave_button.style.paddingLeft = '3px';
gsave_button.style.paddingRight = '3px';
gsave_button.style.backgroundColor = 'white';
gsave_button.style.marginLeft = '5px';
geasy_button.textContent = 'Change Adfly Url';
geasy_button.setAttribute('id', 'easy_button');
geasy_button.style.height = '18px';
geasy_button.style.width = '100px';
geasy_button.style.fontSize = '10px';
geasy_button.style.paddingLeft = '3px';
gdefault_button.textContent = ' D ';
gdefault_button.setAttribute('id', 'default_button');
gdefault_button.style.height = '18px';
gdefault_button.style.width = '20px';
gdefault_button.style.fontSize = '10px';
gdefault_button.style.paddingLeft = '3px';
gdefault_button.style.paddingRight = '3px';
gdefault_button.style.backgroundColor = 'white';
gdefault_button.style.marginLeft = '5px';
gdefault_button.title = 'Return default template';
gdiv.appendChild(gedit_button);
gdiv.appendChild(gsave_button);
gdiv.appendChild(gdefault_button);
gdiv.appendChild(geasy_button);
gsave_button.disabled = true;
gdiv.style.display = 'none';
gtextarea.addEventListener("click", function() {hide_func(gdiv);}, false);
gedit_button.addEventListener("click", function() {edit_func();}, false);
gsave_button.addEventListener("click", function() {save_func();}, false);
gdefault_button.addEventListener("click", function() {default_func();}, false);
document.body.insertBefore(gdiv, document.body.firstChild);
//Functions below were added for the irc export with the help of clickhappier and Cristo
var accountStatus = "loggedOut";
if ( !document.getElementById("lnkWorkerSignin") ) // if sign-in link not present
{
accountStatus = "loggedIn";
}
function getUrlVariable(url, variable)
{
var query = url.split('?');
var vars = query[1].split("&");
for ( var i=0; i 2) {
var toInfo = requestTO.responseText.split('{')[3].split('}')[0].split(',');
for (var t = 0; t < 4; 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;
}
catch(err){ // if mirror unavailable, try main TO server
try{
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 < 4; t++) {
var arrTo = toInfo[t].split(':');
toComp.push(arrTo[1].substring(1,4));
}
}
else { toComp = ['-','-','-','-']; }
}
};
requestTO.open('GET', toUrl2, false);
requestTO.send(null);
return toComp;
}
catch(err){ // if both unavailable, return 'na's
toComp = ['na','na','na','na'];
return toComp;
}
}
}
function getTOMulti(f){
var toComp = {};
var toUrl2 = 'https://mturk-api.istrack.in/multi-attrs.php?ids='+f;
var toUrl = 'https://turkopticon.ucsd.edu/api/multi-attrs.php?ids='+f;
var rids = f.split(',');
var requestTO = new XMLHttpRequest();
try{ // first try Miku's TO mirror server (istrack.in)
requestTO.onreadystatechange = function () {
if ((requestTO.readyState ===4) && (requestTO.status ===200)) {
if (requestTO.responseText.split(':').length > 2)
toComp = $.parseJSON(requestTO.responseText);
else
toComp = null;
}
};
requestTO.open('GET', toUrl, false);
requestTO.send(null);
return toComp;
}
catch(err){ // if mirror unavailable, try main TO server
try{
requestTO.onreadystatechange = function () {
if ((requestTO.readyState ===4) && (requestTO.status ===200)) {
if (requestTO.responseText.split(':').length > 2)
toComp = $.parseJSON(requestTO.responseText);
else
toComp = null;
}
};
requestTO.open('GET', toUrl2, false);
requestTO.send(null);
return toComp;
}
catch(err){ // if both unavailable, return 'na's
toComp = "TO DOWN";
return toComp;
}
}
}
function sleep(ms){ // from http://www.digimantra.com/tutorials/sleep-or-wait-function-in-javascript/
var dt = new Date();
dt.setTime(dt.getTime() + ms);
while (new Date().getTime() < dt.getTime());
}
function ns4tShorten(url){ // mturk-only URL shortener on Tjololo's server ns4t.net
console.log("ns4tShorten function");
var shortUrl;
var urlT = "https://ns4t.net/yourls-api.php" + "?action=shorturl&url=" + encodeURIComponent(url) + "&format=simple&title=MTurk&username=publicuser&password=publicpass";
var requestNs4t = new XMLHttpRequest();
try{
requestNs4t.onreadystatechange = function () {
if (requestNs4t.readyState == 4) {
if (requestNs4t.status == 200) {
shortUrl = requestNs4t.responseText;
console.log("ns4t.net response: " + requestNs4t.status + " " + requestNs4t.statusText + " " + requestNs4t.responseText);
}
else {
console.log('ns4t.net unsuccessful: ' + requestNs4t.status + " " + requestNs4t.statusText);
}
}
};
requestNs4t.open('GET', urlT, false);
requestNs4t.send(null);
return shortUrl;
}
catch(err){
return shortUrl;
}
}
function tnyimShorten(url){ // Tny.im URL Shortener - http://tny.im/aboutapi.php - this is only possible this way because their server has the "Access-Control-Allow-Origin = *" headers enabled (the above TO mirror server does too)
console.log("tnyimShorten function");
var shortUrl;
var urlT = "https://tny.im/yourls-api.php" + "?action=shorturl&url=" + encodeURIComponent(url) + "&format=simple&title=MTurk";
var requestTnyim = new XMLHttpRequest();
try{
requestTnyim.onreadystatechange = function () {
if (requestTnyim.readyState == 4) {
if (requestTnyim.status == 200) {
shortUrl = requestTnyim.responseText;
console.log("tny.im response: " + requestTnyim.status + " " + requestTnyim.statusText + " " + requestTnyim.responseText);
}
else {
console.log('tny.im unsuccessful: ' + requestTnyim.status + " " + requestTnyim.statusText);
}
}
};
requestTnyim.open('GET', urlT, false);
requestTnyim.send(null);
return shortUrl;
}
catch(err){
return shortUrl;
}
}
function googlShorten(url){ // Goo.gl URL Shortener
console.log("googlShorten function");
var shortUrl;
var urlG = "https://www.googleapis.com/urlshortener/v1/url";
var requestGoogl = new XMLHttpRequest();
try{
requestGoogl.open("POST", urlG, false);
requestGoogl.setRequestHeader("Content-Type", "application/json");
requestGoogl.onreadystatechange = function() {
if (requestGoogl.readyState == 4) {
if (requestGoogl.status == 200) {
shortUrl = JSON.parse(requestGoogl.response).id;
console.log("goo.gl response: " + requestGoogl.status + " " + requestGoogl.statusText + " " + JSON.parse(requestGoogl.response).id );
}
else {
console.log('goo.gl unsuccessful: ' + requestGoogl.status + " " + requestGoogl.statusText);
}
}
};
var data = new Object();
data.longUrl = url;
requestGoogl.send(JSON.stringify(data));
return shortUrl;
}
catch(err){
return shortUrl;
}
}
function shortenUrl(url){
sleep(500); // milliseconds delay - wait some milliseconds (currently half a second) between shortens to reduce chance of hitting usage limits
var shortUrl;
shortUrl = ns4tShorten(url);
if ( shortUrl === undefined ) { // if you reached the ns4t.net URL shortener's temporary usage limits or the server is otherwise unavailable
shortUrl = tnyimShorten(url);
if ( shortUrl === undefined ) { // if you reached the tny.im URL shortener's temporary limits or the server is otherwise unavailable
shortUrl = googlShorten(url);
if ( shortUrl === undefined ) { // if you reached the Google URL shortener's temporary limits too or the server is otherwise unavailable
shortUrl = "(x)";
}
}
}
return shortUrl;
}
// output display box
// this is messy
// TODO: make it cleaner
var exportdiv = document.createElement('div');
var exporttextarea1 = document.createElement('textarea'); var exporttextarea2 = document.createElement('textarea');
var exporttextarea3 = document.createElement('textarea'); var exporttextarea4 = document.createElement('textarea');
var exporttextarea5 = document.createElement('textarea');
var exportclosebutton = document.createElement('button');var exporttitlebutton = document.createElement('button');var exporturlbutton = document.createElement('button');
var exportreqbutton = document.createElement('button');var exportpandabutton = document.createElement('button');var exporttobutton = document.createElement('button');
exportclosebutton.style.backgroundColor = 'black';
exportclosebutton.style.color = 'white';
//exportclosebutton.style.border = 'none';
exportclosebutton.style.width = '505px';
exportclosebutton.style.align = 'center';
exportclosebutton.textContent='Close';
exporttitlebutton.style.backgroundColor = 'black';
exporttitlebutton.style.color = 'white';
//exporttitlebutton.style.border = 'none';
exporttitlebutton.style.width = '101px';
exporttitlebutton.style.align = 'center';
exporttitlebutton.textContent='Title';
exporturlbutton.style.backgroundColor = 'black';
exporturlbutton.style.color = 'white';
//exporturlbutton.style.border = 'none';
exporturlbutton.style.width = '101px';
exporturlbutton.style.align = 'center';
exporturlbutton.textContent='URL';
exportreqbutton.style.backgroundColor = 'black';
exportreqbutton.style.color = 'white';
//exportreqbutton.style.border = 'none';
exportreqbutton.style.width = '101px';
exportreqbutton.style.align = 'center';
exportreqbutton.textContent='Req';
exportpandabutton.style.backgroundColor = 'black';
exportpandabutton.style.color = 'white';
//exportpandabutton.style.border = 'none';
exportpandabutton.style.width = '101px';
exportpandabutton.style.align = 'center';
exportpandabutton.textContent='PandA';
exporttobutton.style.backgroundColor = 'black';
exporttobutton.style.color = 'white';
//exporttobutton.style.border = 'none';
exporttobutton.style.width = '101px';
exporttobutton.style.align = 'center';
exporttobutton.textContent='TO';
exportdiv.style.position = 'fixed';
exportdiv.style.width = '505px';
exportdiv.style.height = '155px';
exportdiv.style.left = '50%';
exportdiv.style.right = '50%';
exportdiv.style.margin = '-250px 0px 0px -250px';
exportdiv.style.top = '300px';
exportdiv.style.padding = 'none'; // def 5px
exportdiv.style.border = 'none'; //def 2px
exportdiv.style.backgroundColor = 'black';
exportdiv.style.color = 'white';
exportdiv.style.zIndex = '100';
exportdiv.style.display = 'none';
document.body.insertBefore(exportdiv, document.body.firstChild);
exporttextarea1.style.padding = 'none';
exporttextarea1.style.width = '500px';
exporttextarea2.style.padding = 'none';
exporttextarea2.style.width = '500px';
exporttextarea2.style.height = '30px';
exporttextarea2.style.overflow = 'hidden';
exporttextarea2.setAttribute('id','hwtf_url');
exporttextarea3.style.padding = 'none';
exporttextarea3.style.width = '500px';
exporttextarea3.style.height = '30px';
exporttextarea3.style.overflow = 'hidden';
exporttextarea3.setAttribute('id','hwtf_req');
exporttextarea4.style.padding = 'none';
exporttextarea4.style.width = '500px';
exporttextarea4.style.height = '30px';
exporttextarea4.style.overflow = 'hidden';
exporttextarea4.setAttribute('id','hwtf_panda');
exporttextarea5.style.padding = '2px';
exporttextarea5.style.width = '500px';
exporttextarea5.style.height = '20px';
exporttextarea5.style.overflow = 'hidden';
exporttextarea5.setAttribute('id','hwtf_to');
exportdiv.style.fontSize = '12px';
//exportdiv.style.display = 'block';
function display(hit, extype){
var thisReqName = hit["requester_strip"];
var thisReqId = "unavailable";
if ( accountStatus == "loggedIn" )
{
thisReqId = hit["rid"];
}
var thisTitle = hit["title"].replace(" (Requester link substituted)","");
var thisReward = hit["reward"];
var thisTimeLimit = hit["time"];
var thisHitsAvail = "??";
if ( accountStatus == "loggedIn" )
{
thisHitsAvail = hit["hits"];
}
var qualList = hit["quals"];
var qualColl = qualList.split(';');
var masterQual = '';
var locationStat = 'ICA';
var locationIndex = null;
for ( var m = 0; m < qualColl.length; m++ ) {
if ( qualColl[m].indexOf('Masters') > -1 ) {
masterQual = (extype == "irc") ? 'MASTERS • ' : ' [MASTERS]';
}
else if (qualColl[m].indexOf('is US') > -1) {
locationStat = ' US';
locationIndex = m;
}
else if (qualColl[m].match(/approval rate/)) {
qualColl[m] = qualColl[m].replace(/[A-Za-z ]+\(%\) is (?:not less than (\d+)|greater than (\d+))/, '>$1$2%');
}
else if (qualColl[m].match(/approved HITs/)) {
qualColl[m] = qualColl[m].replace(/Total approved HITs is (?:not less than (\d+)|greater than (\d+))/, '>$1$2');
qualColl[m] = qualColl[m].replace(/Total approved HITs is (?:not greater than (\d+)|less than (\d+))/, '<$1$2');
}
}
if (extype == "reddit" && locationIndex != null) qualColl.splice(locationIndex,1);
if (qualColl[0] == null) qualColl = "None";
var prevUrl = (thisReqId == "unavailable") ? "Unavailable due to logged out scraper" : LINK_BASE+hit["prev_link"];
var accUrl = (thisReqId == "unavailable") ? "Unavailable due to logged out scraper" : LINK_BASE+hit["acc_link"];
var thisPreviewUrl = (extype == "irc") ? shortenUrl(prevUrl) : prevUrl;
var thisPandaUrl = (extype == "irc") ? shortenUrl(accUrl) : accUrl;
var thisReqUrl = "(url n/a)";
if ( thisReqId != "unavailable")
{
if (extype == "irc")
thisReqUrl = shortenUrl('https://www.mturk.com/mturk/searchbar?selectedSearchType=hitgroups&requesterId=' + thisReqId);
else
thisReqUrl = 'https://www.mturk.com/mturk/searchbar?selectedSearchType=hitgroups&requesterId=' + thisReqId;
}
else if ( thisReqId == "unavailable") // handle 2015-07-20 loss of logged-out requester ids
{
if (extype == "irc")
thisReqUrl = shortenUrl('https://www.mturk.com/mturk/searchbar?selectedSearchType=hitgroups&searchWords=' + thisReqName.replace(/ /g, "+") ) + " (search)";
else
thisReqUrl = 'https://www.mturk.com/mturk/searchbar?selectedSearchType=hitgroups&searchWords=' + thisReqName.replace(/ /g, "+") + " (Requester search URL due to logged out scraper)";
}
var hitLinkUnav = '';
//if ( capGId == 'unavailable' ) { capUrl = capReqUrl; pandaUrl = ""; hitLinkUnav = " (preview link unavailable)"; } // handle logged-out export requests for HITs with no preview/notqualified links ** This is handled at line 647
if (hit["prev_link"].indexOf("requesterId") > -1)
{
hitLinkUnav = " (preview link unavailable)";
thisPandaUrl = "";
}
var thisTOUrl = "(url n/a)";
var thisTOStats = "??";
if ( thisReqId != "unavailable" )
{
thisTOUrl = (extype == "irc") ? shortenUrl(TO_BASE+thisReqId) : TO_BASE+thisReqId;
thisTOStats = getTO(thisReqId);
}
else if ( thisReqId == "unavailable") // handle 2015-07-20 loss of logged-out requester ids
{
thisTOUrl = (extype == "irc") ? shortenUrl('https://turkopticon.ucsd.edu/main/php_search?query=' + thisReqName.replace(/ /g, "+") ) + " (search)" : 'https://turkopticon.ucsd.edu/main/php_search?query=' + thisReqName.replace(/ /g, "+") +" (TO search URL due to logged out scraper)";
}
var shortUrlUnav = '';
if ( (thisPreviewUrl == "(x)") && (thisHitGroup != "unavailable") )
{
shortUrlUnav = " \r\n^ https://www.mturk.com/mturk/preview?groupId=" + thisHitGroup;
}
var exportOutput = "";
var loggedOutApology = " (Info missing since logged out.)";
var temp = [];
for (var i = 0; i < qualColl.length; i++)
{
var search = /b\](.*?)\[/.exec(qualColl[i]);
if (search)
temp[i] = search[1].trim();
else
temp[i] = qualColl[i].trim();
}
if (temp[0] != "None")
var qualString = temp.join(", ");
else
qualString = temp;
var exTitle = locationStat + ' - ' + thisTitle.replace(" (Preview link unavailable)","") + ' - ' + thisReqName + ' - ' + thisReward + '/' + 'COMTIME - ' + '(' + qualString + ')' + masterQual;
var exUrl = 'URL: ' + thisPreviewUrl +'\n\n';
var exReq = 'Req: ' + thisReqUrl +'\n\n';
var exTO = 'TO: ' + thisTOUrl +'\n\n';
var exPanda = 'PandA: ' + thisPandaUrl +'\n\n';
if ( accountStatus == "loggedIn" )
{
if (extype == "irc") {
exportOutput = masterQual + 'Requester: ' + thisReqName + ' ' + thisReqUrl + ' • ' + 'HIT: ' + thisTitle + ' ' + thisPreviewUrl + ' • ' + 'Pay: ' + thisReward + ' • ' + 'Avail: ' + thisHitsAvail + ' • ' + 'Limit: ' + thisTimeLimit + ' • ' + 'TO: ' + 'Pay='+thisTOStats[1] + ' Fair='+thisTOStats[2] + ' Comm='+thisTOStats[0] + ' ' + thisTOUrl + ' • ' + 'PandA: ' + thisPandaUrl + shortUrlUnav ;
exporttextarea1.value = exportOutput;
exporttextarea1.style.height = '130px';
exporttextarea1.setAttribute('id', 'ircexport_text');
exportdiv.textContent = 'IRC Export: Press Ctrl+C to (re-)copy to clipboard. Click textarea to close.';
exportdiv.appendChild(exporttextarea1);
exporttextarea1.addEventListener("click", function(){ exportdiv.style.display = 'none'; }, false);
exportdiv.style.display = 'block';
exporttextarea1.select();
if (GM_setClipboard) { GM_setClipboard(exportOutput); }
}
else if (extype == "reddit") {
exporttextarea1.value = exTitle;
exporttextarea2.value = exUrl;
exporttextarea3.value = exReq;
exporttextarea4.value = exPanda;
exporttextarea5.value = exTO;
exporttextarea1.style.height = '50px';
exporttextarea1.setAttribute('id','hwtf_title');
exportdiv.textContent = 'r/HitsWorthTurkingFor Export: Use the buttons for single-click copying.';
exportdiv.appendChild(exporttextarea1);
exportdiv.appendChild(exporttextarea2);
exportdiv.appendChild(exporttextarea3);
exportdiv.appendChild(exporttextarea4);
exportdiv.appendChild(exporttextarea5);
exportdiv.appendChild(exporttitlebutton);
exportdiv.appendChild(exporturlbutton);
exportdiv.appendChild(exportreqbutton);
exportdiv.appendChild(exportpandabutton);
exportdiv.appendChild(exporttobutton);
exportdiv.appendChild(exportclosebutton);
document.body.insertBefore(exportdiv, document.body.firstChild);
exportclosebutton.addEventListener("click", function(){ exportdiv.style.display = 'none'; }, false);
exporttitlebutton.addEventListener("click", function(){ exporttextarea1.select(); if (GM_setClipboard) { GM_setClipboard(exporttextarea1.value); } }, false);
exporturlbutton.addEventListener("click", function(){ exporttextarea2.select(); if (GM_setClipboard) { GM_setClipboard(exporttextarea2.value); } }, false);
exportreqbutton.addEventListener("click", function(){ exporttextarea3.select(); if (GM_setClipboard) { GM_setClipboard(exporttextarea3.value); } }, false);
exportpandabutton.addEventListener("click", function(){ exporttextarea4.select(); if (GM_setClipboard) { GM_setClipboard(exporttextarea4.value); } }, false);
exporttobutton.addEventListener("click", function(){ exporttextarea5.select(); if (GM_setClipboard) { GM_setClipboard(exporttextarea5.value); } }, false);
exportdiv.style.display = 'block';
//exporttextarea1.focus();
var tindex = exTitle.search(/COMTIME/);
exporttextarea1.setSelectionRange(tindex, tindex+7); // pre-select completion time
}
}
else if ( accountStatus == "loggedOut" )
{
if (extype == "irc") {
exportOutput = masterQual + 'Requester: ' + thisReqName + ' ' + thisReqUrl + ' • ' + 'HIT: ' + thisTitle + ' ' + thisPreviewUrl + ' • ' + 'Pay: ' + thisReward + ' • ' + 'Avail: ' + thisHitsAvail + ' • ' + 'Limit: ' + thisTimeLimit + ' • ' + 'TO: ?? ' + thisTOUrl + ' • ' + 'PandA: ' + thisPandaUrl + loggedOutApology + shortUrlUnav ;
exporttextarea1.value = exportOutput;
exporttextarea1.style.height = '130px';
exporttextarea1.setAttribute('id', 'ircexport_text');
exportdiv.textContent = 'IRC Export: Press Ctrl+C to (re-)copy to clipboard. Click textarea to close.';
exportdiv.appendChild(exporttextarea1);
exporttextarea1.addEventListener("click", function(){ exportdiv.style.display = 'none'; }, false);
exportdiv.style.display = 'block';
exporttextarea1.select();
if (GM_setClipboard) { GM_setClipboard(exportOutput); }
}
else if (extype == "reddit") {
exporttextarea1.value = exTitle;
exporttextarea2.value = exUrl;
exporttextarea3.value = exReq;
exporttextarea4.value = exPanda;
exporttextarea5.value = exTO;
exporttextarea1.style.height = '50px';
exporttextarea1.setAttribute('id','hwtf_title');
exportdiv.textContent = 'r/HitsWorthTurkingFor Export: Use the buttons for single-click copying.';
exportdiv.appendChild(exporttextarea1);
exportdiv.appendChild(exporttextarea2);
exportdiv.appendChild(exporttextarea3);
exportdiv.appendChild(exporttextarea4);
exportdiv.appendChild(exporttextarea5);
exportdiv.appendChild(exporttitlebutton);
exportdiv.appendChild(exporturlbutton);
exportdiv.appendChild(exportreqbutton);
exportdiv.appendChild(exportpandabutton);
exportdiv.appendChild(exporttobutton);
exportdiv.appendChild(exportclosebutton);
document.body.insertBefore(exportdiv, document.body.firstChild);
exportclosebutton.addEventListener("click", function(){ exportdiv.style.display = 'none'; }, false);
exporttitlebutton.addEventListener("click", function(){ exporttextarea1.select(); if (GM_setClipboard) { GM_setClipboard(exporttextarea1.value); } }, false);
exporturlbutton.addEventListener("click", function(){ exporttextarea2.select(); if (GM_setClipboard) { GM_setClipboard(exporttextarea2.value); } }, false);
exportreqbutton.addEventListener("click", function(){ exporttextarea3.select(); if (GM_setClipboard) { GM_setClipboard(exporttextarea3.value); } }, false);
exportpandabutton.addEventListener("click", function(){ exporttextarea4.select(); if (GM_setClipboard) { GM_setClipboard(exporttextarea4.value); } }, false);
exporttobutton.addEventListener("click", function(){ exporttextarea5.select(); if (GM_setClipboard) { GM_setClipboard(exporttextarea5.value); } }, false);
exportdiv.style.display = 'block';
//exporttextarea1.focus();
var tindex = exTitle.search(/COMTIME/);
exporttextarea1.setSelectionRange(tindex, tindex+7); // pre-select completion time
}
}
}
// TODO: cleanup, shift OO, readability, modularity