Skip to content

Commit 4abb603

Browse files
committed
[Publications du Quebec] minor cleanup and tweaks
Closes zotero#753. Thanks @marclajoie123
1 parent 19eb187 commit 4abb603

File tree

1 file changed

+70
-86
lines changed

1 file changed

+70
-86
lines changed

Publications du Quebec.js

+70-86
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@
99
"inRepository": true,
1010
"translatorType": 4,
1111
"browserSupport": "gcsib",
12-
"lastUpdated": "2014-06-24 10:16:52"
12+
"lastUpdated": "2014-07-01 19:40:02"
1313
}
14-
/*
1514

15+
/*
1616
Publications du Québec Translator
1717
Copyright (C) 2014 Marc Lajoie
1818
@@ -28,72 +28,68 @@ GNU General Public License for more details.
2828
2929
You should have received a copy of the GNU General Public License
3030
along with this program. If not, see <http://www.gnu.org/licenses/>.
31-
32-
+*/
33-
34-
var pubqcRegexp = /https?:\/\/(?:www2\.)?publicationsduquebec\.gouv\.qc\.ca\/dynamicSearch\/telecharge\.php\?/;
31+
*/
3532

3633
function getMultiple(doc, checkOnly) {
37-
var res = ZU.xpath(doc, '//span[@class="texteNormalBleuB"]/a[2]');
38-
if(!res.length) return false;
39-
if(checkOnly) return true;
34+
var res = ZU.xpath(doc, '//span[@class="texteNormalBleuB"]/a[2]');
35+
if (!res.length) return false;
36+
if (checkOnly) return true;
4037

41-
var items = {};
42-
for(var i=0; i<res.length; i++) {
43-
items[res[i].href] = ZU.trimInternal(res[i].textContent);
44-
}
38+
var items = {};
39+
for (var i = 0; i < res.length; i++) {
40+
items[res[i].href] = ZU.trimInternal(res[i].textContent);
41+
}
4542

46-
return items;
43+
return items;
4744
}
4845

4946
function detectWeb(doc, url) {
50-
if (pubqcRegexp.test(url)) {
47+
if (url.indexOf('/dynamicSearch/telecharge.php?') != -1) {
5148
return "statute";
5249
} else if (getMultiple(doc, true)) {
53-
return "multiple";
54-
}
55-
50+
return "multiple";
5651
}
5752

53+
}
5854

5955
function scrape(doc, url) {
60-
6156
var newItem = new Zotero.Item("statute");
57+
58+
var titleloi = doc.getElementsByClassName('Titreloi')[0]
59+
|| doc.getElementsByClassName('Titrereg')[0];
60+
titleloi = ZU.trimInternal(titleloi.textContent);
6261

63-
var titleloi = doc.getElementsByClassName('Titreloi')[0] || doc.getElementsByClassName('Titrereg')[0];
64-
titleloi = ZU.trimInternal(titleloi.textContent);
65-
var codeloi = doc.getElementsByClassName('Alpha')[0] || doc.getElementsByClassName('Libelle')[0];
62+
var codeloi = doc.getElementsByClassName('Alpha')[0]
63+
|| doc.getElementsByClassName('Libelle')[0];
6664
codeloi = ZU.trimInternal(codeloi.textContent);
67-
68-
newItem.title=titleloi;
69-
70-
if (codeloi.indexOf("chapitre")!=-1){
71-
newItem.language="fr-CA";
72-
codeloi=codeloi.replace("chapitre", "c");
73-
newItem.code="RLRQ " + codeloi;
65+
66+
newItem.title = titleloi;
67+
68+
if (codeloi.indexOf("chapitre") != -1) {
69+
newItem.language = "fr-CA";
70+
codeloi = codeloi.replace("chapitre", "c");
71+
newItem.code = "RLRQ " + codeloi;
7472
} else {
75-
newItem.language="en-CA";
76-
codeloi=codeloi.replace("chapter", "c");
77-
newItem.code="CQLR " + codeloi;
73+
newItem.language = "en-CA";
74+
codeloi = codeloi.replace("chapter", "c");
75+
newItem.code = "CQLR " + codeloi;
7876
}
79-
80-
newItem.rights="© Éditeur officiel du Québec";
81-
82-
newItem.jurisdiction="Québec, Canada";
83-
newItem.url=url;
77+
78+
newItem.rights = "© Éditeur officiel du Québec";
79+
80+
newItem.jurisdiction = "Québec, Canada";
81+
newItem.url = url;
8482

8583
newItem.attachments.push({
8684
document: doc,
8785
title: "Snapshot"
8886
});
89-
9087

91-
9288
newItem.complete();
9389
}
9490

9591
function doWeb(doc, url) {
96-
if (pubqcRegexp.test(url)) {
92+
if (url.indexOf('/dynamicSearch/telecharge.php?') != -1) {
9793
scrape(doc, url);
9894
} else {
9995
var items = getMultiple(doc);
@@ -113,7 +109,7 @@ function doWeb(doc, url) {
113109
var testCases = [
114110
{
115111
"type": "web",
116-
"url": "http://www2.publicationsduquebec.gouv.qc.ca/home.php",
112+
"url": "http://www2.publicationsduquebec.gouv.qc.ca/lois_et_reglements/liste_alpha.php",
117113
"items": "multiple"
118114
},
119115
{
@@ -122,23 +118,20 @@ var testCases = [
122118
"items": [
123119
{
124120
"itemType": "statute",
121+
"nameOfAct": "Loi sur le Barreau",
125122
"creators": [],
126-
"notes": [],
127-
"tags": [],
128-
"seeAlso": [],
123+
"code": "RLRQ c B-1",
124+
"language": "fr-CA",
125+
"rights": "© Éditeur officiel du Québec",
126+
"url": "http://www2.publicationsduquebec.gouv.qc.ca/dynamicSearch/telecharge.php?type=2&file=/B_1/B1.html",
129127
"attachments": [
130128
{
131129
"title": "Snapshot"
132130
}
133131
],
134-
"language": "fr-CA",
135-
"title": "Loi sur le Barreau",
136-
"code": "RLRQ c B-1",
137-
"rights": "© Éditeur officiel du Québec",
138-
"jurisdiction": "Québec, Canada",
139-
"url": "http://www2.publicationsduquebec.gouv.qc.ca/dynamicSearch/telecharge.php?type=2&file=/B_1/B1.html",
140-
"libraryCatalog": "PublicationsduQuébec",
141-
"accessDate": "CURRENT_TIMESTAMP"
132+
"tags": [],
133+
"notes": [],
134+
"seeAlso": []
142135
}
143136
]
144137
},
@@ -148,23 +141,20 @@ var testCases = [
148141
"items": [
149142
{
150143
"itemType": "statute",
144+
"nameOfAct": "An Act respecting the Barreau du Québec",
151145
"creators": [],
152-
"notes": [],
153-
"tags": [],
154-
"seeAlso": [],
146+
"code": "CQLR c B-1",
147+
"language": "en-CA",
148+
"rights": "© Éditeur officiel du Québec",
149+
"url": "http://www2.publicationsduquebec.gouv.qc.ca/dynamicSearch/telecharge.php?type=2&file=/B_1/B1_A.html",
155150
"attachments": [
156151
{
157152
"title": "Snapshot"
158153
}
159154
],
160-
"language": "en-CA",
161-
"title": "An Act respecting the Barreau du Québec",
162-
"code": "CQLR c B-1",
163-
"rights": "© Éditeur officiel du Québec",
164-
"jurisdiction": "Québec, Canada",
165-
"url": "http://www2.publicationsduquebec.gouv.qc.ca/dynamicSearch/telecharge.php?type=2&file=/B_1/B1_A.html",
166-
"libraryCatalog": "PublicationsduQuébec",
167-
"accessDate": "CURRENT_TIMESTAMP"
155+
"tags": [],
156+
"notes": [],
157+
"seeAlso": []
168158
}
169159
]
170160
},
@@ -174,23 +164,20 @@ var testCases = [
174164
"items": [
175165
{
176166
"itemType": "statute",
167+
"nameOfAct": "Code de déontologie des avocats",
177168
"creators": [],
178-
"notes": [],
179-
"tags": [],
180-
"seeAlso": [],
169+
"code": "RLRQ c B-1, r. 3",
170+
"language": "fr-CA",
171+
"rights": "© Éditeur officiel du Québec",
172+
"url": "http://www2.publicationsduquebec.gouv.qc.ca/dynamicSearch/telecharge.php?type=3&file=/B_1/B1R3.HTM",
181173
"attachments": [
182174
{
183175
"title": "Snapshot"
184176
}
185177
],
186-
"language": "fr-CA",
187-
"title": "Code de déontologie des avocats",
188-
"code": "RLRQ c B-1, r. 3",
189-
"rights": "© Éditeur officiel du Québec",
190-
"jurisdiction": "Québec, Canada",
191-
"url": "http://www2.publicationsduquebec.gouv.qc.ca/dynamicSearch/telecharge.php?type=3&file=/B_1/B1R3.HTM",
192-
"libraryCatalog": "PublicationsduQuébec",
193-
"accessDate": "CURRENT_TIMESTAMP"
178+
"tags": [],
179+
"notes": [],
180+
"seeAlso": []
194181
}
195182
]
196183
},
@@ -200,25 +187,22 @@ var testCases = [
200187
"items": [
201188
{
202189
"itemType": "statute",
190+
"nameOfAct": "Code of ethics of advocates",
203191
"creators": [],
204-
"notes": [],
205-
"tags": [],
206-
"seeAlso": [],
192+
"code": "CQLR c B-1, r. 3",
193+
"language": "en-CA",
194+
"rights": "© Éditeur officiel du Québec",
195+
"url": "http://www2.publicationsduquebec.gouv.qc.ca/dynamicSearch/telecharge.php?type=3&file=/B_1/B1R3_A.HTM",
207196
"attachments": [
208197
{
209198
"title": "Snapshot"
210199
}
211200
],
212-
"language": "en-CA",
213-
"title": "Code of ethics of advocates",
214-
"code": "CQLR c B-1, r. 3",
215-
"rights": "© Éditeur officiel du Québec",
216-
"jurisdiction": "Québec, Canada",
217-
"url": "http://www2.publicationsduquebec.gouv.qc.ca/dynamicSearch/telecharge.php?type=3&file=/B_1/B1R3_A.HTM",
218-
"libraryCatalog": "PublicationsduQuébec",
219-
"accessDate": "CURRENT_TIMESTAMP"
201+
"tags": [],
202+
"notes": [],
203+
"seeAlso": []
220204
}
221205
]
222206
}
223207
]
224-
/** END TEST CASES **/
208+
/** END TEST CASES **/

0 commit comments

Comments
 (0)