<commit_before>{
	"translatorID":"d0b1914a-11f1-4dd7-8557-b32fe8a3dd47",
	"translatorType":4,
	"label":"EBSCOhost",
	"creator":"<NAME> and <NAME>",
	"target":"https?://[^/]+/(?:bsi|ehost)/(?:results|detail|folder)",
	"minVersion":"1.0.0b3.r1",
	"maxVersion":"",
	"priority":100,
	"inRepository":true,
	"lastUpdated":"2010-09-12 20:35:00"
}

function detectWeb(doc, url) {
	var namespace = doc.documentElement.namespaceURI;
	var nsResolver = namespace ? function(prefix) {
		if (prefix == 'x') return namespace; else return null;
	} : null;
	
	
	
		// The Scientific American Archive breaks this translator, disabling 
		try {
			var databases = doc.evaluate("//span[@class = 'selected-databases']", doc, nsResolver, XPathResult.ANY_TYPE, null).iterateNext().textContent;
			if(databases.indexOf("Scientific American Archive Online") != -1) {
				return false;
			}
		} catch(e) {
		}
	
	
	// See if this is a search results or folder results page
	var searchResult = doc.evaluate('//ul[@class="result-list" or @class="folder-list"]/li/div[@class="result-list-record" or @class="folder-item"]', doc, nsResolver,
	                                XPathResult.ANY_TYPE, null).iterateNext();         
	if(searchResult) {
		return "multiple";
	}
/*
	var xpath = '//div[@class="citation-wrapping-div"]/dl[@class="citation-fields"]/dt[starts-with(text(), "Persistent link to this record")'
		+' or starts-with(text(), "Vínculo persistente a este informe")'
		+' or starts-with(text(), "Lien permanent à cette donnée")'
		+' or starts-with(text(), "Permanenter Link zu diesem Datensatz")'
		+' or starts-with(text(), "Link permanente al record")'
		+' or starts-with(text(), "Link permanente para este registro")'
		+' or starts-with(text(), "本記錄固定連結")'
		+' or starts-with(text(), "此记录的永久链接")'
		+' or starts-with(text(), "このレコードへのパーシスタント リンク")'
		+' or starts-with(text(), "레코드 링크 URL")'
		+' or starts-with(text(), "Постоянная ссылка на эту запись")'
		+' or starts-with(text(), "Bu kayda sürekli bağlantı")'
		+' or starts-with(text(), "Μόνιμος σύνδεσμος σε αυτό το αρχείο")]';
*/


	

	var xpath = '//input[@id="ctl00_ctl00_Column2_Column2_topDeliveryControl_deliveryButtonControl_lnkExport"]';
	var persistentLink = doc.evaluate(xpath, doc, nsResolver, XPathResult.ANY_TYPE, null);
	if(persistentLink) {
		return "journalArticle";
	}
}

var customViewStateMatch = /<input type="hidden" name="__CUSTOMVIEWSTATE" id="__CUSTOMVIEWSTATE" value="([^"]+)" \/>/
var host;

function fullEscape(text) {
	return escape(text).replace(/\//g, "%2F").replace(/\+/g, "%2B");
}

function generateDeliverString(nsResolver, doc){	
	var hiddenInputs = doc.evaluate('//input[@type="hidden" and not(contains(@name, "folderHas")) and not(@name ="ajax")]', doc, nsResolver, XPathResult.ANY_TYPE, null);
	var hiddenInput;
	var deliverString ="";
	while(hiddenInput = hiddenInputs.iterateNext()) {
		if (hiddenInput.name !== "__EVENTTARGET" && hiddenInput.name !== "") {
			deliverString = deliverString+hiddenInput.name.replace(/\$/g, "%24")+"="+encodeURIComponent(hiddenInput.value) + "&";
		}
	}
	var otherHiddenInputs = doc.evaluate('//input[@type="hidden" and contains(@name, "folderHas")]', doc, nsResolver, XPathResult.ANY_TYPE, null);
	while(hiddenInput = otherHiddenInputs.iterateNext()) {
		deliverString = deliverString+hiddenInput.name.replace(/\$/g, "%24")+"="+escape(hiddenInput.value).replace(/\//g, "%2F").replace(/%20/g, "+") + "&";
	}
	
	deliverString = "__EVENTTARGET=ctl00%24ctl00%24Column2%24Column2%24topDeliveryControl%24deliveryButtonControl%24lnkExport&" + deliverString;
	
	return deliverString;
}


/*
 * given the text of the delivery page, downloads an item
 */
function downloadFunction(text) {
	
	//Zotero.debug("POSTTEXT="+text);
	var postLocation = /<form (?:autocomplete="o(?:ff|n)" )?name="aspnetForm" method="post" action="([^"]+)"/
	var postMatch = postLocation.exec(text);
	var deliveryURL = postMatch[1].replace(/&amp;/g, "&");
	postMatch = customViewStateMatch.exec(text);
	var downloadString = "__EVENTTARGET=&__EVENTARGUMENT=&__CUSTOMVIEWSTATE="+fullEscape(postMatch[1])+"&__VIEWSTATE=&ctl00%24ctl00%24MainContentArea%24MainContentArea%24ctl00%24btnSubmit=Save&ctl00%24ctl00%24MainContentArea%24MainContentArea%24ctl00%24BibFormat=1&ajax=enabled";
	
	Zotero.Utilities.HTTP.doPost(host+"/ehost/"+deliveryURL,
								 downloadString, function(text) {	// get marked records as RIS
		Zotero.debug(text);
		// load translator for RIS
		var test = text.match(/UR\s+\-(.*)/g);
		if (text.match(/AB\s\s\-/)) text = text.replace(/AB\s\s\-/, "N2  -");
		if (!text.match(/TY\s\s-/)) text = text+"\nTY  - JOUR\n"; 
		// load translator for RIS
		var translator = Zotero.loadTranslator("import");
		translator.setTranslator("32d59d2d-b65a-4da4-b0a3-bdd3cfb979e7");
		translator.setString(text);
		translator.setHandler("itemDone", function(obj, item) {
			if (text.match("L3")) {
				item.DOI = text.match(/L3\s+\-\s*(.*)/)[1];
			}
			if (text.match("T1")) {
				item.title = text.match(/T1\s+-\s*(.*)/)[1];
			}
			item.itemType = "journalArticle";
			item.url = false;
			// RIS translator tries to download the link in "UR" this leads to unhappyness<commit_msg>Trans: Support DOI in DO field when reading EBSCO RIS<commit_after>{
	"translatorID":"d0b1914a-11f1-4dd7-8557-b32fe8a3dd47",
	"translatorType":4,
	"label":"EBSCOhost",
	"creator":"<NAME> and <NAME>",
	"target":"https?://[^/]+/(?:bsi|ehost)/(?:results|detail|folder)",
	"minVersion":"1.0.0b3.r1",
	"maxVersion":"",
	"priority":100,
	"inRepository":true,
	"lastUpdated":"2010-09-12 20:35:00"
}

function detectWeb(doc, url) {
	var namespace = doc.documentElement.namespaceURI;
	var nsResolver = namespace ? function(prefix) {
		if (prefix == 'x') return namespace; else return null;
	} : null;
	
	
	
		// The Scientific American Archive breaks this translator, disabling 
		try {
			var databases = doc.evaluate("//span[@class = 'selected-databases']", doc, nsResolver, XPathResult.ANY_TYPE, null).iterateNext().textContent;
			if(databases.indexOf("Scientific American Archive Online") != -1) {
				return false;
			}
		} catch(e) {
		}
	
	
	// See if this is a search results or folder results page
	var searchResult = doc.evaluate('//ul[@class="result-list" or @class="folder-list"]/li/div[@class="result-list-record" or @class="folder-item"]', doc, nsResolver,
	                                XPathResult.ANY_TYPE, null).iterateNext();         
	if(searchResult) {
		return "multiple";
	}
/*
	var xpath = '//div[@class="citation-wrapping-div"]/dl[@class="citation-fields"]/dt[starts-with(text(), "Persistent link to this record")'
		+' or starts-with(text(), "Vínculo persistente a este informe")'
		+' or starts-with(text(), "Lien permanent à cette donnée")'
		+' or starts-with(text(), "Permanenter Link zu diesem Datensatz")'
		+' or starts-with(text(), "Link permanente al record")'
		+' or starts-with(text(), "Link permanente para este registro")'
		+' or starts-with(text(), "本記錄固定連結")'
		+' or starts-with(text(), "此记录的永久链接")'
		+' or starts-with(text(), "このレコードへのパーシスタント リンク")'
		+' or starts-with(text(), "레코드 링크 URL")'
		+' or starts-with(text(), "Постоянная ссылка на эту запись")'
		+' or starts-with(text(), "Bu kayda sürekli bağlantı")'
		+' or starts-with(text(), "Μόνιμος σύνδεσμος σε αυτό το αρχείο")]';
*/


	

	var xpath = '//input[@id="ctl00_ctl00_Column2_Column2_topDeliveryControl_deliveryButtonControl_lnkExport"]';
	var persistentLink = doc.evaluate(xpath, doc, nsResolver, XPathResult.ANY_TYPE, null);
	if(persistentLink) {
		return "journalArticle";
	}
}

var customViewStateMatch = /<input type="hidden" name="__CUSTOMVIEWSTATE" id="__CUSTOMVIEWSTATE" value="([^"]+)" \/>/
var host;

function fullEscape(text) {
	return escape(text).replace(/\//g, "%2F").replace(/\+/g, "%2B");
}

function generateDeliverString(nsResolver, doc){	
	var hiddenInputs = doc.evaluate('//input[@type="hidden" and not(contains(@name, "folderHas")) and not(@name ="ajax")]', doc, nsResolver, XPathResult.ANY_TYPE, null);
	var hiddenInput;
	var deliverString ="";
	while(hiddenInput = hiddenInputs.iterateNext()) {
		if (hiddenInput.name !== "__EVENTTARGET" && hiddenInput.name !== "") {
			deliverString = deliverString+hiddenInput.name.replace(/\$/g, "%24")+"="+encodeURIComponent(hiddenInput.value) + "&";
		}
	}
	var otherHiddenInputs = doc.evaluate('//input[@type="hidden" and contains(@name, "folderHas")]', doc, nsResolver, XPathResult.ANY_TYPE, null);
	while(hiddenInput = otherHiddenInputs.iterateNext()) {
		deliverString = deliverString+hiddenInput.name.replace(/\$/g, "%24")+"="+escape(hiddenInput.value).replace(/\//g, "%2F").replace(/%20/g, "+") + "&";
	}
	
	deliverString = "__EVENTTARGET=ctl00%24ctl00%24Column2%24Column2%24topDeliveryControl%24deliveryButtonControl%24lnkExport&" + deliverString;
	
	return deliverString;
}


/*
 * given the text of the delivery page, downloads an item
 */
function downloadFunction(text) {
	
	//Zotero.debug("POSTTEXT="+text);
	var postLocation = /<form (?:autocomplete="o(?:ff|n)" )?name="aspnetForm" method="post" action="([^"]+)"/
	var postMatch = postLocation.exec(text);
	var deliveryURL = postMatch[1].replace(/&amp;/g, "&");
	postMatch = customViewStateMatch.exec(text);
	var downloadString = "__EVENTTARGET=&__EVENTARGUMENT=&__CUSTOMVIEWSTATE="+fullEscape(postMatch[1])+"&__VIEWSTATE=&ctl00%24ctl00%24MainContentArea%24MainContentArea%24ctl00%24btnSubmit=Save&ctl00%24ctl00%24MainContentArea%24MainContentArea%24ctl00%24BibFormat=1&ajax=enabled";
	
	Zotero.Utilities.HTTP.doPost(host+"/ehost/"+deliveryURL,
								 downloadString, function(text) {	// get marked records as RIS
		Zotero.debug(text);
		// load translator for RIS
		var test = text.match(/UR\s+\-(.*)/g);
		if (text.match(/AB\s\s\-/)) text = text.replace(/AB\s\s\-/, "N2  -");
		if (!text.match(/TY\s\s-/)) text = text+"\nTY  - JOUR\n"; 
		// load translator for RIS
		var translator = Zotero.loadTranslator("import");
		translator.setTranslator("32d59d2d-b65a-4da4-b0a3-bdd3cfb979e7");
		translator.setString(text);
		translator.setHandler("itemDone", function(obj, item) {
			if (text.match("L3")) {
				item.DOI = text.match(/L3\s+\-\s*(.*)/)[1];
			}
			if (text.match("DO")) {
				item.DOI = text.match(/DO\s+\-\s*(.*)/)[1];
			}
			if (text.match("T1")) {
				item.title = text.match(/T1\s+-\s*(.*)/)[1];
			}
			item.itemType = "journalArticle";
			item.url = false;
			// RIS translator tries to download the link in "UR" this leads to unhappyness
{'fraction_non_alphanumeric': 0.18710541419552323, 'fraction_numerical': 0.025923091639563803, 'mean_word_length': 4.89678510998308, 'pattern_counts': {'":': 20, '<': 11, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2817438', 'n_tokens_mistral': 4122, 'n_tokens_neox': 3804, 'n_words': 678}