summaryrefslogtreecommitdiff
path: root/GPO Access e-CFR.js
blob: 981bf05efa244f646cc971bb06b5987816b30163 (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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
{
	"translatorID": "dede653d-d1f8-411e-911c-44a0219bbdad",
	"label": "GPO Access e-CFR",
	"creator": "Bill McKinney, Sebastian Karcher",
	"target": "^https?://(www\\.)?ecfr\\.gov/cgi-bin/",
	"minVersion": "3.0",
	"maxVersion": "",
	"priority": 100,
	"inRepository": true,
	"translatorType": 4,
	"browserSupport": "gcsibv",
	"lastUpdated": "2014-04-03 17:38:54"
}

function detectWeb(doc, url) {
	var re = new RegExp("^https?://(www\.)?ecfr\.gov/cgi-bin/(text-idx|retrieveECFR\?)");
	if(re.test(doc.location.href)) {
		return "statute";
	} else {
		return "multiple";
	}
}

function get_nextsibling(n)
  {
  var x=n.nextSibling;
  while (x.nodeType!=1)
   {
   x=x.nextSibling;
   }
  return x;
}
function scrape(doc) {

	var newItem = new Zotero.Item("statute");
	newItem.url = doc.location.href;
	newItem.code = "Electronic Code of Federal Regulations";
	newItem.language = "en-US";

	var spanTags = doc.getElementsByTagName("span");
	var title;
	if (title = ZU.xpathText(doc, '//p[@class="title"]')){
		var type1 = true;
	}
	else{
		var type2 = true;
	 	title = ZU.xpathText(doc, '//td/div/p[@class="fp"]')
	}
	 	newItem.title = "e-CFR: " + title.trim();
	 	newItem.codeNumber = title.trim();
	 
	 if (type1){
	  	newItem.section = ZU.xpathText(doc, '//p[@class="part"]/a')
	 }
	 else if (type2){
	 	newItem.section = ZU.xpathText(doc, '//h2[contains(text(), "PART ")]')
	 	newItem.history = ZU.xpathText(doc, '//p[@class="source"]');
	 	newItem.extra = ZU.xpathText(doc, '//p[@class="auth"]')
		 
	 }
	 if (newItem.section) newItem.section = ZU.capitalizeTitle(newItem.section.toLowerCase(), true);
	newItem.complete();
}

function doWeb(doc, url) {
	var items = {};
	if(detectWeb(doc, url)=="statute") {
		scrape(doc);
	} else {
		var links = doc.evaluate('//td/a[./span[contains(@style, "font-weight:bold")]]', doc, null, XPathResult.ANY_TYPE, null);
		var link;
		while (link = links.iterateNext()) {
			//Z.debug(link.textContent + ": " + link.href)
			items[link.href] = link.textContent;
		}
		Zotero.selectItems(items, function (items) {
			if (!items) {
				return true;
			}
			for (var i in items) {
				articles.push(i);
			}
			Zotero.Utilities.processDocuments(articles, scrape);
		});
	}
}
/** BEGIN TEST CASES **/
var testCases = [
	{
		"type": "web",
		"url": "http://www.ecfr.gov/cgi-bin/retrieveECFR?gp=&SID=26a49dfbb6ed6cce629ec44a19c7fe94&r=PART&n=13y1.0.1.1.2",
		"items": [
			{
				"itemType": "statute",
				"creators": [],
				"notes": [],
				"tags": [],
				"seeAlso": [],
				"attachments": [],
				"url": "http://www.ecfr.gov/cgi-bin/retrieveECFR?gp=&SID=26a49dfbb6ed6cce629ec44a19c7fe94&r=PART&n=13y1.0.1.1.2",
				"code": "Electronic Code of Federal Regulations",
				"language": "en-US",
				"title": "e-CFR: Title 13: Business Credit and Assistance",
				"codeNumber": "Title 13: Business Credit and Assistance",
				"section": "Part 101—Administration",
				"history": "Source: 61 FR 2394, Jan. 26, 1996, unless otherwise noted.",
				"extra": "Authority: 5 U.S.C. 552 and App. 3, secs. 2, 4(a), 6(a), and 9(a)(1)(T); 15 U.S.C. 633, 634, 687; 31 U.S.C. 6506; 44 U.S.C. 3512; 42 U.S.C. 6307(d); 15 U.S.C. 657h; E.O. 12372 (July 14, 1982), 47 FR 30959, 3 CFR, 1982 Comp., p. 197, as amended by E.O. 12416 (April 8, 1983), 48 FR 15887, 3 CFR, 1983 Comp., p. 186.",
				"libraryCatalog": "GPO Access e-CFR",
				"accessDate": "CURRENT_TIMESTAMP",
				"shortTitle": "e-CFR"
			}
		]
	},
	{
		"type": "web",
		"url": "http://www.ecfr.gov/cgi-bin/text-idx?c=ecfr&SID=26a49dfbb6ed6cce629ec44a19c7fe94&tpl=/ecfrbrowse/Title02/2cfr376_main_02.tpl",
		"items": [
			{
				"itemType": "statute",
				"creators": [],
				"notes": [],
				"tags": [],
				"seeAlso": [],
				"attachments": [],
				"url": "http://www.ecfr.gov/cgi-bin/text-idx?c=ecfr&SID=26a49dfbb6ed6cce629ec44a19c7fe94&tpl=/ecfrbrowse/Title02/2cfr376_main_02.tpl",
				"code": "Electronic Code of Federal Regulations",
				"language": "en-US",
				"codeNumber": "TITLE 2—Grants and Agreements",
				"section": "Part 376—Nonprocurement Debarment and Suspension",
				"shortTitle": "e-CFR",
				"nameOfAct": "e-CFR: TITLE 2—Grants and Agreements"
			}
		]
	}
]
/** END TEST CASES **/