-
Notifications
You must be signed in to change notification settings - Fork 525
/
Weixin.js
130 lines (118 loc) · 3.61 KB
/
Weixin.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
{
"translatorID": "5a325508-cb60-42c3-8b0f-d4e3c6441058",
"label": "Weixin",
"creator": "Fushan Wen, jiaojiaodubai",
"target": "^https?://mp\\.weixin\\.qq\\.com",
"minVersion": "3.0",
"maxVersion": "",
"priority": 100,
"inRepository": true,
"translatorType": 4,
"browserSupport": "gcsibv",
"lastUpdated": "2024-02-24 11:31:40"
}
/*
***** BEGIN LICENSE BLOCK *****
Copyright © 2022 l0o0
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 *****
*/
function detectWeb(doc, _url) {
if (attr(doc, 'meta[property="og:type"]', 'content') === 'article') {
return "blogPost";
}
return false;
}
async function doWeb(doc, url) {
const newItem = new Z.Item('blogPost');
const metas = new Map();
const nodeList = doc.head.querySelectorAll(':scope meta[property^="og:"]');
for (const node of nodeList) {
metas.set(node.getAttribute('property'), node.content);
}
Z.debug(metas);
newItem.title = metas.get('og:title');
newItem.abstractNote = metas.get('og:description');
newItem.blogTitle = text(doc, '#profileBt > a');
// newItem.websiteType = metas.get('og:site_name');
newItem.websiteType = '微信公众号';
newItem.date = text(doc, '#publish_time');
newItem.url = metas.get('og:url');
[...new Set([text(doc, '#js_name'), metas.get('og:article:author')])].forEach((creator) => {
creator = ZU.cleanAuthor(creator, 'author');
if (/[\u4e00-\u9fff]/.test(creator.lastName)) {
creator.lastName = creator.firstName + creator.lastName;
creator.firstName = '';
creator.fieldMode = 1;
}
newItem.creators.push(creator);
});
/* 删除这行启用note记录全文
let note = doc.body.querySelector("#js_content");
if (note) {
note = `<h1>${newItem.title}</h1>`
+ note.innerHTML
.trim()
.replace(/\"/g, "'")
.replace(/<img .*?src='(.*?)'.*?>/g, "<img src='$1'\/>");
newItem.notes.push(note);
}
删除这行启用note记录全文 */
newItem.attachments.push({
url: url,
title: 'Snapshot',
document: doc
});
newItem.complete();
}
/** BEGIN TEST CASES **/
var testCases = [
{
"type": "web",
"url": "https://mp.weixin.qq.com/s/NYENhzx7kF7OX_d4DTD4fA",
"items": [
{
"itemType": "blogPost",
"title": "Zotero 官方安卓测试版来了",
"creators": [
{
"firstName": "",
"lastName": "学术废物收容所",
"creatorType": "author",
"fieldMode": 1
},
{
"firstName": "",
"lastName": "l0o0",
"creatorType": "author"
}
],
"date": "2023-12-26 11:57",
"abstractNote": "来自官方的圣诞礼物🎁——Zotero 安卓测试版来了",
"blogTitle": "学术废物收容所",
"url": "http://mp.weixin.qq.com/s?__biz=MzkyNjUxNjgxNg==&mid=2247483816&idx=1&sn=86afcacc6b0403049380d86e6618cae7&chksm=c2375297f540db817078c81cefd63069b0da43222c8f5b9dfb4ac15eae87f42f0b4555e89fe1#rd",
"websiteType": "微信公众号",
"attachments": [
{
"title": "Snapshot",
"mimeType": "text/html"
}
],
"tags": [],
"notes": [],
"seeAlso": []
}
]
}
]
/** END TEST CASES **/