MTurk Clean Up Data

Pre-cleans data on Matt Aster's "Clean Up Data" HITs

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey, Greasemonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्क्रिप्ट व्यवस्थापक एक्स्टेंशन इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्क्रिप्ट व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्टाईल व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

// ==UserScript==
// @name        MTurk Clean Up Data
// @namespace   http://idlewords.net
// @description Pre-cleans data on Matt Aster's "Clean Up Data" HITs
// @include     https://s3.amazonaws.com/mturk_bulk/hits*
// @version     0.1
// @require     https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js
// @grant       none
// ==/UserScript==

String.prototype.toProperCase = function () {
    return this.replace(/\w\S*/g, function(txt){return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();});
};

function replace_words(text) {
	text = text.replace(/\s(And|Of|To|For|At|A)\s/, function(txt){return txt.toLowerCase()});
	text = text.replace(/\s([NSEW][ew]|Us\s)\s/, function(txt){return txt.toUpperCase()});
	text = text.replace(/P\.?\s?[Oo]\.?\sB/, 'PO B');
	return text;
}

if ($("p:contains('Given the information below, simply copy')").length) {
	$("p>strong").each(function(index, element) {
		var parent_p = $(this).parent();
		var text = $(this).text();
		text = text.split(": ");
		$(this).html(text[0] + "<br />\n<span style='font-weight: normal;'>&nbsp;" + text[1] + "</span>");
		header_text = text[0];
		if (text[1] !== '') {
			text = text[1].replace(" & ", " and ");
			if (header_text.search('Shelter') > -1) {
				text = text.replace(/ Inc\.?/i, '');
				text = text.replace(/ LLC\.?/i, '');
				text = text.replace(/ Ltd\.?/i, '');
				text = text.replace(/ Co\./i, '');
			}
			if (header_text.search('Address') > -1) {
				text = text.replace('.', '');
			}
			if (header_text.search('Phone') > -1 || header_text.search('Fax') > -1) {
				text = text.replace(/\(?(\d{3})[\s\)\-\/\.]?\s?(\d{3})[\s\-\.]?(\d{4})\s?x?[0-9]{0,6}?/i, '$1-$2-$3');
				text = text.replace(' ', '');
			}
			if (header_text.search('Zip') > -1) {
				if (text.length == 3) {
					text = '00' + text;
				} else if (text.length == 4) {
					text = '0' + text;
				}
			}
			text = text.toProperCase();
			text = replace_words(text);
			text = text.trim();
			//var stateList = new Array("AK","AL","AR","AZ","CA","CO","CT","DC","DE","FL","GA","GU","HI","IA","ID", "IL","IN","KS","KY","LA","MA","MD","ME","MH","MI","MN","MO","MS","MT","NC","ND","NE","NH","NJ","NM","NV","NY", "OH","OK","OR","PA","PR","PW","RI","SC","SD","TN","TX","UT","VA","VI","VT","WA","WI","WV","WY");
			while (text.search('  ') > -1) {
				text = text.replace('  ', ' ');
			}
			parent_p.next().children().eq(0).val(text);
		}
	});
	$("#ShelterName").focus();
	$(document).keydown(function(event) {
		if (event.which == 83 && event.ctrlKey) {
			event.preventDefault();
			$("#submitButton").click();
		}
	});
}