forked from l0o0/translators_CN
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Spc.org.cn.js
207 lines (188 loc) · 6.61 KB
/
Spc.org.cn.js
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
{
"translatorID": "3cf79f02-f4af-4392-8b84-26c2bdae2607",
"label": "中国标准在线服务网",
"creator": "018<lyb018@gmail.com>",
"target": "https?://www\\.spc\\.org\\.cn/online",
"minVersion": "3.0",
"maxVersion": "",
"priority": 100,
"inRepository": true,
"translatorType": 4,
"browserSupport": "gcsibv",
"lastUpdated": "2022-10-03 15:51:14"
}
/*
***** BEGIN LICENSE BLOCK *****
Copyright © 2020 018<lyb018@gmail.com>
This file is part of Zotero.
Zotero is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Zotero is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with Zotero. If not, see <http://www.gnu.org/licenses/>.
***** END LICENSE BLOCK *****
*/
// eslint-disable-next-line
function attr(docOrElem,selector,attr,index){var elem=index?docOrElem.querySelectorAll(selector).item(index):docOrElem.querySelector(selector);return elem?elem.getAttribute(attr):null;}function text(docOrElem,selector,index){var elem=index?docOrElem.querySelectorAll(selector).item(index):docOrElem.querySelector(selector);return elem?elem.textContent:null;}function trim(content){return content.replace(/^[\xA0\s]+/gm, '').replace(/[\xA0\s]+$/gm, '').replace(/\n+/g, '\n').replace(/:\n+/g, ': ').replace(/]\n/g, ']').replace(/】\n/g, '】').replace(/\n\/\n/g, '/')}
function detectWeb(doc, url) {
return 'report';
}
function doWeb(doc, url) {
scrapeSpc(doc, url);
}
function scrapeSpc(doc, url) {
if (!url || url.length <= 0) {
return;
}
var itemType = detectWeb(doc, url);
var item = new Zotero.Item(itemType);
item.url = url;
var extraContent = "Type: standard";
var ps = doc.querySelectorAll('ul.detailedinfo-content-collapse > li p');
for (var p of ps) {
var tdTitle = p.textContent.replace(':', '').trim();
if (!p.nextElementSibling) {
continue;
}
var tdContent = p.nextElementSibling.textContent.trim();
if (tdContent.length === 0) {
continue;
}
switch (tdTitle) {
case '标准号':
if (tdContent.startsWith('GB')) {
// 国标编号使用一字线
tdContent = tdContent.replace('-', '—');
}
item.reportNumber = tdContent
break;
case '标准名称':
item.title = tdContent;
break;
case '英文名称':
if (tdContent !== item.title) {
extraContent += '\n英文名称: ' + tdContent
}
break;
case '出版语种':
if (tdContent === '中文简体') {
item.language = 'zh-CN';
} else if (tdContent === 'EN') {
item.language = 'en';
}
break;
case '标准状态':
extraContent += '\nStatus: ' + tdContent;
break;
case '发布日期':
if (tdContent.length > 0) {
item.date = tdContent;
}
break;
case '实施日期':
if (tdContent.length > 0 && (!item.date || item.date.length === 0)) {
item.date = tdContent;
}
break;
case '标准ICS号':
extraContent += '\n标准ICS号: ' + tdContent;
break;
case '中标分类号':
extraContent += '\n中标分类号: ' + tdContent;
break;
case '页数':
extraContent += '\n# of Pages: ' + tdContent.replace(' 页', '');
break;
case '起草人':
extraContent += '\n起草人: ' + tdContent;
break;
case '起草单位':
extraContent += '\n起草单位: ' + tdContent.replace('(SAC/TC 4)', '');
break;
case '归口单位':
for (var c of tdContent.split('、')) {
c = c.replace('(SAC/TC 4)', '');
if (c.startsWith('ISO/')) {
c = 'ISO';
}
item.creators.push({
lastName: c,
creatorType: 'author',
fieldMode: 1
});
}
break;
default:
break;
}
}
item.abstractNote = doc.querySelector('.stand-detail-description').textContent.replace(/标准简介|文前页下载| |\n|\t|/g, '')
.replace('读者对象:', '\n读者对象:')
.replace('适用范围:暂无', '');
item.extra = extraContent;
item.complete();
}
/** BEGIN TEST CASES **/
var testCases = [
{
"type": "web",
"url": "https://www.spc.org.cn/online/75a5d85b40a9a7c6a780bdb4e3c554e7.html",
"items": [
{
"itemType": "report",
"title": "信息与文献 参考文献著录规则",
"creators": [
{
"lastName": "全国信息与文献标准化技术委员会",
"creatorType": "author",
"fieldMode": 1
}
],
"date": "2015-05-15",
"abstractNote": "适用范围:本标准规定了各个学科、各种类型信息资源的参考文献的著录项目、著录顺序、著录用符号、著录用文字、各个著录项目的著录方法以及参考文献在正文中的标注法。本标准适用于著者和编辑著录参考文献,而不是供图书馆员、文献目录编制者以及索引编辑者使用的文献著录规则。",
"extra": "Type: standard\n英文名称: Information and documentation—Rules for bibliographic references and citations to information resources\nStatus: 现行\n标准ICS号: 01.140.20\n中标分类号: A14\n# of Pages: 28\n起草人: 段明莲、白光武、陈浩元、刘曙光、曾燕\n起草单位: 北京大学信息管理系、中国科学技术信息研究所、北京师范大学学报(自然科学版)编辑部、北京大学学报(哲学社会科学版)编辑部、中国科学院文献情报中心",
"language": "zh-CN",
"libraryCatalog": "中国标准在线服务网",
"reportNumber": "GB/T 7714—2015",
"url": "https://www.spc.org.cn/online/75a5d85b40a9a7c6a780bdb4e3c554e7.html",
"attachments": [],
"tags": [],
"notes": [],
"seeAlso": []
}
]
},
{
"type": "web",
"url": "https://www.spc.org.cn/online/dbbd00948cf962988f33ddc307327a60.html",
"items": [
{
"itemType": "report",
"title": "Information and documentation — Guidelines for bibliographic references and citations to information resources",
"creators": [
{
"lastName": "ISO",
"creatorType": "author",
"fieldMode": 1
}
],
"date": "2021-06-11",
"extra": "Type: standard\nStatus: 现行\n标准ICS号: 01.140.20",
"language": "en",
"libraryCatalog": "中国标准在线服务网",
"reportNumber": "ISO 690:2021 EN",
"url": "https://www.spc.org.cn/online/dbbd00948cf962988f33ddc307327a60.html",
"attachments": [],
"tags": [],
"notes": [],
"seeAlso": []
}
]
}
]
/** END TEST CASES **/