summaryrefslogtreecommitdiff
path: root/The Times UK.js
blob: e89c03485050574fc85f5c732ca2768a97868a9b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
{
	"translatorID": "53f8d182-4edc-4eab-b5a1-141698a10101",
	"label": "The Times and Sunday Times",
	"creator": "Andrew Brown",
	"target": "^https?://www\\.thetimes\\.co\\.uk/.+ece$",
	"minVersion": "1.0",
	"maxVersion": "",
	"priority": 100,
	"inRepository": true,
	"translatorType": 4,
	"browserSupport": "g",
	"lastUpdated": "2014-04-04 10:00:38"
}

/**/

// TimesOnline.co.uk translator.
// Version 1.5
// Original by William Smith, see http://www.willsmith.org/contactme/
// extensively tweaked by Andrew Brown to cope with the paywalled structure


function detectWeb(doc, url) {
	return "newspaperArticle" ;
}


function getMeta (doc, field) {
	field='//meta[@name="' + field + '"]/@content';
	content = getXPath(doc, field).iterateNext();

	if (content) {
		return content.value;
	}

}

function getXPath (doc, field) {
	xpath=field;
	return doc.evaluate(xpath, doc, null, XPathResult.ANY_TYPE, null);
}
/*
function getXPathInstance (doc,field) {
	xpath=field;
	return doc.evaluate(xpath, doc, null, XPathResult.ANY_TYPE, null).iterateNext();
}
*/
function doWeb(doc, url){

	var item = new Zotero.Item("newspaperArticle");
	
	//Could be daily or Sunday Times	
	//The ISSN seems to be the same for both:
	item.issn="0140-0460";

	if (url.search(/\/tto\//)!=-1){
		item.publicationTitle = 'The Times (London)';
		item.title = doc.title.replace("| The Times", "");
	}
	
	if(url.search(/\/sto\//)!=-1){
		item.publicationTitle = 'The Sunday Times (London)';
		item.title = doc.title.replace("| The Sunday Times", "");
	}
	
	//Now we have the paper, what section is it in?
	var section=url.match(/\/[ts]to\/([^\/]+)/);
	// Zotero.debug(section[1]);
	// Then print it pretty
	item.section=section[1].substr(0,1).toUpperCase() + section[1].substr(1);
	
	// These next fields are easy...
	item.url = url;
	item.date=getMeta(doc,"dashboard_published_date");
	item.place="London";
	item.abstractNote = getMeta(doc, "description"); 
	// alternative, better, way follows
	var standfirstXpath=doc.evaluate('//div[@class="cf "]//p[@class="f-standfirst"]',doc,null,XPathResult.ANY_TYPE,null); 
	// note space after cf  in class name, haha, Murdoch really got value from those Times designers
	if(standfirstXpath.iterateNext()!=null){
		item.abstractNote=standfirstXpath.iterateNext().textContent;
	}


	// extract authors who may be in an array
	var authorXpath=doc.evaluate('//div[@class="cf "]//strong[@class="f-author"]',doc, null, XPathResult.ANY_TYPE, null);
	var hack;
	while (hack=authorXpath.iterateNext()){
		var hacks= new Array();
		hacks=hack.textContent.split(/and|,/);
//		Zotero.debug("hacks: " +hack.textContent.split(/and/));
		if (hacks.length > 1){
			for (var h in hacks){
				item.creators.push(Zotero.Utilities.cleanAuthor(hacks[h],"author"));	
			}
		}
		else {
			item.creators.push(Zotero.Utilities.cleanAuthor(hack.textContent,"author"));	
		}
	}
		
	//ATTACH A SNAPSHOT
	item.attachments.push({url:url, title:item.title, mimeType:"text/html"});
	item.complete();
}